[Bioperl-l] Question on Tree : Last common ancestor / Internal Nodes

Sendu Bala bix at sendu.me.uk
Tue Jan 9 07:38:26 EST 2007


Himanshu Ardawatia wrote:
> 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:

What version of Bioperl are you using? With 1.5.2 I don't see any
problems except user-error. I've noted the results I get below.


> 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

lca is x for c,d,f
lca is root 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' .

What do you mean? Your script asks the lca of c,d,f and a,z, not e,f or c,d.


> 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

lca is D0L2=1+1 for c,d,f
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.....

Your script asks for the lca of a,z but the tree no longer has a node
'z'. So you ask for the lca of 'a', which is 'a'.


> 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't call method "id" on an undefined value at try_tree_new.pl line 14.


> Can anyone suggest why these differences

Again, your script is asking for nodes that aren't in the tree, so of
course it isn't going to work.


> and how can I obtain 'internal node ids' (eg. in this case 'D1L0=0+0'
> etc. for each leaf seperately ?

You'll want to use the methods get_leaf_nodes() and internal_id() 
(though you almost certainly don't really want the internal id and 
should be using the human-readable id id() instead).


In Bioperl 1.5.2 your code can be written as the much simpler:

#!/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 $lca = $tree->get_lca(@nodes);
print "lca is ",$lca->id, " for ", join(",",map { $_->id } @nodes), "\n";

@nodes = grep { $_->id =~ /a|z/ } $tree->get_nodes;
$lca = $tree->get_lca(@nodes);
print "lca is ",$lca->id, " for ", join(",",map { $_->id } @nodes), "\n";

__DATA__
(a,((c,d)z,(e,f)y)x)root;


More information about the Bioperl-l mailing list