Skip to content

Instantly share code, notes, and snippets.

@j-andrews7
Last active November 1, 2022 11:16
Show Gist options
  • Select an option

  • Save j-andrews7/c2a6c11379d1f6ad402eb8a1e09cd113 to your computer and use it in GitHub Desktop.

Select an option

Save j-andrews7/c2a6c11379d1f6ad402eb8a1e09cd113 to your computer and use it in GitHub Desktop.

Revisions

  1. j-andrews7 revised this gist Jun 5, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion seurat_add_vdj_metadata.R
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    add_clonotype <- function(tcr_location, seurat_obj){
    tcr <- read.csv(paste(tcr_folder,"filtered_contig_annotations.csv", sep=""))

    # Remove the -1 at the end of each barcode, and subsets so only the first line of each barcode is kept.
    # Remove the -1 at the end of each barcode.
    # Subsets so only the first line of each barcode is kept,
    # as each entry for given barcode will have same clonotype.
    tcr$barcode <- gsub("-1", "", tcr$barcode)
    tcr <- tcr[!duplicated(tcr$barcode), ]

  2. j-andrews7 revised this gist Jun 5, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion seurat_add_vdj_metadata.R
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,6 @@ add_clonotype <- function(tcr_location, seurat_obj){

    # Only keep the barcode and clonotype columns.
    # We'll get additional clonotype info from the clonotype table.
    # This one runs the risk of yielding fragments that might not be the consensus for the clonotype.
    tcr <- tcr[,c("barcode", "raw_clonotype_id")]
    names(tcr)[names(tcr) == "raw_clonotype_id"] <- "clonotype_id"

  3. j-andrews7 created this gist Jun 5, 2019.
    28 changes: 28 additions & 0 deletions seurat_add_vdj_metadata.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    add_clonotype <- function(tcr_location, seurat_obj){
    tcr <- read.csv(paste(tcr_folder,"filtered_contig_annotations.csv", sep=""))

    # Remove the -1 at the end of each barcode, and subsets so only the first line of each barcode is kept.
    tcr$barcode <- gsub("-1", "", tcr$barcode)
    tcr <- tcr[!duplicated(tcr$barcode), ]

    # Only keep the barcode and clonotype columns.
    # We'll get additional clonotype info from the clonotype table.
    # This one runs the risk of yielding fragments that might not be the consensus for the clonotype.
    tcr <- tcr[,c("barcode", "raw_clonotype_id")]
    names(tcr)[names(tcr) == "raw_clonotype_id"] <- "clonotype_id"

    # Clonotype-centric info.
    clono <- read.csv(paste(tcr_folder,"clonotypes.csv", sep=""))

    # Slap the AA sequences onto our original table by clonotype_id.
    tcr <- merge(tcr, clono[, c("clonotype_id", "cdr3s_aa")])

    # Reorder so barcodes are first column and set them as rownames.
    tcr <- tcr[, c(2,1,3)]
    rownames(tcr) <- tcr[,1]
    tcr[,1] <- NULL

    # Add to the Seurat object's metadata.
    clono_seurat <- AddMetaData(object=seurat_obj, metadata=tcr)
    return(clono_seurat)
    }