This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error with pheatmap - 'from' must be a finite number

I need to prepare a heatmap on top 36 genes with pheatmap but I keep getting this error:

Error in seq.int(rx[1L], rx[2L], length.out = nb) :
    'from' must be a finite number
In addition:
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

This is my code:

top_36 <- head(results(dds, contrast = c ("strain", "mut", "wt")), n=36)

mat <- counts(dds, normalized = T)[rownames(top_36), ]
mat.z <- t(apply(mat, 1, scale))
colnames(mat.z) <- coldata$sample
df <- as.data.frame(colData(dds)[,c("hour","strain")])

pheatmap(mat.z, annotation_col = df)

Can anyone point me to the error?

pheatmap r deseq2

Show us the output to

mat.z[1:10,1:10]
any(is.infinite(mat.z))
any(is.infinite(mat.z))
[1] FALSE

That answers half of what I asked you. Where's the output to the first command?

Please report

# all(is.finite(dist(mat.z)))  # removed as pointed by Ram
all(is.finite(dist(mat.z)))
pheatmap(mat.z, cluster_rows = FALSE, cluster_cols = FALSE)
pheatmap(mat.z)

You already have the response to the first one, so there was no need to include that.

1 answer

Errors and warnings are clear, we can reproduce them with this simple example

Somewhere pheatmap is getting a minimum value excluding NA values, when all values are NA, min returns Inf:

min(c(NA,NA,NA), na.rm = TRUE)
# [1] Inf
# Warning message:
#   In min(c(NA, NA, NA), na.rm = TRUE) :
#   no non-missing arguments to min; returning Inf

Then when we want to get a sequence of integers with from set to Inf, as expected, we get an error:

seq.int(from = Inf, to = 10)
# Error in seq.int(from = Inf, to = 10) : 'from' must be a finite number

Thanks, how should I proceed?

I am not familiar with deseq data, but if it makes sense, remove rows/columns that have only NAs.

#remove rows
x<- mat.z[ rowSums(is.na(mat.z)) != ncol(mat.z), ]
#remove cols
mat.z.clean <- x[, colSums(is.na(mat.z)) != nrow(mat.z) ]

Log in to answer this question.