[Bioperl-l] Find distances between LCA's and the other nodes from a tree

Ross KK Leung ross at cuhk.edu.hk
Mon Oct 3 04:19:52 UTC 2011

The LCA obtained by get_lca from TreeFunctionsI is not a NodeI object. And
from NodeI documentation, I cannot identify a way to make a Node object to a
NodeI object. By the same token, methods like is_monophyletic or
is_paraphyletic are also unable to work on LCA's. Web search does not return
any examples about the manipulation of the LCA. Any hints would be highly
appreciated so I can continue to dig out the remaining on my own.


use Bio::TreeIO;

use Bio::Tree::TreeFunctionsI;


$tab = "\t"; $nl = "\n";

my ($testtree) = @ARGV; #or by the following _DATA_

my $treein = Bio::TreeIO->new( -file => $testtree, -format => 'newick' );

while( my $tree = $treein->next_tree ){

        %dist_matrix = ();


        my @leaves = $tree->get_leaf_nodes;

        foreach my $leaf1( @leaves ){

                my $id1 = $leaf1->id;      

                foreach my $leaf2( @leaves ){

                        my $id2 = $leaf2->id;

                        if ($id1 eq $id2) {

                                $dist_matrix{$id1}->{$id2} = 0;



                        my $distance = $tree->distance( -nodes => [$leaf1,
$leaf2] );

                        if ($id1 eq "A" and $id2 eq "B") {

                                my $lca = $tree->get_lca(-nodes => [$leaf1,
$leaf2] );


                        print "$leaf1:LCA:$lca:ACL:$leaf2"; <STDIN>;

                        #print $lca->id; <STDIN>;

                        my $distance2 = $tree->distance( -nodes => [$lca,
$leaf2] );

                        print $distance2; <STDIN>;


                        $dist_matrix{$id1}->{$id2} = $distance;







More information about the Bioperl-l mailing list