I'm trying to run scran::quickCluster on an scRNA expression matrix (the class of the matrix is data frame). Code inside the quickCluster function returns the following error:
> scuttle::normalizeCounts(scRNA_matrix, librarySizeFactors(scRNA_matrix))
Error in .local(x, ...) : size factors should be positive
Running some checks on my matrix shows all its values are finite and positive:
> any(sapply(scRNA_matrix, is.infinite))
[1] FALSE
> sum(scRNA_matrix < 0)
[1] 0
However, running some checks on the result of librarySizeFactors(scRNA_matrix) shows some values are infinite:
> lsf <- librarySizeFactors(scRNA_matrix)
> any(lsf, is.infinite)
[1] TRUE
> sum(lsf < 0)
[1] 0
I assume this is what's causing the error, but I don't understand how to prevent it. Why might librarySizeFactors return non-finite values? If the solution is to remove certain samples from the dataset, where should I start looking? I can't easily share a reprex but the dataset I'm using is Pancreas from Tabula Sapiens, transposed (cell barcodes in rows, genes in columns) and contains mostly 0s.
Thank you in advance! (And apologies that these are likely very amateur questions, I'm extremely new to working with single cell RNA data, as this is actually an intermediary step in a project based on DNA methylation data.)
Hi Peter, thank you for the suggestions and clear response. The problem was caused by the data being transposed the wrong way (a package I need to use after this one requires cells in rows & genes in columns, for some reason, so I put the data in that format). I've also since learned to use SingleCellExperiment objects and everything is running much more smoothly!