Skip to content

Commit e9db732

Browse files
committed
Allow hashing to be run retroactively
1 parent 292dfb5 commit e9db732

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

singlecell/resources/chunks/RunCellHashing.R

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@ for (datasetId in names(seuratObjects)) {
22
seuratObj <- seuratObjects[[datasetId]]
33
seuratObjects[[datasetId]] <- NULL
44

5-
if (!(datasetId %in% names(featureData))) {
6-
stop(paste0('No hashing information found for datasetId: ', datasetId))
7-
}
5+
for (id in unique(seuratObj$DatasetId)) {
6+
if (!(id %in% names(featureData))) {
7+
stop(paste0('No hashing information found for datasetId: ', id))
8+
}
89

9-
callFile <- featureData[[datasetId]]
10-
if (!is.null(callFile)) {
11-
seuratObj <- cellhashR::AppendCellHashing(seuratObj, barcodeCallFile = callFile, barcodePrefix = datasetId)
12-
} else {
13-
# Add empty columns to keep objects consistent
14-
seuratObj$HTO <- c('NotUsed')
15-
seuratObj$HTO.Classification <- c('NotUsed')
10+
callFile <- featureData[[id]]
11+
if (!is.null(callFile)) {
12+
seuratObj <- cellhashR::AppendCellHashing(seuratObj, barcodeCallFile = callFile, barcodePrefix = id)
13+
} else {
14+
# Add empty columns to keep objects consistent
15+
if (!'HTO' %in% names(seuratObj@meta.data)) {
16+
seuratObj$HTO <- c('NotUsed')
17+
} else {
18+
seuratObj$HTO <- as.character(seuratObj$HTO)
19+
seuratObj$HTO[seuratObj$DatasetId == id] <- 'NotUsed'
20+
seuratObj$HTO <- naturalsort::naturalfactor(seuratObj$HTO)
21+
}
22+
23+
if (!'HTO.Classification' %in% names(seuratObj@meta.data)) {
24+
seuratObj$HTO.Classification <- c('NotUsed')
25+
} else {
26+
seuratObj$HTO.Classification <- as.character(seuratObj$HTO.Classification)
27+
seuratObj$HTO.Classification[seuratObj$DatasetId == id] <- 'NotUsed'
28+
seuratObj$HTO.Classification <- naturalsort::naturalfactor(seuratObj$HTO.Classification)
29+
}
30+
}
1631
}
1732

1833
newSeuratObjects[[datasetId]] <- seuratObj

0 commit comments

Comments
 (0)