ncborcherding / scRepertoire

A toolkit for single-cell immune profiling
https://www.borch.dev/uploads/screpertoire/
MIT License
302 stars 49 forks source link

Compare clonotype for specific T cell population using alluvial graph after ScRNAseq and ScTCRseq integration #295

Closed synatkeamsk closed 8 months ago

synatkeamsk commented 8 months ago

Dear Nick,

Hope you are doing great. Thank for creating a wonderful scRepertoire package. I am wondering whether you have a tutorial/code to compare T cell clones of specific single cell cluster using compareClonotypes after we integrate ScTCRseq and ScRNAseq. if you could help, that would be great. Thank you in advance!

Kind Regards,

Synat

ncborcherding commented 8 months ago

Hey Synat,

Thanks for reaching out - happy to help. I am not sure exactly what you are asking, so feel free to add more details.

You should be able to use clonalCompare() to look at only specific clusters and clones at the same time. To isolate specific clones - you can use the clones argument and for specific clusters, you should be able to use the samples argument.

Here would be an example:

clonalCompare(seuratObj, 
              clones = ("CVVSDNTGGFKTIF_CASSVRRERANTGELFF", "NA_CASSVRRERANTGELFF"),
              samples = c(1,2)
              cloneCall="aa", 
              graph = "alluvial")

Happy to help if I can get more info.

Nick

ncborcherding commented 8 months ago

Closing this for no activity, but will be happy to follow up when I get more info.

synatkeamsk commented 8 months ago

Dear Nick,

I apologized for not being able to respond to you because I was away from work outside the US. Hope you do not mind me. I meant that I would like to visualize the top 10 or top 20 TCR clone from CD4 or CD8 cluster using "alluvial plot" after integrating ScRNAseq and ScTCRseq.

For example, in the attached cluster image I got from your vignette, if I would like to visualize the top 10 TCR clone in cluster 3, what R codes should I use. Hope you get what would like to ask. Have a good day!

Best Regards,

synat

Capture

ncborcherding commented 8 months ago

No problem - you should be able to use clonalCompare() to do just that. Check out more info here

Here is an example to get the top 10 clones - you can use the samples argument to get only CD4 or only CD8 clusters

clonalCompare(seuratObj
              top.clones = 10, 
              samples = c("C5", "C4", ...)
              cloneCall="aa", 
              graph = "alluvial")

Hope that helps, Nick

synatkeamsk commented 8 months ago

Thanks, this is a great help. Wish you all the best and happy new year!

Best Regards, Synat

synatkeamsk commented 6 months ago

Hi Nick,

Hope you are well. I love your packages and thank for creating it for us. I have a couple of questions. Hope you could help again. I am wondering whether you could help with the following. I added the example (clusters = "C1") just to elaborate on my question and what I would like to get. Basically, I would like to compare the TCR clone from the specific cluster after integration, for example, "C1" between patient1 and patient2. Is there a way to do it in clonalCompare and add sth like in the following.

clonalCompare(seuratObj
              top.clones = 10, 
              clusters = "C1",
              samples = c("patient1", "patient2"),
              cloneCall="aa", 
              graph = "alluvial")

Also, with clonaloverlap, how could I reduce the size of number in the heatmap, I tried to read your tutorial, but could not find it yet (kindly review the attach-- TCR file**) and is it possible to get a full heatmap (I attached one example (full heatmap), if not that is fine)?

** I would like to calculate the TCR number of each cluster from each/individual patients, is it possible to do it with ScRepertoir package (Kindly review my attach example).

TCR

full heatmap

number of TCR clone

Hope you could help again. I appreciated all your support so far!

Kind Regards,

Synat,

ncborcherding commented 6 months ago

Hey Synat,

Hope things are going well.

Basically, I would like to compare the TCR clone from the specific cluster after integration, for example, "C1" between patient1 and patient2. Is there a way to do it in clonalCompare and add sth like in the following.

I think the easiest way to do this would be to subset your Seurat object by patients.

Seurat_patient1 <- subset(seuratObj, orig.ident = "patient1")
Seurat_patient2 <- subset(seuratObj, orig.ident = "patient2")
clonalCompare(Seurat_patient1 
              top.clones = 10, 
              cloneCall="aa", 
              graph = "alluvial")

Also, with clonaloverlap, how could I reduce the size of number in the heatmap, I tried to read your tutorial, but could not find it yet (kindly review the attach-- TCR file) and is it possible to get a full heatmap (I attached one example (full heatmap), if not that is fine)?

There is a raw count method for clonalOverlap() that you can use to get the exact numbers.

clonalOverlap(seuratObj, 
              cloneCall = "aa", 
              method = "raw")

I would like to calculate the TCR number of each cluster from each/individual patients, is it possible to do it with ScRepertoir package (Kindly review my attach example).

You could try summarizing your meta data and counting total clones and unique clontypes, then plotting them using ggplot().

clonotype.summary <- seuratObj@meta.data %>%
                               group_by(orig.ident, seurat_clusters) %>%
                               summarise(total.cells = n(),
                                         unique.clones = n_distinct(CTaa))

Hope that helps, let me know if you have any other questions.

Nick

synatkeamsk commented 6 months ago

Hi Nick,

Thank you, Nick. I would like to share my workflow with scripts I used. I acknowledged that you helped with these codes especially matching barcodes.

If we use the following code to generate alluvial plot from patient1 and paient2 using combined contig (no integration with ScRNAseq), we know only the overall TCR clone, but we do not know whether the shared clones are from CD4 or CD8 at all.

compareClonotypes(combined, numbers = 10,        
                  samples = c("patient1", "patient2"),   
                  cloneCall = "aa", 
graph = "alluvial") 

alluvial

I would like to do alluvial plot between two patients from specific CD4 or CD8 cluster. So I perform integration as using the following workflow and my strategy is to subset the specific cluster from integrated object of ScRNAseq and ScTCRseq.

# Match barcodes
seurat.obj.T<- readRDS("umap.obj.pc15.rds")
cell.barcodes.T <- rownames(seurat.obj.T[[]])
cell.barcodes.T <- stringr::str_split(cell.barcodes.T, "_", simplify = TRUE)[,1] #This is removing the _1 at the end of the barcodes)
cell.barcodes.T <- paste0(seurat.obj.T$orig.ident, "_", cell.barcodes.T) #This is adding the prefix of the orig.ident to the barcodes, assuming that is the sample ids
seurat.obj.T <- RenameCells(seurat.obj.T, new.names = cell.barcodes.T)

# Integration of seurat T cell subcluster and ScTCR
integrated.obj.T <- combineExpression(combined, seurat.obj.T, 
                            cloneCall = "gene", 
                            group.by = "type", 
                            proportion = FALSE, 
                            cloneTypes = c(Single=1, Small=5, Medium=20, Large=100, Hyperexpanded=500))

#Shared clone from Cluster 1. 
#Subset cluster 1 
cluster.1 <- subset(integrated.obj.T, idents = c("1"))
view(cluster.1@meta.data)_

#compare clone of patient1 and patient2 from cluster1 
compareClonotypes(cluster.1, numbers = 10,         # top 10 abundance
                  samples = c("patient1", "patient2"),   
                  cloneCall = "CTaa", 
                  graph = "alluvial") 

error: Error in `[.data.frame`(meta, , split.by) : undefined columns selected

I would like to highlight that after integrating ScTCRseq and ScRNAseq, I could see barcode, CTgene, CTnt, CTaa, CTstrict, Frequency and cloneType (kindly review the attach). so in this case, I specify "CTaa" in cloneCall. I tried "aa" too but it did not work.

Could you kindly help me again to check whether it is the right way to subset the cluster from integrated obj and used compareClonotypes function to examine the shared clone between patient1 and patient1 from cluster1. Why am I getting error (error: Error in [.data.frame(meta, , split.by) : undefined columns selected). Could you suggest sth else. Apologise that I am trying to learn and thank you for your help.

Kind Regards,

Synat

amino acid

synatkeamsk commented 6 months ago

Hi Nick,

Hope you could help suggest whether my approach is okay to subset the Seurat cluster and compare T cell clone between two patients as described above. Hope you could help!

Kind Regards,

Synat

ncborcherding commented 6 months ago

Hey Synat,

Apologies was traveling and your question got lost in my inbox.

I would like to do alluvial plot between two patients from specific CD4 or CD8 cluster. So I perform integration as using the following workflow and my strategy is to subset the specific cluster from integrated object of ScRNAseq and ScTCRseq.

For this to work you will need to explicitly call the split.by variable to get clones at the individual patient level.

compareClonotypes(cluster.1, numbers = 10,      
                  split.by = "patient.column", #Modify here for what the name is in the meta data
                  samples = c("patient1", "patient2"),   
                  cloneCall = "CTaa", 
                  graph = "alluvial") 

I would like to highlight that after integrating ScTCRseq and ScRNAseq, I could see barcode, CTgene, CTnt, CTaa, CTstrict, Frequency and cloneType (kindly review the attach). so in this case, I specify "CTaa" in cloneCall. I tried "aa" too but it did not work.

In terms of CTaa vs aa - this may be a version issue. At somepoint in scRepertoire development, we allowed users to enter either.

Hope that helps, Nick

synatkeamsk commented 6 months ago

Thanks, Nick. It worked perfectly well. I have one last question. In scatterClonotype function, Could we track the clone ID (e.g., CAGTAMRGATNKLIF_NA etc) in the plot or label the clone ID of interest. My PI really liked the package, but they would like to see what ID they are in scatterClonotype particle ones that are hyperexpanded. Kindly review the example that I circled in red. Thanks for your enormous help.

Kind Regards,

Synat,

Clone_ID

ncborcherding commented 6 months ago

Hey Synat,

You can use exportTable to get the clones that are in the scatterplot.

Nick