[Bioperl-l] Find distances between LCA's and the other nodes from a tree
Thomas Sharpton
thomas.sharpton at gmail.com
Mon Oct 3 18:24:32 UTC 2011
Hi Ross,
On Mon, Oct 3, 2011 at 10:41 AM, Ross KK Leung <ross at cuhk.edu.hk> wrote:
> Thanks Tom. This is the 2nd time you help me.
>
This list has been a vital resource for me, so I'm happy to contribute when
I can.
> Suppose I change the structure to:****
>
> ** **
>
> ((A:0.1,B:0.2)F:0.3,(C:0.3,D:0.4)E:0.5)G;****
>
> ** **
>
> I have identified two problems.****
>
> ** **
>
> 1) The distance of A and F, I suppose to be 0.1, cannot be calculated (a warning will prompt and the value shown is wrong).
>
> Can you provide the code you are using and the result and error it produces
in your next email? This will help diagnose the problem.
> ****
>
> 2) Nodes F, E and G are annotated by me, but in fact the newick tree generated does not contain any ID. So that means I have to manually supplement ID's for such intermediate nodes before further processing (this is indeed dealing with "recursive descent parsing" myself...)? ****
>
> Yes, this is unfortunate, but you can automate the labeling of internal
node ids using something like the following:
#$tree_in is a TreeIO object
while( my $tree = $tree_in->next_tree() ){
my $id_basename = "intnode_";
my $id_count = 0;
my @nodes = $tree->get_nodes();
foreach my $node( @nodes ){
next if $node->is_Leaf();
my $id = $node->id();
if( !(defined( $id ) ) ){
$id = $id_basename . $id_count;
$node->id( $id );
$id_count++;
}
}
#print the new tree or continue processing it
}
Now all of the nodes in the tree will have some identifier associated with
it. I haven't tried the above code block so I can't verify that it works
perfectly. One issue I foresee is that node ids will be added to the tree in
the order in which they appear in @nodes; you will have to cross reference a
tree to interpret your results.
Others might have better solutions to this problem. Let me know if you have
questions.
Best,
Tom
More information about the Bioperl-l
mailing list