Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DESeq2 "NA values are not allowed" error when any(is.na(counts)) = FALSE

I have a count matrix that had NA values in it.

I set them to 0 using

counts[is.na(counts)] <- 0

Which then successfully sets them to 0 and I can see this.

But then when I try to use

DESeqDataSetFromMatrix(counts, colData = data.frame(colnames(counts)), design = ~1)

I get the error

Error in validObject(.Object) : invalid class “DESeqDataSet” object: NA values are not allowed in the count matrix

Which seems pretty clear but I don't understand because I set all NA values to 0 and now if I do

any(is.na(counts))

I get FALSE.

Any help is greatly appreciated thankyou!

like image 733
Jack Henry Avatar asked Nov 02 '25 03:11

Jack Henry


1 Answers

If you only have NAs, it should work.

library(DESeq2)

counts = matrix(rnbinom(1000,mu=50,size=1),100,10)
colnames(counts) = paste0("c",1:10)
counts[sample(length(counts),10)] = NA
counts[is.na(counts)] <- 0

DESeqDataSetFromMatrix(counts, colData = data.frame(colnames(counts)), design = ~1)

If you have infinite values, it gives you a slightly different error:

counts = matrix(rnbinom(1000,mu=100,size=1),100,10)
colnames(counts) = paste0("c",1:10)
counts[1] = 2.5e9

DESeqDataSetFromMatrix(counts, colData = data.frame(colnames(counts)), design = ~1)

It looks like this:

converting counts to integer mode
Error in validObject(.Object) : 
  invalid class “DESeqDataSet” object: NA values are not allowed in the count matrix
In addition: Warning message:
In mde(x) : NAs introduced by coercion to integer range

Error comes about because you cannot convert the large numbers to integer:

max(counts)
[1] 8007375876

as.integer(max(counts))
[1] NA
Warning message:
NAs introduced by coercion to integer range 

And this is smaller than the maximum allowed:

.Machine$integer.max
[1] 2147483647

For analysis purpose, since you are more interested in the difference between genes, one way is to scale the matrix down

DESeqDataSetFromMatrix(round(counts/2), colData = data.frame(colnames(counts)), design = ~1)
like image 136
StupidWolf Avatar answered Nov 03 '25 16:11

StupidWolf