vchris_ngs vchris_ngs - 1 month ago 21
R Question

Pheatmap error Error in hclust(d, method = method) : NA/NaN/Inf in foreign function call (arg 11)

I am trying to create a heatmap with gene expression values with the package pheatmap in r. I have used the code numerous times and never had a problem untill today. It seems when I do the scale="row" , I end up with this error. I cannot create the z-scores. So probably some rows have no variability for which this is happening. How can I get rid of this. The matrix is having 1100 rown and 9 columns. Below is the code am using

data<-read.table("~path/DEGs_DESeq.txt",sep="\t")
data2<-as.matrix(data[,2:9])
data3<-data2[-1,]
samples<-data2[1,]
genes<-data[2:length(data2[,1]),1]
vett<-as.numeric(data3)
data4<-matrix(vett,length(genes),length(samples), dimnames=list(paste(genes),paste(samples)))
head(data4)

pheatmap(as.matrix(data4),col=bluered(200), scale="row", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.6, fontsize_row = 8,,fontsize_col = 10)


Error in hclust(d, method = method) :
NA/NaN/Inf in foreign function call (arg 11)


How can I get rid of this error?

Answer

I infact worked it out.. i had to remove the rows for which no SD was coming up while performing the z score calculation and it reconstructed the heatmap. Thanks