[Bioperl-l] Number of internal nodes on a tree

Jason Stajich jason.stajich at duke.edu
Fri May 13 14:44:34 EDT 2005


yes.
see the code in Bio::Tree::TreeFunctionsI for the distance method.   
It computes the distance between  two nodes by adding the branch  
lengths - if you just want the count you can modify it .

Basically find the LCA of the two nodes and count the number of steps  
it takes for each to get to the LCA.  You are just iterating on the - 
 >ancestor call.

Something like this should work - I haven't tried it out though so I  
don't know for sure.


my $lca = $tree->get_lca($node1,$node2);
my $count = 0;

for my $n ( $node1,$node2 ) {
  my $node = $n; # do a copy otherwise we'll be updating the value of  
$node1 and $node2
  while( $node->ancestor ) {
   last if( $node->ancestor->internal_id == $lca->internal_id);
   $count++;
   $node = $node->ancestor;
  }
}


-jason

On May 13, 2005, at 2:27 PM, Goel, Manisha wrote:

> Hi All,
>
> I am trying to claculate the number of nodes between any two given  
> nodes
> (or leaves) on a phylogenetic tree.
> Can I do this using the existing functionalities in Bio::Tree ?
> Please suggest.
>
> Thanks,
> -Manisha Goel
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>



More information about the Bioperl-l mailing list