Skip to content

Commit 8b67f38

Browse files
committed
More automatic capture of TCR updates
1 parent 7306b2d commit 8b67f38

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

singlecell/resources/chunks/ClassifyTNKByExpression.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ for (datasetId in names(seuratObjects)) {
1111
printName(datasetId)
1212
seuratObj <- readSeuratRDS(seuratObjects[[datasetId]])
1313

14-
if (!'HasCDR3Data' %in% names(seuratObj@meta.data)) {
14+
if (.ShouldReapplyTcr(seuratObj)) {
1515
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj)
1616
}
1717

singlecell/resources/chunks/Functions.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,13 @@ if (Sys.getenv('SEURAT_MAX_THREADS') != '') {
191191

192192
future::plan(strategy = fs, workers = mt)
193193
}
194+
195+
.ShouldReapplyTcr <- function(seuratObj) {
196+
return (
197+
!'HasCDR3Data' %in% names(seuratObj@meta.data) ||
198+
'TRB_Segments' %in% names(seuratObj@meta.data) ||
199+
!'TRB_WithProductive' %in% names(seuratObj@meta.data) ||
200+
# This purpose of this is to catch a previous bug where every cell was tagged as (NP)
201+
(sum(seuratObj@meta.data$TRB_WithProductive, pattern = '(NP)' == sum(!is.na(seuratObj@meta.data$TRB_WithProductive))))
202+
)
203+
}

singlecell/resources/chunks/IdentifyAndStoreActiveClonotypes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ for (datasetId in names(seuratObjects)) {
1111
printName(datasetId)
1212
seuratObj <- readSeuratRDS(seuratObjects[[datasetId]])
1313

14-
if (! 'TRB_WithProductive' %in% names(seuratObj@meta.data)) {
14+
if (.ShouldReapplyTcr(seuratObj)) {
1515
print('Re-running AppendTcr to add segment columns')
1616
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = TRUE)
1717
}

singlecell/resources/chunks/PredictTcellActivation.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ for (datasetId in names(seuratObjects)) {
1111
printName(datasetId)
1212
seuratObj <- readSeuratRDS(seuratObjects[[datasetId]])
1313

14-
if (! 'TRB_WithProductive' %in% names(seuratObj@meta.data)) {
14+
if (.ShouldReapplyTcr(seuratObj)) {
1515
print('Re-running AppendTcr to add segment columns')
1616
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = TRUE)
1717
}
@@ -24,11 +24,6 @@ for (datasetId in names(seuratObjects)) {
2424
}
2525
}
2626

27-
if (! 'TRB_Segments' %in% names(seuratObj@meta.data)) {
28-
print('Re-running AppendTcr to add segment columns')
29-
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = TRUE)
30-
}
31-
3227
seuratObj <- RIRA::PredictTcellActivation(seuratObj)
3328

3429
saveData(seuratObj, datasetId)

singlecell/resources/chunks/SummarizeTCellActivation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ for (datasetId in names(seuratObjects)) {
1111
printName(datasetId)
1212
seuratObj <- readSeuratRDS(seuratObjects[[datasetId]])
1313

14-
if (!'HasCDR3Data' %in% names(seuratObj@meta.data)){
14+
if (.ShouldReapplyTcr(seuratObj)){
1515
seuratObj <- seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = FALSE)
1616
}
1717

singlecell/resources/chunks/UpdateSeuratPrototype.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ for (datasetId in names(seuratObjects)) {
2121
seuratObj <- Rdiscvr::QueryAndApplyCdnaMetadata(seuratObj)
2222
}
2323

24+
if (applyTCR) {
25+
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = allowMissingTcr)
26+
}
27+
2428
if (runRira) {
2529
seuratObj <- RIRA::Classify_ImmuneCells(seuratObj, maxBatchSize = maxBatchSize, retainProbabilityMatrix = retainProbabilityMatrix)
2630
seuratObj <- RIRA::Classify_TNK(seuratObj, maxBatchSize = maxBatchSize, retainProbabilityMatrix = retainProbabilityMatrix)
2731
seuratObj <- RIRA::Classify_Myeloid(seuratObj, maxBatchSize = maxBatchSize, retainProbabilityMatrix = retainProbabilityMatrix)
2832
}
2933

30-
if (applyTCR) {
31-
seuratObj <- Rdiscvr::DownloadAndAppendTcrClonotypes(seuratObj, allowMissing = allowMissingTcr)
32-
}
33-
3434
if (runTNKClassification) {
3535
# ClassifyTNKByExpression will fail without this, so ignore allowMissingTcr
3636
if (!'HasCDR3Data' %in% names(seuratObj@meta.data)) {

0 commit comments

Comments
 (0)