LuyiTian / scPipe

a pipeline for single cell RNA-seq data analysis
69 stars 24 forks source link

Use `drop = FALSE` when subsetting matrices #132

Closed PeteHaitch closed 3 years ago

PeteHaitch commented 3 years ago

This was failing for me when I only had 1 ERCC detected. In that case, colSums(assay(sce,"counts")[grepl("^ERCC-", rownames(sce)), ]) gives an error because it tries to compute the colSums() of a vector. E.g.,

x <- matrix(1:12, nrow = 3)

# Fails because x[1, ] is no longer a matrix.
colSums(x[1, ])
#> Error in colSums(x[1, ]): 'x' must be an array of at least two dimensions
x[1, ]
#> [1]  1  4  7 10
class(x[1, ])
#> [1] "integer"

# Succeeds because x[1, , drop = FALSE] is preserved as a matrix
colSums(x[1, , drop = FALSE])
#> [1]  1  4  7 10
x[1, , drop = FALSE]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
class(x[1, , drop = FALSE])
#> [1] "matrix" "array"

There are likely other instances in scPipe of this underlying bug, I've only fixed some I could immediately spot in calculate_QC_metrics().