<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Immune receptor repertoire diversity • Platypus</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/yeti/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Immune receptor repertoire diversity">
<meta property="og:description" content="Platypus">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
    

    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">Platypus</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">3.4.1</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
    <span class="fa fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../articles/quickstart.html">Get started</a>
</li>
<li>
  <a href="../vignette_index.html">Vignettes</a>
</li>
<li>
  <a href="../PlatypusDB_index.html">PlatypusDB</a>
</li>
<li>
  <a href="../reference/index.html">Functions</a>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Other Packages
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="https://immunesim.readthedocs.io/en/latest/" class="external-link">ImmuneSIM</a>
    </li>
  </ul>
</li>
<li>
  <a href="../cute_monotremes.html">Cute Monotremes</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://twitter.com/alexyermanos" class="external-link">
    <span class="fa fa-twitter"></span>
     
  </a>
</li>
<li>
  <a href="https://github.com/alexyermanos/Platypus" class="external-link">
    <span class="fa fa-github"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Immune receptor repertoire diversity</h1>
                        <h4 data-toc-skip class="author">Tudor-Stefan
Cotet, Victor Kreiner, Alexander Yermanos</h4>
            
            <h4 data-toc-skip class="date">09/06/2022</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/alexyermanos/Platypus/tree/mastervignettes/Diversity%20and%20sampling.Rmd" class="external-link"><code>vignettes/Diversity and sampling.Rmd</code></a></small>
      <div class="hidden name"><code>Diversity and sampling.Rmd</code></div>

    </div>

    
    
<div class="section level2">
<h2 id="introduction">1. Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2>
<p>The Platypus family of packages are meant to provide potential
pipelines and examples relevant to the broad field of computational
immunology. The core set of functions can be found at <a href="https://github.com/alexyermanos/Platypus" class="external-link uri">https://github.com/alexyermanos/Platypus</a> and examples of
use can be found in the publications <a href="https://doi.org/10.1093/nargab/lqab023" class="external-link uri">https://doi.org/10.1093/nargab/lqab023</a> and
<strong>insert biorxiv database manuscript here</strong></p>
<p>Stay tuned for updates <a href="https://twitter.com/AlexYermanos" class="external-link uri">https://twitter.com/AlexYermanos</a></p>
<p>Given the immense diversity encoded in adaptive immune repertoires,
there has been significant progress in developing mathematical models
and bioinformatic pipelines to profile and compare the sequence
diversity across repertoires. This further includes metrics that can
help estimate the extent to which total diversity is captured in immune
repertoire sequencing experiments.</p>
</div>
<div class="section level2">
<h2 id="loading-the-vgm">2. Loading the VGM<a class="anchor" aria-label="anchor" href="#loading-the-vgm"></a>
</h2>
<p>The output of the VDJ_GEX_matrix is the main object for all
downstream functions in Platypus. We can create this directly into the R
session by using the public data available on PlatypusDB. We will use
the VDJ data of bone marrow plasma cells from five mice that were
immunized with OVA (and the MPLA adjuvant) from Neumeier^, Yermanos^ et
al 2022 PNAS.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va">Platypus</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Currently sourcing the scripts as these functions are not in the most recent Platypus version</span></span>
<span><span class="co">#source('VDJ_abundances.R')</span></span>
<span><span class="co">#source('VDJ_diversity.R')</span></span>
<span><span class="co">#source('VDJ_rarefaction.R')</span></span>
<span><span class="co">#source('VDJ_ordination.R')</span></span>
<span></span>
<span><span class="fu"><a href="../reference/PlatypusDB_fetch.html">PlatypusDB_fetch</a></span><span class="op">(</span>PlatypusDB.links <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"neumeier2021b//VDJmatrix"</span><span class="op">)</span>, </span>
<span>                                     load.to.enviroment <span class="op">=</span> <span class="cn">T</span>, combine.objects <span class="op">=</span> <span class="cn">F</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## 2022-08-07 20:18:15: Starting download of neumeier2021b__VDJmatrix.RData...</span></span></code></pre>
<pre><code><span><span class="co">## [1] "neumeier2021b__VDJmatrix"</span></span></code></pre>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">VDJ</span> <span class="op">&lt;-</span> <span class="va">neumeier2021b__VDJmatrix</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="vdj_abundances-for-feature-richness-plots">3. VDJ_abundances for feature richness plots<a class="anchor" aria-label="anchor" href="#vdj_abundances-for-feature-richness-plots"></a>
</h2>
<p>We will first visualize the CDRH3 and CDR species richness densities
per clonotype via VDJ_abundances. This function is a flexible utility
for calculating cell counts/abundances for different unique features
(via the feature.columns parameter), across multiple groups (via
grouping.column), and/or multiple samples (via sample.column).
VDJ_abundances is used internally to get abundance data for the
diversity, rarefaction, and ordination analyses, but can also be used to
obtain feature barplots (output.format = ‘barplot’) or feature richness
density plots (output.format = ‘density’) which we will see next. We
will only plot 3 samples for better clarity.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#CDRH3 richness density plots across 3 samples</span></span>
<span><span class="fu"><a href="../reference/VDJ_abundances.html">VDJ_abundances</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'CDR3aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               sample.column <span class="op">=</span> <span class="st">'none'</span>, </span>
<span>               output.format <span class="op">=</span> <span class="st">'density'</span>, </span>
<span>               specific.groups <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">'s1'</span>,<span class="st">'s2'</span>,<span class="st">'s3'</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [[1]]</span></span></code></pre>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-3-1.png" width="700"></p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#CDR3 richness density plots across 3 samples</span></span>
<span><span class="fu"><a href="../reference/VDJ_abundances.html">VDJ_abundances</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'CDR3aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               sample.column <span class="op">=</span> <span class="st">'none'</span>, </span>
<span>               output.format <span class="op">=</span> <span class="st">'density'</span>, </span>
<span>               specific.groups <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">'s1'</span>,<span class="st">'s2'</span>,<span class="st">'s3'</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [[1]]</span></span></code></pre>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-4-1.png" width="700"></p>
<p>Species richness densities can also be visualized as ridgeline plots,
by changing the output.format parameter to ‘density.ridges’. This
requires the <em>ggridges</em> package.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VDJ_abundances.html">VDJ_abundances</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               sample.column <span class="op">=</span> <span class="st">'none'</span>, </span>
<span>               output.format <span class="op">=</span> <span class="st">'density.ridges'</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [[1]]</span></span></code></pre>
<pre><code><span><span class="co">## Picking joint bandwidth of 50.6</span></span></code></pre>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-5-1.png" width="700"></p>
</div>
<div class="section level2">
<h2 id="vdj_diversity-for-α-β-diversity-and-species-evenness-metrics">4. VDJ_diversity for α, β-diversity, and species evenness
metrics<a class="anchor" aria-label="anchor" href="#vdj_diversity-for-%CE%B1-%CE%B2-diversity-and-species-evenness-metrics"></a>
</h2>
<p>α, β-Diversity, and species evenness can be computed via
VDJ_diversity.To allow flexibility, VDJ_diversity can be used to
calculate diversity metrics for a wide range of features/species
definitions (denoted as VDJ columns in the feature.columns parameter),
across different groups (group.column parameter). We will next focus on
calculating the diversity of unique CDRH3 sequences (feature.columns =
‘VDJ_cdr3s_aa’) across samples (grouping.column = ‘sample_id’).</p>
<div class="section level3">
<h3 id="α-diversity">4.1 α-Diversity<a class="anchor" aria-label="anchor" href="#%CE%B1-diversity"></a>
</h3>
<p>α-Diversity metrics currently implemented in VDJ_diversity include:
species richness (<em>‘richness’</em>), the Berger-Parker index
(<em>‘bergerparker’</em>), the Simpson index (<em>‘simpson’</em>), the
Gini-Simpson index (<em>‘ginisimpson’</em>), the inverse Simpson index
(<em>‘inversesimpson’</em>), Shannon index (<em>‘shannon’</em>), Chao1
(<em>‘chao1’</em>), ACE (<em>‘ace’</em>), and Good’s coverage metric
(<em>‘coverage’</em>).</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Chao1 index for CDRH3s</span></span>
<span><span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               metric <span class="op">=</span> <span class="st">'chao1'</span>,</span>
<span>               subsample.to.same.n <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-6-1.png" width="700"></p>
<p>The parameter subsample.to.same.n allows subsampling each group to
the smallest group’s size, standardizing the diversity metric across all
groups for fairer comparisons. We will check the difference in species
richness using subsample.to.same.n set to TRUE and then FALSE.
subsample.to.same.n is set to TRUE by default for α-diversity/evenness
comparisons.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#subsample.to.same.n = T</span></span>
<span><span class="va">p1</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>              feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>              grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>              metric <span class="op">=</span> <span class="st">'richness'</span>,</span>
<span>              subsample.to.same.n <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#subsample.to.same.n = F</span></span>
<span><span class="va">p2</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               metric <span class="op">=</span> <span class="st">'richness'</span>,</span>
<span>               subsample.to.same.n <span class="op">=</span> <span class="cn">F</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">cowplot</span><span class="fu">::</span><span class="fu"><a href="https://wilkelab.org/cowplot/reference/plot_grid.html" class="external-link">plot_grid</a></span><span class="op">(</span><span class="va">p1</span>, <span class="va">p2</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-7-1.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="evenness">4.2 Evenness<a class="anchor" aria-label="anchor" href="#evenness"></a>
</h3>
<p>Evenness metrics implemented in VDJ_diversity include: the Shannon
evenness index (<em>‘shannonevenness’</em>), Simpson evenness
(<em>‘simpsonevenness’</em>), Bulla index (<em>‘bulla’</em>), Camargo
index (<em>‘camargo’</em>), Smith-Wilson index (<em>‘smithwilson’</em>),
and the Heip index (<em>‘heip’</em>).</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Simpson evenness index for CDRH3s across each sample</span></span>
<span><span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               metric <span class="op">=</span> <span class="st">'simpsonevenness'</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-8-1.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="β-diversity">4.3 β-Diversity<a class="anchor" aria-label="anchor" href="#%CE%B2-diversity"></a>
</h3>
<p>β-Diversity calculators available for VDJ_diversity include: the
Anderberg index (‘<em>anderberg’</em>), Bray-Curtis index
(<em>’braycurtis’</em>), cosine similarity (<em>’cosine’</em>),
Euclidean distance (’euclidean’), Hamming distance (<em>‘hamming’</em>),
the Jaccard overlap index (<em>‘jaccard’</em>), Manhattan distance
(<em>‘manhattan’</em>), the Morisita-Horn index
(<em>‘morisitahorn’</em>), the Sørensen–Dice coefficient
(<em>‘sorensen’</em>). Currently, β-Diversity can only be visualized as
a heatmap across groups.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p1</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               metric <span class="op">=</span> <span class="st">'jaccard'</span><span class="op">)</span></span>
<span></span>
<span><span class="va">p2</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_diversity.html">VDJ_diversity</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>, </span>
<span>               metric <span class="op">=</span> <span class="st">'cosine'</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">cowplot</span><span class="fu">::</span><span class="fu"><a href="https://wilkelab.org/cowplot/reference/plot_grid.html" class="external-link">plot_grid</a></span><span class="op">(</span><span class="va">p1</span>, <span class="va">p2</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-9-1.png" width="700"></p>
</div>
</div>
<div class="section level2">
<h2 id="vdj_rarefaction-for-rarefaction-plots">5. VDJ_rarefaction for rarefaction plots<a class="anchor" aria-label="anchor" href="#vdj_rarefaction-for-rarefaction-plots"></a>
</h2>
<p>Consistent with the analyses showcases before, VDJ_rarefaction allows
a wide range of features/sequences to be rarefied (determined by their
respective VDJ column names in the feature.columns parameter), across
different samples or groups (grouping.column parameter). Rarefaction and
extrapolation are performed via the <em>iNEXT</em> package. <a href="https://doi.org/10.1111/2041-210X.12613" class="external-link"><strong>https://doi.org/10.1111/2041-210X.12613</strong></a><strong>.</strong></p>
<div class="section level3">
<h3 id="choosing-features-to-rarefy">5.1 Choosing features to rarefy<a class="anchor" aria-label="anchor" href="#choosing-features-to-rarefy"></a>
</h3>
<p>We will perform the rarefaction analyses for unique
CDRH3s(‘VDJ_cdr3s_aa’) across samples (‘sample_id’). Moreover, features
can also be combined (e.g., feature.columns = c(‘VDJ_cdr3s_aa’,
‘VJ_cdr3s_aa’) to rarefy the CDR3 sequences).</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_rarefaction.html">VDJ_rarefaction</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>                feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>                grouping.column <span class="op">=</span> <span class="st">'sample_id'</span><span class="op">)</span></span>
<span></span>
<span><span class="va">p</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-10-1.png" width="700"></p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-11-1.png" width="700"></p>
<p>The output of VDJ_rarefaction is a list of two plots: the first plot
includes the rarefaction curves of each sample across each Hill number,
whereas the second has the Hill numbers in the same subplot, grouped by
samples.</p>
</div>
<div class="section level3">
<h3 id="selecting-hill-numbers">5.2 Selecting Hill numbers<a class="anchor" aria-label="anchor" href="#selecting-hill-numbers"></a>
</h3>
<p>We can select particular Hill numbers to be plotted via the
hill.numbers parameter. 0 - species richness, 1 - Shannon diversity, 2 -
Simpson diversity. For example, we chose to only rarefy the species
richness in the following plots.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_rarefaction.html">VDJ_rarefaction</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>                feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>                grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>                hill.numbers <span class="op">=</span> <span class="fl">0</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## Warning in ggiNEXT.iNEXT(inext_object, type =</span></span>
<span><span class="co">## rarefaction_type_dict[rarefaction.type], : invalid facet.var setting, the iNEXT</span></span>
<span><span class="co">## object do not consist multiple orders.</span></span></code></pre>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-12-1.png" width="700"></p>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-13-1.png" width="700"></p>
</div>
</div>
<div class="section level2">
<h2 id="vdj_ordination-dimensionality-reductionordination-analysis">6. VDJ_ordination dimensionality reduction/ordination analysis<a class="anchor" aria-label="anchor" href="#vdj_ordination-dimensionality-reductionordination-analysis"></a>
</h2>
<p>Ordination methods are a set of dimensionality reduction approaches
used in community ecology for easier visualization of samples and/or
species from an incidence matrix/ community data matrix (samples by
species). Currently, the following dimensionality reduction algorithms
are supported in VDJ_ordination: PCA (method = ‘pca’), t-SNE via the
<em>Rtsne</em> R package (method = ‘tsne’), UMAP via the <em>umap</em> R
package (method = ‘umap’), detrended correspondence analysis/DCA via the
<em>vegan</em> package (method = ‘dca’) and PCOA/ Multidimensional
scaling - MDS via the <em>vegan</em> package (method = ‘mds’).</p>
<div class="section level3">
<h3 id="ordination-methodsalgorithms">6.1 Ordination methods/algorithms<a class="anchor" aria-label="anchor" href="#ordination-methodsalgorithms"></a>
</h3>
<p>We will showcase the sample ordination for the following methods:
PCA, t-SNE, UMAP, and DCA.</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#PCA dim reduction/ ordination</span></span>
<span><span class="va">p1</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'pca'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'groups'</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#t-SNE dim reduction/ ordination</span></span>
<span><span class="va">p2</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'tsne'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'groups'</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#UMAP dim reduction/ ordination</span></span>
<span><span class="va">p3</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'umap'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'groups'</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#DCA dim reduction/ ordination</span></span>
<span><span class="va">p4</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'dca'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'groups'</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">cowplot</span><span class="fu">::</span><span class="fu"><a href="https://wilkelab.org/cowplot/reference/plot_grid.html" class="external-link">plot_grid</a></span><span class="op">(</span><span class="va">p1</span>, <span class="va">p2</span>, <span class="va">p3</span>, <span class="va">p4</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-14-1.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="ordination-across-groups">6.2 Ordination across groups<a class="anchor" aria-label="anchor" href="#ordination-across-groups"></a>
</h3>
<p>The reduction.level parameter controls whether dimensionality
reduction will be performed across samples, features/sequences, or
across both (resulting in a plot with both samples and shared features).
For ordination across samples, use reduction.level = ‘groups’.</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'mds'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'groups'</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-15-1.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="ordination-across-features">6.3 Ordination across features<a class="anchor" aria-label="anchor" href="#ordination-across-features"></a>
</h3>
<p>For ordination across the CDRH3 incidence vectors, use
reduction.level = ‘features’. Currently, custom point colors in the
resulting graph are not available.</p>
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'mds'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'features'</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-16-1.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="ordination-across-both-groups-and-samples">6.4 Ordination across both groups and samples<a class="anchor" aria-label="anchor" href="#ordination-across-both-groups-and-samples"></a>
</h3>
<p>reduction.level = ‘both’ performs dimensionality reduction for both
samples and features.</p>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VDJ_ordination.html">VDJ_ordination</a></span><span class="op">(</span><span class="va">VDJ</span>, </span>
<span>               feature.columns <span class="op">=</span> <span class="st">'VDJ_cdr3s_aa'</span>, </span>
<span>               grouping.column <span class="op">=</span> <span class="st">'sample_id'</span>,</span>
<span>               method <span class="op">=</span> <span class="st">'mds'</span>,</span>
<span>               reduction.level <span class="op">=</span> <span class="st">'both'</span><span class="op">)</span></span></code></pre></div>
<p><img src="Diversity%20and%20sampling_files/figure-html/unnamed-chunk-17-1.png" width="700"></p>
</div>
</div>
<div class="section level2">
<h2 id="version-information">7. Version information<a class="anchor" aria-label="anchor" href="#version-information"></a>
</h2>
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/sessionInfo.html" class="external-link">sessionInfo</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## R version 4.2.1 (2022-06-23 ucrt)</span></span>
<span><span class="co">## Platform: x86_64-w64-mingw32/x64 (64-bit)</span></span>
<span><span class="co">## Running under: Windows 10 x64 (build 19044)</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Matrix products: default</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## locale:</span></span>
<span><span class="co">## [1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   </span></span>
<span><span class="co">## [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   </span></span>
<span><span class="co">## [5] LC_TIME=German_Germany.utf8    </span></span>
<span><span class="co">## </span></span>
<span><span class="co">## attached base packages:</span></span>
<span><span class="co">## [1] stats     graphics  grDevices utils     datasets  methods   base     </span></span>
<span><span class="co">## </span></span>
<span><span class="co">## other attached packages:</span></span>
<span><span class="co">## [1] Platypus_3.4.1</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## loaded via a namespace (and not attached):</span></span>
<span><span class="co">##  [1] sass_0.4.2         tidyr_1.2.0        jsonlite_1.8.0     viridisLite_0.4.0 </span></span>
<span><span class="co">##  [5] splines_4.2.1      bslib_0.4.0        assertthat_0.2.1   askpass_1.1       </span></span>
<span><span class="co">##  [9] highr_0.9          yulab.utils_0.0.5  yaml_2.3.5         pillar_1.8.0      </span></span>
<span><span class="co">## [13] lattice_0.20-45    reticulate_1.25    glue_1.6.2         digest_0.6.29     </span></span>
<span><span class="co">## [17] colorspace_2.0-3   ggfun_0.0.6        cowplot_1.1.1      htmltools_0.5.3   </span></span>
<span><span class="co">## [21] Matrix_1.4-1       plyr_1.8.7         pkgconfig_2.0.3    purrr_0.3.4       </span></span>
<span><span class="co">## [25] patchwork_1.1.1    tidytree_0.3.9     scales_1.2.0       ggplotify_0.1.0   </span></span>
<span><span class="co">## [29] RSpectra_0.16-1    Rtsne_0.16         openssl_2.0.2      tibble_3.1.8      </span></span>
<span><span class="co">## [33] mgcv_1.8-40        generics_0.1.3     farver_2.1.1       ggplot2_3.3.6     </span></span>
<span><span class="co">## [37] ellipsis_0.3.2     cachem_1.0.6       umap_0.2.8.0       lazyeval_0.2.2    </span></span>
<span><span class="co">## [41] cli_3.3.0          magrittr_2.0.3     memoise_2.0.1      evaluate_0.15     </span></span>
<span><span class="co">## [45] fs_1.5.2           fansi_1.0.3        nlme_3.1-157       MASS_7.3-57       </span></span>
<span><span class="co">## [49] vegan_2.6-2        textshaping_0.3.6  tools_4.2.1        lifecycle_1.0.1   </span></span>
<span><span class="co">## [53] stringr_1.4.0      aplot_0.1.6        ggtree_3.4.1       munsell_0.5.0     </span></span>
<span><span class="co">## [57] cluster_2.1.3      compiler_4.2.1     pkgdown_2.0.6      jquerylib_0.1.4   </span></span>
<span><span class="co">## [61] gridGraphics_0.5-1 systemfonts_1.0.4  rlang_1.0.4        grid_4.2.1        </span></span>
<span><span class="co">## [65] ggridges_0.5.3     rstudioapi_0.13    labeling_0.4.2     rmarkdown_2.14    </span></span>
<span><span class="co">## [69] gtable_0.3.0       DBI_1.1.3          reshape2_1.4.4     iNEXT_2.0.20      </span></span>
<span><span class="co">## [73] R6_2.5.1           knitr_1.39         dplyr_1.0.9        fastmap_1.1.0     </span></span>
<span><span class="co">## [77] utf8_1.2.2         rprojroot_2.0.3    treeio_1.20.1      ragg_1.2.2        </span></span>
<span><span class="co">## [81] permute_0.9-7      desc_1.4.1         ape_5.6-2          stringi_1.7.8     </span></span>
<span><span class="co">## [85] parallel_4.2.1     Rcpp_1.0.9         png_0.1-7          vctrs_0.4.1       </span></span>
<span><span class="co">## [89] tidyselect_1.1.2   xfun_0.31</span></span></code></pre>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p></p>
<p>Developed by Alexander Yermanos.</p>
</div>

<div class="pkgdown">
  <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.6.</p>
</div>

      </footer>
</div>

  


  

  </body>
</html>
