pkgdown/extra.css

Skip to contents

TIRTLtools has a number of built-in metrics for repertoire diversity estimation.

We start by loading an example TIRTLseq dataset of some CD4/8-isolated samples from COVID-infected patients at a few timepoints.

library(TIRTLtools)
library(dplyr)
library(rmarkdown)
library(ggplot2)
folder = system.file("extdata/SJTRC_TIRTL_seq_longitudinal", package = "TIRTLtools")
dir(folder)
##  [1] "cd4_tp1_v2_pseudobulk_TRA.tsv.gz" "cd4_tp1_v2_pseudobulk_TRB.tsv.gz"
##  [3] "cd4_tp1_v2_TIRTLoutput.tsv.gz"    "cd4_tp2_v2_pseudobulk_TRA.tsv.gz"
##  [5] "cd4_tp2_v2_pseudobulk_TRB.tsv.gz" "cd4_tp2_v2_TIRTLoutput.tsv.gz"   
##  [7] "cd4_tp3_v2_pseudobulk_TRA.tsv.gz" "cd4_tp3_v2_pseudobulk_TRB.tsv.gz"
##  [9] "cd4_tp3_v2_TIRTLoutput.tsv.gz"    "cd8_tp1_v2_pseudobulk_TRA.tsv.gz"
## [11] "cd8_tp1_v2_pseudobulk_TRB.tsv.gz" "cd8_tp1_v2_TIRTLoutput.tsv.gz"   
## [13] "cd8_tp2_v2_pseudobulk_TRA.tsv.gz" "cd8_tp2_v2_pseudobulk_TRB.tsv.gz"
## [15] "cd8_tp2_v2_TIRTLoutput.tsv.gz"    "cd8_tp3_v2_pseudobulk_TRA.tsv.gz"
## [17] "cd8_tp3_v2_pseudobulk_TRB.tsv.gz" "cd8_tp3_v2_TIRTLoutput.tsv.gz"
ts_data = load_tirtlseq(folder, meta_columns = c("marker", "timepoint", "version"), sep = "_")
## these files are named (marker)_(timepoint)_(version)_etc.tsv.gz

We offer the following diversity metrics/indices:

For a full list of the currently available metrics, run get_all_div_metrics().

##  [1] "simpson"        "gini"           "gini.simpson"   "inv.simpson"   
##  [5] "shannon"        "berger.parker"  "richness"       "d50"           
##  [9] "dXX"            "renyi"          "hill"           "top10fraction" 
## [13] "top100fraction" "topNfraction"
div = calculate_diversity(ts_data, chain = "beta")
## 
## -- Calculating diversity indices for sample 1 of 6.
## -- Calculating diversity indices for sample 2 of 6.
## -- Calculating diversity indices for sample 3 of 6.
## -- Calculating diversity indices for sample 4 of 6.
## -- Calculating diversity indices for sample 5 of 6.
## -- Calculating diversity indices for sample 6 of 6.
plot_diversity(div, metric = "d50")

The plot_diversity() function returns a ggplot object that contains the sample metadata in ts_data$meta, so we can use ggplot to make the plot more informative.

plot_diversity(div, metric = "richness") + 
  facet_wrap(~marker, scales = "free_x") + 
  aes(fill=marker)

plot_diversity(div, metric = "berger.parker") + 
  facet_wrap(~marker, scales = "free_x") + 
  aes(fill=marker) +
  scale_fill_manual(values = c("red3", "blue4"))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

plot_diversity(div, metric = "simpson") + 
  facet_wrap(~timepoint, scales = "free_x") + 
  aes(fill=marker) +
  scale_fill_manual(values = c("red3", "blue4"))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

plot_diversity(div, metric = "shannon") + 
  facet_wrap(~timepoint, scales = "free_x") + 
  aes(fill=marker) +
  scale_fill_manual(values = c("red3", "blue4"))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

plot_diversity(div, metric = "top10fraction") + 
  facet_wrap(~timepoint, scales = "free_x") + 
  aes(fill=marker) +
  scale_fill_manual(values = c("red3", "blue4"))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.