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

Thomas Sharpton thomas.sharpton at gmail.com
Wed Oct 5 01:43:38 UTC 2011

Hi Ross,

I think Rutger has given you a good idea and it is certainly simpler than
the solution I just concocted (no surprise there).

Regarding your most recent note:

2011/10/4 Ross KK Leung <ross at cuhk.edu.hk>

> Thanks, Rutger. While there is a convenient function to help calculate the
> distances between leaf nodes, I find it difficult for ancestors. After
> using
> get_lca, it seems that bioperl has no data structures to help manipulate
> these LCA's.
>From what I understand, the get_lca does return a node object, specifically
an internal node. The following is from the BioPerl documentation (note the
"Returns" line):

 Title   : get_lca
 Usage   : get_lca(-nodes => \@nodes ); OR
 Function: given two or more nodes, returns the lowest common ancestor (aka most
           recent common ancestor)

 Returns : node object or undef if there is no common ancestor
 Args    : -nodes => arrayref of nodes to test, OR
           just a list of nodes

You can get the distance between any two nodes, including an internal node,
using the distance method. Note that the nodes you input into the distance
function do not need to have ids associated with them. For example,

#$nodeA and $nodeB are BioPerl node objects that correspond to any node on
the tree
my $lca = get_lca( $nodeA, $nodeB );
my $distance = distance( $nodeA, $lca );

$distance will now contain the total branch length between nodeA and the
last common ancestor between nodes A and B. At no point are node ids used to
conduct calculation; only the node objects themselves are needed. Anything
that you can do to a node, you can do to $lca.

This is how I understand the functions, at least. Someone please correct me
if I'm wrong, as I fear I sound like a broken record at this point....


More information about the Bioperl-l mailing list