<!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>Spatial transcriptomics • 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="Spatial transcriptomics">
<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>Spatial transcriptomics</h1>
                        <h4 data-toc-skip class="author">Solène Masserey, Andreas Agrafiotis, Alexanded Yermanos</h4>
            
            <h4 data-toc-skip class="date">2022-07-04</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/alexyermanos/Platypus/tree/mastervignettes/Spatial_transcriptomics.Rmd" class="external-link"><code>vignettes/Spatial_transcriptomics.Rmd</code></a></small>
      <div class="hidden name"><code>Spatial_transcriptomics.Rmd</code></div>

    </div>

    
    
<div class="section level2">
<h2 id="introduction">1. Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2>
<p>Spatial transcriptomics is a novel method to visualize and quantify
gene expression profiles on tissue samples. It holds the potential to
provide novel insight into our understanding of the spatial dynamics of
the adaptive immune response. Platypus now offers a computational
pipeline specifically tailored for spatial transcriptome data. This
spatial transcriptomic module provides new functions to integrate GEX,
VDJ, and spatial information into a single object. Some features include
the ability to classify cells as B or T cells based on a list of
markers, to re-cluster the annotated cells on the image, to integrate
VDJ and spatial information, and to visualize repertoire features such
as clonal expansion, isotype usage, somatic hypermutation directly on
the image.</p>
</div>
<div class="section level2">
<h2 id="dataset-overview">2. Dataset overview<a class="anchor" aria-label="anchor" href="#dataset-overview"></a>
</h2>
<p>This vignette is currently compatible with public data provided by
10X Genomics. The example data in this module is from spatial
transcriptomics of a human lymph node given the high number of T and B
cells and potential of including germinal centers. The majority of
analyses in this vignette use Platypus v3, which revolves around the
VDJ_GEX_matrix (VGM) data structure. This is used as input to the
majority of downstream analysis functions. The vgm containing the VDJ
and the GEX information corresponding to the following analysis can be
directly download with the following link: <a href="https://storage.googleapis.com/platypus_private/masserey2022a_spatial_vgm.RData" class="external-link uri">https://storage.googleapis.com/platypus_private/masserey2022a_spatial_vgm.RData</a>.
As downloading public data can sometimes be complicated, the lymph node
spatial data can be downloaded with the following link: <a href="https://storage.googleapis.com/platypus_private/masserey2022a_spatial_GEX.zip" class="external-link uri">https://storage.googleapis.com/platypus_private/masserey2022a_spatial_GEX.zip</a>.
We additionally demonstrate a way to to download and arrange the public
dataset from 10X Genomics in the user’s computer.</p>
<p>The first step, data downloading, is to go to the dataset tab of the
10X Genomics website (add link) and select the dataset of interest - for
example: “Human Lymph Node”. Then under “output files”, we have to
download 1) “Feature / barcode matrix HDF5 (filtered)” file and rename
it filtered_feature_bc_matrix.h5, 2)“Feature / barcode matrix
(filtered)” file, decompress it to obtain three files: “barcode.tsv”,
“features.tsv”, and “matrix.mtx”, 3) “Clustering analysis” file,
decompress it to get a file named “analysis”, and 4) “Spatial imaging
data”, decompress it to obtain a file named “spatial”.</p>
</div>
<div class="section level2">
<h2 id="setup">3. Setup<a class="anchor" aria-label="anchor" href="#setup"></a>
</h2>
<p>Loading the necessary packages.</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://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">## Attaching package: 'dplyr'</span></span></code></pre>
<pre><code><span><span class="co">## The following objects are masked from 'package:stats':</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##     filter, lag</span></span></code></pre>
<pre><code><span><span class="co">## The following objects are masked from 'package:base':</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##     intersect, setdiff, setequal, union</span></span></code></pre>
</div>
<div class="section level2">
<h2 id="addition-of-spatial-component-to-vgm">4. Addition of spatial component to VGM<a class="anchor" aria-label="anchor" href="#addition-of-spatial-component-to-vgm"></a>
</h2>
<p>To start, we first load the VGM into the R environment. We also need
to provide access paths to add the spatial data to the VGM.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">sample_names</span><span class="op">&lt;-</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">"Human LN"</span><span class="op">)</span></span>
<span></span>
<span><span class="va">tissue_lowres_image_path</span><span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">tissue_lowres_image_path</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/spatial/tissue_lowres_image.png"</span><span class="op">)</span></span>
<span>  </span>
<span><span class="va">scalefactors_json_path</span><span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">scalefactors_json_path</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/spatial/scalefactors_json.json"</span><span class="op">)</span></span>
<span>    </span>
<span><span class="va">tissue_positions_list_path</span><span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">tissue_positions_list_path</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/spatial/tissue_positions_list.csv"</span><span class="op">)</span></span>
<span>    </span>
<span><span class="va">cluster_path</span><span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">cluster_path</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/clusteranalysis/analysis/clustering/graphclust/clusters.csv"</span><span class="op">)</span></span>
<span>    </span>
<span><span class="va">matrix_path</span><span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">matrix_path</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/filtered_feature_bc_matrix/filtered_feature_bc_matrix.h5"</span><span class="op">)</span></span>
<span></span>
<span><span class="va">GEX.out.directory.list</span> <span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</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">"C:/Users/PlatypusDB/GEX/filtered_feature_bc_matrix/"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#vgm containing GEX and VDJ</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/load.html" class="external-link">load</a></span><span class="op">(</span><span class="st">"C:/Users/PlatypusDB/masserey2022a_spatial_vgm.Rdata"</span><span class="op">)</span></span></code></pre></div>
<p>Starting from the VGM containing both transcriptome and sequence
data, we still need to add spatial data that will allow us to represent
different features directly on the image.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">vgm</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_vgm_formation.html">Spatial_vgm_formation</a></span><span class="op">(</span>vgm <span class="op">=</span> <span class="va">vgm</span>,tissue_lowres_image_path <span class="op">=</span> <span class="va">tissue_lowres_image_path</span>,tissue_positions_list_path <span class="op">=</span> <span class="va">tissue_positions_list_path</span>, scalefactors_json_path <span class="op">=</span> <span class="va">scalefactors_json_path</span>, cluster_path <span class="op">=</span> <span class="va">cluster_path</span>, matrix_path <span class="op">=</span> <span class="va">matrix_path</span><span class="op">)</span></span></code></pre></div>
<p>In order to represent both the transcriptome data (GEX) and the
sequence data (VDJ) on an image we need to assign x and y coordinates to
each cell (or each barcode). To do this, a matrix including both the
barcodes and the coordinates can be extracted from the spatial data in
the VGM[[6]] (spatial). To facilitate the spatial analyses, we will add
the coordinates x and y directly to each cell/barcode in the data frame
of the VGM[[1]] which contains the VDJ data.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Extract coordinates</span></span>
<span><span class="va">scaling_parameters</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_scaling_parameters.html">Spatial_scaling_parameters</a></span><span class="op">(</span>vgm_spatial <span class="op">=</span> <span class="va">vgm</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span><span class="op">)</span></span>
<span></span>
<span><span class="va">coordinates</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/subset.html" class="external-link">subset</a></span><span class="op">(</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, select <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="va">imagerow</span>, <span class="va">imagecol</span>,<span class="va">barcode</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">coordinates</span><span class="op">)</span><span class="op">[</span><span class="fl">1</span><span class="op">]</span><span class="op">&lt;-</span><span class="st">"y"</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">coordinates</span><span class="op">)</span><span class="op">[</span><span class="fl">2</span><span class="op">]</span><span class="op">&lt;-</span><span class="st">"x"</span></span>
<span></span>
<span><span class="co">#Add coordinates to VGM[[1]]</span></span>
<span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span></span>
<span><span class="va">VDJ</span><span class="op">$</span><span class="va">barcode</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">gsub</a></span><span class="op">(</span><span class="st">"s1_"</span>,<span class="st">""</span>,<span class="va">VDJ</span><span class="op">$</span><span class="va">barcode</span><span class="op">)</span></span>
<span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/merge.html" class="external-link">merge</a></span><span class="op">(</span><span class="va">VDJ</span>, <span class="va">coordinates</span>, by<span class="op">=</span><span class="st">"barcode"</span><span class="op">)</span></span>
<span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">VDJ</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="analysis">5. Analysis<a class="anchor" aria-label="anchor" href="#analysis"></a>
</h2>
<p>Once the VGM contains the transcriptome, immune receptor and spatial
location we can now proceed to additional analyses. We have divided the
current analysis pipeline into two parts: 5.1 analysis of the immune
receptor data (VDJ) and 5.2 analysis of the gene expression data (GEX).
In this example we focus on B cells but the same analysis is compatible
with T cells.</p>
<div class="section level3">
<h3 id="vdj-analysis">5.1 VDJ analysis<a class="anchor" aria-label="anchor" href="#vdj-analysis"></a>
</h3>
<p>We will first focus on the analysis of BCR sequences of B cells
present on the tissue. We have created three analysis functions. First,
the user can choose to visualize repertoire features directly on the
image. This includes features such as isotype usage or the number of
somatic hypermutations. The user can also track the evolution of clones
within a clonotype. All these functions are detailed below.</p>
<div class="section level4">
<h4 id="isotype">5.1.1 Isotype<a class="anchor" aria-label="anchor" href="#isotype"></a>
</h4>
<p>This first analysis tool enables the visualization of B cell isotypes
on the spatial image. The isotype data are collected in the VGM[[1]]
(VDJ). This lymph node contains a large number of B cells and different
clonotypes. For a better visualization of the results, we have chosen to
display the 5 most expanded clonotypes. A function has also been created
for this. This tool also works with the whole dataset by replacing the
vgm_VDJ parameter as well as the analysis parameter by VGM[[1]].</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#VDJ containing only the top 5 more expanded clones</span></span>
<span><span class="va">top_5_VDJ_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">5</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span><span class="co">#Isotypes plotting</span></span>
<span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_data</span>, analysis <span class="op">=</span> <span class="va">top_5_VDJ_data</span><span class="op">$</span><span class="va">VDJ_cgene</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell"</span>, legend <span class="op">=</span> <span class="st">"Isotype"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-6-1.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="somatic-hypermutation-shm-and-clonotype-evolution-tracking">5.1.2 Somatic hypermutation (SHM) and clonotype evolution
tracking<a class="anchor" aria-label="anchor" href="#somatic-hypermutation-shm-and-clonotype-evolution-tracking"></a>
</h4>
<p>Somatic hypermutations refer to mutations in BCR/antibody sequence
that diverges from the germline genes encoded within the genome. To
define the germline sequence and to calculate and classify the sequences
of each clone, we used the AntibodyForest function within Platypus that
reconstructs phylogenetic networks based on inferred evolutionary
histories. A node refers to a unique antibody variant within a given
clone and the edges connect clonally related sequences. In our example,
node 5 is empty, which means that no cell belonging to this clonotype
has a germline sequence (CLARIFY). However, there are several other
nodes containing cells with a calculated distance (number of SHM) from
the germinal node. We will represent on the image the number of
mutations for each cell that separates their sequence from the germline
sequence.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#1)trees without intermediate</span></span>
<span><span class="va">forest</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/AntibodyForests.html">AntibodyForests</a></span><span class="op">(</span>VDJ<span class="op">=</span><span class="va">vgm</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>, network.algorithm<span class="op">=</span><span class="st">'tree'</span>,  expand.intermediates<span class="op">=</span><span class="cn">F</span>, network.level<span class="op">=</span><span class="st">'intraclonal'</span>,parallel<span class="op">=</span><span class="cn">F</span><span class="op">)</span></span></code></pre></div>
<p>We display a phylogenetic network as an example.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Clonotype we study</span></span>
<span><span class="va">clonotype_number</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">forest</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[</span><span class="fl">2</span><span class="op">]</span><span class="op">)</span></span>
<span><span class="va">clonotype_number</span></span></code></pre></div>
<pre><code><span><span class="co">## [1] "clonotype10"</span></span></code></pre>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#plot</span></span>
<span><span class="va">tree_plot</span><span class="op">&lt;-</span><span class="va">forest</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</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/AntibodyForests_plot.html">AntibodyForests_plot</a></span><span class="op">(</span>node.label <span class="op">=</span> <span class="st">"rank"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-8-1.png" width="700"></p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">igraph</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/igraph/man/plot.igraph.html" class="external-link">plot.igraph</a></span><span class="op">(</span><span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-8-2.png" width="700"></p>
<p>We display a tree corresponding to clonotype 10. This tree is
composed of 5 nodes, each of which has a different node label. This
number has nothing to do with the number of cells in a node (CLARIFY).
Node 5 is, for example, the germline node and contains no cells. The
node whose sequences are closest to the germline node is node 4. From
this node two inferred descendants follow: the first with node 1 and the
second with node 3. The sequences contained in node 2 are “closer” to
those contained in node 1. One could summarize by saying that node 4
contains the cells that first evolved from the germline, that nodes 3
and 1 contain the cells that evolved from the cells of node 4 and that
finally the cells belonging to node 2 evolved from those of node 1. Data
frame (CLARIFY) containing the previous described information like node
relations (tree_pathway) and distance between node and germline sequence
(vertices_dataframe) can be extracted from output of AntibodyForest
function.</p>
<p>The new VDJ data frame now contains node labels and the distances
from germline for all cell with each clonotype. We can plot this
information.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Spatial_nb_SHM_compare_to_germline_plot.html">Spatial_nb_SHM_compare_to_germline_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,AbForest_output<span class="op">=</span><span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title <span class="op">=</span> <span class="st">"Number of SHM of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-9-1.png" width="700"></p>
<p>As we infer the relationships between the nodes, we can connect the
cells with arrows to represent these relationships on the image. The
arrow starts from a progenitor cell (located in a node closer to the
germline node) and points to a offspring cell (which has evolved and
therefore has additional SHMs and is located in a node further from the
germline node). In this case, we will link the cells of node 1 to the
cells of node 2 and the cells of node 4 to the cells of nodes 1 and 3.
Node 5 does not come into play because it is empty (CLARIFY - what does
empty mean?). To link these cells, we have two possibilities. First, we
can link a progenitor cell to a offspring cell (example: cell from node
1 to cell from node 2) based on their distance, the progenitor cell
closest to a offspring cell is assigned to it. Or, secondly, we can link
all progenitor cells to all their potential offspring cells.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Daughter cell assign to the closest mother cell</span></span>
<span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,tracking_type <span class="op">=</span> <span class="st">"closest"</span>,AbForest_output <span class="op">=</span> <span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>,VDJ<span class="op">=</span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"Tracking evolution of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span> <span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-10-1.png" width="700"></p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#All mother cells link all daughter cells</span></span>
<span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,tracking_type <span class="op">=</span> <span class="st">"all"</span>,AbForest_output <span class="op">=</span> <span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>,VDJ<span class="op">=</span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"Tracking evolution of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span> <span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-10-2.png" width="700"></p>
</div>
</div>
<div class="section level3">
<h3 id="gex-analysis">5.2 GEX analysis<a class="anchor" aria-label="anchor" href="#gex-analysis"></a>
</h3>
<p>We now proceed to the analyses concerning the gene expression (GEX)
of the cells on the tissue. The user can visualize a cell type on the
tissue by entering custom phenotypic labels (e.g. from ProjectTILS or
the Platypus GEX_phenotype function). They can also display the
expression of a gene or a gene module. Finally, it is also possible to
recluster the cells according to their cell type. The first thing to do
is to define a cell type of interest. We selected B and T cells in this
vignette to remain consistent with the previous repertoire analysis. A
column “cell.state” will be added to the VGM[[2]] data (GEX).</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Function to directly add the celltype.</span></span>
<span><span class="va">celltype_GEX_assignment</span><span class="op">&lt;-</span><span class="kw">function</span><span class="op">(</span><span class="va">vgm</span>, <span class="va">cell_names</span>, <span class="va">cell_markers</span><span class="op">)</span><span class="op">{</span></span>
<span>  <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/GEX_phenotype.html">GEX_phenotype</a></span><span class="op">(</span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span>, cell.state.names <span class="op">=</span> <span class="va">cell_names</span>, cell.state.markers <span class="op">=</span> <span class="va">cell_markers</span>, default <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span>  <span class="op">}</span></span>
<span><span class="co">#Assignment of T and B cell type to vgm containing only GEX under cell.state.</span></span>
<span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu">celltype_GEX_assignment</span><span class="op">(</span>vgm<span class="op">=</span><span class="va">vgm</span>, cell_names <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">"T"</span>,<span class="st">"B"</span><span class="op">)</span>, cell_markers <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">"CD3E+;CD4+;CD8A+"</span>,<span class="st">"CD19+;SDC1+;XBP1+"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<div class="section level4">
<h4 id="celltype-plotting-and-density">5.2.1 Celltype plotting and density<a class="anchor" aria-label="anchor" href="#celltype-plotting-and-density"></a>
</h4>
<p>After assigning cell types, they can be plotted together or
separately. The cell density of each type on the image can also be
calculated. In our example we choose to represent B cells as well as T
cells. The cells are detected by markers present in their transcriptome
(for B cells: CD19, SDC1, and XBP1 and for T cells: CD3E, CD4, and
CD8A). We also represent the density of each cell type on the spatial
image to get an idea of their distribution on the sample.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#B and T cells plotting on the same graph</span></span>
<span><span class="fu"><a href="../reference/Spatial_celltype_plot.html">Spatial_celltype_plot</a></span><span class="op">(</span>bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,vgm_GEX <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">@</span><span class="va">meta.data</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title<span class="op">=</span><span class="st">"B and T celltype"</span>, legend_title <span class="op">=</span> <span class="st">"Celltype"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-12-1.png" width="700"></p>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#B cells plotting alone</span></span>
<span><span class="va">B_celltype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_celltype_plot.html">Spatial_celltype_plot</a></span><span class="op">(</span>bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,vgm_GEX <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">@</span><span class="va">meta.data</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title<span class="op">=</span><span class="st">"B celltype"</span>, legend_title <span class="op">=</span> <span class="st">"Celltype"</span>, specific_celltype <span class="op">=</span> <span class="st">"B"</span>, density <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">B_celltype</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-12-2.png" width="700"></p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#B cells density plotting</span></span>
<span><span class="va">B_celltype</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-12-3.png" width="700"></p>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#T cells plotting alone</span></span>
<span><span class="va">T_celltype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_celltype_plot.html">Spatial_celltype_plot</a></span><span class="op">(</span>bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,vgm_GEX <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">@</span><span class="va">meta.data</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title<span class="op">=</span><span class="st">"T celltype"</span>, legend_title <span class="op">=</span> <span class="st">"Celltype"</span>, specific_celltype <span class="op">=</span> <span class="st">"T"</span>, density <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">T_celltype</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-12-4.png" width="700"></p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#T cells density</span></span>
<span><span class="va">T_celltype</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-12-5.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="single-gene-expression">5.2.2 Single gene expression<a class="anchor" aria-label="anchor" href="#single-gene-expression"></a>
</h4>
<p>An important feature of spatial analysis is the ability to visualize
the expression of a gene/marker on the tissue sample. We can choose to
express this marker according to its expression level or we can set a
threshold above which the marker must be expressed to be plotted. For
our example we will choose a marker present in B lymphocytes: CD19.</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Without a threshold</span></span>
<span><span class="va">p_spatial_marker_expression_without_threshold</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_marker_expression.html">Spatial_marker_expression</a></span><span class="op">(</span>matrix<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">9</span><span class="op">]</span><span class="op">]</span>, marker<span class="op">=</span><span class="st">"CD19"</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,GEX_barcode<span class="op">=</span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span><span class="op">$</span><span class="va">barcode</span>,sample_names<span class="op">=</span><span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"Single gene expression"</span>, threshold <span class="op">=</span> <span class="st">"No"</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## New names:</span></span>
<span><span class="co">## <span style="color: #00BBBB;">•</span> `` -&gt; `...13`</span></span></code></pre>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p_spatial_marker_expression_without_threshold</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-13-1.png" width="700"></p>
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#With a threshold</span></span>
<span><span class="va">p_spatial_marker_expression_with_threshold</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_marker_expression.html">Spatial_marker_expression</a></span><span class="op">(</span>matrix<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">9</span><span class="op">]</span><span class="op">]</span>, marker<span class="op">=</span><span class="st">"CD19"</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,GEX_barcode<span class="op">=</span><span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span><span class="op">$</span><span class="va">barcode</span>,sample_names<span class="op">=</span><span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"Single gene expression"</span>, threshold <span class="op">=</span> <span class="fl">5</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## New names:</span></span>
<span><span class="co">## <span style="color: #00BBBB;">•</span> `` -&gt; `...13`</span></span></code></pre>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p_spatial_marker_expression_with_threshold</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-13-2.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="gene-module-expression">5.2.3 Gene module expression<a class="anchor" aria-label="anchor" href="#gene-module-expression"></a>
</h4>
<p>The visualization of a single marker is often not sufficient to
answer immunological questions within a tissue. Another tool concerning
gene expression is a function allowing to visualize the expression of a
gene module that can be defined by the user. Again, to stay in the theme
of immune cells, we choose to analyze the list of markers used to detect
B cells in the transcriptome: CD19, XBP1, and SDC1.</p>
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">gene.set</span> <span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">gene.set</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</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">"CD19"</span>,<span class="st">"XBP1"</span>,<span class="st">"SDC1"</span><span class="op">)</span></span></code></pre></div>
<p>As for gene expression, the user can choose to add a threshold or not
to visualize the expression of the gene module.</p>
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Without a threshold</span></span>
<span><span class="fu"><a href="../reference/Spatial_module_expression.html">Spatial_module_expression</a></span><span class="op">(</span>sample_names <span class="op">=</span> <span class="va">sample_names</span>,gene.set <span class="op">=</span> <span class="va">gene.set</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, threshold <span class="op">=</span> <span class="st">"No"</span>, title <span class="op">=</span> <span class="st">"Gene module visualization"</span>, legend_title <span class="op">=</span> <span class="st">"CD19, XBP1 and SDC1"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-15-1.png" width="700"></p>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#With a threshold</span></span>
<span><span class="fu"><a href="../reference/Spatial_module_expression.html">Spatial_module_expression</a></span><span class="op">(</span>sample_names <span class="op">=</span> <span class="va">sample_names</span>,gene.set <span class="op">=</span> <span class="va">gene.set</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, threshold <span class="op">=</span> <span class="fl">1</span>,title <span class="op">=</span> <span class="st">"Gene module visualization"</span>, legend_title <span class="op">=</span> <span class="st">"CD19, XBP1 and SDC1"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-15-2.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="clustering">5.2.4 Clustering<a class="anchor" aria-label="anchor" href="#clustering"></a>
</h4>
<p>Clustering of cells based on their gene expression is already
proposed by 10X Genomics. However, this classification takes into
account the GEX data of the whole tissue sample. We have implemented a
function capable of reclustering the cells according to a subset. This
can be useful to recluster only the B cells detected on the image to
further investigate B cell heterogeneity. With a single function call
the user can modify the cluster resolution parameter to represent the
cluster previously defined by 10X genomics (cluster = “GEX_cluster”) or
to recluster the cells according to a subtype (cluster =
“reclustering”). Again, this function does not only work for B cells but
also for any other cell type or any other subgroup of cells. For a
better visualization, we also propose an image containing only the 5
most expanded clonotypes.</p>
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Old GEX clusters given by 10X</span></span>
<span><span class="va">GEX_cluster_B_cells</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_cluster.html">Spatial_cluster</a></span><span class="op">(</span>cluster <span class="op">=</span> <span class="st">"GEX_cluster"</span>, vgm_cluster <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">spatial</span><span class="op">$</span><span class="va">cluster</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"B cells"</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, legend_title <span class="op">=</span> <span class="st">"GEX clusters"</span> <span class="op">)</span></span>
<span><span class="va">p_spatial_B_cells_GEX_cluster</span><span class="op">&lt;-</span><span class="va">GEX_cluster_B_cells</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">p_spatial_B_cells_GEX_cluster</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-16-1.png" width="700"></p>
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Reclustering with only B cells</span></span>
<span><span class="va">reclustering_B_cells</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_cluster.html">Spatial_cluster</a></span><span class="op">(</span>cluster <span class="op">=</span> <span class="st">"reclustering"</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"B cells"</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, legend_title <span class="op">=</span> <span class="st">"Reclustering"</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## Centering and scaling data matrix</span></span></code></pre>
<pre><code><span><span class="co">## PC_ 1 </span></span>
<span><span class="co">## Positive:  HMGN2, CR2, CLU, HMGB2, ELL3, PFN1, SERPINE2, RGS13, ACTG1, FDCSP </span></span>
<span><span class="co">##     SERF2, TUBA1B, TUBB, STMN1, SERPINA9, LRMP, MEF2B, FCAMR, H3F3A, HMGB1 </span></span>
<span><span class="co">##     H2AFZ, HMGN1, MARCKSL1, PPIA, HMCES, CFL1, PTTG1, VPREB3, RFTN1, SUGCT </span></span>
<span><span class="co">## Negative:  IGKC, IGHG1, IGHG4, IGHG2, IGHG3, CCL2, IGLC2, IGHA1, SSR4, C7 </span></span>
<span><span class="co">##     XBP1, IGHGP, NR4A1, C1QA, CCL21, CST3, IGLC1, JCHAIN, SOCS3, THBS1 </span></span>
<span><span class="co">##     C11orf96, IGLC3, CCN1, DUSP1, GAS6, HSP90B1, CXCL12, STAB1, EGFL7, IFITM3 </span></span>
<span><span class="co">## PC_ 2 </span></span>
<span><span class="co">## Positive:  TRAC, TRBC2, TRBC1, TCF7, LINC00861, LDLRAP1, IL7R, CD3E, CCL21, LAT </span></span>
<span><span class="co">##     CD6, ZAP70, TNFRSF25, CCR7, CD3D, CD247, CHRM3-AS2, LEF1, GIMAP7, PIK3IP1 </span></span>
<span><span class="co">##     XBP1, AQP3, ITK, IL32, CD5, PRKCQ-AS1, MZB1, GIMAP5, CD2, PIM2 </span></span>
<span><span class="co">## Negative:  VIM, IGFBP7, SERPINE1, CCL20, TIMP1, CEMIP, CHI3L1, SOD2, TNC, THY1 </span></span>
<span><span class="co">##     TIMP3, CLDN5, THBD, CSF2RB, STAB1, CXCL5, MT-CO1, PTGDS, SPARC, GRN </span></span>
<span><span class="co">##     CXCL2, FUCA1, MARCKS, IGFBP4, PDLIM1, LMNA, LYZ, TFPI, FN1, MT-CO2 </span></span>
<span><span class="co">## PC_ 3 </span></span>
<span><span class="co">## Positive:  TRBC2, TRBC1, CCL19, TRAC, IL32, CCR7, IL7R, TCF7, LAMP3, CD3D </span></span>
<span><span class="co">##     CD7, C3, STAT1, CCL21, CD6, GIMAP7, PIK3IP1, IFITM1, CD247, LINC00861 </span></span>
<span><span class="co">##     CD2, CD3E, LAT, CXCL9, SPOCK2, LEF1, CTLA4, GIMAP5, RGS1, FSCN1 </span></span>
<span><span class="co">## Negative:  IGHG4, IGKC, IGHG1, IGLC2, MZB1, IGHG3, IGHG2, IGHGP, IGLC1, JCHAIN </span></span>
<span><span class="co">##     XBP1, IGLC3, SSR4, IGHM, BTG2, TXNDC5, DERL3, TENT5C, HERPUD1, POU2AF1 </span></span>
<span><span class="co">##     GAS6, TCL1A, IGHA1, CXCL12, FKBP11, SEL1L3, CD79A, PRDX4, AC012236.1, SOCS3 </span></span>
<span><span class="co">## PC_ 4 </span></span>
<span><span class="co">## Positive:  CXCL13, MS4A1, FDCSP, FCER2, CD79A, CD22, TNFRSF13C, BANK1, IGHD, HLA-DQA1 </span></span>
<span><span class="co">##     CD79B, CD83, CR2, VPREB3, TLR10, CXCR5, SELE, CCL20, CD1C, LTF </span></span>
<span><span class="co">##     MT-ND4, SPIB, FCRLA, CD24, PAX5, SMIM14, MT-ATP6, MT-CYB, MT-ND1, C3 </span></span>
<span><span class="co">## Negative:  C1QB, C1QC, CST3, CCL21, SELENOP, C1QA, CCL2, CCL14, SLC40A1, CEBPD </span></span>
<span><span class="co">##     LGMN, JCHAIN, TUBA1B, SIGLEC1, APOE, CD209, RRM2, CXCL12, S100A10, GAPDH </span></span>
<span><span class="co">##     SDC3, CCL18, TYROBP, FCER1G, HSP90B1, CCN1, PLK1, UBE2S, MS4A6A, IL7R </span></span>
<span><span class="co">## PC_ 5 </span></span>
<span><span class="co">## Positive:  SFRP2, MYL9, CNN1, ACTA2, ACTG2, FBLN1, TAGLN, MYH11, CCDC80, MGP </span></span>
<span><span class="co">##     SFRP4, SFRP1, DES, ADIRF, SOD3, APOD, HSPB6, MT-ND3, MT-CYB, BGN </span></span>
<span><span class="co">##     COL1A2, MT-ATP6, MUSTN1, WFDC1, MT-CO3, FLNC, COL1A1, MT-ND4, CAVIN3, PLA2G2A </span></span>
<span><span class="co">## Negative:  CLEC4M, CEMIP, MARCO, CD209, CLEC4G, SIGLEC1, MMP9, ICAM1, SOD2, LYVE1 </span></span>
<span><span class="co">##     LYZ, IL1B, EGFL7, CETP, IFI30, STAB1, LPL, STAB2, APOE, PLAUR </span></span>
<span><span class="co">##     CCL14, LGMN, NR1H3, CFP, NAMPT, GZMB, NCEH1, ADAMTS4, CSF1R, SPHK1</span></span></code></pre>
<pre><code><span><span class="co">## Computing nearest neighbor graph</span></span></code></pre>
<pre><code><span><span class="co">## Computing SNN</span></span></code></pre>
<pre><code><span><span class="co">## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Number of nodes: 1645</span></span>
<span><span class="co">## Number of edges: 53909</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Running Louvain algorithm...</span></span>
<span><span class="co">## Maximum modularity in 10 random starts: 0.7298</span></span>
<span><span class="co">## Number of communities: 11</span></span>
<span><span class="co">## Elapsed time: 0 seconds</span></span></code></pre>
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p_spatial_B_cells_new_cluster</span><span class="op">&lt;-</span><span class="va">reclustering_B_cells</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">p_spatial_B_cells_new_cluster</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-16-2.png" width="700"></p>
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Reclustering of the top 5 more expanded clones</span></span>
<span><span class="va">top_5_VDJ_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">10</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span>  <span class="va">a</span><span class="op">&lt;-</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">top_5_VDJ_data</span>, <span class="va">orig_barcode</span>, <span class="va">x</span>, <span class="va">y</span><span class="op">)</span></span>
<span>  <span class="va">b</span><span class="op">&lt;-</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">reclustering_B_cells</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span>, <span class="va">Cluster</span>, <span class="va">orig_barcode</span><span class="op">)</span></span>
<span><span class="va">top_5_VDJ_data_cluster</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/merge.html" class="external-link">merge</a></span><span class="op">(</span><span class="va">a</span>,<span class="va">b</span>, by <span class="op">=</span> <span class="st">"orig_barcode"</span><span class="op">)</span></span>
<span></span>
<span><span class="va">p_spatial_B_cells_new_cluster_top_5_clonotype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_data_cluster</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_data_cluster</span><span class="op">$</span><span class="va">Cluster</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell density assignment"</span>, legend <span class="op">=</span> <span class="st">"Reclustering"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_B_cells_new_cluster_top_5_clonotype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-16-3.png" width="700"></p>
</div>
</div>
</div>
<div class="section level2">
<h2 id="interactive-plotting">6. Interactive plotting<a class="anchor" aria-label="anchor" href="#interactive-plotting"></a>
</h2>
<div class="section level3">
<h3 id="cell-selection">6.1 Cell selection<a class="anchor" aria-label="anchor" href="#cell-selection"></a>
</h3>
<p>So far we have studied cells selected according to their
transcriptome (e.g. according to their cluster), or according to their
VDJ (e.g. according to their clonotypes or isotypes) and displayed them
on the image. The next idea is to reverse the process by first manually
selecting an area of interest and then extracting the corresponding
cells and corresponding information. We can use the VDJ repertoire to
run the Spatial_selection_of_cells_on_image function. This function
allows us to select several areas directly with the computer mouse and
extract cells within this region of interest. It creates a spatial image
of the tissue on which the user can directly interact with by selecting
points with the computer mouse. These points will be connected to form a
polygon. This action can be repeated several times to select different
areas of the same tissue. The cells inside the different polygons will
then be extracted. The function will return, if plotting parameter is
TRUE, a plot of the selected groups and in addition to a data frame
containing all the sequence information of selected cells and their
location on the sample. If the plotting parameter is set to FALSE, the
function only returned the data frame of selected cells. The following
code will run directly in an RMD file but it can be copied and pasted on
an RData file.</p>
<div class="sourceCode" id="cb41"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Example of code</span></span>
<span><span class="va">selected_cells</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_of_cells_on_image.html">Spatial_selection_of_cells_on_image</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">vgm</span><span class="op">$</span><span class="va">VDJ</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,plotting <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="analysis-1">6.2 Analysis<a class="anchor" aria-label="anchor" href="#analysis-1"></a>
</h3>
<p>Based on the output data frame returned from the previous function
(section 7.1) we can use the same analysis tools as presented before.
Clonotypes, clustering and reclustering of cells, isotypes, or number of
somatic hypermutations can be plotted on the spatial image. The first
step is to filter the VDJ data to extract only data corresponding to
selected cells.</p>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Example of code for cell filtering</span></span>
<span><span class="va">BCR_selected</span><span class="op">&lt;-</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="va">selected_cells</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span>, <span class="va">selection_group</span> <span class="op">!=</span> <span class="fl">0</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Example of code for selection group plotting</span></span>
<span><span class="va">p_spatial_BCR_selected</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">BCR_selected</span>, analysis <span class="op">=</span> <span class="va">BCR_selected</span><span class="op">$</span><span class="va">selection_group</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell"</span>, legend <span class="op">=</span> <span class="st">"Selection group"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_selected</span></span>
<span></span>
<span><span class="co">#Example of code for clonotypes plotting</span></span>
<span><span class="va">p_spatial_BCR_selected_clonotypes</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">BCR_selected</span>, analysis <span class="op">=</span> <span class="va">BCR_selected</span><span class="op">$</span><span class="va">clonotype_id</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell"</span>, legend <span class="op">=</span> <span class="st">"Clonotype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_selected_clonotypes</span></span>
<span></span>
<span><span class="co">#Example of code for isotypes plotting</span></span>
<span><span class="va">p_spatial_BCR_selected_isotypes</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">BCR_selected</span>, analysis <span class="op">=</span> <span class="va">BCR_selected</span><span class="op">$</span><span class="va">VDJ_cgene</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell"</span>, legend <span class="op">=</span> <span class="st">"Isotype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_selected_isotypes</span></span>
<span></span>
<span><span class="co">#Example of code for SHM and clonotype tracking</span></span>
<span><span class="co">#1)trees without intermediate</span></span>
<span><span class="va">forest</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/AntibodyForests.html">AntibodyForests</a></span><span class="op">(</span>VDJ<span class="op">=</span><span class="va">BCR_selected</span>, network.algorithm<span class="op">=</span><span class="st">'tree'</span>,  expand.intermediates<span class="op">=</span><span class="cn">F</span>, network.level<span class="op">=</span><span class="st">'intraclonal'</span>,parallel<span class="op">=</span><span class="cn">F</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Clonotype we study</span></span>
<span><span class="va">clonotype_number</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">forest</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[</span><span class="fl">2</span><span class="op">]</span><span class="op">)</span></span>
<span><span class="va">clonotype_number</span></span>
<span><span class="co">#plot</span></span>
<span><span class="va">tree_plot</span><span class="op">&lt;-</span><span class="va">forest</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</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/AntibodyForests_plot.html">AntibodyForests_plot</a></span><span class="op">(</span>node.label <span class="op">=</span> <span class="st">"rank"</span><span class="op">)</span></span>
<span><span class="fu">igraph</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/igraph/man/plot.igraph.html" class="external-link">plot.igraph</a></span><span class="op">(</span><span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="../reference/Spatial_nb_SHM_compare_to_germline_plot.html">Spatial_nb_SHM_compare_to_germline_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,AbForest_output<span class="op">=</span><span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>, vgm_VDJ <span class="op">=</span> <span class="va">BCR_selected</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title <span class="op">=</span> <span class="st">"Number of SHM of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Daughter cell assign to the closest mother cell</span></span>
<span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,tracking_type <span class="op">=</span> <span class="st">"closest"</span>,AbForest_output <span class="op">=</span> <span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>,VDJ<span class="op">=</span><span class="va">BCR_selected</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"Tracking evolution of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span> <span class="op">)</span></span>
<span><span class="co">#All mother cells link all daughter cells</span></span>
<span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">FALSE</span>,tracking_type <span class="op">=</span> <span class="st">"all"</span>,AbForest_output <span class="op">=</span> <span class="va">tree_plot</span><span class="op">@</span><span class="va">plot_ready</span>,VDJ<span class="op">=</span><span class="va">BCR_selected</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"Tracking evolution of clonotype 10"</span>, legend_title <span class="op">=</span> <span class="st">"nb of SHM"</span> <span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level2">
<h2 id="echidna-simulation-of-the-vdj">7. Echidna simulation of the VDJ<a class="anchor" aria-label="anchor" href="#echidna-simulation-of-the-vdj"></a>
</h2>
<p>Often VDJ data is not available for spatial transcriptomic datasets.
If VDJ.out.directory.list corresponding to immune receptor data is
missing, we have integrated a simulation framework, called Echidna, to
simulate the VDJ sequences of BCR or TCR according to the number of B or
T cells detected on the image. If VDJ repertoire is not given,
VDJ.out.directory.list can be set to “NULL”. First, we give the path to
the spatial files and we set up the needed libraries.</p>
<p>We can then run the VDJ_GEX_matrix function to form a VGM containing
only transcriptome information.</p>
<div class="sourceCode" id="cb43"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#VGM without VDJ</span></span>
<span><span class="va">vgm_with_transcriptome_only</span><span class="op">&lt;-</span> <span class="fu"><a href="../reference/VDJ_GEX_matrix.html">VDJ_GEX_matrix</a></span><span class="op">(</span>GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span>,</span>
<span>                                                 exclude.on.cell.state.markers <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">"no filtering"</span><span class="op">)</span>, </span>
<span>                                                 group.id <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">"Human Lymph Node"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## 09:15:36 </span></span>
<span><span class="co">##  Loading in data</span></span></code></pre>
<pre><code><span><span class="co">## 09:16:02 Loaded GEX data</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">## For sample 1: 4035 cell assigned barcodes in GEX</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  In GEX sample 1 failed to exclude cells based on: NO FILTERING Please check gene spelling</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  Starting GEX pipeline</span></span></code></pre>
<pre><code><span><span class="co">## Centering and scaling data matrix</span></span></code></pre>
<pre><code><span><span class="co">## PC_ 1 </span></span>
<span><span class="co">## Positive:  CR2, HMGN2, ELL3, RGS13, SERPINE2, MEF2B, HMGB2, FDCSP, CLU, FCAMR </span></span>
<span><span class="co">##     LRMP, STMN1, SERPINA9, HMCES, HMGN1, MARCKSL1, VPREB3, H2AFZ, SUGCT, HMGB1 </span></span>
<span><span class="co">##     TUBA1B, MYBL1, TUBB, TCL1A, CDCA7, RFTN1, H3F3A, EZR, PTTG1, SERF2 </span></span>
<span><span class="co">## Negative:  CCL21, CCL2, CST3, IGFBP7, NR4A1, IFITM3, C1QA, C7, DUSP1, CCN1 </span></span>
<span><span class="co">##     THBS1, CCL19, C11ORF96, C1QB, SOD2, EGFL7, STAB1, ZFP36, CEBPD, SOCS3 </span></span>
<span><span class="co">##     C1R, C1QC, CLDN5, NNMT, TIMP3, TAGLN, TNC, SERPING1, PECAM1, CEMIP </span></span>
<span><span class="co">## PC_ 2 </span></span>
<span><span class="co">## Positive:  CD74, HLA-DRA, TIMP3, CEMIP, IGFBP7, SERPINE1, CLDN5, STAB1, PSAP, EGFL7 </span></span>
<span><span class="co">##     VIM, TIMP1, TNC, LYZ, SOD2, MARCO, CCL20, CD79A, CLEC4M, DUSP1 </span></span>
<span><span class="co">##     IGFBP4, CTSD, SPARC, CHI3L1, PTGDS, GRN, MS4A1, TFPI, IFITM3, PRCP </span></span>
<span><span class="co">## Negative:  TCF7, CCR7, CD6, CD3E, CD247, IL7R, GIMAP7, CD3D, LEF1, LINC00861 </span></span>
<span><span class="co">##     LAT, ZAP70, PIK3IP1, CHRM3-AS2, DGKA, LDLRAP1, CD2, PRKCQ-AS1, CD7, CD3G </span></span>
<span><span class="co">##     TNFRSF25, IL32, BCL11B, CD5, GIMAP5, ITK, CTLA4, SPOCK2, MAL, GIMAP1 </span></span>
<span><span class="co">## PC_ 3 </span></span>
<span><span class="co">## Positive:  CCL21, C1QB, IL7R, CCL19, CCL2, C1QC, LINC00861, LDLRAP1, CEBPD, GAPDH </span></span>
<span><span class="co">##     TCF7, SLC40A1, CD247, TXNDC5, CD3D, CD3E, TUBA1B, C1QA, CST3, TNFRSF25 </span></span>
<span><span class="co">##     XBP1, CXCL9, CD6, LEF1, MZB1, LAT, PIM2, ZAP70, HSP90B1, SELENOP </span></span>
<span><span class="co">## Negative:  CXCL13, FDCSP, CD74, MS4A1, HLA-DRA, FCER2, HLA-DQA1, BANK1, TNFRSF13C, CD19 </span></span>
<span><span class="co">##     CCL20, CD22, CD79A, SELE, MT-CO2, VPREB3, LINC00926, MT-CO3, MT-CO1, CR2 </span></span>
<span><span class="co">##     CD79B, LTF, CR1, MT-ND1, MT-ND4, CD24, TLR10, CHI3L1, SMIM14, CD1C </span></span>
<span><span class="co">## PC_ 4 </span></span>
<span><span class="co">## Positive:  TMSB4X, CCL20, STAT1, IFIT1, ISG15, LAMP3, IFI6, IFIT3, ITGAX, MX1 </span></span>
<span><span class="co">##     OAS3, FSCN1, IFI44L, CXCL5, CHI3L1, EPSTI1, IFI44, VIM, FUCA1, PLA2G2D </span></span>
<span><span class="co">##     CSF2RB, UBD, SOD2, ATOX1, ENPP2, RSAD2, DNASE1L3, OAS1, MX2, CXCL10 </span></span>
<span><span class="co">## Negative:  MZB1, XBP1, BTG2, CXCL12, SSR4, TXNDC5, RNASE1, GAS6, DERL3, MYL9 </span></span>
<span><span class="co">##     SDC1, A2M, GPX3, ADIRF, IGFBP5, MYH11, ACTA2, TAGLN, ACTG2, CNN1 </span></span>
<span><span class="co">##     SLIT3, DPEP1, TENT5C, FBLN1, CCL14, FKBP11, APOD, SFRP2, AQP1, SPARCL1 </span></span>
<span><span class="co">## PC_ 5 </span></span>
<span><span class="co">## Positive:  SIGLEC1, CD209, CLEC4M, CLEC4G, LINC00926, XBP1, MZB1, LYVE1, MARCO, BTG2 </span></span>
<span><span class="co">##     CXCL12, CCL14, STAB2, GZMB, DERL3, HERPUD1, TXNDC5, HSP90B1, CEMIP, PIM2 </span></span>
<span><span class="co">##     SLAMF7, TCL1A, CCL2, ICAM1, POU2AF1, FCER2, CD22, CD19, CETP, CD74 </span></span>
<span><span class="co">## Negative:  MT-CO3, MT-CYB, MYH11, ACTG2, MT-ND3, MT-ATP6, CNN1, MT-CO2, MYL9, ACTA2 </span></span>
<span><span class="co">##     ADIRF, MT-CO1, SOD3, SFRP2, MT-ND1, COL1A2, MT-ND4, MGP, MT-ND2, CCDC80 </span></span>
<span><span class="co">##     DES, MUSTN1, FBLN1, WFDC1, BGN, COL1A1, TAGLN, C3, SULF1, CCL19</span></span></code></pre>
<pre><code><span><span class="co">## Computing nearest neighbor graph</span></span></code></pre>
<pre><code><span><span class="co">## Computing SNN</span></span></code></pre>
<pre><code><span><span class="co">## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Number of nodes: 4035</span></span>
<span><span class="co">## Number of edges: 134810</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Running Louvain algorithm...</span></span>
<span><span class="co">## Maximum modularity in 10 random starts: 0.8360</span></span>
<span><span class="co">## Number of communities: 8</span></span>
<span><span class="co">## Elapsed time: 0 seconds</span></span></code></pre>
<pre><code><span><span class="co">## Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric</span></span>
<span><span class="co">## To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'</span></span>
<span><span class="co">## This message will be shown once per session</span></span></code></pre>
<pre><code><span><span class="co">## 09:16:46 UMAP embedding parameters a = 0.9922 b = 1.112</span></span></code></pre>
<pre><code><span><span class="co">## 09:16:46 Read 4035 rows and found 10 numeric columns</span></span></code></pre>
<pre><code><span><span class="co">## 09:16:46 Using Annoy for neighbor search, n_neighbors = 30</span></span></code></pre>
<pre><code><span><span class="co">## 09:16:46 Building Annoy index with metric = cosine, n_trees = 50</span></span></code></pre>
<pre><code><span><span class="co">## 0%   10   20   30   40   50   60   70   80   90   100%</span></span></code></pre>
<pre><code><span><span class="co">## [----|----|----|----|----|----|----|----|----|----|</span></span></code></pre>
<pre><code><span><span class="co">## **************************************************|</span></span>
<span><span class="co">## 09:16:47 Writing NN index file to temp file C:\Users\vickr\AppData\Local\Temp\RtmpS8QzWs\file6dd46b9044b6</span></span>
<span><span class="co">## 09:16:47 Searching Annoy index using 1 thread, search_k = 3000</span></span>
<span><span class="co">## 09:16:48 Annoy recall = 100%</span></span>
<span><span class="co">## 09:16:49 Commencing smooth kNN distance calibration using 1 thread</span></span>
<span><span class="co">## 09:16:51 Initializing from normalized Laplacian + noise</span></span>
<span><span class="co">## 09:16:51 Commencing optimization for 500 epochs, with 166522 positive edges</span></span>
<span><span class="co">## 09:17:04 Optimization finished</span></span>
<span><span class="co">## 09:17:04 Calculating TSNE embedding</span></span>
<span><span class="co">## 09:17:23 Done with GEX pipeline</span></span>
<span><span class="co">##  Adding runtime params</span></span>
<span><span class="co">## 09:17:24 Done!</span></span>
<span><span class="co">## 2022-08-18 09:17:24</span></span></code></pre>
<p>To simulate the correct number of BCRs or TCRs we need to know how
many B or T cell are found in the dataset. With a list of chosen markers
for T (CD3E+, CD4+, CD8A+) and B (CD19+, SDC1+, XBP1+) cells, we
classified lymphocytes based on their transcriptome. If a cell expresses
the three genes, they will be classified as either a T or B cell. The
user can of course define their own markers according to their own cell
type by using the GEX_phenotype function. After cell type assignment, it
is possible to count the number of cells of each type to know how many
BCR or TCR the user has to simulate.</p>
<div class="sourceCode" id="cb62"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Function to directly add the celltype.</span></span>
<span><span class="va">celltype_GEX_assignment</span><span class="op">&lt;-</span><span class="kw">function</span><span class="op">(</span><span class="va">vgm</span>, <span class="va">cell_names</span>, <span class="va">cell_markers</span><span class="op">)</span><span class="op">{</span></span>
<span>  <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/GEX_phenotype.html">GEX_phenotype</a></span><span class="op">(</span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span>, cell.state.names <span class="op">=</span> <span class="va">cell_names</span>, cell.state.markers <span class="op">=</span> <span class="va">cell_markers</span>, default <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span>  <span class="op">}</span></span>
<span><span class="co">#Assignment of T and B cell type to vgm containing only GEX under cell.state.</span></span>
<span><span class="va">vgm_with_transcriptome_only</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu">celltype_GEX_assignment</span><span class="op">(</span>vgm<span class="op">=</span><span class="va">vgm_with_transcriptome_only</span>, cell_names <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">"T"</span>,<span class="st">"B"</span><span class="op">)</span>, cell_markers <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">"CD3E+;CD4+;CD8A+"</span>,<span class="st">"CD19+;SDC1+;XBP1+"</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Function</span></span>
<span><span class="va">count_nb_of_cell</span><span class="op">&lt;-</span><span class="kw">function</span><span class="op">(</span><span class="va">vgm</span>, <span class="va">celltype</span><span class="op">)</span><span class="op">{</span></span>
<span>  <span class="va">nb</span><span class="op">&lt;-</span><span class="fl">0</span></span>
<span>  <span class="kw">for</span> <span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/length.html" class="external-link">length</a></span><span class="op">(</span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">$</span><span class="va">cell.state</span><span class="op">)</span><span class="op">)</span><span class="op">{</span></span>
<span>    <span class="kw">if</span> <span class="op">(</span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">$</span><span class="va">cell.state</span><span class="op">[[</span><span class="va">i</span><span class="op">]</span><span class="op">]</span><span class="op">==</span><span class="va">celltype</span><span class="op">)</span><span class="op">{</span></span>
<span>      <span class="va">nb</span><span class="op">=</span><span class="va">nb</span><span class="op">+</span><span class="fl">1</span></span>
<span>    <span class="op">}</span></span>
<span>  <span class="op">}</span></span>
<span>  <span class="kw"><a href="https://rdrr.io/r/base/function.html" class="external-link">return</a></span><span class="op">(</span><span class="va">nb</span><span class="op">)</span></span>
<span><span class="op">}</span></span>
<span><span class="co">#Number of B cells</span></span>
<span><span class="va">nb_B_cell</span><span class="op">&lt;-</span><span class="fu">count_nb_of_cell</span><span class="op">(</span>vgm <span class="op">=</span> <span class="va">vgm_with_transcriptome_only</span>, celltype <span class="op">=</span> <span class="st">"B"</span><span class="op">)</span></span>
<span><span class="va">nb_B_cell</span></span></code></pre></div>
<pre><code><span><span class="co">## [1] 1645</span></span></code></pre>
<div class="sourceCode" id="cb64"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Number of T cells</span></span>
<span><span class="va">nb_T_cell</span><span class="op">&lt;-</span><span class="fu">count_nb_of_cell</span><span class="op">(</span>vgm<span class="op">=</span><span class="va">vgm_with_transcriptome_only</span>, celltype <span class="op">=</span> <span class="st">"T"</span><span class="op">)</span> </span>
<span><span class="va">nb_T_cell</span></span></code></pre></div>
<pre><code><span><span class="co">## [1] 1119</span></span></code></pre>
<div class="section level3">
<h3 id="bcrs-simulation">7.1 BCRs simulation<a class="anchor" aria-label="anchor" href="#bcrs-simulation"></a>
</h3>
<p>As the number of B and T cells is known, we simulate the
corresponding number of BCRs or TCRs. The WriteFasta function is
necessary to save data locally in the fasta format. We decided to
simulate B cell receptor sequences but the same can be done for TCRs by
setting the cell.type parameter to “T” and max.cell.number as well as
max.clonotype.number to number of T cells in the simulate_repertoire
function. First, we need to simulate the number of B-cell receptors
(VDJ) corresponding to the number of B cells detected on the image based
on our provided vector of genes. The user has to locally save four main
files corresponding to the VDJ data that can be then integrated to the
VGM. To simplify the path to the folder, we propose to group the locally
downloaded sub-files in a file named VDJ_simulated but it works for any
name as long as the folder contains all four of the necessary files. The
path should be given in VDJ.out.directory.list instead of “NULL”. The
last step is to re-run the whole VGM function call at the same time
including the transcriptome and immune receptor sequence
information.</p>
<div class="sourceCode" id="cb66"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Simulation with Echidna</span></span>
<span><span class="va">simulated_B_cells_VDJ</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Echidna_simulate_repertoire.html">Echidna_simulate_repertoire</a></span><span class="op">(</span>initial.size.of.repertoire <span class="op">=</span> <span class="fl">50</span>,</span>
<span>                                                   species <span class="op">=</span> <span class="st">"hum"</span>,</span>
<span>                                                   cell.type <span class="op">=</span> <span class="st">"B"</span>,</span>
<span>                                                   duration.of.evolution <span class="op">=</span> <span class="fl">30</span>,</span>
<span>                                                   vdj.branch.prob <span class="op">=</span> <span class="fl">0</span>,</span>
<span>                                                   cell.division.prob <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="fl">0.2</span>,<span class="fl">0.2</span>,<span class="fl">0.5</span><span class="op">)</span>,</span>
<span>                                                   max.cell.number <span class="op">=</span> <span class="va">nb_B_cell</span>,</span>
<span>                                                   max.clonotype.number <span class="op">=</span> <span class="va">nb_B_cell</span>,</span>
<span>                                                   complete.duration<span class="op">=</span><span class="cn">T</span>,</span>
<span>                                                   clonal.selection <span class="op">=</span><span class="cn">T</span>,</span>
<span>                                                   class.switch.independent<span class="op">=</span><span class="cn">F</span>,</span>
<span>                                                   transcriptome.on <span class="op">=</span> <span class="cn">T</span>,</span>
<span>                                                   death.rate <span class="op">=</span> <span class="fl">0</span>,</span>
<span>                                                   igraph.on <span class="op">=</span> <span class="cn">T</span>,</span>
<span>                                                   SHM.isotype.dependent <span class="op">=</span> <span class="cn">T</span>,</span>
<span>                                                   SHM.nuc.prob <span class="op">=</span> <span class="fl">0.00001</span>,</span>
<span>                                                   sequence.selection.prob <span class="op">=</span> <span class="fl">0.5</span>,</span>
<span>                                                   transcriptome.switch.selection.dependent <span class="op">=</span> <span class="cn">T</span>,</span>
<span>                                                   class.switch.selection.dependent <span class="op">=</span> <span class="cn">T</span></span>
<span>        <span class="op">)</span></span>
<span><span class="co">#Some modifications to use the simulation as an input for the vgm function</span></span>
<span><span class="va">all_contig_annotations</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/as.data.frame.html" class="external-link">as.data.frame</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">all_contig_annotations</span><span class="op">)</span></span>
<span><span class="va">all_contig_annotations</span><span class="op">[</span><span class="va">all_contig_annotations</span><span class="op">==</span><span class="st">'Ture'</span><span class="op">]</span><span class="op">&lt;-</span><span class="st">'true'</span></span>
<span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">all_contig_annotations</span><span class="op">&lt;-</span><span class="va">all_contig_annotations</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">all_contig_annotations</span><span class="op">)</span><span class="op">[</span><span class="fl">3</span><span class="op">]</span><span class="op">&lt;-</span><span class="st">"contig_id"</span></span>
<span></span>
<span><span class="co">#Write fasta function</span></span>
<span><span class="va">writeFasta</span><span class="op">&lt;-</span><span class="kw">function</span><span class="op">(</span><span class="va">data</span>, <span class="va">filename</span><span class="op">)</span><span class="op">{</span></span>
<span>  <span class="va">fastaLines</span> <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="op">)</span></span>
<span>  <span class="kw">for</span> <span class="op">(</span><span class="va">rowNum</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">nrow</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span><span class="op">)</span><span class="op">{</span></span>
<span>    <span class="va">fastaLines</span> <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="va">fastaLines</span>, <span class="fu"><a href="https://rdrr.io/r/base/character.html" class="external-link">as.character</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html" class="external-link">paste</a></span><span class="op">(</span><span class="st">"&gt;"</span>, <span class="va">data</span><span class="op">[</span><span class="va">rowNum</span>,<span class="st">"name"</span><span class="op">]</span>, sep <span class="op">=</span> <span class="st">""</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span>    <span class="va">fastaLines</span> <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="va">fastaLines</span>,<span class="fu"><a href="https://rdrr.io/r/base/character.html" class="external-link">as.character</a></span><span class="op">(</span><span class="va">data</span><span class="op">[</span><span class="va">rowNum</span>,<span class="st">"seq"</span><span class="op">]</span><span class="op">)</span><span class="op">)</span></span>
<span>    <span class="op">}</span></span>
<span>  <span class="va">fileConn</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/connections.html" class="external-link">file</a></span><span class="op">(</span><span class="va">filename</span><span class="op">)</span></span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/writeLines.html" class="external-link">writeLines</a></span><span class="op">(</span><span class="va">fastaLines</span>, <span class="va">fileConn</span><span class="op">)</span></span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/connections.html" class="external-link">close</a></span><span class="op">(</span><span class="va">fileConn</span><span class="op">)</span></span>
<span><span class="op">}</span></span>
<span></span>
<span><span class="co">#Save locally VDJ files needed</span></span>
<span><span class="co">#1) filtered_contig_annotations.csv</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/write.table.html" class="external-link">write.csv</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">all_contig_annotations</span>,<span class="st">"C:/Users/vickr/VDJ_simulated/filtered_contig_annotations.csv"</span>,row.names <span class="op">=</span> <span class="cn">FALSE</span>, quote<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co">#2) clonotypes.csv</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/write.table.html" class="external-link">write.csv</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">clonotypes</span>, <span class="st">"C:/Users/vickr/VDJ_simulated/clonotypes.csv"</span>, row.names <span class="op">=</span> <span class="cn">FALSE</span>, quote<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co">#3) concat_ref.fasta</span></span>
<span><span class="va">concat_ref</span><span class="op">&lt;-</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">reference</span></span>
<span><span class="va">concat_ref</span><span class="op">=</span><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html" class="external-link">tibble</a></span><span class="op">(</span>name<span class="op">=</span><span class="va">concat_ref</span><span class="op">$</span><span class="va">reference_id</span>, seq<span class="op">=</span><span class="va">concat_ref</span><span class="op">$</span><span class="va">reference_seq</span><span class="op">)</span></span>
<span><span class="fu">writeFasta</span><span class="op">(</span><span class="va">concat_ref</span>,<span class="st">"C:/Users/vickr/VDJ_simulated/concat_ref.fasta"</span><span class="op">)</span></span>
<span><span class="co">#4) filtered_contig.fasta</span></span>
<span><span class="va">all_contig</span><span class="op">&lt;-</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">all_contig</span></span>
<span><span class="va">all_contig</span><span class="op">=</span><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html" class="external-link">tibble</a></span><span class="op">(</span>name<span class="op">=</span><span class="va">all_contig</span><span class="op">$</span><span class="va">raw_contig_id</span>, seq<span class="op">=</span><span class="va">all_contig</span><span class="op">$</span><span class="va">seq</span><span class="op">)</span></span>
<span><span class="fu">writeFasta</span><span class="op">(</span><span class="va">all_contig</span>,<span class="st">"C:/Users/vickr/VDJ_simulated/filtered_contig.fasta"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Give path to VDJ file</span></span>
<span><span class="va">VDJ.out.directory.list</span> <span class="op">&lt;-</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="op">)</span></span>
<span><span class="va">VDJ.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span><span class="op">&lt;-</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">"C:/Users/vickr/VDJ_simulated/"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Re-run VGM with VDJ information</span></span>
<span><span class="va">vgm_with_VDJ</span> <span class="op">&lt;-</span><span class="fu"><a href="../reference/VDJ_GEX_matrix.html">VDJ_GEX_matrix</a></span><span class="op">(</span>VDJ.out.directory.list <span class="op">=</span> <span class="va">VDJ.out.directory.list</span>,                         </span>
<span>                                              GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span>,</span>
<span>                                              exclude.on.cell.state.markers <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">"no filtering"</span><span class="op">)</span>, </span>
<span>                                              group.id <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">"Human Lymph Node"</span><span class="op">)</span><span class="op">)</span> </span></code></pre></div>
<pre><code><span><span class="co">## 09:21:56 </span></span>
<span><span class="co">##  Loading in data</span></span></code></pre>
<pre><code><span><span class="co">## ! metrics_summary.csv file not available in at least one of the VDJ input directories. Loading will be skipped</span></span></code></pre>
<pre><code><span><span class="co">## 09:21:57 Loaded VDJ data</span></span></code></pre>
<pre><code><span><span class="co">## 09:22:36 Loaded GEX data</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  Getting VDJ GEX stats</span></span></code></pre>
<pre><code><span><span class="co">## Starting with 1 of 1</span></span></code></pre>
<pre><code><span><span class="co">## VDJ stats failed: Error in `$&lt;-.data.frame`(`*tmp*`, "cdr3s_aa", value = character(0)): replacement has 0 rows, data has 50</span></span></code></pre>
<pre><code><span><span class="co">## </span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  For sample 1: 4035 cell assigned barcodes in GEX, 1645 cell assigned high confidence barcodes in VDJ. Overlap: 0</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  In GEX sample 1 failed to exclude cells based on: NO FILTERING Please check gene spelling</span></span></code></pre>
<pre><code><span><span class="co">## 09:22:36  Starting VDJ barcode iteration 1 of 1...</span></span></code></pre>
<pre><code><span><span class="co">## Warning in VDJ.proc$Nr_of_VJ_chains == 0 &amp;&amp; VDJ.proc$Nr_of_VDJ_chains == :</span></span>
<span><span class="co">## 'length(x) = 1645 &gt; 1' in coercion to 'logical(1)'</span></span></code></pre>
<pre><code><span><span class="co">## 09:24:23 Done with 1 of 1</span></span></code></pre>
<pre><code><span><span class="co">## </span></span>
<span><span class="co">##  Starting GEX pipeline</span></span></code></pre>
<pre><code><span><span class="co">## Centering and scaling data matrix</span></span></code></pre>
<pre><code><span><span class="co">## PC_ 1 </span></span>
<span><span class="co">## Positive:  CR2, HMGN2, ELL3, RGS13, SERPINE2, MEF2B, HMGB2, FDCSP, CLU, FCAMR </span></span>
<span><span class="co">##     LRMP, STMN1, SERPINA9, HMCES, HMGN1, MARCKSL1, VPREB3, H2AFZ, SUGCT, HMGB1 </span></span>
<span><span class="co">##     TUBA1B, MYBL1, TUBB, TCL1A, CDCA7, RFTN1, H3F3A, EZR, PTTG1, SERF2 </span></span>
<span><span class="co">## Negative:  CCL21, CCL2, CST3, IGFBP7, NR4A1, IFITM3, C1QA, C7, DUSP1, CCN1 </span></span>
<span><span class="co">##     THBS1, CCL19, C11ORF96, C1QB, SOD2, EGFL7, STAB1, ZFP36, CEBPD, SOCS3 </span></span>
<span><span class="co">##     C1R, C1QC, CLDN5, NNMT, TIMP3, TAGLN, TNC, SERPING1, PECAM1, CEMIP </span></span>
<span><span class="co">## PC_ 2 </span></span>
<span><span class="co">## Positive:  CD74, HLA-DRA, TIMP3, CEMIP, IGFBP7, SERPINE1, CLDN5, STAB1, PSAP, EGFL7 </span></span>
<span><span class="co">##     VIM, TIMP1, TNC, LYZ, SOD2, MARCO, CCL20, CD79A, CLEC4M, DUSP1 </span></span>
<span><span class="co">##     IGFBP4, CTSD, SPARC, CHI3L1, PTGDS, GRN, MS4A1, TFPI, IFITM3, PRCP </span></span>
<span><span class="co">## Negative:  TCF7, CCR7, CD6, CD3E, CD247, IL7R, GIMAP7, CD3D, LEF1, LINC00861 </span></span>
<span><span class="co">##     LAT, ZAP70, PIK3IP1, CHRM3-AS2, DGKA, LDLRAP1, CD2, PRKCQ-AS1, CD7, CD3G </span></span>
<span><span class="co">##     TNFRSF25, IL32, BCL11B, CD5, GIMAP5, ITK, CTLA4, SPOCK2, MAL, GIMAP1 </span></span>
<span><span class="co">## PC_ 3 </span></span>
<span><span class="co">## Positive:  CCL21, C1QB, IL7R, CCL19, CCL2, C1QC, LINC00861, LDLRAP1, CEBPD, GAPDH </span></span>
<span><span class="co">##     TCF7, SLC40A1, CD247, TXNDC5, CD3D, CD3E, TUBA1B, C1QA, CST3, TNFRSF25 </span></span>
<span><span class="co">##     XBP1, CXCL9, CD6, LEF1, MZB1, LAT, PIM2, ZAP70, HSP90B1, SELENOP </span></span>
<span><span class="co">## Negative:  CXCL13, FDCSP, CD74, MS4A1, HLA-DRA, FCER2, HLA-DQA1, BANK1, TNFRSF13C, CD19 </span></span>
<span><span class="co">##     CCL20, CD22, CD79A, SELE, MT-CO2, VPREB3, LINC00926, MT-CO3, MT-CO1, CR2 </span></span>
<span><span class="co">##     CD79B, LTF, CR1, MT-ND1, MT-ND4, CD24, TLR10, CHI3L1, SMIM14, CD1C </span></span>
<span><span class="co">## PC_ 4 </span></span>
<span><span class="co">## Positive:  TMSB4X, CCL20, STAT1, IFIT1, ISG15, LAMP3, IFI6, IFIT3, ITGAX, MX1 </span></span>
<span><span class="co">##     OAS3, FSCN1, IFI44L, CXCL5, CHI3L1, EPSTI1, IFI44, VIM, FUCA1, PLA2G2D </span></span>
<span><span class="co">##     CSF2RB, UBD, SOD2, ATOX1, ENPP2, RSAD2, DNASE1L3, OAS1, MX2, CXCL10 </span></span>
<span><span class="co">## Negative:  MZB1, XBP1, BTG2, CXCL12, SSR4, TXNDC5, RNASE1, GAS6, DERL3, MYL9 </span></span>
<span><span class="co">##     SDC1, A2M, GPX3, ADIRF, IGFBP5, MYH11, ACTA2, TAGLN, ACTG2, CNN1 </span></span>
<span><span class="co">##     SLIT3, DPEP1, TENT5C, FBLN1, CCL14, FKBP11, APOD, SFRP2, AQP1, SPARCL1 </span></span>
<span><span class="co">## PC_ 5 </span></span>
<span><span class="co">## Positive:  SIGLEC1, CD209, CLEC4M, CLEC4G, LINC00926, XBP1, MZB1, LYVE1, MARCO, BTG2 </span></span>
<span><span class="co">##     CXCL12, CCL14, STAB2, GZMB, DERL3, HERPUD1, TXNDC5, HSP90B1, CEMIP, PIM2 </span></span>
<span><span class="co">##     SLAMF7, TCL1A, CCL2, ICAM1, POU2AF1, FCER2, CD22, CD19, CETP, CD74 </span></span>
<span><span class="co">## Negative:  MT-CO3, MT-CYB, MYH11, ACTG2, MT-ND3, MT-ATP6, CNN1, MT-CO2, MYL9, ACTA2 </span></span>
<span><span class="co">##     ADIRF, MT-CO1, SOD3, SFRP2, MT-ND1, COL1A2, MT-ND4, MGP, MT-ND2, CCDC80 </span></span>
<span><span class="co">##     DES, MUSTN1, FBLN1, WFDC1, BGN, COL1A1, TAGLN, C3, SULF1, CCL19</span></span></code></pre>
<pre><code><span><span class="co">## Computing nearest neighbor graph</span></span></code></pre>
<pre><code><span><span class="co">## Computing SNN</span></span></code></pre>
<pre><code><span><span class="co">## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Number of nodes: 4035</span></span>
<span><span class="co">## Number of edges: 134810</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Running Louvain algorithm...</span></span>
<span><span class="co">## Maximum modularity in 10 random starts: 0.8360</span></span>
<span><span class="co">## Number of communities: 8</span></span>
<span><span class="co">## Elapsed time: 0 seconds</span></span></code></pre>
<pre><code><span><span class="co">## 09:25:16 UMAP embedding parameters a = 0.9922 b = 1.112</span></span></code></pre>
<pre><code><span><span class="co">## 09:25:16 Read 4035 rows and found 10 numeric columns</span></span></code></pre>
<pre><code><span><span class="co">## 09:25:16 Using Annoy for neighbor search, n_neighbors = 30</span></span></code></pre>
<pre><code><span><span class="co">## 09:25:16 Building Annoy index with metric = cosine, n_trees = 50</span></span></code></pre>
<pre><code><span><span class="co">## 0%   10   20   30   40   50   60   70   80   90   100%</span></span></code></pre>
<pre><code><span><span class="co">## [----|----|----|----|----|----|----|----|----|----|</span></span></code></pre>
<pre><code><span><span class="co">## **************************************************|</span></span>
<span><span class="co">## 09:25:17 Writing NN index file to temp file C:\Users\vickr\AppData\Local\Temp\RtmpS8QzWs\file6dd46eb329ac</span></span>
<span><span class="co">## 09:25:17 Searching Annoy index using 1 thread, search_k = 3000</span></span>
<span><span class="co">## 09:25:19 Annoy recall = 100%</span></span>
<span><span class="co">## 09:25:20 Commencing smooth kNN distance calibration using 1 thread</span></span>
<span><span class="co">## 09:25:22 Initializing from normalized Laplacian + noise</span></span>
<span><span class="co">## 09:25:23 Commencing optimization for 500 epochs, with 166522 positive edges</span></span>
<span><span class="co">## 09:25:37 Optimization finished</span></span>
<span><span class="co">## 09:25:37 Calculating TSNE embedding</span></span>
<span><span class="co">## 09:25:59 Done with GEX pipeline</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##  Integrating VDJ and GEX </span></span>
<span><span class="co">##  Adding runtime params</span></span>
<span><span class="co">## 09:26:00 Done!</span></span>
<span><span class="co">## 2022-08-18 09:26:00</span></span></code></pre>
<div class="sourceCode" id="cb93"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#saveRDS(vgm_with_VDJ, file = "C:/Users/PlatypusDB/VDJ_simulated/Spatial_vgm_with_VDJ.rds")</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="spatial-information-addition-to-vgm-and-vdj-assignment">7.2 Spatial information addition to VGM and VDJ assignment<a class="anchor" aria-label="anchor" href="#spatial-information-addition-to-vgm-and-vdj-assignment"></a>
</h3>
<p>We have now a VGM that contains both the cell transcriptome and
simulated receptor sequences. Spatial data can be added. It now remains
necessary to link the simulated sequences to the transcriptomes. To
allow a wide range of possibilities in the analysis of spatial
transcriptomics, we implemented three different methods to assign the
simulated immune receptor sequences to the annotated B or T cells on the
spatial image: (i) Random assignment of the simulated VDJ to cells
detected by spatial gene expression. (ii) Cell density-based assignment,
where the simulated BCR or TCR sequences corresponding to the more
expanded clone are preferentially assigned to the locations with higher
density in the image. (iii) Germline cell centered assignment: The
simulated sequences from more expanded clonotypes are preferentially
assigned to locations with higher cell density. Additionally, the
locations of the cells within a clone are subject to a
germline-cell-centered distribution, where cells from the same clone get
assigned to cells with the closest euclidean distance relative to the
germline cell. We demonstrate two plots of each assignment method. The
first one is the representation of the top 5 most expanded clones and
the second one visualizes the spatial density of the most expanded
clone.</p>
<div class="sourceCode" id="cb94"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Add spatial data</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_vgm_formation.html">Spatial_vgm_formation</a></span><span class="op">(</span>vgm <span class="op">=</span> <span class="va">vgm_with_VDJ</span>,tissue_lowres_image_path <span class="op">=</span> <span class="va">tissue_lowres_image_path</span>,tissue_positions_list_path <span class="op">=</span> <span class="va">tissue_positions_list_path</span>, scalefactors_json_path <span class="op">=</span> <span class="va">scalefactors_json_path</span>, cluster_path <span class="op">=</span> <span class="va">cluster_path</span>, matrix_path <span class="op">=</span> <span class="va">matrix_path</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Parameters---------------------------------------------------------------------------------------</span></span>
<span><span class="co">#Scaling parameters are necessary for almost all analysis, we have made a function that calculate all the parameters.</span></span>
<span><span class="va">scaling_parameters</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_scaling_parameters.html">Spatial_scaling_parameters</a></span><span class="op">(</span>vgm_spatial <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Dataframe containing, barcode, imagecol and imagerow</span></span>
<span><span class="va">bcs_merge</span><span class="op">&lt;-</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">GEX_matrix</span><span class="op">&lt;-</span><span class="fu">dplyr</span><span class="fu">::</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">bcs_merge</span>, <span class="va">barcode</span>, <span class="va">imagecol</span>, <span class="va">imagerow</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Add cell.state---------------------------------------------------------------------------------------</span></span>
<span><span class="co">#Function to directly add the celltype.</span></span>
<span><span class="va">celltype_GEX_assignment</span><span class="op">&lt;-</span><span class="kw">function</span><span class="op">(</span><span class="va">vgm</span>, <span class="va">cell_names</span>, <span class="va">cell_markers</span><span class="op">)</span><span class="op">{</span></span>
<span>  <span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/GEX_phenotype.html">GEX_phenotype</a></span><span class="op">(</span><span class="va">vgm</span><span class="op">$</span><span class="va">GEX</span>, cell.state.names <span class="op">=</span> <span class="va">cell_names</span>, cell.state.markers <span class="op">=</span> <span class="va">cell_markers</span>, default <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span>  <span class="op">}</span></span>
<span><span class="co">#Assignment of T and B cell type to vgm containing only GEX under cell.state.</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">GEX</span><span class="op">&lt;-</span><span class="fu">celltype_GEX_assignment</span><span class="op">(</span>vgm<span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span>, cell_names <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">"T"</span>,<span class="st">"B"</span><span class="op">)</span>, cell_markers <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">"CD3E+;CD4+;CD8A+"</span>,<span class="st">"CD19+;SDC1+;XBP1+"</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Assignment--------------------------------------------------------------------------------------- </span></span>
<span><span class="co">#1)Assignment random to GEX</span></span>
<span><span class="va">random_BCR_assignment</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Spatial_VDJ_assignment.html">Spatial_VDJ_assignment</a></span><span class="op">(</span>GEX_matrix <span class="op">=</span> <span class="va">GEX_matrix</span>,vgm <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>, celltype <span class="op">=</span> <span class="st">"B"</span>, simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>, method <span class="op">=</span> <span class="st">"random"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#2)Assignment density-based</span></span>
<span><span class="va">density_BCR_assignment</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_assignment.html">Spatial_VDJ_assignment</a></span><span class="op">(</span>GEX_matrix <span class="op">=</span> <span class="va">GEX_matrix</span>,vgm <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span>,vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>, celltype <span class="op">=</span> <span class="st">"B"</span>, simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>, method <span class="op">=</span> <span class="st">"density"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#3)Assignment germline-based</span></span>
<span><span class="va">germline_BCR_assignment</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_assignment.html">Spatial_VDJ_assignment</a></span><span class="op">(</span>GEX_matrix <span class="op">=</span> <span class="va">GEX_matrix</span>,vgm <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span>,vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>, celltype <span class="op">=</span> <span class="st">"B"</span>, simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>, method <span class="op">=</span> <span class="st">"germline"</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#Analysis---------------------------------------------------------------------------------------</span></span>
<span><span class="co">#1)Random</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">random_BCR_assignment</span></span>
<span><span class="va">top_5_VDJ_BCR_random_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">5</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#clonotypes</span></span>
<span><span class="va">p_spatial_BCR_random_clonotype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_BCR_random_data</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_BCR_random_data</span><span class="op">$</span><span class="va">clonotype_id</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell random assignment"</span>, legend <span class="op">=</span> <span class="st">"Clonotype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_random_clonotype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-1.png" width="700"></p>
<div class="sourceCode" id="cb95"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Density of most expanded clone</span></span>
<span><span class="va">top_1_VDJ_BCR_random_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">1</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_random_clonotype_density</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_density_plot.html">Spatial_density_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_1_VDJ_BCR_random_data</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell random assignment"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_random_clonotype_density</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-2.png" width="700"></p>
<div class="sourceCode" id="cb96"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#2)Density</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">density_BCR_assignment</span></span>
<span><span class="va">top_5_VDJ_BCR_density_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">5</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#clonotypes</span></span>
<span><span class="va">p_spatial_BCR_density_clonotype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_BCR_density_data</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_BCR_density_data</span><span class="op">$</span><span class="va">clonotype_id</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell density assignment"</span>, legend <span class="op">=</span> <span class="st">"Clonotype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_density_clonotype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-3.png" width="700"></p>
<div class="sourceCode" id="cb97"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Density of most expanded clone</span></span>
<span><span class="va">top_1_VDJ_BCR_density_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">1</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_density_clonotype_density</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_density_plot.html">Spatial_density_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_1_VDJ_BCR_density_data</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell density assignment"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_density_clonotype_density</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-4.png" width="700"></p>
<div class="sourceCode" id="cb98"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#3)Germline</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">germline_BCR_assignment</span></span>
<span><span class="va">top_5_VDJ_BCR_germline_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">5</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span></span>
<span><span class="co">#clonotypes</span></span>
<span><span class="va">p_spatial_BCR_germline_clonotype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data</span><span class="op">$</span><span class="va">clonotype_id</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell germline assignment"</span>, legend <span class="op">=</span> <span class="st">"Clonotype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_germline_clonotype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-5.png" width="700"></p>
<div class="sourceCode" id="cb99"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Density of most expanded clone</span></span>
<span><span class="va">top_1_VDJ_BCR_germline_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">1</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_germline_clonotype_density</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_density_plot.html">Spatial_density_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_1_VDJ_BCR_germline_data</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell germline assignment"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_BCR_germline_clonotype_density</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-24-6.png" width="700"></p>
</div>
<div class="section level3">
<h3 id="analysis-2">7.3 Analysis<a class="anchor" aria-label="anchor" href="#analysis-2"></a>
</h3>
<p>We have now a VGM containing transcriptomic information and B cell
receptor sequences. The same functions can be used for real experimental
data. We already have visualized repertoire features, such as clonotype,
isotype, somatic hypermutation, clonal evolution, single or module gene
expression, in addition to transcriptional clusters. For the next plots
we decided to only use the germline-based assignment of the simulated
BCR sequences but the analysis pipeline would work with any assignment
method or experimental data.</p>
<div class="section level4">
<h4 id="vdj-analysis-1">7.3.1 VDJ analysis<a class="anchor" aria-label="anchor" href="#vdj-analysis-1"></a>
</h4>
<p>As with analyses of the experimental immune repertoire sequencing
data, we start the analysis of the simulated VDJ information. To
simplify the analysis, we only consider germline-based assignment. To be
able to use the AntibodyForest function and visualize SHMs as well as
track the evolution of a clonotype, we need to modify the simulated VDJ.
AntibodyForest is based on trimmed sequences but Echidna does not
generate them. However, the raw sequences simulated by Echidna can be
used instead, given these span framework1 to framework4 (and are already
“trimmed”).</p>
<div class="sourceCode" id="cb100"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#1)Isotpye</span></span>
<span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data</span><span class="op">$</span><span class="va">VDJ_cgene</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell germline assignment"</span>, legend <span class="op">=</span> <span class="st">"Isotype"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-1.png" width="700"></p>
<div class="sourceCode" id="cb101"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">density_BCR_assignment</span></span>
<span></span>
<span><span class="co">#2)Nb SHM</span></span>
<span><span class="fu"><a href="../reference/Spatial_nb_SHM_compare_to_germline_plot.html">Spatial_nb_SHM_compare_to_germline_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">TRUE</span>, vgm_VDJ <span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>,nb_clonotype <span class="op">=</span> <span class="fl">3</span>, simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title <span class="op">=</span> <span class="st">"B cells"</span>, legend_title <span class="op">=</span> <span class="st">"nb SHM"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-2.png" width="700"></p>
<div class="sourceCode" id="cb102"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#3) Clonotype tracking</span></span>
<span><span class="fu">igraph</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/igraph/man/plot.igraph.html" class="external-link">plot.igraph</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">igraph_list_trans</span><span class="op">[[</span><span class="fl">3</span><span class="op">]</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-3.png" width="700"></p>
<div class="sourceCode" id="cb103"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">igraph</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/igraph/man/plot.igraph.html" class="external-link">plot.igraph</a></span><span class="op">(</span><span class="va">simulated_B_cells_VDJ</span><span class="op">$</span><span class="va">igraph_list_trans</span><span class="op">[[</span><span class="fl">46</span><span class="op">]</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-4.png" width="700"></p>
<div class="sourceCode" id="cb104"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">TRUE</span>,tracking_type <span class="op">=</span> <span class="st">"all"</span>,nb_clonotype <span class="op">=</span> <span class="fl">3</span> ,simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>,VDJ <span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>,bcs_merge <span class="op">=</span> <span class="va">bcs_merge</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,title <span class="op">=</span> <span class="st">"B cell density"</span>, legend_title <span class="op">=</span> <span class="st">"nb_of_SHM"</span>,sample_names<span class="op">=</span><span class="va">sample_names</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-5.png" width="700"></p>
<div class="sourceCode" id="cb105"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">TRUE</span>,tracking_type <span class="op">=</span> <span class="st">"closest"</span>,nb_clonotype <span class="op">=</span> <span class="fl">3</span> ,simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>,VDJ <span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>,bcs_merge <span class="op">=</span> <span class="va">bcs_merge</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,title <span class="op">=</span> <span class="st">"B cell density"</span>, legend_title <span class="op">=</span> <span class="st">"nb_of_SHM"</span>,sample_names<span class="op">=</span><span class="va">sample_names</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-6.png" width="700"></p>
<div class="sourceCode" id="cb106"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Top expanded clone</span></span>
<span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">TRUE</span>,tracking_type <span class="op">=</span> <span class="st">"all"</span>,nb_clonotype <span class="op">=</span> <span class="fl">46</span> ,simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>,VDJ <span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>,bcs_merge <span class="op">=</span> <span class="va">bcs_merge</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,title <span class="op">=</span> <span class="st">"B cell density"</span>, legend_title <span class="op">=</span> <span class="st">"nb_of_SHM"</span>,sample_names<span class="op">=</span><span class="va">sample_names</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-7.png" width="700"></p>
<div class="sourceCode" id="cb107"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Spatial_evolution_of_clonotype_plot.html">Spatial_evolution_of_clonotype_plot</a></span><span class="op">(</span>simulation <span class="op">=</span> <span class="cn">TRUE</span>,tracking_type <span class="op">=</span> <span class="st">"closest"</span>,nb_clonotype <span class="op">=</span> <span class="fl">46</span> ,simulated_VDJ <span class="op">=</span> <span class="va">simulated_B_cells_VDJ</span>,VDJ <span class="op">=</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>,bcs_merge <span class="op">=</span> <span class="va">bcs_merge</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,title <span class="op">=</span> <span class="st">"B cell density"</span>, legend_title <span class="op">=</span> <span class="st">"nb_of_SHM"</span>,sample_names<span class="op">=</span><span class="va">sample_names</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-25-8.png" width="700"></p>
</div>
<div class="section level4">
<h4 id="gex-analysis-1">7.3.2 GEX analysis<a class="anchor" aria-label="anchor" href="#gex-analysis-1"></a>
</h4>
<p>We can also display the transcriptome information for the spatial
VGM</p>
<div class="sourceCode" id="cb108"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#4) Celltype B and T cells</span></span>
<span><span class="va">p_spatial_T_and_B_celltype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_celltype_plot.html">Spatial_celltype_plot</a></span><span class="op">(</span>bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,vgm_GEX <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">GEX</span><span class="op">@</span><span class="va">meta.data</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title<span class="op">=</span><span class="st">"B and T celltype"</span>, legend_title <span class="op">=</span> <span class="st">"Celltype"</span><span class="op">)</span></span>
<span><span class="va">p_spatial_T_and_B_celltype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-1.png" width="700"></p>
<div class="sourceCode" id="cb109"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#4.1)B cells and density</span></span>
<span><span class="va">B_celltype</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_celltype_plot.html">Spatial_celltype_plot</a></span><span class="op">(</span>bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,vgm_GEX <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">GEX</span><span class="op">@</span><span class="va">meta.data</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>,title<span class="op">=</span><span class="st">"B celltype"</span>, legend_title <span class="op">=</span> <span class="st">"Celltype"</span>, specific_celltype <span class="op">=</span> <span class="st">"B"</span>, density <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">p_B_celltype</span><span class="op">&lt;-</span><span class="va">B_celltype</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">p_B_celltype_density</span><span class="op">&lt;-</span><span class="va">B_celltype</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span></span>
<span><span class="va">p_B_celltype</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-2.png" width="700"></p>
<div class="sourceCode" id="cb110"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">p_B_celltype_density</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-3.png" width="700"></p>
<div class="sourceCode" id="cb111"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#5)Single gene expression</span></span>
<span><span class="va">GEX_BCR_barcode</span><span class="op">&lt;-</span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">$</span><span class="va">GEX_barcode</span></span>
<span></span>
<span><span class="va">GEX_BCR_barcode</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/paste.html" class="external-link">paste0</a></span><span class="op">(</span><span class="va">GEX_BCR_barcode</span>,<span class="st">"-1"</span><span class="op">)</span> <span class="co">#Add -1 at the end of each barcode</span></span>
<span><span class="fu"><a href="../reference/Spatial_marker_expression.html">Spatial_marker_expression</a></span><span class="op">(</span>matrix<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">9</span><span class="op">]</span><span class="op">]</span>, marker<span class="op">=</span><span class="st">"CD3E"</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,GEX_barcode<span class="op">=</span><span class="va">GEX_BCR_barcode</span>,sample_names<span class="op">=</span><span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cells"</span>, threshold <span class="op">=</span> <span class="st">"No"</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## New names:</span></span>
<span><span class="co">## <span style="color: #00BBBB;">•</span> `` -&gt; `...13`</span></span></code></pre>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-4.png" width="700"></p>
<div class="sourceCode" id="cb113"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Spatial_marker_expression(matrix=scaling_parameters[[9]], marker="CD3E",bcs_merge=scaling_parameters[[10]],images_tibble=scaling_parameters[[5]],GEX_barcode=GEX_BCR_barcode,sample_names=sample_names, title = "B cells", threshold = 5)</span></span>
<span></span>
<span><span class="co">#6)Gene module expression</span></span>
<span><span class="va">gene.set</span> <span class="op">&lt;-</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="op">)</span> <span class="co"># make empty list </span></span>
<span><span class="va">gene.set</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span> <span class="op">&lt;-</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">"CD19"</span>,<span class="st">"XBP1"</span>,<span class="st">"SDC1"</span><span class="op">)</span> <span class="co"># put gene set in list</span></span>
<span><span class="fu"><a href="../reference/Spatial_module_expression.html">Spatial_module_expression</a></span><span class="op">(</span>sample_names <span class="op">=</span> <span class="va">sample_names</span>,gene.set <span class="op">=</span> <span class="va">gene.set</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, threshold <span class="op">=</span> <span class="st">"No"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-5.png" width="700"></p>
<div class="sourceCode" id="cb114"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Spatial_module_expression.html">Spatial_module_expression</a></span><span class="op">(</span>sample_names <span class="op">=</span> <span class="va">sample_names</span>,gene.set <span class="op">=</span> <span class="va">gene.set</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, threshold <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-6.png" width="700"></p>
<div class="sourceCode" id="cb115"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#7) Clustering</span></span>
<span><span class="va">germline_BCR_assignment</span><span class="op">$</span><span class="va">barcode</span><span class="op">&lt;-</span><span class="va">germline_BCR_assignment</span><span class="op">$</span><span class="va">GEX_barcode</span></span>
<span><span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">&lt;-</span><span class="va">germline_BCR_assignment</span></span>
<span></span>
<span><span class="co">#Old GEX clusters given by 10X</span></span>
<span><span class="va">GEX_cluster_B_cells</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_cluster.html">Spatial_cluster</a></span><span class="op">(</span>cluster <span class="op">=</span> <span class="st">"GEX_cluster"</span>, vgm_cluster <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">spatial</span><span class="op">$</span><span class="va">cluster</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"B cells"</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, legend_title <span class="op">=</span> <span class="st">"GEX clusters"</span> <span class="op">)</span></span>
<span><span class="va">GEX_cluster_B_cells</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-7.png" width="700"></p>
<div class="sourceCode" id="cb116"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Reclustering with only B cells</span></span>
<span><span class="va">reclustering_B_cells</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_cluster.html">Spatial_cluster</a></span><span class="op">(</span>cluster <span class="op">=</span> <span class="st">"reclustering"</span>, vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span>, GEX.out.directory.list <span class="op">=</span> <span class="va">GEX.out.directory.list</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,images_tibble<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>,bcs_merge<span class="op">=</span><span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>, title <span class="op">=</span> <span class="st">"B cells"</span>, sample_names <span class="op">=</span> <span class="va">sample_names</span>, legend_title <span class="op">=</span> <span class="st">"Reclustering"</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## Centering and scaling data matrix</span></span>
<span><span class="co">## PC_ 1 </span></span>
<span><span class="co">## Positive:  HMGN2, CR2, CLU, HMGB2, ELL3, PFN1, SERPINE2, RGS13, ACTG1, FDCSP </span></span>
<span><span class="co">##     SERF2, TUBA1B, TUBB, STMN1, SERPINA9, LRMP, MEF2B, FCAMR, H3F3A, HMGB1 </span></span>
<span><span class="co">##     H2AFZ, HMGN1, MARCKSL1, PPIA, HMCES, CFL1, PTTG1, VPREB3, RFTN1, SUGCT </span></span>
<span><span class="co">## Negative:  IGKC, IGHG1, IGHG4, IGHG2, IGHG3, CCL2, IGLC2, IGHA1, SSR4, C7 </span></span>
<span><span class="co">##     XBP1, IGHGP, NR4A1, C1QA, CCL21, CST3, IGLC1, JCHAIN, SOCS3, THBS1 </span></span>
<span><span class="co">##     C11orf96, IGLC3, CCN1, DUSP1, GAS6, HSP90B1, CXCL12, STAB1, EGFL7, IFITM3 </span></span>
<span><span class="co">## PC_ 2 </span></span>
<span><span class="co">## Positive:  TRAC, TRBC2, TRBC1, TCF7, LINC00861, LDLRAP1, IL7R, CD3E, CCL21, LAT </span></span>
<span><span class="co">##     CD6, ZAP70, TNFRSF25, CCR7, CD3D, CD247, CHRM3-AS2, LEF1, GIMAP7, PIK3IP1 </span></span>
<span><span class="co">##     XBP1, AQP3, ITK, IL32, CD5, PRKCQ-AS1, MZB1, GIMAP5, CD2, PIM2 </span></span>
<span><span class="co">## Negative:  VIM, IGFBP7, SERPINE1, CCL20, TIMP1, CEMIP, CHI3L1, SOD2, TNC, THY1 </span></span>
<span><span class="co">##     TIMP3, CLDN5, THBD, CSF2RB, STAB1, CXCL5, MT-CO1, PTGDS, SPARC, GRN </span></span>
<span><span class="co">##     CXCL2, FUCA1, MARCKS, IGFBP4, PDLIM1, LMNA, LYZ, TFPI, FN1, MT-CO2 </span></span>
<span><span class="co">## PC_ 3 </span></span>
<span><span class="co">## Positive:  TRBC2, TRBC1, CCL19, TRAC, IL32, CCR7, IL7R, TCF7, LAMP3, CD3D </span></span>
<span><span class="co">##     CD7, C3, STAT1, CCL21, CD6, GIMAP7, PIK3IP1, IFITM1, CD247, LINC00861 </span></span>
<span><span class="co">##     CD2, CD3E, LAT, CXCL9, SPOCK2, LEF1, CTLA4, GIMAP5, RGS1, FSCN1 </span></span>
<span><span class="co">## Negative:  IGHG4, IGKC, IGHG1, IGLC2, MZB1, IGHG3, IGHG2, IGHGP, IGLC1, JCHAIN </span></span>
<span><span class="co">##     XBP1, IGLC3, SSR4, IGHM, BTG2, TXNDC5, DERL3, TENT5C, HERPUD1, POU2AF1 </span></span>
<span><span class="co">##     GAS6, TCL1A, IGHA1, CXCL12, FKBP11, SEL1L3, CD79A, PRDX4, AC012236.1, SOCS3 </span></span>
<span><span class="co">## PC_ 4 </span></span>
<span><span class="co">## Positive:  CXCL13, MS4A1, FDCSP, FCER2, CD79A, CD22, TNFRSF13C, BANK1, IGHD, HLA-DQA1 </span></span>
<span><span class="co">##     CD79B, CD83, CR2, VPREB3, TLR10, CXCR5, SELE, CCL20, CD1C, LTF </span></span>
<span><span class="co">##     MT-ND4, SPIB, FCRLA, CD24, PAX5, SMIM14, MT-ATP6, MT-CYB, MT-ND1, C3 </span></span>
<span><span class="co">## Negative:  C1QB, C1QC, CST3, CCL21, SELENOP, C1QA, CCL2, CCL14, SLC40A1, CEBPD </span></span>
<span><span class="co">##     LGMN, JCHAIN, TUBA1B, SIGLEC1, APOE, CD209, RRM2, CXCL12, S100A10, GAPDH </span></span>
<span><span class="co">##     SDC3, CCL18, TYROBP, FCER1G, HSP90B1, CCN1, PLK1, UBE2S, MS4A6A, IL7R </span></span>
<span><span class="co">## PC_ 5 </span></span>
<span><span class="co">## Positive:  SFRP2, MYL9, CNN1, ACTA2, ACTG2, FBLN1, TAGLN, MYH11, CCDC80, MGP </span></span>
<span><span class="co">##     SFRP4, SFRP1, DES, ADIRF, SOD3, APOD, HSPB6, MT-ND3, MT-CYB, BGN </span></span>
<span><span class="co">##     COL1A2, MT-ATP6, MUSTN1, WFDC1, MT-CO3, FLNC, COL1A1, MT-ND4, CAVIN3, PLA2G2A </span></span>
<span><span class="co">## Negative:  CLEC4M, CEMIP, MARCO, CD209, CLEC4G, SIGLEC1, MMP9, ICAM1, SOD2, LYVE1 </span></span>
<span><span class="co">##     LYZ, IL1B, EGFL7, CETP, IFI30, STAB1, LPL, STAB2, APOE, PLAUR </span></span>
<span><span class="co">##     CCL14, LGMN, NR1H3, CFP, NAMPT, GZMB, NCEH1, ADAMTS4, CSF1R, SPHK1 </span></span>
<span><span class="co">## Computing nearest neighbor graph</span></span>
<span><span class="co">## Computing SNN</span></span></code></pre>
<pre><code><span><span class="co">## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Number of nodes: 1645</span></span>
<span><span class="co">## Number of edges: 53917</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Running Louvain algorithm...</span></span>
<span><span class="co">## Maximum modularity in 10 random starts: 0.7303</span></span>
<span><span class="co">## Number of communities: 11</span></span>
<span><span class="co">## Elapsed time: 1 seconds</span></span></code></pre>
<div class="sourceCode" id="cb119"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">reclustering_B_cells</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="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-8.png" width="700"></p>
<div class="sourceCode" id="cb120"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">#Reclustering of the top 5 more expanded clones</span></span>
<span><span class="va">top_5_VDJ_BCR_germline_data</span><span class="op">&lt;-</span><span class="fu"><a href="../reference/Spatial_selection_expanded_clonotypes.html">Spatial_selection_expanded_clonotypes</a></span><span class="op">(</span>nb_clonotype <span class="op">=</span> <span class="fl">5</span>,  vgm_VDJ <span class="op">=</span> <span class="va">vgm_with_simulated_VDJ</span><span class="op">$</span><span class="va">VDJ</span><span class="op">)</span></span>
<span>  <span class="va">a</span><span class="op">&lt;-</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">top_5_VDJ_BCR_germline_data</span>, <span class="va">orig_barcode</span>, <span class="va">x</span>, <span class="va">y</span><span class="op">)</span></span>
<span>  <span class="va">b</span><span class="op">&lt;-</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">reclustering_B_cells</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span>, <span class="va">Cluster</span>, <span class="va">orig_barcode</span><span class="op">)</span></span>
<span><span class="va">top_5_VDJ_BCR_germline_data_cluster</span><span class="op">&lt;-</span><span class="fu"><a href="https://rdrr.io/r/base/merge.html" class="external-link">merge</a></span><span class="op">(</span><span class="va">a</span>,<span class="va">b</span>, by <span class="op">=</span> <span class="st">"orig_barcode"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/Spatial_VDJ_plot.html">Spatial_VDJ_plot</a></span><span class="op">(</span>vgm_VDJ <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data_cluster</span>,analysis <span class="op">=</span> <span class="va">top_5_VDJ_BCR_germline_data_cluster</span><span class="op">$</span><span class="va">Cluster</span>, images_tibble <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">5</span><span class="op">]</span><span class="op">]</span>, bcs_merge <span class="op">=</span> <span class="va">scaling_parameters</span><span class="op">[[</span><span class="fl">10</span><span class="op">]</span><span class="op">]</span>,sample_names <span class="op">=</span> <span class="va">sample_names</span>, title <span class="op">=</span> <span class="st">"B cell germline assignment"</span>, legend <span class="op">=</span> <span class="st">"Reclustering"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Spatial_transcriptomics_files/figure-html/unnamed-chunk-26-9.png" width="700"></p>
</div>
</div>
</div>
<div class="section level2">
<h2 id="version-information">8 Version information<a class="anchor" aria-label="anchor" href="#version-information"></a>
</h2>
<div class="sourceCode" id="cb121"><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] dplyr_1.0.9    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] systemfonts_1.0.4     plyr_1.8.7            igraph_1.3.4         </span></span>
<span><span class="co">##   [4] lazyeval_0.2.2        sp_1.5-0              splines_4.2.1        </span></span>
<span><span class="co">##   [7] listenv_0.8.0         scattermore_0.8       ggplot2_3.3.6        </span></span>
<span><span class="co">##  [10] digest_0.6.29         useful_1.2.6          foreach_1.5.2        </span></span>
<span><span class="co">##  [13] yulab.utils_0.0.5     htmltools_0.5.3       tiff_0.1-11          </span></span>
<span><span class="co">##  [16] fansi_1.0.3           magrittr_2.0.3        memoise_2.0.1        </span></span>
<span><span class="co">##  [19] tensor_1.5            cluster_2.1.3         ROCR_1.0-11          </span></span>
<span><span class="co">##  [22] globals_0.15.1        matrixStats_0.62.0    pkgdown_2.0.6        </span></span>
<span><span class="co">##  [25] spatstat.sparse_2.1-1 jpeg_0.1-9            colorspace_2.0-3     </span></span>
<span><span class="co">##  [28] ggrepel_0.9.1         textshaping_0.3.6     xfun_0.31            </span></span>
<span><span class="co">##  [31] crayon_1.5.1          jsonlite_1.8.0        progressr_0.10.1     </span></span>
<span><span class="co">##  [34] spatstat.data_2.2-0   survival_3.3-1        zoo_1.8-10           </span></span>
<span><span class="co">##  [37] iterators_1.0.14      ape_5.6-2             glue_1.6.2           </span></span>
<span><span class="co">##  [40] polyclip_1.10-0       gtable_0.3.0          seqinr_4.2-16        </span></span>
<span><span class="co">##  [43] leiden_0.4.2          future.apply_1.9.0    abind_1.4-5          </span></span>
<span><span class="co">##  [46] scales_1.2.0          DBI_1.1.3             spatstat.random_2.2-0</span></span>
<span><span class="co">##  [49] miniUI_0.1.1.1        Rcpp_1.0.9            isoband_0.2.5        </span></span>
<span><span class="co">##  [52] viridisLite_0.4.0     xtable_1.8-4          gridGraphics_0.5-1   </span></span>
<span><span class="co">##  [55] tidytree_0.3.9        reticulate_1.25       spatstat.core_2.4-4  </span></span>
<span><span class="co">##  [58] bit_4.0.4             htmlwidgets_1.5.4     httr_1.4.3           </span></span>
<span><span class="co">##  [61] RColorBrewer_1.1-3    ellipsis_0.3.2        Seurat_4.1.1         </span></span>
<span><span class="co">##  [64] ica_1.0-3             farver_2.1.1          pkgconfig_2.0.3      </span></span>
<span><span class="co">##  [67] sass_0.4.2            uwot_0.1.11           deldir_1.0-6         </span></span>
<span><span class="co">##  [70] utf8_1.2.2            labeling_0.4.2        ggplotify_0.1.0      </span></span>
<span><span class="co">##  [73] tidyselect_1.1.2      rlang_1.0.4           reshape2_1.4.4       </span></span>
<span><span class="co">##  [76] later_1.3.0           munsell_0.5.0         tools_4.2.1          </span></span>
<span><span class="co">##  [79] cachem_1.0.6          cli_3.3.0             generics_0.1.3       </span></span>
<span><span class="co">##  [82] ade4_1.7-19           ggridges_0.5.3        evaluate_0.15        </span></span>
<span><span class="co">##  [85] stringr_1.4.0         fastmap_1.1.0         yaml_2.3.5           </span></span>
<span><span class="co">##  [88] ragg_1.2.2            goftest_1.2-3         ggtree_3.4.1         </span></span>
<span><span class="co">##  [91] bit64_4.0.5           knitr_1.39            fs_1.5.2             </span></span>
<span><span class="co">##  [94] fitdistrplus_1.1-8    purrr_0.3.4           RANN_2.6.1           </span></span>
<span><span class="co">##  [97] readbitmap_0.1.5      pbapply_1.5-0         future_1.27.0        </span></span>
<span><span class="co">## [100] nlme_3.1-157          mime_0.12             aplot_0.1.6          </span></span>
<span><span class="co">## [103] hdf5r_1.3.5           compiler_4.2.1        rstudioapi_0.13      </span></span>
<span><span class="co">## [106] plotly_4.10.0         png_0.1-7             spatstat.utils_2.3-1 </span></span>
<span><span class="co">## [109] treeio_1.20.1         tibble_3.1.8          bslib_0.4.0          </span></span>
<span><span class="co">## [112] stringi_1.7.8         highr_0.9             RSpectra_0.16-1      </span></span>
<span><span class="co">## [115] desc_1.4.1            rgeos_0.5-9           lattice_0.20-45      </span></span>
<span><span class="co">## [118] Matrix_1.4-1          vctrs_0.4.1           stringdist_0.9.8     </span></span>
<span><span class="co">## [121] pillar_1.8.0          lifecycle_1.0.1       spatstat.geom_2.4-0  </span></span>
<span><span class="co">## [124] lmtest_0.9-40         jquerylib_0.1.4       RcppAnnoy_0.0.19     </span></span>
<span><span class="co">## [127] data.table_1.14.2     cowplot_1.1.1         irlba_2.3.5          </span></span>
<span><span class="co">## [130] httpuv_1.6.5          patchwork_1.1.1       R6_2.5.1             </span></span>
<span><span class="co">## [133] promises_1.2.0.1      bmp_0.3               KernSmooth_2.23-20   </span></span>
<span><span class="co">## [136] gridExtra_2.3         parallelly_1.32.1     codetools_0.2-18     </span></span>
<span><span class="co">## [139] MASS_7.3-57           assertthat_0.2.1      rprojroot_2.0.3      </span></span>
<span><span class="co">## [142] SeuratObject_4.1.0    sctransform_0.3.3     mgcv_1.8-40          </span></span>
<span><span class="co">## [145] parallel_4.2.1        grid_4.2.1            rpart_4.1.16         </span></span>
<span><span class="co">## [148] ggfun_0.0.6           tidyr_1.2.0           rmarkdown_2.14       </span></span>
<span><span class="co">## [151] Rtsne_0.16            shiny_1.7.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>
