LTLA / scuttle

Clone of the Bioconductor repository for the scuttle package.
https://bioconductor.org/packages/devel/bioc/html/scuttle.html
9 stars 7 forks source link

calculateAverage() throw error 'rowMeans' : size factors should be positive #24

Open boutrys opened 1 year ago

boutrys commented 1 year ago

Hello all,

I was running

kept <- calculateAverage(counts(sce_filtered)) lost <- calculateAverage(counts(sce_rejected))

Works fine for kept cells, but lost throw me the following error

Error in h(simpleError(msg, call)) : erreur d'�valuation de l'argument 'x' lors de la s�lection d'une m�thode pour la fonction 'rowMeans' : size factors should be positive

My guess is that in calculateAverage() we do

exprs <- normalizeCounts(x, size.factors=scaling, center.size.factors=FALSE, log=FALSE) ave.cell <- rowMeans(exprs) * mean(scaling) # equivalent to calculateAverage().

but why does normalizeCounts() introduce non-positive terms

I've constructed sce_filtered and sce_rejected as follow

sce <- SingleCellExperiment(assays = list(counts = counts_matrix), colData = full_coldata, rowData = gene_annot )

qc.df <- perCellQCMetrics(sce, subsets=list(Mito=mito_genes)) qc.lib <- isOutlier(qc.df$sum, log = TRUE, type ="lower") # Determine which values are outliers based on the median absolute deviation (MAD) qc.expr <- isOutlier(qc.df$detected, log = TRUE, type = "lower") qc.mito <- isOutlier(qc.df$subsets_Mito_percent, type = "higher")

Discared cells

discard <- qc.lib | qc.expr | qc.mito # Cells to discard

rejected_cell <- sce$Cell_ID[which(sce$discard)] idx_rejected <- which(colnames(counts_matrix) %in% rejected_cell) counts_rejected <- counts_matrix[ , ..idx_rejected] full_coldata_rejected <- full_coldata[which(full_coldata$Cell_ID %in% rejected_cell) , ] sce_rejected <- SingleCellExperiment(assays = list(counts = counts_rejected), colData = full_coldata_rejected, rowData = gene_annot)

only kepts cells

filtered_cell <- sce$Cell_ID[which(!sce$discard)] idx_filtered <- which(colnames(counts_matrix) %in% filtered_cell) counts_filtered <- counts_matrix[ , ..idx_filtered] full_coldata_filtered <- full_coldata[which(full_coldata$Cell_ID %in% filtered_cell) , ] sce_filtered <- SingleCellExperiment(assays = list(counts = counts_filtered), colData = full_coldata_filtered, rowData = gene_annot)

If you need any additionnal informations let me know :)

Thanks in advance for your answer

LTLA commented 1 year ago

Hmm. I'm guessing that you have all-zero columns in sce_rejected, and this causes size factors of zero to be computed. Try removing them before calculateAverage(); such columns are unlikely to be very informative anyway.