简体   繁体   中英

Finding Sum of Branch Lengths in a Phylo / Phylo4 object in R

The problem I am working on right now requires that, given a phylogenetic tree object in R and a particular tip of that tree, I need to find the sum of all the branch lengths up to that tip. Finding this for either a phylo or a phylo4 object would be equivalent, as I can freely convert between the two kinds of object.

I imagine that this should not be to complicated. The package " phylobase " provides a function for finding all the ancestors of a prespecified node, and we can access the edge lengths on a tree using @edge.lengths for a phylo4 object.

However, I'm having trouble accessing the edges that I need without resorting to string manipulation on the edge labels. Does anyone know of a more direct way to solve this problem?

I think distRoot() with the "patristic" option from the adephylo package will do what you want. Only slightly modified from the example:

library(ape)
library(phylobase)
library(adephylo)

## make a tree
x <- as(rtree(50),"phylo4")
D <- distRoot(x, method = "patristic")
D <- as.data.frame(D)

## plot these distances along with the tree
temp <- phylo4d(x, D)
table.phylo4d(temp, show.node=FALSE, cex.lab=.6)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM