NAME
Bio::Tree::Tree - An implementation of the TreeI interface.
SYNOPSIS
use Bio::TreeIO;# like from a TreeIOmy $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'treefile.dnd');my $tree = $treeio->next_tree;my @nodes = $tree->get_nodes;my $root = $tree->get_root_node;
DESCRIPTION
This object holds handles to Nodes which make up a tree.
IMPLEMENTATION NOTE
This implementation of Bio::Tree::Tree contains Bio::Tree:::NodeI; mainly linked via the root node. As NodeI can potentially contain circular references (as nodes will need to refer to both parent and child nodes), Bio::Tree::Tree will remove those circular references when the object is garbage-collected. This has some side effects; primarily, one must keep the Tree in scope or have at least one reference to it if working with nodes. The fix is to count the references to the nodes and if it is greater than expected retain all of them, but it requires an additional prereq and thus may not be worth the effort. This only shows up in minor edge cases, though (see Bug #2869).
Example of issue:
# tree is not assigned to a variable, so passes from memory after# root node is passedmy $root = Bio::TreeIO->new(-format => 'newick', -file => 'foo.txt')->next_tree->get_root_node;# gets nothing, as all Node links are broken when Tree is garbage-collected abovemy @descendents = $root->get_all_Descendents;
FEEDBACK
Mailing Lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated.
[email protected] - General discussionhttp://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support
Please direct usage questions or support issues to the mailing list:
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible.
Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web:
https://github.com/bioperl/bioperl-live/issues
AUTHOR - Jason Stajich
Email [email protected]
CONTRIBUTORS
Aaron Mackey [email protected] Sendu Bala [email protected] Mark A. Jensen [email protected]
APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
new
Title : newUsage : my $obj = Bio::Tree::Tree->new();Function: Builds a new Bio::Tree::Tree objectReturns : Bio::Tree::TreeArgs : -root => L<Bio::Tree::NodeI> object which is the rootOR-node => L<Bio::Tree::NodeI> object from which the root will bedetermined-nodelete => boolean, whether or not to try and cleanup allthe nodes when this this tree goes out of scope.-id => optional tree ID-score => optional tree score value
nodelete
Title : nodeleteUsage : $obj->nodelete($newval)Function: Get/Set Boolean whether or not to delete the underlyingnodes when it goes out of scope. By default this is falsemeaning trees are cleaned up.Returns : booleanArgs : on set, new boolean value
get_nodes
Title : get_nodesUsage : my @nodes = $tree->get_nodes()Function: Return list of Bio::Tree::NodeI objectsReturns : array of Bio::Tree::NodeI objectsArgs : (named values) hash with one valueorder => 'b|breadth' first order or 'd|depth' first ordersortby => [optional] "height", "creation", "alpha", "revalpha",or coderef to be used to sort the order of children nodes. See L<Bio::Tree::Node> for details
get_root_node
Title : get_root_nodeUsage : my $node = $tree->get_root_node();Function: Get the Top Node in the tree, in this implementationTrees only have one top node.Returns : Bio::Tree::NodeI objectArgs : none
set_root_node
Title : set_root_nodeUsage : $tree->set_root_node($node)Function: Set the Root Node for the TreeReturns : Bio::Tree::NodeIArgs : Bio::Tree::NodeI
total_branch_length
Title : total_branch_lengthUsage : my $size = $tree->total_branch_lengthFunction: Returns the sum of the length of all branchesReturns : realArgs : none
subtree_length
Title : subtree_lengthUsage : my $subtree_size = $tree->subtree_length($internal_node)Function: Returns the sum of the length of all branches in a subtreeunder the node. Calculates the size of the whole treewithout an argument (but only if root node is defined)Returns : real or undefArgs : Bio::Tree::NodeI object, defaults to the root node
id
Title : idUsage : my $id = $tree->id();Function: An id value for the treeReturns : scalarArgs : [optional] new value to set
score
Title : scoreUsage : $obj->score($newval)Function: Sets the associated score with this treeThis is a generic slot which is probably best usedfor log likelihood or other overall tree scoreReturns : value of scoreArgs : newvalue (optional)
height
Title : heightUsage : my $height = $tree->heightFunction: Gets the height of tree - this LOG_2($number_nodes)WARNING: this is only true for strict binary trees. The TreeIOsystem is capable of building non-binary trees, for which thismethod will currently return an incorrect value!!Returns : integerArgs : none
number_nodes
Title : number_nodesUsage : my $size = $tree->number_nodesFunction: Returns the number of nodes in the treeReturns : integerArgs : none
as_text
Title : as_textUsage : my $tree_as_string = $tree->as_text($format)Function: Returns the tree as a string representation in thedesired format, e.g.: 'newick', 'nhx' or 'tabtree' (the default)Returns : scalar stringArgs : format type as specified by Bio::TreeIONote : This method loads the Bio::TreeIO::$format moduleon the fly, and commandeers the _write_tree_Helperroutine therein to create the tree string.
Methods for associating Tag/Values with a Tree
These methods associate tag/value pairs with a Tree
set_tag_value
Title : set_tag_valueUsage : $tree->set_tag_value($tag,$value)$tree->set_tag_value($tag,@values)Function: Sets a tag value(s) to a tree. Replaces old values.Returns : number of values stored for this tagArgs : $tag - tag name$value - value to store for the tag
add_tag_value
Title : add_tag_valueUsage : $tree->add_tag_value($tag,$value)Function: Adds a tag value to a treeReturns : number of values stored for this tagArgs : $tag - tag name$value - value to store for the tag
remove_tag
Title : remove_tagUsage : $tree->remove_tag($tag)Function: Remove the tag and all values for this tagReturns : boolean representing success (0 if tag does not exist)Args : $tag - tagname to remove
remove_all_tags
Title : remove_all_tagsUsage : $tree->remove_all_tags()Function: Removes all tagsReturns : NoneArgs : None
get_all_tags
Title : get_all_tagsUsage : my @tags = $tree->get_all_tags()Function: Gets all the tag names for this TreeReturns : Array of tagnamesArgs : None
get_tag_values
Title : get_tag_valuesUsage : my @values = $tree->get_tag_values($tag)Function: Gets the values for given tag ($tag)Returns : Array of values or empty list if tag does not existArgs : $tag - tag name
has_tag
Title : has_tagUsage : $tree->has_tag($tag)Function: Boolean test if tag exists in the TreeReturns : BooleanArgs : $tag - tagname
clone
Title : cloneAlias : _cloneUsage : $tree_copy = $tree->clone();$subtree_copy = $tree->clone($internal_node);Function: Safe tree clone that doesn't segfaultReturns : Bio::Tree::Tree objectArgs : [optional] $start_node, Bio::Tree::Node object