我正在尝试使用 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”值,但没有,否则它也不应该适用于完整数据集。
任何人都可以帮我解决这个错误吗?或建议发生此错误的可能原因是什么?