2 # BioPerl module for Bio::Tree::TreeI
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Tree::TreeI - A Tree object suitable for lots of things, designed
17 originally for Phylogenetic Trees.
21 # get a Bio::Tree::TreeI somehow
23 my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'treefile.dnd');
24 my $tree = $treeio->next_tree;
25 my @nodes = $tree->get_nodes;
26 my @leaves = $tree->get_leaf_nodes;
27 my $root = $tree->get_root_node;
31 This object holds a pointer to the Root of a Tree which is a
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 Please direct usage questions or support issues to the mailing list:
49 I<bioperl-l@bioperl.org>
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 of the bugs and their resolution. Bug reports can be submitted via
62 https://github.com/bioperl/bioperl-live/issues
64 =head1 AUTHOR - Jason Stajich
66 Email jason@bioperl.org
70 Aaron Mackey, amackey@virginia.edu
71 Elia Stupka, elia@fugu-sg.org
72 Sendu Bala, bix@sendu.me.uk
76 The rest of the documentation details each of the object methods.
77 Internal methods are usually preceded with a _
82 # Let the code begin...
85 package Bio
::Tree
::TreeI
;
88 use base
qw(Bio::Root::RootI);
93 Usage : my @nodes = $tree->get_nodes()
94 Function: Return list of Tree::NodeI objects
95 Returns : array of Tree::NodeI objects
96 Args : (named values) hash with one value
97 order => 'b|breadth' first order or 'd|depth' first order
103 $self->throw_not_implemented();
108 Title : get_root_node
109 Usage : my $node = $tree->get_root_node();
110 Function: Get the Top Node in the tree, in this implementation
111 Trees only have one top node.
112 Returns : Bio::Tree::NodeI object
119 $self->throw_not_implemented();
125 Usage : my $size = $tree->number_nodes
126 Function: Find the number of nodes in the tree.
134 my $root = $self->get_root_node;
135 if( defined $root && $root->isa('Bio::Tree::NodeI')) {
136 return ($root->descendent_count + 1);
141 =head2 total_branch_length
143 Title : total_branch_length
144 Usage : my $size = $tree->total_branch_length
145 Function: Returns the sum of the length of all branches
151 sub total_branch_length
{
153 $self->throw_not_implemented();
159 Usage : my $height = $tree->height
160 Function: Gets the height of tree - this LOG_2($number_nodes)
161 WARNING: this is only true for strict binary trees. The TreeIO
162 system is capable of building non-binary trees, for which this
163 method will currently return an incorrect value!!
171 my $nodect = $self->number_nodes;
172 return 0 if( ! $nodect );
173 return log($nodect) / log(2);
179 Usage : my $id = $tree->id();
180 Function: An id value for the tree
188 my ($self,@args) = @_;
189 $self->throw_not_implemented();
195 Usage : $obj->score($newval)
196 Function: Sets the associated score with this tree
197 This is a generic slot which is probably best used
198 for log likelihood or other overall tree score
199 Returns : value of score
200 Args : newvalue (optional)
206 my ($self,$value) = @_;
207 $self->throw_not_implemented();
210 =head2 get_leaf_nodes
212 Title : get_leaf_nodes
213 Usage : my @leaves = $tree->get_leaf_nodes()
214 Function: Returns the leaves (tips) of the tree
215 Returns : Array of Bio::Tree::NodeI objects
223 return grep { $_->is_Leaf() } $self->get_nodes(-sortby
=> 'none');
227 =head2 Methods for associating Tag/Values with a Tree
229 These methods associate tag/value pairs with a Tree
233 Title : set_tag_value
234 Usage : $tree->set_tag_value($tag,$value)
235 $tree->set_tag_value($tag,@values)
236 Function: Sets a tag value(s) to a tree. Replaces old values.
237 Returns : number of values stored for this tag
238 Args : $tag - tag name
239 $value - value to store for the tag
244 shift->throw_not_implemented();
249 Title : add_tag_value
250 Usage : $tree->add_tag_value($tag,$value)
251 Function: Adds a tag value to a tree
252 Returns : number of values stored for this tag
253 Args : $tag - tag name
254 $value - value to store for the tag
260 shift->throw_not_implemented();
266 Usage : $tree->remove_tag($tag)
267 Function: Remove the tag and all values for this tag
268 Returns : boolean representing success (0 if tag does not exist)
269 Args : $tag - tagname to remove
275 shift->throw_not_implemented();
278 =head2 remove_all_tags
280 Title : remove_all_tags
281 Usage : $tree->remove_all_tags()
282 Function: Removes all tags
290 shift->throw_not_implemented();
296 Usage : my @tags = $tree->get_all_tags()
297 Function: Gets all the tag names for this Tree
298 Returns : Array of tagnames
305 shift->throw_not_implemented();
308 =head2 get_tag_values
310 Title : get_tag_values
311 Usage : my @values = $tree->get_tag_values($tag)
312 Function: Gets the values for given tag ($tag)
313 Returns : Array of values or empty list if tag does not exist
314 Args : $tag - tag name
320 shift->throw_not_implemented();
326 Usage : $tree->has_tag($tag)
327 Function: Boolean test if tag exists in the Tree
329 Args : $tag - tagname
335 shift->throw_not_implemented();