Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Nov 30, 2023
1 parent 28143ae commit 04246ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
43 changes: 23 additions & 20 deletions R/TCR.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ DownloadAndAppendTcrClonotypes <- function(seuratObject, outPath = tempdir(), dr
#' @param downloadPath The output filepath for per-dataset files
#' @param allowMissing If true, samples missing data will be skipped. Otherwise, the function will fail.
#' @param cellRangerType The type of cellranger data to download. Either all_contig_annotations.csv or filtered_contig_annotations.csv
#' @param dropConflictingVJSegments If true, any TRB rows with a TRA/D V/J segments will as dropped, as are TRA rows with TRB/G segments
#' @export
CreateMergedTcrClonotypeFile <- function(seuratObj, outputFile, overwriteTcrTable = F, downloadPath = tempdir(), allowMissing = FALSE, cellRangerType = 'filtered_contig_annotations.csv'){
CreateMergedTcrClonotypeFile <- function(seuratObj, outputFile, overwriteTcrTable = F, downloadPath = tempdir(), allowMissing = FALSE, cellRangerType = 'filtered_contig_annotations.csv', dropConflictingVJSegments = TRUE){
if (all(is.null(seuratObj[['BarcodePrefix']]))){
stop('Seurat object lacks BarcodePrefix column')
}
Expand Down Expand Up @@ -95,28 +96,30 @@ CreateMergedTcrClonotypeFile <- function(seuratObj, outputFile, overwriteTcrTabl
dat$raw_clonotype_id <- ifelse(dat$is_cell == "true" & dat$productive == "true", yes = paste0(barcodePrefix,'_', dat$raw_clonotype_id), no = "")

# Check for TRA/B segments that dont match the chain:
sel <- dat$chain == 'TRA' & grepl(dat$v_gene, pattern = 'BV|GV')
if (sum(sel) > 0) {
print(paste0('Dropping TRA rows with a BV/GV genes, total: ', sum(sel)))
dat <- dat[!sel]
}
if (dropConflictingVJSegments) {
sel <- dat$chain == 'TRA' & grepl(dat$v_gene, pattern = 'BV|GV')
if (sum(sel) > 0) {
print(paste0('Dropping TRA rows with a BV/GV genes, total: ', sum(sel)))
dat <- dat[!sel,]
}

sel <- dat$chain == 'TRA' & grepl(dat$j_gene, pattern = 'BJ|GJ')
if (sum(sel) > 0) {
print(paste0('Dropping TRA rows with a BJ/GJ genes, total: ', sum(sel)))
dat <- dat[!sel]
}
sel <- dat$chain == 'TRA' & grepl(dat$j_gene, pattern = 'BJ|GJ')
if (sum(sel) > 0) {
print(paste0('Dropping TRA rows with a BJ/GJ genes, total: ', sum(sel)))
dat <- dat[!sel,]
}

sel <- dat$chain == 'TRB' & grepl(dat$v_gene, pattern = 'AV|DV')
if (sum(sel) > 0) {
print(paste0('Dropping TRB rows with a AV/DV genes, total: ', sum(sel)))
dat <- dat[!sel]
}
sel <- dat$chain == 'TRB' & grepl(dat$v_gene, pattern = 'AV|DV')
if (sum(sel) > 0) {
print(paste0('Dropping TRB rows with a AV/DV genes, total: ', sum(sel)))
dat <- dat[!sel,]
}

sel <- dat$chain == 'TRB' & grepl(dat$v_gene, pattern = 'AJ|DJ')
if (sum(sel) > 0) {
print(paste0('Dropping TRB rows with a AJ/DJ genes, total: ', sum(sel)))
dat <- dat[!sel]
sel <- dat$chain == 'TRB' & grepl(dat$v_gene, pattern = 'AJ|DJ')
if (sum(sel) > 0) {
print(paste0('Dropping TRB rows with a AJ/DJ genes, total: ', sum(sel)))
dat <- dat[!sel,]
}
}

write.table(dat,
Expand Down
5 changes: 4 additions & 1 deletion man/CreateMergedTcrClonotypeFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04246ec

Please sign in to comment.