如何在 R 中将树转换为树状图?
如何将树(Java 程序的输出)转换为 R 中的树形图?
目前,我正在使用此处给出的建议将树转换为 Newick 格式< /a>.然后我使用 R 中的 ape
包来读取 Newick 格式的树:
library("ape")
cPhylo <- read.tree(file = "gc.tree")
最后我使用 R 中的 as.hclust
将树转换为树状图:
dendrogram <- as.hclust(gcPhylo)
然而,树状图需要分支长度。尽管我插入了分支长度,但我收到一条错误消息,指出该树不是超度量的:
as.hclust.phylo(gcPhylo) 中的错误:树不是超度量的
我想我在插入分支长度时做错了什么。
我还有其他方法可以遵循吗?或者如何在将树转换为 Newick 格式时插入分支长度?相等的分支长度就可以了。
How can I convert a tree (which is the output of my Java program) to a dendrogram in R?
Currently, I am converting the tree into the Newick format, using the suggestion given here. And then I use the ape
package in R to read the Newick-formatted tree:
library("ape")
cPhylo <- read.tree(file = "gc.tree")
Finally I use as.hclust
in R to convert the tree into a dendrogram:
dendrogram <- as.hclust(gcPhylo)
However, the dendrogram requires the branch lengths. Although I insert the branch lengths, I am getting an error saying that the tree is not ultrametric:
Error in as.hclust.phylo(gcPhylo) : the tree is not ultrametric
I guess I am doing something wrong while inserting the branch lengths.
Is there any other way that I can follow? Or how can I insert the branch lengths while converting the tree into the Newick format? Equal branch lengths would be fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个老问题,但迄今为止没有足够的答案。由于我遇到了同样的问题,并且我的 googlefoo 无法找到答案,所以您可以:
This is an old question, but it has inadequate answers so far. Since I had the same problem, and my googlefoo was having problems finding the answer, here you go:
这是一个老问题,但是之前的所有答案都要求在将树转换为树形图对象之前将树制作为超度量。
您可以使用 DECIPHER 包从 Newick 格式的文件中读取树状图对象:
This is an old question, but all of the previous answers require the tree to be made ultrametric before being converted to a dendrogram object.
You can use the DECIPHER package to read a dendrogram object from a Newick formatted file:
我认为问题实际上是你的“gc.tree”不是超度量的。确保从根部到每个尖端的距离相同。以下代码有效:
但使树成为非超度量(注意 D 的分支长度):
并且 as.hclust.phylo 将引发错误。
I think the problem is in fact that your "gc.tree" isn't ultrametric. Make sure that the distance from the root to each tip is the same. The following code works:
but make the tree non-ultrametric (note D's branch length):
and as.hclust.phylo will raise an error.