如何在 R 中将树转换为树状图?

发布于 2024-12-05 11:18:59 字数 643 浏览 4 评论 0原文

如何将树(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

始于初秋 2024-12-12 11:18:59

这是一个老问题,但迄今为止没有足够的答案。由于我遇到了同样的问题,并且我的 googlefoo 无法找到答案,所以您可以:

library("ape")
cPhylo <- read.tree(file = "gc.tree")
dendrogram <- chronos(cPhylo)

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:

library("ape")
cPhylo <- read.tree(file = "gc.tree")
dendrogram <- chronos(cPhylo)
安人多梦 2024-12-12 11:18:59

这是一个老问题,但是之前的所有答案都要求在将树转换为树形图对象之前将树制作为超度量。

您可以使用 DECIPHER 包从 Newick 格式的文件中读取树状图对象:

dend <- ReadDendrogram(path_to_newick_file)

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:

dend <- ReadDendrogram(path_to_newick_file)
浅黛梨妆こ 2024-12-12 11:18:59

我认为问题实际上是你的“gc.tree”不是超度量的。确保从根部到每个尖端的距离相同。以下代码有效:

library('ape')
tree <- read.tree(text='(((A:4.2,B:4.2):3.1,C:7.3):6.3,D:13.6);')
is.ultrametric(tree)
is.binary.tree(tree)
is.rooted(tree)
hc <- as.hclust.phylo(tree)

但使树成为非超度量(注意 D 的分支长度):

tree <- read.tree(text='(((A:4.2,B:4.2):3.1,C:7.3):6.3,D:15);')

并且 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:

library('ape')
tree <- read.tree(text='(((A:4.2,B:4.2):3.1,C:7.3):6.3,D:13.6);')
is.ultrametric(tree)
is.binary.tree(tree)
is.rooted(tree)
hc <- as.hclust.phylo(tree)

but make the tree non-ultrametric (note D's branch length):

tree <- read.tree(text='(((A:4.2,B:4.2):3.1,C:7.3):6.3,D:15);')

and as.hclust.phylo will raise an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文