Skip to content

Commit 67fa418

Browse files
committed
Bugfix to subsetting negative cells from seurat objects
1 parent ec49a52 commit 67fa418

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

singlecell/resources/chunks/CommonFilters.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,19 @@ for (datasetId in names(seuratObjects)) {
138138
}
139139

140140
tryCatch({
141-
cells <- Seurat::WhichCells(seuratObj, expression = HTO.Classification=='Negative')
142-
if (length(cells) == 0) {
141+
negativeCells <- Seurat::WhichCells(seuratObj, expression = HTO.Classification=='Negative')
142+
if (length(negativeCells) == 0) {
143+
print('All cells have hashing data')
144+
} else if (length(negativeCells) == ncol(seuratObj)) {
143145
print(paste0('There were no cells remaining after dropping cells where hashing is negative'))
144146
seuratObj <- NULL
145147
} else {
146-
seuratObj <- subset(seuratObj, cells = cells, invert = TRUE)
148+
expectedCells <- ncol(seuratObj) - length(negativeCells)
149+
seuratObj <- subset(seuratObj, cells = negativeCells, invert = TRUE)
147150
print(paste0('After removing cells with negative hashing calls: ', ncol(seuratObj)))
151+
if (ncol(seuratObj) != expectedCells) {
152+
stop(paste0('The subset for negative hashing cells did not work as expected. Expected cells: ', expectedCells, ', actual: ', ncol(seuratObj))
153+
}
148154
}
149155
}, error = function(e){
150156
if (!is.null(e) && e$message == 'Cannot find cells provided') {

0 commit comments

Comments
 (0)