Skip to content

Commit 0bb755a

Browse files
committed
Limit custom UCells to genes present in the object
1 parent 072220a commit 0bb755a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

singlecell/resources/chunks/CustomUCell.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ for (datasetId in names(seuratObjects)) {
99
stop(paste0('Improper gene set: ', geneSet))
1010
}
1111

12-
toCalculate[[vals[1]]] <- unlist(strsplit(vals[2], split = ','))
12+
geneList <- unlist(strsplit(vals[2], split = ','))
13+
missingGenes <- dplyr::setdiff(geneList, rownames(seuratObj@assays[[assayName]]))
14+
if (length(missingGenes) > 0) {
15+
print(paste0('The following genes were not present in the object and will be skipped: ', paste0(missingGenes, collapse = ',')))
16+
}
17+
18+
geneList <- intersect(geneList, rownames(seuratObj@assays[[assayName]]))
19+
if (length(geneList) == 0) {
20+
print(paste0('No genes retained, skipping: ', vals[[1]]))
21+
}
22+
23+
toCalculate[[vals[1]]] <- geneList
1324
}
1425

1526
seuratObj <- UCell::AddModuleScore_UCell(seuratObj, features = toCalculate, storeRanks = storeRanks, assay = assayName)

0 commit comments

Comments
 (0)