How to calculate sum of branch lengths between specified leaves from a Newick tree?
2
0
Entering edit mode
9.9 years ago
Kame ▴ 20

Dear all,

I would like to find a way to calculate the total branch lengths between all specified leaves from a newick file, and the first node common to them all.

I am grateful for ideas on how to do this. I hope this is clear enough.

Many thanks for your help.

KS.

phylogenetics tree Newick Phylogenetics Tree • 7.0k views
ADD COMMENT
0
Entering edit mode
9.9 years ago
Pavel Senin ★ 1.9k

I believe that bioPerl has that solved, bioPython may help too, for the total length they have a built-in method:

my $total_length = $tree->total_branch_length;
ADD COMMENT
0
Entering edit mode

Many thanks for your fast reply. Does it also work for a given, specific list of leaves and not the whole tree? Thanks.

ADD REPLY
0
Entering edit mode

Likely, there is no way to provide a list of nodes as a parameter. I would approach this via pruning the tree instance by splicing not-needed nodes out at first and computing the sum second. But I am not sure how well this will preserve the branches lengths (however that manual says it does with "-preserve_lengths => 1"). Hope this helps. You are welcome!

ADD REPLY
0
Entering edit mode
9.9 years ago
David W 4.9k

the R package apeprovides a function, cophenetic, for this. It calculates a square matrix for all tips and you can slice out the comparisons you are interested in:

library(ape)
data(bird.families)
cophenetic(bird.families)['Eurostopodidae', 'Passeridae']

There is also dist.nodes for any pair of nodes (one of which can be a tip) and mrca to find the first-shared node for two tips, but it's probably easier just to calculate the whole matrix. You can read in trees with read.tree.

ADD COMMENT

Login before adding your answer.

Traffic: 2231 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6