Last active
November 1, 2022 11:16
-
-
Save j-andrews7/c2a6c11379d1f6ad402eb8a1e09cd113 to your computer and use it in GitHub Desktop.
A simple function to add 10x V(D)J info to a Seurat object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
# 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), ] | |
# Only keep the barcode and clonotype columns. | |
# We'll get additional clonotype info from the clonotype table. | |
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment