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)

## This loads a TIRTLseqDataSet object called "SJTRC_longitudinal"
load_example_data("SJTRC_longitudinal")
## 36.029 sec elapsed

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(SJTRC_longitudinal, 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.