Question: How to calculate sum of branch lengths between specified leaves from a Newick tree?
0
4.8 years ago by
Kame20
UK
Kame20 wrote:

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.

KS.

newick tree phylogenetics • 3.4k views
modified 4.8 years ago by David W4.7k • written 4.8 years ago by Kame20
0
4.8 years ago by
Pavel Senin1.9k
Los Alamos, NM
Pavel Senin1.9k wrote:

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;`

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

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!

0
4.8 years ago by
David W4.7k
New Zealand
David W4.7k wrote:

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.

Content
Help
Access

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