[Bioperl-l] Question on Tree : Last common ancestor / Internal Nodes
Himanshu Ardawatia
himanshu.ardawatia at bccs.uib.no
Tue Jan 9 11:26:22 UTC 2007
Hi,
I am trying the available bioperl script (attached below), and as I see it
seems to give (or not give at all) strange results:
Input tree:
__DATA__
(a,((c,d)z,(e,f)y)x)root;
Output :
Use of uninitialized value in pattern match (m//) at try_tree_new.pl line 9.
lca is x for c,d,f
Use of uninitialized value in pattern match (m//) at try_tree_new.pl line
18.
Use of uninitialized value in print at try_tree_new.pl line 25.
lca is for a,z
However, here we can see that actually, 'lca' for 'e' and 'f' should be 'y'
and 'lca' for 'c' and 'd' should be 'z' .
In another case, if my input tree is :
__DATA__
(a,((c,d)D0L0=0+0,(e,f)D0L1=1+0)D0L2=1+1)D1L0=0+0;
(where I have replaced 'x', 'y', 'z' and 'root' internal nodes with some
other values which are important for me)
I get the Output:
Use of uninitialized value in pattern match (m//) at try_tree_new.pl line 9.
lca is D0L2=1+1 for c,d,f
Use of uninitialized value in pattern match (m//) at try_tree_new.pl line
18.
lca is a for a
Here the last line is changed ' lca is a for a' as comapred to the previous
result.
I wonder why this change.....
If a use a completely different tree :
Input:
__DATA_
((48355,(21337,65453)D0L0=0+0)D0L1=1+0,(38243,18116)D0L2=1+1)D1L0=0+0;
I do not get any result in the output at all...
Output :
Use of uninitialized value in pattern match (m//) at try_tree_new.pl line 9.
Can't call method "id" on an undefined value at try_tree_new.pl line 17.
Can anyone suggest why these differences and how can I obtain 'internal node
ids' (eg. in this case 'D1L0=0+0' etc. for each leaf seperately ?
Thanks
Himanshu
Script:
#!/usr/bin/perl -w
use strict;
use Bio::TreeIO;
my $tree = Bio::TreeIO->new(-format => 'newick', -fh => \*DATA)->next_tree;
my @nodes = grep { $_->id =~ /c|d|f/ } $tree->get_nodes;
my @orig = @nodes;
while( @nodes > 1 ) {
my $lca = $tree->get_lca(-nodes => [shift @nodes, shift @nodes]);
push @nodes, $lca;
}
my $lca = shift @nodes;
print "lca is ",$lca->id, " for ", join(",",map { $_->id } @orig), "\n";
@nodes = grep { $_->id =~ /a|z/ } $tree->get_nodes;
@orig = @nodes;
while( @nodes > 1 ) {
my $lca = $tree->get_lca(-nodes => [shift @nodes, shift @nodes]);
push @nodes, $lca;
}
$lca = shift @nodes;
print "lca is ",$lca->id, " for ", join(",",map { $_->id } @orig), "\n";
__DATA__
More information about the Bioperl-l
mailing list