[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;

                                next;

                        }

                        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;

                }

        }

}

 

#_DATA_

((((((A:1.00000000,B:1.00000000):1.00000000,C:1.00000000):0.00000000,D:0.000
00000):1.00000000,(E:0.00000000,(F:2.00000000,G:1.00000000):0.00000000):0.00
000000):2.00000000,(H:3.00000000,(I:2.00000000,(J:1.00000000,(K:2.00000000,(
L:2.00000000,M:2.00000000):0.00000000):0.00000000):0.00000000):0.00000000):0
.00000000):1.00000000,(N:0.00000000,((O:0.00000000,P:0.00000000):1.00000000,
(Q:2.00000000,(R:2.66666667,S:3.66666667):3.66666667):0.00000000):1.00000000
):3.00000000,(T:0.00000000,(U:0.00000000,V:0.00000000):1.00000000):16.000000
00);




More information about the Bioperl-l mailing list