JEFworks-Lab / STdeconvolve

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

'x' must be an array of at least two dimensions error #56

Open wangjiawen2013 opened 4 months ago

wangjiawen2013 commented 4 months ago

Hi, When I ran the following code:

data(mOB)
pos <- mOB$pos ## x and y positions of each pixel
cd <- mOB$counts ## matrix of gene counts in each pixel
annot <- mOB$annot

mobCorpus1 <- preprocess(t(cd),
                       extractPos = FALSE, # optional argument
                       selected.genes = c("Bpifb9a", "Bpifb9b", "Col1a1", "Dcn", "Cyp2a5", "Sox11"),
                       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,
                       plot = TRUE)

An error occurred:

Initial genes: 15928 Initial pixels: 262

- Using genes in `selected.genes` for corpus.

 6 genes are present in dataset.

- Removing poor pixels with <= 100 reads

- Removing genes with <= 10 reads across pixels and detected in <= 1 pixels

Error in base::rowSums(x, na.rm = na.rm, dims = dims, ...): 'x'必需是阵列,而且至少得有两个维度
Traceback:

1. preprocess(t(cd), extractPos = FALSE, selected.genes = c("Bpifb9a", 
 .     "Bpifb9b", "Col1a1", "Dcn", "Cyp2a5", "Sox11"), nTopGenes = 3, 
 .     genes.to.remove = c("^Trmt"), removeAbove = 0.95, removeBelow = 0.05, 
 .     min.reads = 10, min.lib.size = 100, min.detected = 1, ODgenes = TRUE, 
 .     nTopOD = 100, od.genes.alpha = 0.05, gam.k = 5, verbose = TRUE, 
 .     plot = TRUE)
2. cleanCounts(counts = t(counts), min.reads = min.reads, min.lib.size = min.lib.size, 
 .     min.detected = min.detected, plot = plot, verbose = FALSE)
3. Matrix::rowSums(counts)
4. Matrix::rowSums(counts)
5. base::rowSums(x, na.rm = na.rm, dims = dims, ...)
6. stop("'x' must be an array of at least two dimensions")

But when I set selected.genes to NA, it ran sucessfully. So how to set selected. genes ?

bmill3r commented 3 months ago

Hi @wangjiawen2013,

My guess is that the genes you are using and the filtering parameters are resulting in a matrix with no genes remaining. I would check that the genes you are choosing are present in the dataset above the thresholds you are using.

Hope this helps, Brendan