The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bio::Phylo::Treedrawer - An object-oriented facade for drawing trees.

SYNOPSIS

use Bio::Phylo::IO 'parse';
use Bio::Phylo::Treedrawer;

my $string = '((A:1,B:2)n1:3,C:4)n2:0;';
my $tree = parse( -format => 'newick', -string => $string )->first;

my $treedrawer = Bio::Phylo::Treedrawer->new(
   -width  => 800,
   -height => 600,
   -shape  => 'CURVY', # curvogram
   -mode   => 'PHYLO', # cladogram
   -format => 'SVG'
);

$treedrawer->set_scale_options(
   -width => '100%',
   -major => '10%', # major cross hatch interval
   -minor => '2%',  # minor cross hatch interval
   -label => 'MYA',
);

$treedrawer->set_tree($tree);
print $treedrawer->draw;

DESCRIPTION

This module prepares a tree object for drawing (calculating coordinates for nodes) and calls the appropriate format-specific drawer.

METHODS

CONSTRUCTOR

new()
Type    : Constructor
Title   : new
Usage   : my $treedrawer = Bio::Phylo::Treedrawer->new(
              %args 
          );
Function: Initializes a Bio::Phylo::Treedrawer object.
Alias   :
Returns : A Bio::Phylo::Treedrawer object.
Args    : none.

MUTATORS

set_format()
Type    : Mutator
Title   : set_format
Usage   : $treedrawer->set_format('Svg');
Function: Sets the drawer submodule.
Returns :
Args    : Name of an image format (currently 
          only Svg supported)
set_width()
Type    : Mutator
Title   : set_width
Usage   : $treedrawer->set_width(1000);
Function: sets the width of the drawer canvas.
Returns :
Args    : Integer width in pixels.
set_height()
Type    : Mutator
Title   : set_height
Usage   : $treedrawer->set_height(1000);
Function: sets the height of the canvas.
Returns :
Args    : Integer height in pixels.
set_mode()
Type    : Mutator
Title   : set_mode
Usage   : $treedrawer->set_mode('clado');
Function: Sets the tree mode, i.e. cladogram 
          or phylogram.
Returns : Invocant.
Args    : String, [clado|phylo]
set_shape()
Type    : Mutator
Title   : set_shape
Usage   : $treedrawer->set_shape('rect');
Function: Sets the tree shape, i.e. 
          rectangular, diagonal or curvy.
Returns : Invocant.
Args    : String, [rect|diag|curvy]
set_padding()
Type    : Mutator
Title   : set_padding
Usage   : $treedrawer->set_padding(100);
Function: Sets the canvas padding.
Returns :
Args    : Integer value in pixels.
set_node_radius()
Type    : Mutator
Title   : set_node_radius
Usage   : $treedrawer->set_node_radius(20);
Function: Sets the node radius in pixels.
Returns :
Args    : Integer value in pixels.
set_text_horiz_offset()
Type    : Mutator
Title   : set_text_horiz_offset
Usage   : $treedrawer->set_text_horiz_offset(5);
Function: Sets the distance between 
          tips and text, in pixels.
Returns :
Args    : Integer value in pixels.
set_text_vert_offset()
Type    : Mutator
Title   : set_text_vert_offset
Usage   : $treedrawer->set_text_vert_offset(3);
Function: Sets the text baseline 
          relative to the tips, in pixels.
Returns :
Args    : Integer value in pixels.
set_text_width()
Type    : Mutator
Title   : set_text_width
Usage   : $treedrawer->set_text_width(150);
Function: Sets the canvas width for 
          terminal taxon names.
Returns :
Args    : Integer value in pixels.
set_tree()
Type    : Mutator
Title   : set_tree
Usage   : $treedrawer->set_tree($tree);
Function: Sets the Bio::Phylo::Forest::Tree 
          object to unparse.
Returns :
Args    : A Bio::Phylo::Forest::Tree object.
set_scale_options()
Type    : Mutator
Title   : set_scale_options
Usage   : $treedrawer->set_scale_options(
               -width => 400,
               -major => '10%', # major cross hatch interval
               -minor => '2%',  # minor cross hatch interval
               -label => 'MYA',
           );
Function: Sets the options for time (distance) scale
Returns :
Args    : -width => (if a number, like 100, pixel 
                     width is assumed, if a percentage, 
                     scale width relative to longest root
                     to tip path)
          -major => ( ditto, value for major tick marks )
          -minor => ( ditto, value for minor tick marks )
          -label => ( text string displayed next to scale )

ACCESSORS

get_format()
Type    : Mutator
Title   : get_format
Usage   : my $format = $treedrawer->get_format;
Function: Gets the image format.
Returns :
Args    : None.
get_width()
Type    : Mutator
Title   : get_width
Usage   : my $width = $treedrawer->get_width;
Function: Gets the width of the drawer canvas.
Returns :
Args    : None.
get_height()
Type    : Accessor
Title   : get_height
Usage   : my $height = $treedrawer->get_height;
Function: Gets the height of the canvas.
Returns :
Args    : None.
get_mode()
Type    : Accessor
Title   : get_mode
Usage   : my $mode = $treedrawer->get_mode('clado');
Function: Gets the tree mode, i.e. cladogram or phylogram.
Returns :
Args    : None.
get_shape()
Type    : Accessor
Title   : get_shape
Usage   : my $shape = $treedrawer->get_shape;
Function: Gets the tree shape, i.e. rectangular, 
          diagonal or curvy.
Returns :
Args    : None.
get_padding()
Type    : Accessor
Title   : get_padding
Usage   : my $padding = $treedrawer->get_padding;
Function: Gets the canvas padding.
Returns :
Args    : None.
get_node_radius()
Type    : Accessor
Title   : get_node_radius
Usage   : my $node_radius = $treedrawer->get_node_radius;
Function: Gets the node radius in pixels.
Returns : SCALAR
Args    : None.
get_text_horiz_offset()
Type    : Accessor
Title   : get_text_horiz_offset
Usage   : my $text_horiz_offset = 
          $treedrawer->get_text_horiz_offset;
Function: Gets the distance between 
          tips and text, in pixels.
Returns : SCALAR
Args    : None.
get_text_vert_offset()
Type    : Accessor
Title   : get_text_vert_offset
Usage   : my $text_vert_offset = 
          $treedrawer->get_text_vert_offset;
Function: Gets the text baseline relative 
          to the tips, in pixels.
Returns :
Args    : None.
get_text_width()
Type    : Accessor
Title   : get_text_width
Usage   : my $textwidth = 
          $treedrawer->get_text_width;
Function: Returns the canvas width 
          for terminal taxon names.
Returns :
Args    : None.
get_tree()
Type    : Accessor
Title   : get_tree
Usage   : my $tree = $treedrawer->get_tree;
Function: Returns the Bio::Phylo::Forest::Tree 
          object to unparse.
Returns : A Bio::Phylo::Forest::Tree object.
Args    : None.
get_scale_options()
Type    : Accessor
Title   : get_scale_options
Usage   : my %options = %{ 
              $treedrawer->get_scale_options  
          };
Function: Returns the time/distance 
          scale options.
Returns : A hash ref.
Args    : None.

TREE DRAWING

draw()
Type    : Unparsers
Title   : draw
Usage   : my $drawing = $treedrawer->draw;
Function: Unparses a Bio::Phylo::Forest::Tree 
          object into a drawing.
Returns : SCALAR
Args    :

SEE ALSO

Bio::Phylo

The Bio::Phylo::Treedrawer object inherits from the Bio::Phylo object. Look there for more methods applicable to the treedrawer object.

Bio::Phylo::Manual

Also see the manual: Bio::Phylo::Manual.

FORUM

CPAN hosts a discussion forum for Bio::Phylo. If you have trouble using this module the discussion forum is a good place to start posting questions (NOT bug reports, see below): http://www.cpanforum.com/dist/Bio-Phylo

BUGS

Please report any bugs or feature requests to bug-bio-phylo@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-Phylo. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. Be sure to include the following in your request or comment, so that I know what version you're using:

$Id: Treedrawer.pm 4153 2007-07-11 01:33:20Z rvosa $

AUTHOR

Rutger Vos,

email: rvosa@sfu.ca
web page: http://www.sfu.ca/~rvosa/

ACKNOWLEDGEMENTS

The author would like to thank Jason Stajich for many ideas borrowed from BioPerl http://www.bioperl.org, and CIPRES http://www.phylo.org and FAB* http://www.sfu.ca/~fabstar for comments and requests.

COPYRIGHT & LICENSE

Copyright 2005 Rutger Vos, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.