ncborcherding / scRepertoire

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

van diagram of number of clones shared between clusters #170

Closed EAC-T closed 2 years ago

EAC-T commented 2 years ago

Dear all,

I'm using seurat and I have 4 clusters of T cells, I was wondering how I can show the number of pair wise shared TCR clones between my clusters?

Thank you a lot

ncborcherding commented 2 years ago

Hey EAC-T,

There is no built-in function to make a venn diagram. However, the clonalOverlap() function will calculate the clonal overlap/similarity between clusters.

You can get the raw number of clones overlap as a data frame (which you can then use to make a venn diagram) with the following:

clonalOverlap <- function(seuratObj, 
                                             method = "raw", 
                                             exportTable = TRUE)

I'd also recommend checking out the other methods built into clonalOverlap(), particularly "morisita" and "jaccard" are ideal for adjusting for large difference in clonotype repertoire sizes.

Thanks, Nick

EAC-T commented 2 years ago

Hi Nick, when I type clonalOverlap <- function(seuratObj, method = "raw", exportTable = TRUE) It looks as if the function is not over, R is still waiting for my input, I'm not an expert at coding so I'm not sure what is happening.

ncborcherding commented 2 years ago

Sorry should be

clonalOverlap(seuratObj, method = "raw", exportTable = TRUE)

EAC-T commented 2 years ago

it is still not working, anyway, this is what I'm trying to do, I have a seurat object with 4 clusters, (1,2,3,4), in the metadata they are named under "new.ident", I used overlap3to4<-Reduce(intersect,list(combined2[["3"]]$CTaa,combined2[["4"]]$CTaa)) to find overlap between cluster 3 and 4, and then used highlight clonotype and dimplot to visualize them on the tSNE.

I now repeated that for all the clusters, however, instead of plotting them on the tSNE, I want to visualize that there are some clones that go from 1-->2-->3 and some from 2-->3 or 2-->4 and so on. What is the way of doing so?

I tried alluvial plot, with y-axes = c("1","2","3","4") as of my new.ident of the 4 clusters and didn't work.

How can I achieve that? any idea?

EAC-T commented 2 years ago

Hi Nick ,

I figured it out. compareClonotypes(combined2, numbers = 10, cloneCall="aa", graph = "alluvial", exportTable = F) is doing what I want, which is finding a clone that is shared between the clusters.

One more question, it's just that I haven't used your package and now I need to do revision for the paper. How can I not plot the legend (sequence of clone?) Also, is there a way where I can plot the same thing but split by "orig.ident"? I have WT and KO, I merged them and got the 4 clusters. Now I want to show them separately, is that possible?

Thank you a lot for this amazing tool!

ncborcherding commented 2 years ago

Hey EAC-T,

What version of scRepertoire are you using? I'd make sure you are using the newest github version with:

devtools::install_github("ncborcherding/scRepertoire")

How can I not plot the legend (sequence of clone?) You can modify the plot with ggplot grammar.

compareClonotypes() + 
     guides(fill = "none")

Also, is there a way where I can plot the same thing but split by "orig.ident"? I have WT and KO, I merged them and got the 4 clusters. Now I want to show them separately, is that possible? In the current version there is a split.by parameter that will allow you to set "orig.ident"

Nick

EAC-T commented 2 years ago

I'm using v1.2, before I update, would this still work? overlap3to4<-Reduce(intersect,list(combined2[["3"]]$CTaa,combined2[["4"]]$CTaa)) This is to find the overlap between cluster 3 and 4, this is the most important piece for my analysis, in the new version this line of code will still work as expected?

Thank you

EAC-T commented 2 years ago

Hi Nick, I just installed the new version and then typed this:

compareClonotypes(combined2, clonotypes =interest2,cloneCall="aa", graph = "alluvial", exportTable = F,split.by = "orig.ident") but didn't split accordingly, am I doing anything wrong?

ncborcherding commented 2 years ago
overlap3to4<-Reduce(intersect,list(combined2[["3"]]$CTaa,combined2[["4"]]$CTaa))

The above code should still work. However, there has been some changes in the clonal organization in combineTCR() from version 1.2 to 1.5.2, so the numbers may vary slightly from your previous analysis.

but didn't split accordingly, am I doing anything wrong?

compareClonotypes(combined2, clonotypes =interest2,cloneCall="aa", graph = "alluvial", exportTable = F,split.by = "orig.ident")

What is the output? Are there errors or warnings?

EAC-T commented 2 years ago

Hi Nick,

Here is what I did: seurat<- SetIdent(object =seurat, value ="new.ident") ## new.ident are 1,2,3,4 because I have 4 T cell cluster combined3 <- expression2List(seurat,split.by = "new.ident") overlap3to4<-Reduce(intersect,list(combined3[["3"]]$CTaa,combined3[["4"]]$CTaa)) ## I used this to find the shared clonetypes interest<-c("CALSDYNQGKLIF_CASSVGGQDTQYF", ...) this is the list of clonetypes that I'm interested in

compareClonotypes(combined3, clonotypes = interest, cloneCall="aa", graph = "alluvial", exportTable = F, split.by = "orig.ident")

Here I'm getting a graph, with 4 columns that correspond to my new.ident clusters (1,2,3,4) by it's not splitting. I expect to see 2 graphs, with 4 columns each. I'm interested in knowing which clone belong to which orig.ident (WT or KO)

Does that make sense?

How can I acheive that?

Thank you

ncborcherding commented 2 years ago
compareClonotypes(combined3, clonotypes = interest, cloneCall="aa", graph = "alluvial", exportTable = F, split.by = "orig.ident")

split.by is a parameter used to sort the Seurat object in order to produce the columns. The code above is asking to make 2 columns by your original identity (WT and KO).

Currenlty there is no support for faceting - you could subset the seurat object first and use 2 seurat objects (WT and KO) to produce the 2 graphs.