<!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>Phylogenetic trees • 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="Phylogenetic trees">
<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>Phylogenetic trees</h1>
                        <h4 data-toc-skip class="author">Tudor-Stefan
Cotet, Alexander Yermanos</h4>
            
            <h4 data-toc-skip class="date">10/06/2022</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/alexyermanos/Platypus/tree/mastervignettes/Phylogenetic%20trees.Rmd" class="external-link"><code>vignettes/Phylogenetic trees.Rmd</code></a></small>
      <div class="hidden name"><code>Phylogenetic trees.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>To explore the clonal evolution across multiple clonotypes and
samples (or at a whole-repertoire/global level), the Platypus ecosystem
includes phylogenetic tree inference and plotting functions, with
typical tree algorithms such as Neighbour-Joining, Maximum-Likelihood,
and Maximum-Parsimony. Moreover, future Platypus updates will add
ancestral sequence reconstruction utilities via the PHYLIP and IQ-TREE
bioinformatics tools.</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 class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://tidyverse.tidyverse.org" class="external-link">tidyverse</a></span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## ── <span style="font-weight: bold;">Attaching packages</span> ─────────────────────────────────────── tidyverse 1.3.2 ──</span></span>
<span><span class="co">## <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">ggplot2</span> 3.3.6     <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">purrr  </span> 0.3.4</span></span>
<span><span class="co">## <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">tibble </span> 3.1.8     <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">dplyr  </span> 1.0.9</span></span>
<span><span class="co">## <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">tidyr  </span> 1.2.0     <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">stringr</span> 1.4.0</span></span>
<span><span class="co">## <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">readr  </span> 2.1.2     <span style="color: #00BB00;">✔</span> <span style="color: #0000BB;">forcats</span> 0.5.1</span></span>
<span><span class="co">## ── <span style="font-weight: bold;">Conflicts</span> ────────────────────────────────────────── tidyverse_conflicts() ──</span></span>
<span><span class="co">## <span style="color: #BB0000;">✖</span> <span style="color: #0000BB;">dplyr</span>::<span style="color: #00BB00;">filter()</span> masks <span style="color: #0000BB;">stats</span>::filter()</span></span>
<span><span class="co">## <span style="color: #BB0000;">✖</span> <span style="color: #0000BB;">dplyr</span>::<span style="color: #00BB00;">lag()</span>    masks <span style="color: #0000BB;">stats</span>::lag()</span></span></code></pre>
<div class="sourceCode" id="cb3"><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"><a href="https://yulab-smu.top/treedata-book/" class="external-link">ggtree</a></span><span class="op">)</span> <span class="co">#Used for plotting the resulting phylogenetic trees</span></span></code></pre></div>
<pre><code><span><span class="co">## <span style="color: #949494;">ggtree v3.4.1 For help: https://yulab-smu.top/treedata-book/</span></span></span>
<span><span class="co"><span style="color: #949494;">## </span></span></span>
<span><span class="co"><span style="color: #949494;">## If you use the ggtree package suite in published research, please cite</span></span></span>
<span><span class="co"><span style="color: #949494;">## the appropriate paper(s):</span></span></span>
<span><span class="co"><span style="color: #949494;">## </span></span></span>
<span><span class="co"><span style="color: #949494;">## Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam.</span></span></span>
<span><span class="co"><span style="color: #949494;">## ggtree: an R package for visualization and annotation of phylogenetic</span></span></span>
<span><span class="co"><span style="color: #949494;">## trees with their covariates and other associated data. Methods in</span></span></span>
<span><span class="co"><span style="color: #949494;">## Ecology and Evolution. 2017, 8(1):28-36. doi:10.1111/2041-210X.12628</span></span></span>
<span><span class="co"><span style="color: #949494;">## </span></span></span>
<span><span class="co"><span style="color: #949494;">## LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR</span></span></span>
<span><span class="co"><span style="color: #949494;">## Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu. treeio: an R package</span></span></span>
<span><span class="co"><span style="color: #949494;">## for phylogenetic tree input and output with richly annotated and</span></span></span>
<span><span class="co"><span style="color: #949494;">## associated data. Molecular Biology and Evolution. 2020, 37(2):599-603.</span></span></span>
<span><span class="co"><span style="color: #949494;">## doi: 10.1093/molbev/msz240</span></span></span>
<span><span class="co"><span style="color: #949494;">## </span></span></span>
<span><span class="co"><span style="color: #949494;">## S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L</span></span></span>
<span><span class="co"><span style="color: #949494;">## Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ggtreeExtra: Compact</span></span></span>
<span><span class="co"><span style="color: #949494;">## visualization of richly annotated phylogenetic data. Molecular Biology</span></span></span>
<span><span class="co"><span style="color: #949494;">## and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166 </span></span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Attaching package: 'ggtree'</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## The following object is masked from 'package:tidyr':</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##     expand</span></span></code></pre>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><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-22 12:05:07: 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="cb8"><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="creating-phylogenetic-trees-via-vdj_phylogenetic_trees">3. Creating phylogenetic trees via VDJ_phylogenetic_trees<a class="anchor" aria-label="anchor" href="#creating-phylogenetic-trees-via-vdj_phylogenetic_trees"></a>
</h2>
<div class="section level3">
<h3 id="choosing-the-sequence-type">1. Choosing the sequence type<a class="anchor" aria-label="anchor" href="#choosing-the-sequence-type"></a>
</h3>
<p>The sequence type an be controlled via the sequence.type,
as.nucleotide, and trimmed parameters in VDJ_phylogenetic_trees. For
sequence.type, the following options are available: ‘VDJ’ for the VDJ
full sequence, ‘VJ’ for the full VJ sequence, ‘VDJ.VJ’ for the combined
VDJ/VJ sequences, ‘cdr3’ for the CDR3 region, ‘cdrh3’ for the CDRH3
region. To infer trees for protein sequences, use as.nucleotide = F. If
trimmed is set to T, VDJ_phylogenetic_trees will look for the trimmed
full sequences - ensure trim.and.align was set to T when obtaining your
VGM using the VDJ_GEX_matrix function; else, trees will be inferred for
the raw sequences.</p>
<p>We will next infer trees for the CDR3 sequences, with as.nucleotide
set to T. We will only create 3 trees for a single sample
(maximum.lineages = 3 which will subset the VDJ for the 3 most abundant
clonotypes before creating the trees) for easier visualization. However,
the usual output of VDJ_phylogenetic_trees is a nested list of
<em>tidytree</em> objects (per sample, per clonotype), whereas the
output of VDJ_phylogenetic_trees_plot is a list of intraclonal trees for
each clonotype/lineage obtained from VDJ_phylogenetic_trees.</p>
<p>We will also set the maximum.sequences parameter to 20 to only obtain
trees with a maximum of 20 sequences (the top 20 most frequent sequences
per clonotype) and minimum.sequences to 1 (avoiding singletons).
Moreover, we will set include.germline to F (otherwise
VDJ_phylogenetic_trees will look for germlines/10x references in the VDJ
and VJ_trimmed_ref columns).</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">p</span> <span class="op">&lt;-</span> <span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                     as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                     trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     minimum.sequences <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     maximum.sequences <span class="op">=</span> <span class="fl">20</span>,</span>
<span>                                     maximum.lineages <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     include.germline <span class="op">=</span> <span class="cn">F</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>                   <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</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>plotlist <span class="op">=</span> <span class="va">p</span><span class="op">)</span></span></code></pre></div>
<p><img src="Phylogenetic%20trees_files/figure-html/unnamed-chunk-2-1.png" width="700"></p>
<p>We can see how the first clonotype was filtered out, as it had fewer
sequences that the minimum in minimum.sequences.</p>
</div>
<div class="section level3">
<h3 id="phylogenetic-tree-algorithms">2. Phylogenetic tree algorithms<a class="anchor" aria-label="anchor" href="#phylogenetic-tree-algorithms"></a>
</h3>
<p>The following tree inference algorithms are supported by
VDJ_phylogenetic_trees: Neighbour-Joining via the <em>ape</em> package
(tree.algorithm = ‘nj’), Maximum-Likelihood via the <em>phangorn</em>
package (tree.algorithm = ‘ml’), and Maximum-Parsimony via the
<em>phangorn</em> package (tree.algorithm = ‘mp’).</p>
<div class="section level4">
<h4 id="neighbour-joining-trees">Neighbour-joining trees<a class="anchor" aria-label="anchor" href="#neighbour-joining-trees"></a>
</h4>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Neighbour-joining trees via the ape package</span></span>
<span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">p</span> <span class="op">&lt;-</span> <span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                     as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                     trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     minimum.sequences <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     maximum.sequences <span class="op">=</span> <span class="fl">20</span>,</span>
<span>                                     maximum.lineages <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     tree.algorithm <span class="op">=</span> <span class="st">'nj'</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>                   <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</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>plotlist <span class="op">=</span> <span class="va">p</span><span class="op">)</span></span></code></pre></div>
<p><img src="Phylogenetic%20trees_files/figure-html/unnamed-chunk-3-1.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="maximum-likelihood-trees">Maximum-likelihood trees<a class="anchor" aria-label="anchor" href="#maximum-likelihood-trees"></a>
</h4>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Maximum-likelihood trees via the phangorn package</span></span>
<span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">p</span> <span class="op">&lt;-</span> <span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                     as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                     trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     minimum.sequences <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     maximum.sequences <span class="op">=</span> <span class="fl">20</span>,</span>
<span>                                     maximum.lineages <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     tree.algorithm <span class="op">=</span> <span class="st">'ml'</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>                   <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</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>plotlist <span class="op">=</span> <span class="va">p</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="maximum-parsimony-trees">Maximum parsimony trees<a class="anchor" aria-label="anchor" href="#maximum-parsimony-trees"></a>
</h4>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Maximum parsimony trees via the phangorn package</span></span>
<span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">p</span> <span class="op">&lt;-</span> <span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                     as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                     trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     minimum.sequences <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     maximum.sequences <span class="op">=</span> <span class="fl">20</span>,</span>
<span>                                     maximum.lineages <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                     include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                     tree.algorithm <span class="op">=</span> <span class="st">'mp'</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>                   <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</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>plotlist <span class="op">=</span> <span class="va">p</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="coming-soon---tree-inference-and-ancestral-sequence-reconstruction-via-iq-tree-and-phylip">Coming soon - tree inference and ancestral sequence reconstruction
via IQ-TREE and PHYLIP<a class="anchor" aria-label="anchor" href="#coming-soon---tree-inference-and-ancestral-sequence-reconstruction-via-iq-tree-and-phylip"></a>
</h4>
</div>
</div>
<div class="section level3">
<h3 id="per-repertoireglobal-trees">3. Per-repertoire/global trees<a class="anchor" aria-label="anchor" href="#per-repertoireglobal-trees"></a>
</h3>
<p>VDJ_phylogentic_trees can also be used to obtain per-repertoire or
global trees, by combining all sequences available across a single
repertoire/across all repertoires. This can be customized via the
tree.level parameter, which defaults to <em>‘intraclonal’</em> (per
clonotype trees). Setting tree.level to ‘combine.first.trees’ will
combine the n most abundant clonotypes in a single sample, as determined
by the parameter n.trees.combined. The other option for tree.level is
‘global.clonotype’ which will combine trees in the same clonotype,
irrespective of samples (useful when global clonotypes are defined
across multiple repertoire, via VDJ_call_enclone).</p>
<p>We will combine the first 3 trees in sample s1 by setting tree.level
to ‘combine.first.trees’ and n.trees.combined = 3. We will also set
maximum.sequences to NULL to allow trees to be inferred from all
sequences available.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                         as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                         trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         maximum.sequences <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>                                         include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         minimum.sequences <span class="op">=</span> <span class="fl">0</span>,</span>
<span>                                         tree.algorithm <span class="op">=</span> <span class="st">'nj'</span>,</span>
<span>                                         tree.level <span class="op">=</span> <span class="st">'combine.first.trees'</span>,</span>
<span>                                         n.trees.combined <span class="op">=</span> <span class="fl">3</span></span>
<span>                                         <span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>                   <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></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="Phylogenetic%20trees_files/figure-html/unnamed-chunk-6-1.png" width="700"></p>
</div>
</div>
<div class="section level2">
<h2 id="custom-tree-plots-via-vdj_phylogenetic_trees_plot">4. Custom tree plots via VDJ_phylogenetic_trees_plot<a class="anchor" aria-label="anchor" href="#custom-tree-plots-via-vdj_phylogenetic_trees_plot"></a>
</h2>
<p>To add new features to your trees (from the VDJ matrix), use the
additional.feature.columns parameter. These new features can be used for
more flexible plotting. For example, additional.feature.columns =
c(‘VDJ_vgene’, ‘VDJ_jgene’) will add the respective V and J genes per
unique sequence.</p>
<div class="section level3">
<h3 id="change-the-tip-colors">Change the tip colors<a class="anchor" aria-label="anchor" href="#change-the-tip-colors"></a>
</h3>
<p>You can change tree tip colors via the color.by parameter in
VDJ_phylogenetic_trees_plot.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Trees with tips colored by V gene.</span></span>
<span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                         as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                         trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         maximum.sequences <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>                                         include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         minimum.sequences <span class="op">=</span> <span class="fl">0</span>,</span>
<span>                                         tree.algorithm <span class="op">=</span> <span class="st">'nj'</span>,</span>
<span>                                         tree.level <span class="op">=</span> <span class="st">'combine.first.trees'</span>,</span>
<span>                                         n.trees.combined <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                         additional.feature.columns <span class="op">=</span> <span class="st">'VDJ_vgene'</span></span>
<span>                                         <span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>              <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</span>color.by <span class="op">=</span> <span class="st">'VDJ_vgene'</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [[1]]</span></span></code></pre>
<p><img src="Phylogenetic%20trees_files/figure-html/unnamed-chunk-7-1.png" width="700"></p>
<p>Moreover, you can specify a list of custom colors in the
specific.leaf.colors parameter.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Trees with tips colored by V gene.</span></span>
<span><span class="va">s1_subset</span> <span class="op">&lt;-</span> <span class="va">VDJ</span><span class="op">[</span><span class="va">VDJ</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">==</span> <span class="st">'s1'</span>,<span class="op">]</span></span>
<span><span class="va">s1_subset</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="../reference/VDJ_phylogenetic_trees.html">VDJ_phylogenetic_trees</a></span><span class="op">(</span>sequence.type <span class="op">=</span> <span class="st">'cdr3'</span>, </span>
<span>                                         as.nucleotide <span class="op">=</span> <span class="cn">T</span>, </span>
<span>                                         trimmed <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         maximum.sequences <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>                                         include.germline <span class="op">=</span> <span class="cn">F</span>,</span>
<span>                                         minimum.sequences <span class="op">=</span> <span class="fl">0</span>,</span>
<span>                                         tree.algorithm <span class="op">=</span> <span class="st">'nj'</span>,</span>
<span>                                         tree.level <span class="op">=</span> <span class="st">'combine.first.trees'</span>,</span>
<span>                                         n.trees.combined <span class="op">=</span> <span class="fl">3</span>,</span>
<span>                                         additional.feature.columns <span class="op">=</span> <span class="st">'VDJ_vgene'</span></span>
<span>                                         <span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> </span>
<span>              <span class="fu"><a href="../reference/VDJ_phylogenetic_trees_plot.html">VDJ_phylogenetic_trees_plot</a></span><span class="op">(</span>color.by <span class="op">=</span> <span class="st">'VDJ_vgene'</span>,</span>
<span>                                           specific.leaf.colors <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span><span class="st">'IGHV3-1'</span> <span class="op">=</span> <span class="st">'yellow'</span>,<span class="st">'IGHV11-2'</span> <span class="op">=</span> <span class="st">'orange'</span>, <span class="st">'IGHV1-5'</span> <span class="op">=</span> <span class="st">'red'</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="Phylogenetic%20trees_files/figure-html/unnamed-chunk-8-1.png" width="700"></p>
</div>
</div>
<div class="section level2">
<h2 id="version-information">5. Version information<a class="anchor" aria-label="anchor" href="#version-information"></a>
</h2>
<div class="sourceCode" id="cb19"><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] ggtree_3.4.1    forcats_0.5.1   stringr_1.4.0   dplyr_1.0.9    </span></span>
<span><span class="co">##  [5] purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.8   </span></span>
<span><span class="co">##  [9] ggplot2_3.3.6   tidyverse_1.3.2 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] nlme_3.1-157        fs_1.5.2            lubridate_1.8.0    </span></span>
<span><span class="co">##  [4] httr_1.4.3          rprojroot_2.0.3     tools_4.2.1        </span></span>
<span><span class="co">##  [7] backports_1.4.1     bslib_0.4.0         utf8_1.2.2         </span></span>
<span><span class="co">## [10] R6_2.5.1            DBI_1.1.3           lazyeval_0.2.2     </span></span>
<span><span class="co">## [13] colorspace_2.0-3    withr_2.5.0         tidyselect_1.1.2   </span></span>
<span><span class="co">## [16] curl_4.3.2          compiler_4.2.1      textshaping_0.3.6  </span></span>
<span><span class="co">## [19] cli_3.3.0           rvest_1.0.2         xml2_1.3.3         </span></span>
<span><span class="co">## [22] desc_1.4.1          labeling_0.4.2      sass_0.4.2         </span></span>
<span><span class="co">## [25] scales_1.2.0        pkgdown_2.0.6       systemfonts_1.0.4  </span></span>
<span><span class="co">## [28] digest_0.6.29       yulab.utils_0.0.5   rmarkdown_2.14     </span></span>
<span><span class="co">## [31] stringdist_0.9.8    pkgconfig_2.0.3     htmltools_0.5.3    </span></span>
<span><span class="co">## [34] highr_0.9           dbplyr_2.2.1        fastmap_1.1.0      </span></span>
<span><span class="co">## [37] rlang_1.0.4         readxl_1.4.0        rstudioapi_0.13    </span></span>
<span><span class="co">## [40] farver_2.1.1        gridGraphics_0.5-1  jquerylib_0.1.4    </span></span>
<span><span class="co">## [43] generics_0.1.3      jsonlite_1.8.0      googlesheets4_1.0.0</span></span>
<span><span class="co">## [46] magrittr_2.0.3      ggplotify_0.1.0     patchwork_1.1.1    </span></span>
<span><span class="co">## [49] Rcpp_1.0.9          munsell_0.5.0       fansi_1.0.3        </span></span>
<span><span class="co">## [52] ape_5.6-2           lifecycle_1.0.1     stringi_1.7.8      </span></span>
<span><span class="co">## [55] yaml_2.3.5          grid_4.2.1          parallel_4.2.1     </span></span>
<span><span class="co">## [58] crayon_1.5.1        lattice_0.20-45     haven_2.5.0        </span></span>
<span><span class="co">## [61] cowplot_1.1.1       hms_1.1.1           knitr_1.39         </span></span>
<span><span class="co">## [64] pillar_1.8.0        codetools_0.2-18    reprex_2.0.1       </span></span>
<span><span class="co">## [67] glue_1.6.2          evaluate_0.15       ggfun_0.0.6        </span></span>
<span><span class="co">## [70] modelr_0.1.8        vctrs_0.4.1         treeio_1.20.1      </span></span>
<span><span class="co">## [73] tzdb_0.3.0          foreach_1.5.2       cellranger_1.1.0   </span></span>
<span><span class="co">## [76] gtable_0.3.0        assertthat_0.2.1    cachem_1.0.6       </span></span>
<span><span class="co">## [79] xfun_0.31           broom_1.0.0         tidytree_0.3.9     </span></span>
<span><span class="co">## [82] ragg_1.2.2          googledrive_2.0.0   gargle_1.2.0       </span></span>
<span><span class="co">## [85] iterators_1.0.14    aplot_0.1.6         memoise_2.0.1      </span></span>
<span><span class="co">## [88] ellipsis_0.3.2</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>
