JEFworks-Lab / STdeconvolve

Reference-free cell-type deconvolution of multi-cellular spatially resolved transcriptomics data
http://jef.works/STdeconvolve/
99 stars 11 forks source link

Error when loading counts matrix in "additional features" preprocessing step #2

Closed djgroso closed 2 years ago

djgroso commented 2 years ago

Hello,

Hope you are all doing well. I've had success running MERINGUE and implementing the "getting started" tutorial for STdeconvolve with our data. I had no issues loading in our counts (cd) matrix (large dgCMatrix) until the pre-processing step in the "additional features" tutorial:

corpus1 <- preprocess(t(cd),
                       alignFile = NA, # if there is a file to adjust pixel coordinates this can be included.
                       extractPos = FALSE, # optional argument
                       selected.genes = NA, # 
                       nTopGenes = 3, # remove the top 3 expressed genes (genes with most counts) in dataset
                       genes.to.remove = c("^Trmt"), # ex: remove tRNA methyltransferase genes (gene names that begin with "Trmt")
                       removeAbove = 0.95, # remove genes present in 95% or more of pixels
                       removeBelow = 0.05, # remove genes present in 5% or less of pixels
                       min.reads = 10, # minimum number of reads a gene must have across pixels
                       min.lib.size = 100, # minimum number of reads a pixel must have to keep (before gene filtering)
                       min.detected = 1, # minimum number of pixels a gene needs to have been detected in
                       ODgenes = TRUE, # feature select for over dispersed genes
                       nTopOD = 100, # number of top over dispersed genes to use, otherwise use all that pass filters if `NA`
                       od.genes.alpha = 0.05, # alpha param for over dispersed genes
                       gam.k = 5, # gam param for over dispersed genes
                       verbose = TRUE)

I get the error: Error in t.default(cd) : argument is not a matrix

Was wondering if you had any insight as to why it does not recognize the cd counts matrix considering that it was working for the other analyses-- can share what our matrix looks like if need be.

Thanks in advance!

bmill3r commented 2 years ago

Thank you for pointing this out!

I looked into it on my end testing:

library(STdeconvolve)
data("mOB")
cd <- as(mOB$counts, "dgCMatrix")
dat <- base::t(cd)

and got the same error:

Error in t.default(cd) : argument is not a matrix

So it seems like the base transpose function t() doesn't like sparse matrices for some reason.

So for now, to run the code, you can try: t(as.matrix(cd)) as the input matrix.

Let me know if you're still having issues.

djgroso commented 2 years ago

This worked-- thanks for your help!