scuttle:: librarySizeFactors returning non-finite values
1
0
Entering edit mode
behr201 • 0
@336ed33e
Last seen 9 months ago
United Kingdom

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.)

normalizeCounts scran librarySizeFactors scuttle scRNAseq • 458 views
ADD COMMENT
2
Entering edit mode
Peter Hickey ▴ 630
@petehaitch
Last seen 15 days ago
Walter and Eliza Hall Institute of Mediā€¦

It's hard to know without a reproducible example, but I suspect you have one or more columns that are all zeros in scRNA_matrix. This will lead to library size factors that are zero and the error message Error in .local(x, ...) : size factors should be positive, e.g.,

suppressPackageStartupMessages(library(scuttle))
x <- matrix(
  c(0, 1, 4, 12,
    3, 0, 0, 7,
    0, 0, 0, 0),
  ncol = 3)
x
#>      [,1] [,2] [,3]
#> [1,]    0    3    0
#> [2,]    1    0    0
#> [3,]    4    0    0
#> [4,]   12    7    0
librarySizeFactors(x)
#> [1] 1.888889 1.111111 0.000000
normalizeCounts(x, librarySizeFactors(x))
#> Error in .local(x, ...): size factors should be positive

I recommend having a read through https://osca.bioconductor.org/ to learn how to analyse scRNA-seq data with Bioconductor tools. For example, you're doing a few things with your analysis that are making your life harder than it needs to be, e.g.,

  • It's better to store your count data as matrix or sparse matrix rather than a data frame. Ideally, wrap that matrix up in a SingleCellExperiment for better integration with Bioconductor packages like scuttle, scater, scran, etc.
  • Don't transpose the data that way; cells should be in columns and genes (features) in rows
  • Some of your code doesn't appear to be valid R code, e.g., any(lsf, is.infinite).
ADD COMMENT
0
Entering edit mode

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!

ADD REPLY

Login before adding your answer.

Traffic: 468 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6