【发布时间】: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