# knitr::knit_hooks$set(optipng = knitr::hook_optipng) # knitr::opts_chunk$set(optipng = '-o7') knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(fig.align = "center") knitr::opts_chunk$set(fig.width = 12) knitr::opts_chunk$set(fig.height = 6) library(immunarch) # source("../R/testing.R") # immdata = load_test_data() data(immdata)
Repertoire overlap is the most common approach to measure repertoire similarity. It is achieved by computation of specific statistics on clonotypes shared between given repertoires, also called "public" clonotypes. immunarch
provides several indices:
- number of public clonotypes (.method = "public"
) - a classic measure of overlap similarity.
overlap coefficient (.method = "overlap"
) - a normalised measure of overlap similarity. It is defined as the size of the intersection divided by the smaller of the size of the two sets.
Jaccard index (.method = "jaccard"
) - it measures similarity between finite sample sets, and is defined as the size of the intersection divided by the size of the union of the sample sets.
Tversky index (.method = "tversky"
) - an asymmetric similarity measure on sets that compares a variant to a prototype. If using default arguments, it's similar to Dice's coefficient.
cosine similarity (.method = "cosine"
) - a measure of similarity between two non-zero vectors
Morisita's overlap index (.method = "morisita"
) - a statistical measure of dispersion of individuals in a population. It is used to compare overlap among samples.
incremental overlap - overlaps of the N most abundant clonotypes with incrementally growing N (.method = "inc+METHOD"
, e.g., "inc+public"
or "inc+morisita"
).
The function that includes described methods is repOverlap
. Again the output is easily visualised when passed to vis()
function that does all the work:
imm_ov1 <- repOverlap(immdata$data, .method = "public", .verbose = F) imm_ov2 <- repOverlap(immdata$data, .method = "morisita", .verbose = F) p1 <- vis(imm_ov1) p2 <- vis(imm_ov2, .text.size = 2) p1 + p2 vis(imm_ov1, "heatmap2")
You can easily change the number of significant digits:
p1 <- vis(imm_ov2, .text.size = 2.5, .signif.digits = 1) p2 <- vis(imm_ov2, .text.size = 2, .signif.digits = 2) p1 + p2
To analyse the computed overlap measures function apply repOverlapAnalysis
.
# Apply different analysis algorithms to the matrix of public clonotypes: # "mds" - Multi-dimensional Scaling repOverlapAnalysis(imm_ov1, "mds") # "tsne" - t-Stochastic Neighbor Embedding repOverlapAnalysis(imm_ov1, "tsne") # Visualise the results repOverlapAnalysis(imm_ov1, "mds") %>% vis()
# Apply different analysis algorithms to the matrix of public clonotypes: # "mds" - Multi-dimensional Scaling repOverlapAnalysis(imm_ov1, "mds") # "tsne" - t-Stochastic Neighbor Embedding repOverlapAnalysis(imm_ov1, "tsne") # Visualise the results repOverlapAnalysis(imm_ov1, "mds") %>% vis() # Clusterise the MDS resulting components using K-means repOverlapAnalysis(imm_ov1, "mds+kmeans") %>% vis()
In order to build a massive table with all clonotypes from the list of repertoires use the pubRep
function.
# Pass "nt" as the second parameter to build the public repertoire table using CDR3 nucleotide sequences pr.nt <- pubRep(immdata$data, "nt", .verbose = F) pr.nt
# Pass "aa+v" as the second parameter to build the public repertoire table using CDR3 aminoacid sequences and V alleles # In order to use only CDR3 aminoacid sequences, just pass "aa" pr.aav <- pubRep(immdata$data, "aa+v", .verbose = F) pr.aav
# You can also pass the ".coding" parameter to filter out all noncoding sequences first: pr.aav.cod <- pubRep(immdata$data, "aa+v", .coding = T)
# Create a public repertoire with coding-only sequences using both CDR3 amino acid sequences and V genes pr <- pubRep(immdata$data, "aa+v", .coding = T, .verbose = F) # Apply the filter subroutine to leave clonotypes presented only in healthy individuals pr1 <- pubRepFilter(pr, immdata$meta, c(Status = "C")) # Apply the filter subroutine to leave clonotypes presented only in diseased individuals pr2 <- pubRepFilter(pr, immdata$meta, c(Status = "MS")) # Divide one by another pr3 <- pubRepApply(pr1, pr2) # Plot it p <- ggplot() + geom_jitter(aes(x = "Treatment", y = Result), data = pr3) p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.