Skip to content

Commit 9bd148b

Browse files
committed
Clarify TCR filter
1 parent 3ffb456 commit 9bd148b

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed
Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
totalPassed <- 0
2-
for (datasetId in names(seuratObjects)) {
3-
printName(datasetId)
4-
seuratObj <- readRDS(seuratObjects[[datasetId]])
5-
6-
cellsToKeep <- NULL
7-
for (locus in c('A', 'B', 'D', 'G')) {
8-
fieldName <- paste0('TR', locus)
9-
10-
cdr3ForLocus <- cdr3s[grepl(cdr3s, pattern = paste0(fieldName, ':'))]
11-
if (length(cdr3ForLocus) == 0) {
12-
next
13-
}
14-
15-
cdr3ForLocus <- gsub(cdr3ForLocus, pattern = paste0(fieldName, ':'), replacement = '')
16-
matchingCells <- sapply(seuratObj@meta.data[[fieldName]], function(x){
17-
values <- unlist(strsplit(x, split = ','))
18-
return(length(intersect(values, cdr3ForLocus)) > 0)
19-
})
20-
21-
if (sum(matchingCells) == 0) {
22-
next
23-
}
24-
25-
matchingCells <- colnames(seuratObj)[matchingCells]
26-
if (all(is.null(cellsToKeep))) {
27-
cellsToKeep <- matchingCells
28-
} else {
29-
cellsToKeep <- unique(c(cellsToKeep, matchingCells))
30-
}
2+
for (datasetId in names(seuratObjects)) {
3+
printName(datasetId)
4+
seuratObj <- readRDS(seuratObjects[[datasetId]])
5+
6+
cellsToKeep <- NULL
7+
for (locus in c('A', 'B', 'D', 'G')) {
8+
fieldName <- paste0('TR', locus)
9+
10+
cdr3ForLocus <- cdr3s[grepl(cdr3s, pattern = paste0(fieldName, ':'))]
11+
if (length(cdr3ForLocus) == 0) {
12+
next
3113
}
32-
14+
15+
if (!(fieldName %in% names(seuratObj@meta.data))) {
16+
stop(paste0('Missing field: ', fieldName))
17+
}
18+
19+
cdr3ForLocus <- gsub(cdr3ForLocus, pattern = paste0(fieldName, ':'), replacement = '')
20+
matchingCells <- sapply(seuratObj@meta.data[[fieldName]], function(x){
21+
values <- unlist(strsplit(x, split = ','))
22+
return(length(intersect(values, cdr3ForLocus)) != 0)
23+
})
24+
25+
if (sum(matchingCells) == 0) {
26+
next
27+
}
28+
29+
matchingCells <- colnames(seuratObj)[matchingCells]
3330
if (all(is.null(cellsToKeep))) {
34-
print('There were no matching cells')
31+
cellsToKeep <- matchingCells
3532
} else {
36-
seuratObj <- subset(seuratObj, cells = cellsToKeep)
37-
saveData(seuratObj, datasetId)
38-
totalPassed <- totalPassed + 1
33+
cellsToKeep <- unique(c(cellsToKeep, matchingCells))
3934
}
35+
}
36+
37+
if (all(is.null(cellsToKeep))) {
38+
print('There were no matching cells')
39+
} else {
40+
seuratObj <- subset(seuratObj, cells = cellsToKeep)
41+
#saveData(seuratObj, datasetId)
42+
totalPassed <- totalPassed + 1
43+
}
4044

41-
# Cleanup
42-
rm(seuratObj)
43-
gc()
45+
# Cleanup
46+
rm(seuratObj)
47+
gc()
4448
}
4549

4650
if (totalPassed == 0) {
47-
addErrorMessage('No cells remained in any seurat objects after subsetting')
51+
addErrorMessage('No cells remained in any seurat objects after subsetting')
4852
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class Provider extends AbstractPipelineStepProvider<SingleCellStep
2020
public Provider()
2121
{
2222
super("TcrFilter", "TCR-Based Filter", "CellMembrane/Seurat", "This will run standard Seurat processing steps to normalize and scale the data.", Arrays.asList(
23-
SeuratToolParameter.create("cdr3s", "CDR3s To Keep", "A list of CDR3 sequences where locus prefixes the AA sequence (i.e. TRB:XXXXXX or TRA:YYYYYYY). These should not contain commas. Any cell matching any of these CDR3s will be kept. If that cell has multiple chains for a locus (i.e. 'CASSXXXXX,CASSYYYYY'), then only one of these needs to match for that cell to be kept.", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
23+
SeuratToolParameter.create("cdr3s", "CDR3s To Keep", "A comma- or newline-delimited list of CDR3 sequences where locus prefixes the AA sequence (i.e. TRB:XXXXXX or TRA:YYYYYYY). These should not contain commas. Any cell matching any of these CDR3s will be kept. If that cell has multiple chains for a locus (i.e. 'CASSXXXXX,CASSYYYYY'), then only one of these needs to match for that cell to be kept.", "sequenceanalysis-trimmingtextarea", new JSONObject(){{
2424
put("height", 150);
2525
put("delimiter", ",");
2626
}}, null).delimiter(",")

0 commit comments

Comments
 (0)