++ed by:

11 PAUSE users
14 non-PAUSE users.

Christopher Fields
and 1 contributors


Bio::Tree::TreeFunctionsI - Decorated Interface implementing basic Tree exploration methods


  use Bio::TreeIO;
  my $in = Bio::TreeIO->new(-format => 'newick', -file => 'tree.tre');

  my $tree = $in->next_tree;

  my @nodes = $tree->find_node('id1');

  if( $tree->is_monophyletic(-nodes => \@nodes, -outgroup => $outnode) ){


This interface provides a set of implementated Tree functions which only use the defined methods in the TreeI or NodeI interface.


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.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

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:


AUTHOR - Jason Stajich, Aaron Mackey, Justin Reese

Email jason-at-bioperl-dot-org Email amackey-at-virginia.edu Email jtr4v-at-virginia.edu


Sendu Bala, bix@sendu.me.uk

Rerooting code was worked on by

  Daniel Barker d.barker-at-reading.ac.uk
  Ramiro Barrantes Ramiro.Barrantes-at-uvm.edu


The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _


 Title   : find_node
 Usage   : my @nodes = $self->find_node(-id => 'node1');
 Function: returns all nodes that match a specific field, by default this
           is id, but different branch_length, 
 Returns : List of nodes which matched search
 Args    : text string to search for
           -fieldname => $textstring


 Title   : remove_Node
 Usage   : $tree->remove_Node($node)
 Function: Removes a node from the tree
 Returns : boolean represent status of success
 Args    : either Bio::Tree::NodeI or string of the node id


 Title   : get_lineage_nodes
 Usage   : my @nodes = $tree->get_lineage_nodes($node);
 Function: Get the full lineage of a node (all its ancestors, in the order
           root->most recent ancestor)
 Returns : list of nodes
 Args    : either Bio::Tree::NodeI or string of the node id


 Title   : splice
 Usage   : $tree->splice(-remove_id => \@ids);
 Function: Remove all the nodes from a tree that correspond to the supplied
           args, making all the descendents of a removed node the descendents
           of the removed node's ancestor.
           You can ask to explicitly remove certain nodes by using -remove_*,
           remove them conditionally by using -remove_* in combination with
           -keep_*, or remove everything except certain nodes by using only
 Returns : n/a
 Args    : just a list of Bio::Tree::NodeI objects to remove, OR
           -key => value pairs, where -key has the prefix 'remove' or 'keep',
           followed by an underscore, followed by a fieldname (like for the
           method find_node). Value should be a scalar or an array ref of
           scalars (again, like you might supply to find_node).

           So (-remove_id => [1, 2]) will remove all nodes from the tree that
           have an id() of '1' or '2', while
           (-remove_id => [1, 2], -keep_id => [2]) will remove all nodes with
           an id() of '1'.
           (-keep_id => [2]) will remove all nodes unless they have an id() of
           '2' (note, no -remove_*).


 Title   : get_lca
 Usage   : get_lca(-nodes => \@nodes ); OR
 Function: given two or more nodes, returns the lowest common ancestor (aka most
           recent common ancestor)
 Returns : node object or undef if there is no common ancestor
 Args    : -nodes => arrayref of nodes to test, OR
           just a list of nodes


 Title   : merge_lineage
 Usage   : merge_lineage($node)
 Function: Merge a lineage of nodes with this tree.
 Returns : n/a
 Args    : Bio::Tree::TreeI with only one leaf, OR
           Bio::Tree::NodeI which has an ancestor

 For example, if we are the tree $tree:


 and we want to merge the lineage $other_tree:


 After calling $tree->merge_lineage($other_tree), $tree looks like:



 Title   : contract_linear_paths
 Usage   : contract_linear_paths()
 Function: Splices out all nodes in the tree that have an ancestor and only one
 Returns : n/a
 Args    : none for normal behaviour, true to dis-regard the ancestor requirment
           and re-root the tree as necessary

 For example, if we are the tree $tree:


 After calling $tree->contract_linear_paths(), $tree looks like:


 Instead, $tree->contract_linear_paths(1) would have given:



  Example    : is_binary(); is_binary($node);
  Description: Finds if the tree or subtree defined by
               the internal node is a true binary tree
               without polytomies
  Returns    : boolean
  Exceptions : 
  Args       : Internal node Bio::Tree::NodeI, optional


 Title   : force_binary
 Usage   : force_binary()
 Function: Forces the tree into a binary tree, splitting branches arbitrarily
           and creating extra nodes as necessary, such that all nodes have
           exactly two or zero descendants.
 Returns : n/a
 Args    : none

 For example, if we are the tree $tree:


 (A has 6 descendants B-G)

 After calling $tree->force_binary(), $tree looks like:

     |   |
     |   +---X
 |   |
 |   |   +---G
 |   |   |
 |   +---X
 |       |
 |       +---F
 |       +---E
 |       |
 |   +---X
 |   |   |
 |   |   +---D
 |   |
     |   +---C
     |   |

 (Where X are artificially created nodes with ids 'artificial_n', where n is
 an integer making the id unique within the tree)


 Title   : simplify_to_leaves_string
 Usage   : my $leaves_string = $tree->simplify_to_leaves_string()
 Function: Creates a simple textual representation of the relationship between
           leaves in self. It forces the tree to be binary, so the result may
           not strictly correspond to the tree (if the tree wasn't binary), but
           will be as close as possible. The tree object is not altered. Only
           leaf node ids are output, in a newick-like format.
 Returns : string
 Args    : none


 Title   : distance
 Usage   : distance(-nodes => \@nodes )
 Function: returns the distance between two given nodes
 Returns : numerical distance
 Args    : -nodes => arrayref of nodes to test


 Title   : is_monophyletic
 Usage   : if( $tree->is_monophyletic(-nodes => \@nodes, 
                                      -outgroup => $outgroup)
 Function: Will do a test of monophyly for the nodes specified
           in comparison to a chosen outgroup
 Returns : boolean
 Args    : -nodes    => arrayref of nodes to test
           -outgroup => outgroup to serve as a reference


 Title   : is_paraphyletic
 Usage   : if( $tree->is_paraphyletic(-nodes =>\@nodes,
                                      -outgroup => $node) ){ }
 Function: Tests whether or not a given set of nodes are paraphyletic
           (representing the full clade) given an outgroup
 Returns : [-1,0,1] , -1 if the group is not monophyletic
                       0 if the group is not paraphyletic
                       1 if the group is paraphyletic
 Args    : -nodes => Array of Bio::Tree::NodeI objects which are in the tree
           -outgroup => a Bio::Tree::NodeI to compare the nodes to


 Title   : reroot
 Usage   : $tree->reroot($node);
 Function: Reroots a tree making a new node the root
 Returns : 1 on success, 0 on failure
 Args    : Bio::Tree::NodeI that is in the tree, but is not the current root


 Title   : findnode_by_id
 Usage   : my $node = $tree->findnode_by_id($id);
 Function: Get a node by its id (which should be 
           unique for the tree)
 Returns : L<Bio::Tree::NodeI>
 Args    : node id


 Title   : move_id_to_bootstrap
 Usage   : $tree->move_id_to_bootstrap
 Function: Move internal IDs to bootstrap slot
 Returns : undef
 Args    : undef


  Example    : $key = $stat->add_traits($tree, $trait_file, 3);
  Description: Add traits to a Bio::Tree:Tree nodes
               of a tree from a file.
  Returns    : trait name
  Exceptions : log an error if a node has no value in the file
  Caller     : main()

The trait file is a tab-delimied text file and need to have a header line giving names to traits. The first column contains the leaf node ids. Subsequent columns contain different trait value sets. Columns numbering starts from 0. The default trait column is the second (1). The returned hashref has one special key, my_trait_name, that holds the trait name. Single or double quotes are removed.