I have the results of VDJ profile (5') and the gene expression profile (3') from 10X, I already generate the cluster based on gene expression profiles, how do I include the VDJ profile with gene expression profile? I could not find any examples online.
Thank you
We don't have any examples online and won't be able to add some in the near future. However, you can save the clonotype information in the object meta data (see the AddMetaData function). This way you can reference it during any downstream analyses in the object. This is how we analyze VDJ data from 10X in our lab
Which file of the Cell Ranger output of VDJ profile should I load to add to the metadata?
@hemadelon
Here is a function I wrote to add to add my 10x TCR clonotype data to the metadata of a Seurat object. I keep the clonotype ID in addition to the AA sequence since the clonotype ID may not be unique if samples are combined. I presume B cell VDJ should be similar.
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)
}
This is really helpful
Thank you so much
On Wed, Jun 5, 2019 at 4:31 PM Jared Andrews notifications@github.com
wrote:
@hemadelon https://github.com/hemadelon
Here is a function I wrote to add to add my 10x TCR clonotype data to the
metadata of a Seurat object. I keep the clonotype ID in addition to the AA
sequence since the clonotype ID may not be unique if samples are combined.
I presume B cell VDJ should be similar.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) }—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/satijalab/seurat/issues/1435?email_source=notifications&email_token=ABTLCXZOQZBDYGEQ5G3AI4DPZAPBDA5CNFSM4HINDJ2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXA5SUA#issuecomment-499243344,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABTLCXYYLPAI3ABSMV6L4UDPZAPBDANCNFSM4HINDJ2A
.
@j-andrews7 Thanks so much! I really appreciate it.
@j-andrews7 thanks for this vignette. I expanded it further to work with my own data.
The detailed tutorial can be found at my Biostars post.
This was a great help! Took your function and (1) fixed the issue of defined tcr_location vs. used tcr_folder and (2) added in some extra metadata from the vdj analysis (v_gene, j_gene, chain, etc.). Thanks!
@christensensm Care to share? I've been too lazy to devote much time to parsing out the genes, but it'd be super helpful to have.
Of course @j-andrews7! See the below altered code.
The line tcr <-tcr[,c("barcode","raw_clonotype_id","chain","v_gene","d_gene","j_gene")] can be changed to include whatever columns you want from the vdj result file. Other changes were needed as well but this will get you colontype id, v d and j genes, and cdr3aa sequences added as metadata to your seurat object.
```add_clonotype <- function(tcr_folder, 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","chain","v_gene","d_gene","j_gene")]
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:7)]
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)
}```
Hell
Of course @j-andrews7! See the below altered code.
The linetcr <-tcr[,c("barcode","raw_clonotype_id","chain","v_gene","d_gene","j_gene")]can be changed to include whatever columns you want from the vdj result file. Other changes were needed as well but this will get you colontype id, v d and j genes, and cdr3aa sequences added as metadata to your seurat object.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","chain","v_gene","d_gene","j_gene")] 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:7)] 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) }```
@christensensm
How do you then export the data all together?
Thanks
Most helpful comment
@j-andrews7 thanks for this vignette. I expanded it further to work with my own data.
The detailed tutorial can be found at my Biostars post.