如何从R中的集群创建newick文件?

如何从R中的集群创建newick文件?,r,cluster-computing,hclust,R,Cluster Computing,Hclust,下面这个脚本运行得很好,可以获得包含大量数据集的集群,但我需要将集群放入一个newick文件或文本文件中,这样我就可以将它从R导出到其他编辑程序中,但我找不到将hclust转换为newick格式的方法,我该怎么做? 我觉得新的2PHYLO功能可以完成这项工作,但我们没有设法让它工作 我真的很感激你的帮助,因为我们到处都找不到解决办法=( datos您可以使用ape软件包中的write.tree函数来执行此操作。请尝试以下操作: library(ape) class(fit) # must be

下面这个脚本运行得很好,可以获得包含大量数据集的集群,但我需要将集群放入一个newick文件或文本文件中,这样我就可以将它从R导出到其他编辑程序中,但我找不到将hclust转换为newick格式的方法,我该怎么做? 我觉得新的2PHYLO功能可以完成这项工作,但我们没有设法让它工作

我真的很感激你的帮助,因为我们到处都找不到解决办法=(


datos您可以使用
ape
软件包中的
write.tree
函数来执行此操作。请尝试以下操作:

library(ape)
class(fit) # must be hclust class
my_tree <- as.phylo(fit) 
write.tree(phy=my_tree, file="exported_tree.newick") # look for the file in your working directory
库(ape)
等级(适合)#必须是hclust等级

my_tree我只通过以下转换步骤从热图中提取.nwk格式:

  • dendro-->hcclust-->phylo-->nwk
我知道这有点像黑客,但代码如下:

# Heatmap of data frame 'data' saved as 'heat'
heat <- heatmap.2(as.matrix(data))

# Extract dendrograms for rows and columns from 'heat'
row.dendro <- heat$rowDendrogram
col.dendro <- heat$colDendrogram

# Convert dendrograms to nwk (via .hcclust and .phylo formats!)
as.hclust (row.dendro)  ->row.hcclust
as.phylo  (row.hcclust) ->row.phylo
write.tree(row.phylo)   ->row.nwk

as.hclust (col.dendro)  ->col.hcclust
as.phylo  (col.hcclust) ->col.phylo
write.tree(col.phylo)   ->col.nwk
#数据框“data”的热图保存为“heat”
热排
as.hclust(col.dendro)->col.hcclust
as.phylo(col.hcclust)->col.phylo
write.tree(col.philo)->col.nwk

什么是newick文件?您是否检查过Bioconductor或库(sos);findFn(“write newick”)
?非常感谢Roman!!它工作正常!太棒了!函数来自ctc write(hc2Newick(fit),file='hclust.newick')@Spacedman newick格式(文件)。
# Heatmap of data frame 'data' saved as 'heat'
heat <- heatmap.2(as.matrix(data))

# Extract dendrograms for rows and columns from 'heat'
row.dendro <- heat$rowDendrogram
col.dendro <- heat$colDendrogram

# Convert dendrograms to nwk (via .hcclust and .phylo formats!)
as.hclust (row.dendro)  ->row.hcclust
as.phylo  (row.hcclust) ->row.phylo
write.tree(row.phylo)   ->row.nwk

as.hclust (col.dendro)  ->col.hcclust
as.phylo  (col.hcclust) ->col.phylo
write.tree(col.phylo)   ->col.nwk