开发者

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

开发者 https://www.devze.com 2023-03-26 16:07 出处:网络
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 t

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 开发者_如何学Pythonnot 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号