Skip to content

Commit c7d9707

Browse files
committed
Allow CommonFilters to drop entire objects if too few cells remain
1 parent e094e6d commit c7d9707

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

singlecell/resources/chunks/CommonFilters.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for (datasetId in names(seuratObjects)) {
66

77
print(paste0('Initial cells for dataset ', datasetId, ': ', ncol(seuratObj)))
88

9-
if (!is.null(saturation.RNA.min)) {
9+
if (!is.null(saturation.RNA.min) && !is.null(seuratObj)) {
1010
if (!'Saturation.RNA' %in% names(seuratObj@meta.data)) {
1111
stop('Missing field: Saturation.RNA')
1212
}
@@ -27,7 +27,7 @@ for (datasetId in names(seuratObjects)) {
2727
}
2828
}
2929

30-
if (!is.null(saturation.RNA.max)) {
30+
if (!is.null(saturation.RNA.max) && !is.null(seuratObj)) {
3131
if (!'Saturation.RNA' %in% names(seuratObj@meta.data)) {
3232
stop('Missing field: Saturation.RNA')
3333
}
@@ -48,7 +48,7 @@ for (datasetId in names(seuratObjects)) {
4848
}
4949
}
5050

51-
if (!is.null(saturation.ADT.min)) {
51+
if (!is.null(saturation.ADT.min) && !is.null(seuratObj)) {
5252
if (!'Saturation.ADT' %in% names(seuratObj@meta.data)) {
5353
stop('Missing field: Saturation.ADT')
5454
}
@@ -69,7 +69,7 @@ for (datasetId in names(seuratObjects)) {
6969
}
7070
}
7171

72-
if (!is.null(saturation.ADT.max)) {
72+
if (!is.null(saturation.ADT.max) && !is.null(seuratObj)) {
7373
if (!'Saturation.ADT' %in% names(seuratObj@meta.data)) {
7474
stop('Missing field: Saturation.ADT')
7575
}
@@ -90,7 +90,7 @@ for (datasetId in names(seuratObjects)) {
9090
}
9191
}
9292

93-
if (dropHashingFail) {
93+
if (dropHashingFail && !is.null(seuratObj)) {
9494
if (!'HTO.Classification' %in% names(seuratObj@meta.data)) {
9595
stop('Missing field: HTO.Classification')
9696
}
@@ -111,7 +111,7 @@ for (datasetId in names(seuratObjects)) {
111111
})
112112
}
113113

114-
if (dropDoubletFinder) {
114+
if (dropDoubletFinder && !is.null(seuratObj)) {
115115
if (!'scDblFinder.class' %in% names(seuratObj@meta.data)) {
116116
stop('Missing field: scDblFinder.class')
117117
}
@@ -132,7 +132,7 @@ for (datasetId in names(seuratObjects)) {
132132
})
133133
}
134134

135-
if (dropHashingNegatives) {
135+
if (dropHashingNegatives && !is.null(seuratObj)) {
136136
if (!'HTO.Classification' %in% names(seuratObj@meta.data)) {
137137
stop('Missing field: HTO.Classification')
138138
}
@@ -153,7 +153,7 @@ for (datasetId in names(seuratObjects)) {
153153
})
154154
}
155155

156-
if (dropNullScGateConsensus) {
156+
if (dropNullScGateConsensus && !is.null(seuratObj)) {
157157
if (!'scGateConsensus' %in% names(seuratObj@meta.data)) {
158158
stop('Missing field: scGateConsensus')
159159
}
@@ -168,6 +168,13 @@ for (datasetId in names(seuratObjects)) {
168168
}
169169
}
170170

171+
if (!is.null(dropThreshold) && !is.null(seuratObj)) {
172+
if (ncol(seuratObj) < dropThreshold) {
173+
print(paste0('Dropping object since remaining cells were below threshold: ', ncol(seuratObj)))
174+
seuratObj <- NULL
175+
}
176+
}
177+
171178
if (!is.null(seuratObj)) {
172179
saveData(seuratObj, datasetId)
173180
totalPassed <- totalPassed + 1

singlecell/src/org/labkey/singlecell/pipeline/singlecell/CommonFilters.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public Provider()
5454
}}, false),
5555
SeuratToolParameter.create("dropNullScGateConsensus", "Drop Cells Without scGateConsensus", "If checked, any cell that lacks a call from scGateConsensus will be dropped.", "checkbox", new JSONObject(){{
5656
put("checked", true);
57-
}}, false)
57+
}}, false),
58+
SeuratToolParameter.create("dropThreshold", "Drop Dataset Threshold", "If fewer than this number of cells remain, skip the entire dataset", "ldk-integerfield", new JSONObject(){{
59+
put("minValue", 0);
60+
}}, 25)
5861
), null, null);
5962
}
6063

0 commit comments

Comments
 (0)