3 # BioPerl module for Bio::Tree::TreeI
5 # Cared for by Jason Stajich <jason@bioperl.org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Tree::TreeI - A Tree object suitable for lots of things, designed
16 originally for Phylogenetic Trees.
20 # get a Bio::Tree::TreeI somehow
22 my $treeio = new Bio::TreeIO(-format => 'newick', -file => 'treefile.dnd');
23 my $tree = $treeio->next_tree;
24 my @nodes = $tree->get_nodes;
25 my @leaves = $tree->get_leaf_nodes;
26 my $root = $tree->get_root_node;
30 This object holds a pointer to the Root of a Tree which is a
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to
39 the Bioperl mailing list. Your participation is much appreciated.
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/MailList.shtml - About the mailing lists
46 Report bugs to the Bioperl bug tracking system to help us keep track
47 of the bugs and their resolution. Bug reports can be submitted via
50 http://bugzilla.bioperl.org/
52 =head1 AUTHOR - Jason Stajich
54 Email jason@bioperl.org
58 Aaron Mackey amackey@virginia.edu
59 Elia Stupka, elia@fugu-sg.org
63 The rest of the documentation details each of the object methods.
64 Internal methods are usually preceded with a _
69 # Let the code begin...
72 package Bio
::Tree
::TreeI
;
77 @ISA = qw(Bio::Tree::NodeI);
82 Usage : my @nodes = $tree->get_nodes()
83 Function: Return list of Tree::NodeI objects
84 Returns : array of Tree::NodeI objects
85 Args : (named values) hash with one value
86 order => 'b|breadth' first order or 'd|depth' first order
92 $self->throw_not_implemented();
98 Usage : my $node = $tree->get_root_node();
99 Function: Get the Top Node in the tree, in this implementation
100 Trees only have one top node.
101 Returns : Bio::Tree::NodeI object
108 $self->throw_not_implemented();
114 Usage : my $size = $tree->number_nodes
115 Function: Returns the number of nodes
125 my $root = $self->get_root_node;
126 if( defined $root && $root->isa('Bio::Tree::NodeI')) {
127 return $root->descendent_count;
132 =head2 total_branch_length
134 Title : total_branch_length
135 Usage : my $size = $tree->total_branch_length
136 Function: Returns the sum of the length of all branches
142 sub total_branch_length
{
144 $self->throw_not_implemented();
150 Usage : my $height = $tree->height
151 Function: Gets the height of tree - this LOG_2($number_nodes)
152 WARNING: this is only true for strict binary trees. The TreeIO
153 system is capable of building non-binary trees, for which this
154 method will currently return an incorrect value!!
162 my $nodect = $self->number_nodes;
163 return 0 if( ! $nodect );
164 return log($nodect) / log(2);
170 Usage : my $id = $tree->id();
171 Function: An id value for the tree
179 my ($self,@args) = @_;
180 $self->throw_not_implemented();
186 Usage : $obj->score($newval)
187 Function: Sets the associated score with this tree
188 This is a generic slot which is probably best used
189 for log likelihood or other overall tree score
190 Returns : value of score
191 Args : newvalue (optional)
197 my ($self,$value) = @_;
198 $self->throw_not_implemented();
201 =head2 get_leaf_nodes
203 Title : get_leaf_nodes
204 Usage : my @leaves = $tree->get_leaf_nodes()
205 Function: Returns the leaves (tips) of the tree
206 Returns : Array of Bio::Tree::NodeI objects
214 return grep { $_->is_Leaf() } $self->get_nodes(-sortby
=> 'none');