3

This script below runs nicely to get the cluster with a huge data set, but I need to get the cluster into a newick file or a text file so I can export it from R to other editing programs but I can't find a way to get the hclust into a newick format, how can I do it? I feel the new2phylo function may do the job but we did not manage to make it work.

I would really appreciate your help as we have searched everywhere and can't find a solution =(

datos <- read.table("morphclustersred.csv",header=T,sep="\t")
head(datos)
distfunc <- function(x) daisy(x,metric="gower")
d <- distfunc(datos)
hclustfunc <- function(x) hclust(x, method="complete")
fit <- hclustfunc(d)
plot(fit)
plot(fit, labels=datos$Species,main='Morphological Clustering')
rect.hclust(fit, k=5, border="red")
4

2 回答 2

7

您可以使用包中的write.tree函数来完成ape。尝试这个:

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

希望这可以帮助。

于 2014-03-29T18:38:01.027 回答
4

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

  • dendro --> hcclust --> phylo --> nwk

我知道这有点 hack,但这里是代码:

# 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
于 2014-11-27T22:44:36.490 回答