Skip to content

Commit 32a2965

Browse files
committed
Error handling for seurat filtering
1 parent d53e456 commit 32a2965

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

singlecell/resources/chunks/CommonFilters.R

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ for (datasetId in names(seuratObjects)) {
1111
}
1212

1313
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.RNA')
14-
seuratObj <- seuratObj[, which(x = expr >= saturation.RNA.min)]
15-
print(paste0('After saturation.RNA.min filter: ', length(colnames(x = seuratObj))))
16-
if (ncol(seuratObj) == 0) {
14+
cells <- which(x = expr >= saturation.RNA.min)
15+
if (length(cells) > 0){
16+
seuratObj <- seuratObj[, cells]
17+
print(paste0('After saturation.RNA.min filter: ', length(colnames(x = seuratObj))))
18+
if (ncol(seuratObj) == 0) {
19+
seuratObj <- NULL
20+
next
21+
}
22+
} else {
23+
print(paste0('No cells passing saturation.RNA.min filter'))
1724
seuratObj <- NULL
1825
next
1926
}
@@ -25,9 +32,16 @@ for (datasetId in names(seuratObjects)) {
2532
}
2633

2734
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.RNA')
28-
seuratObj <- seuratObj[, which(x = expr <= saturation.RNA.max)]
29-
print(paste0('After saturation.RNA.max filter: ', length(colnames(x = seuratObj))))
30-
if (ncol(seuratObj) == 0) {
35+
cells <- which(x = expr <= saturation.RNA.max)
36+
if (length(cells) > 0){
37+
seuratObj <- seuratObj[, cells]
38+
print(paste0('After saturation.RNA.max filter: ', length(colnames(x = seuratObj))))
39+
if (ncol(seuratObj) == 0) {
40+
seuratObj <- NULL
41+
next
42+
}
43+
} else {
44+
print(paste0('No cells passing saturation.RNA.max filter'))
3145
seuratObj <- NULL
3246
next
3347
}
@@ -39,9 +53,16 @@ for (datasetId in names(seuratObjects)) {
3953
}
4054

4155
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.ADT')
42-
seuratObj <- seuratObj[, which(x = expr >= saturation.ADT.min)]
43-
print(paste0('After saturation.ADT.min filter: ', length(colnames(x = seuratObj))))
44-
if (ncol(seuratObj) == 0) {
56+
cells <- which(x = expr >= saturation.ADT.min)
57+
if (length(cells) > 0){
58+
seuratObj <- seuratObj[, cells]
59+
print(paste0('After saturation.ADT.min filter: ', length(colnames(x = seuratObj))))
60+
if (ncol(seuratObj) == 0) {
61+
seuratObj <- NULL
62+
next
63+
}
64+
} else {
65+
print(paste0('No cells passing saturation.ADT.min filter'))
4566
seuratObj <- NULL
4667
next
4768
}
@@ -53,9 +74,16 @@ for (datasetId in names(seuratObjects)) {
5374
}
5475

5576
expr <- Seurat::FetchData(object = seuratObj, vars = 'Saturation.ADT')
56-
seuratObj <- seuratObj[, which(x = expr <= saturation.ADT.max)]
57-
print(paste0('After saturation.ADT.max filter: ', length(colnames(x = seuratObj))))
58-
if (ncol(seuratObj) == 0) {
77+
cells <- which(x = expr <= saturation.ADT.max)
78+
if (length(cells) > 0){
79+
seuratObj <- seuratObj[, cells]
80+
print(paste0('After saturation.ADT.max filter: ', length(colnames(x = seuratObj))))
81+
if (ncol(seuratObj) == 0) {
82+
seuratObj <- NULL
83+
next
84+
}
85+
} else {
86+
print(paste0('No cells passing saturation.ADT.max filter'))
5987
seuratObj <- NULL
6088
next
6189
}

0 commit comments

Comments
 (0)