我正在寻找一种在R中将系统发生树(Newick格式或类"phylo")转换为数据帧的方法。我们的目标是获得一个很好的概述,哪些提示从树的每个节点下降。有没有人有这个问题的经验?
我可以从一个系统树中获得所有的tip标签,或者从一个节点中获得所有的后代节点,但我无法获得属于某个节点的tip标签。
#for a random tree x
x <- rtree(10, tip.label = LETTERS[1:10])
#get all tip labels by asking for tree information
> x
Phylogenetic tree with 10 tips and 9 internal nodes.
Tip labels:
H, G, D, B, I, C, ...
Rooted; includes branch lengths.
#descendant nodes from a node
test <- phytools::getDescendants(x, node=5, curr=NULL)
#the package ggphylo seemed to have the answer to my problem, but it is no longer supported (last updates were in 2012)
ggphylo::tree.as.data.frame(x)(我认为转换为dataframe是最简单的方法,但如果您知道从节点获取后代提示的另一种方法,我愿意接受任何可能的解决方案)
发布于 2019-07-16 08:29:50
您是否在寻找边缘表(即显示每个tip和节点之间的连接的表)?您可以使用以下命令在phylo对象中直接访问它:
## The edge table
x$edge您可以在following SO question中找到它的更奇特的可视化。
发布于 2019-07-16 13:32:05
phytools包中的函数compute.mr将一个发展史转换为它的矩阵表示,这可能就是您想要的。
x <- rtree(10, tip.label = LETTERS[1:10])
phytools::compute.mr(x, type = "matrix")
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
# H "1" "1" "1" "0" "0" "0" "0" "0"
# E "1" "1" "1" "0" "0" "0" "0" "0"
# C "1" "1" "0" "1" "1" "0" "0" "0"
# I "1" "1" "0" "1" "1" "0" "0" "0"
# J "1" "1" "0" "1" "0" "0" "0" "0"
# F "1" "0" "0" "0" "0" "1" "0" "0"
# A "1" "0" "0" "0" "0" "1" "0" "0"
# D "0" "0" "0" "0" "0" "0" "1" "0"
# G "0" "0" "0" "0" "0" "0" "1" "1"
# B "0" "0" "0" "0" "0" "0" "1" "1" 发布于 2019-07-23 19:22:29
谢谢你的建议。我找到了一个同事,找到了我想要的答案。ape包中的函数prop.part很好地概述了每个节点的所有提示。结果是一个列表而不是一个数据帧,但它做到了这一点。
list_all_tips <- c(prop.part(tree, check.labels = TRUE)) https://stackoverflow.com/questions/57041303
复制相似问题