【问题标题】:Error while extracting dendrogram from a heat map从热图中提取树状图时出错
【发布时间】:2016-07-28 16:38:18
【问题描述】:

我正在尝试使用 heatmap.2 函数从二进制矩阵创建热图,并从热图中提取树状图,并将树状图保存为 newick 文件格式。矩阵的行是基因组,列是基因。

为此,我正在运行以下代码。

library(ggdendro)
library(ape)
library(gplots)
library(vegan)

profile <-as.data.frame(read.delim("profile_file.txt",row.names=1,sep="\t", as.is=T))

dist_func<-function(x) vegdist(x,"jaccard",binary=TRUE)

hclust_func<-function(x) hclust(x,method="ward.D2")

heat<-heatmap.2(as.matrix(profile),Rowv=TRUE,Colv=TRUE,distfun=dist_func,hclustfun=hclust_func,trace="none")

row.dendro<-heat$rowDendrogram

row.hcclust<-as.hclust(row.dendro)

row.phylo<-as.phylo(row.hcclust)

write.tree(phy=row.phylo, file="tree_file.nwk")

此代码在我尝试运行时运行良好,它将完整配置文件。但是当我减少基因列的数量时,我在尝试将树状图转换为 hclust 对象的步骤中遇到错误。

row.hcclust<-as.hclust(row.dendro)

错误:all(vapply(s, is.integer, NA)) 不是 TRUE

我尝试在我的数据集中查找任何“NA”值,但没有,否则它也不应该适用于完整数据集。

谁能帮我解决这个错误?或建议发生此错误的可能原因是什么?

【问题讨论】:

标签: r heatmap dendrogram hclust


【解决方案1】:

heatmap.2 使用 hclust 构建树状图。如果您想要的只是树状图,则没有理由使用它。如果原因是您想要树状图的排序,只需使用dendextend package 中的排序即可获得所需的顺序。否则,请继续使用 hclust。方法如下:

library(ape); library(vegan); 
library(magrittr) # for the pipes: %>%

profile <- as.data.frame(read.delim("profile_file.txt",row.names=1,sep="\t", as.is=T))
row_hclust <- profile %>% as.matrix %>% t %>% vegdist("jaccard",binary=TRUE) %>% hclust(method="ward.D2")
row.phylo <- as.phylo(row_hclust)
write.tree(phy=row.phylo, file="tree_file.nwk")

【讨论】:

    猜你喜欢
    • 2019-03-25
    • 1970-01-01
    • 2017-06-20
    • 2016-12-08
    • 2017-12-07
    • 1970-01-01
    • 2011-10-06
    • 2013-03-01
    • 1970-01-01
    相关资源
    最近更新 更多