Skip to content

Commit 93bb5df

Browse files
committed
Bugfix when ADT filter specified by no ADT data exist
1 parent 7ab62f3 commit 93bb5df

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

singlecell/resources/chunks/CommonFilters.R

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,34 @@ for (datasetId in names(seuratObjects)) {
4949
}
5050

5151
if (!is.null(saturation.ADT.min) && !is.null(seuratObj)) {
52-
if (!'Saturation.ADT' %in% names(seuratObj@meta.data)) {
53-
stop('Missing field: Saturation.ADT')
54-
}
55-
56-
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.ADT')
57-
cells <- which(x = expr >= saturation.ADT.min)
58-
if (length(cells) > 0){
59-
seuratObj <- seuratObj[, cells]
60-
print(paste0('After saturation.ADT.min filter: ', length(colnames(x = seuratObj))))
61-
if (ncol(seuratObj) == 0) {
62-
seuratObj <- NULL
63-
next
64-
}
65-
} else {
66-
print(paste0('No cells passing saturation.ADT.min filter'))
67-
seuratObj <- NULL
68-
next
69-
}
52+
if (! 'ADT' %in% names(seuratObj@assays)) {
53+
print('No ADT assay, skipping ADT saturation filters')
54+
} else {
55+
if (!'Saturation.ADT' %in% names(seuratObj@meta.data)) {
56+
stop('Missing field: Saturation.ADT')
57+
}
58+
59+
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.ADT')
60+
cells <- which(x = expr >= saturation.ADT.min)
61+
if (length(cells) > 0){
62+
seuratObj <- seuratObj[, cells]
63+
print(paste0('After saturation.ADT.min filter: ', length(colnames(x = seuratObj))))
64+
if (ncol(seuratObj) == 0) {
65+
seuratObj <- NULL
66+
next
67+
}
68+
} else {
69+
print(paste0('No cells passing saturation.ADT.min filter'))
70+
seuratObj <- NULL
71+
next
72+
}
73+
}
7074
}
7175

7276
if (!is.null(saturation.ADT.max) && !is.null(seuratObj)) {
77+
if (! 'ADT' %in% names(seuratObj@assays)) {
78+
print('No ADT assay, skipping ADT saturation filters')
79+
} else {
7380
if (!'Saturation.ADT' %in% names(seuratObj@meta.data)) {
7481
stop('Missing field: Saturation.ADT')
7582
}
@@ -88,6 +95,7 @@ for (datasetId in names(seuratObjects)) {
8895
seuratObj <- NULL
8996
next
9097
}
98+
}
9199
}
92100

93101
if (dropHashingFail && !is.null(seuratObj)) {

0 commit comments

Comments
 (0)