Bio::Tree NodeI
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::Tree::NodeI - Interface describing a Tree Node
Package variables
No package variables defined.
Inherit
Bio::Root::RootI
Synopsis
    # get a Tree::NodeI somehow
# like from a TreeIO
use Bio::TreeIO;
# read in a clustalw NJ in phylip/newick format
my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'file.dnd');
my $tree = $treeio->next_tree; # we'll assume it worked for demo purposes # you might want to test that it was defined my $rootnode = $tree->get_root_node; # process just the next generation foreach my $node ( $rootnode->each_Descendent() ) { print "branch len is ", $node->branch_length, "\n"; } # process all the children my $example_leaf_node; foreach my $node ( $rootnode->get_all_Descendents() ) { if( $node->is_Leaf ) { print "node is a leaf ... "; # for example use below $example_leaf_node = $node unless defined $example_leaf_node; } print "branch len is ", $node->branch_length, "\n"; } # The ancestor() method points to the parent of a node # A node can only have one parent my $parent = $example_leaf_node->ancestor; # parent won't likely have an description because it is an internal node # but child will because it is a leaf print "Parent id: ", $parent->id," child id: ", $example_leaf_node->id, "\n";
Description
A NodeI is capable of the basic structure of building a tree and
storing the branch length between nodes. The branch length is the
length of the branch between the node and its ancestor, thus a root
node in a Tree will not typically have a valid branch length.
Various implementations of NodeI may extend the basic functions and
allow storing of other information (like attatching a species object
or full sequences used to build a tree or alternative sequences). If
you don't know how to extend a Bioperl object please ask, happy to
help, we would also greatly appreciate contributions with improvements
or extensions of the objects back to the Bioperl code base so that
others don't have to reinvent your ideas.
Methods
add_DescendentDescriptionCode
each_DescendentDescriptionCode
get_all_DescendentsDescriptionCode
is_LeafDescriptionCode
descendent_countDescriptionCode
to_stringDescriptionCode
heightDescriptionCode
depthDescriptionCode
branch_lengthDescriptionCode
idDescriptionCode
internal_idDescriptionCode
descriptionDescriptionCode
bootstrapDescriptionCode
ancestorDescriptionCode
invalidate_heightDescriptionCode
set_tag_valueDescriptionCode
add_tag_valueDescriptionCode
remove_tagDescriptionCode
remove_all_tagsDescriptionCode
get_all_tagsDescriptionCode
get_tag_valuesDescriptionCode
has_tagDescriptionCode
id_outputDescriptionCode
Methods description
add_Descendentcode    nextTop
 Title   : add_Descendent
Usage : $node->add_Descendent($node);
Function: Adds a descendent to a node
Returns : number of current descendents for this node
Args : Bio::Node::NodeI
each_DescendentcodeprevnextTop
 Title   : each_Descendent
Usage : my @nodes = $node->each_Descendent;
Function: all the descendents for this Node (but not their descendents
i.e. not a recursive fetchall)
Returns : Array of Bio::Tree::NodeI objects
Args : none
get_all_DescendentscodeprevnextTop
 Title   : get_all_Descendents($sortby)
Usage : my @nodes = $node->get_all_Descendents;
Function: Recursively fetch all the nodes and their descendents
*NOTE* This is different from each_Descendent
Returns : Array or Bio::Tree::NodeI objects
Args : $sortby [optional] "height", "creation", "alpha", "revalpha",
or a coderef to be used to sort the order of children nodes.
is_LeafcodeprevnextTop
 Title   : is_Leaf
Usage : if( $node->is_Leaf )
Function: Get Leaf status
Returns : boolean
Args : none
descendent_countcodeprevnextTop
 Title   : descendent_count
Usage : my $count = $node->descendent_count;
Function: Counts the number of descendents a node has
(and all of their subnodes)
Returns : integer
Args : none
to_stringcodeprevnextTop
 Title   : to_string
Usage : my $str = $node->to_string()
Function: For debugging, provide a node as a string
Returns : string
Args : none
heightcodeprevnextTop
 Title   : height
Usage : my $len = $node->height
Function: Returns the height of the tree starting at this
node. Height is the maximum branchlength to get to the tip.
Returns : The longest length (weighting branches with branch_length) to a leaf
Args : none
depthcodeprevnextTop
 Title   : depth
Usage : my $len = $node->depth
Function: Returns the depth of the tree starting at this
node. Depth is the distance from this node to the root.
Returns : The branch length to the root.
Args : none
branch_lengthcodeprevnextTop
 Title   : branch_length
Usage : $obj->branch_length()
Function: Get/Set the branch length
Returns : value of branch_length
Args : newvalue (optional)
idcodeprevnextTop
 Title   : id
Usage : $obj->id($newval)
Function: The human readable identifier for the node
Returns : value of human readable id
Args : newvalue (optional)
internal_idcodeprevnextTop
 Title   : internal_id
Usage : my $internalid = $node->internal_id
Function: Returns the internal unique id for this Node
Returns : unique id
Args : none
descriptioncodeprevnextTop
 Title   : description
Usage : $obj->description($newval)
Function: Get/Set the description string
Returns : value of description
Args : newvalue (optional)
bootstrapcodeprevnextTop
 Title   : bootstrap
Usage : $obj->bootstrap($newval)
Function: Get/Set the bootstrap value
Returns : value of bootstrap
Args : newvalue (optional)
ancestorcodeprevnextTop
 Title   : ancestor
Usage : my $node = $node->ancestor;
Function: Get/Set the ancestor node pointer for a Node
Returns : Null if this is top level node
Args : none
invalidate_heightcodeprevnextTop
 Title   : invalidate_height
Usage : private helper method
Function: Invalidate our cached value of the node height in the tree
Returns : nothing
Args : none
set_tag_valuecodeprevnextTop
 Title   : set_tag_value
Usage : $node->set_tag_value($tag,$value)
$node->set_tag_value($tag,@values)
Function: Sets a tag value(s) to a node. Replaces old values.
Returns : number of values stored for this tag
Args : $tag - tag name
$value - value to store for the tag
add_tag_valuecodeprevnextTop
 Title   : add_tag_value
Usage : $node->add_tag_value($tag,$value)
Function: Adds a tag value to a node
Returns : number of values stored for this tag
Args : $tag - tag name
$value - value to store for the tag
remove_tagcodeprevnextTop
 Title   : remove_tag
Usage : $node->remove_tag($tag)
Function: Remove the tag and all values for this tag
Returns : boolean representing success (0 if tag does not exist)
Args : $tag - tagname to remove
remove_all_tagscodeprevnextTop
 Title   : remove_all_tags
Usage : $node->remove_all_tags()
Function: Removes all tags
Returns : None
Args : None
get_all_tagscodeprevnextTop
 Title   : get_all_tags
Usage : my @tags = $node->get_all_tags()
Function: Gets all the tag names for this Node
Returns : Array of tagnames
Args : None
get_tag_valuescodeprevnextTop
 Title   : get_tag_values
Usage : my @values = $node->get_tag_values($tag)
Function: Gets the values for given tag ($tag)
Returns : Array of values or empty list if tag does not exist
Args : $tag - tag name
has_tagcodeprevnextTop
 Title   : has_tag
Usage : $node->has_tag($tag)
Function: Boolean test if tag exists in the Node
Returns : Boolean
Args : $tag - tagname
id_outputcodeprevnextTop
 Title   : id_output
Usage : my $id = $node->id_output;
Function: Return an id suitable for output in format like newick
so that if it contains spaces or ():; characters it is properly
quoted
Returns : $id string if $node->id has a value
Args : none
Methods code
add_DescendentdescriptionprevnextTop
sub add_Descendent {
   my ($self,@args) = @_;

   $self->throw_not_implemented();
}
each_DescendentdescriptionprevnextTop
sub each_Descendent {
   my ($self) = @_;
   $self->throw_not_implemented();
}
get_all_DescendentsdescriptionprevnextTop
sub get_all_Descendents {
   my ($self, $sortby) = @_;
   $sortby ||= 'none';   
   my @nodes;
   foreach my $node ( $self->each_Descendent($sortby) ) {
       push @nodes, ($node,$node->get_all_Descendents($sortby));
   }
   return @nodes;
}

*get_Descendents =\& get_all_Descendents;
}
is_LeafdescriptionprevnextTop
sub is_Leaf {
    my ($self) = @_;
    $self->throw_not_implemented();
}
descendent_countdescriptionprevnextTop
sub descendent_count {
   my ($self) = @_;
   my $count = 0;
   
   foreach my $node ( $self->each_Descendent ) { 
       $count += 1;
       $node->can('descendent_count') ? $count += $node->descendent_count : next;
   }
   return $count;
}
to_stringdescriptionprevnextTop
sub to_string {
   my ($self) = @_;
   return join('',defined $self->id_output ? $self->id_output : '',
		  defined $self->branch_length ? ':' . $self->branch_length 
		  : ' ')
}
heightdescriptionprevnextTop
sub height {
    my ($self) = @_;

    return 0 if( $self->is_Leaf );
    
    my $max = 0;
    foreach my $subnode ( $self->each_Descendent ) { 
	my $s = $subnode->height + $subnode->branch_length;;
	if( $s > $max ) { $max = $s; }
    }
    return $max;
}
depthdescriptionprevnextTop
sub depth {
   my ($self) = @_;
   
   my $depth = 0;
   my $node = $self;
   while( defined $node->ancestor ) { 
       $depth += $node->branch_length;
       $node = $node->ancestor;
   }
   return $depth;
}
branch_lengthdescriptionprevnextTop
sub branch_length {
    my ($self)= @_;
    $self->throw_not_implemented();
}
iddescriptionprevnextTop
sub id {
    my ($self)= @_;
    $self->throw_not_implemented();
}
internal_iddescriptionprevnextTop
sub internal_id {
   my ($self) = @_;
   $self->throw_not_implemented();
}
descriptiondescriptionprevnextTop
sub description {
    my ($self) = @_;
    $self->throw_not_implemented();
}
bootstrapdescriptionprevnextTop
sub bootstrap {
    my ($self) = @_;
    $self->throw_not_implemented();
}
ancestordescriptionprevnextTop
sub ancestor {
   my ($self,@args) = @_;
    $self->throw_not_implemented();
}
invalidate_heightdescriptionprevnextTop
sub invalidate_height {
     shift->throw_not_implemented();
}
set_tag_valuedescriptionprevnextTop
sub set_tag_value {
    shift->throw_not_implemented();
}
add_tag_valuedescriptionprevnextTop
sub add_tag_value {
    shift->throw_not_implemented();
}
remove_tagdescriptionprevnextTop
sub remove_tag {
    shift->throw_not_implemented();
}
remove_all_tagsdescriptionprevnextTop
sub remove_all_tags {
    shift->throw_not_implemented();
}
get_all_tagsdescriptionprevnextTop
sub get_all_tags {
    shift->throw_not_implemented();
}
get_tag_valuesdescriptionprevnextTop
sub get_tag_values {
    shift->throw_not_implemented();
}
has_tagdescriptionprevnextTop
sub has_tag {
    shift->throw_not_implemented();
}
id_outputdescriptionprevnextTop
sub id_output {
    my $node = shift;
    my $id = $node->id;
    return unless( defined $id && length($id ) );
    # single quotes must become double quotes
# $id =~ s/'/''/g;
if( $id =~ /[\(\);:,\s]/ ) { $id = '"'.$id.'"'; } return $id; } 1;
}
General documentation
FEEDBACKTop
Mailing ListsTop
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
Support Top
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
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 BugsTop
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://redmine.open-bio.org/projects/bioperl/
AUTHOR - Jason StajichTop
Email jason@bioperl.org
CONTRIBUTORSTop
Aaron Mackey amackey@virginia.edu
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Decorated Interface methodsTop
Get/Set methodsTop
Methods for associating Tag/Values with a NodeTop
These methods associate tag/value pairs with a Node
Helper FunctionsTop