MarioniLab / DropletUtils

Clone of the Bioconductor repository for the DropletUtils package.
https://bioconductor.org/packages/devel/bioc/html/DropletUtils.html
56 stars 27 forks source link

write10xCounts converts NAs to 1e308 #69

Closed jasminelmah closed 3 years ago

jasminelmah commented 3 years ago

Hi! Thanks for writing DropletUtils, which has been super helpful towards my analyses.

My sparse matrix has NAs (I realize that sparse matrices are not supposed to have NAs, but this is unique to my particular analyses). When I use write10xCounts, it seems as if it converts these NAs to 1e308. Do you have any idea why this particular number? Should I just search and replace 1e308 with NA in my analysis?

Thanks for your help!

LTLA commented 3 years ago

I'm guessing you're using type="sparse", in which case I'm just calling Matrix::writeMM:

library(Matrix)
y <- rsparsematrix(100, 100, 0.1)
y[1,1]<-NA
writeMM(file="xxx.mtx", y)

Gives me:

%%MatrixMarket matrix coordinate real general
100 100 1001
1 1 1e308
4 1 1.7
5 1 -1.2
33 1 -.91
35 1 -.094
41 1 .58

Possibly a bug in Matrix, but I'm not sure that the Matrix Market format even supports NA values, in which case their treatment is at the discretion of the Matrix maintainers (or however C decides to format it).

I can ask, but the safest bet is to just replace NAs with some magic number (e.g., -1, or 1234567890, or something equally impossible in your data) before saving, and then replace the magic number when loading them back in.

jasminelmah commented 3 years ago

Thanks for your reply, that's really helpful to know. I'll go with the magic number strategy.