pheatmap scale="row" giving Error in hclust(d, method = method) : NA/NaN/Inf in foreign function call

ivivek_ngs picture ivivek_ngs · May 20, 2015 · Viewed 14.6k times · Source

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 rows and 9 columns. My code:

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

ivivek_ngs picture ivivek_ngs · Oct 28, 2016

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