<!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, shrink-to-fit=no">
<title>Enrichment Analyses • myTAI</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">
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet">
<link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet">
<script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Enrichment Analyses">
</head>
<body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">myTAI</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">2.0.0</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto">
<li class="nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="active nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles">
<li><a class="dropdown-item" href="../articles/Advanced.html">Advanced Phylotranscriptomics Analyses</a></li>
    <li><a class="dropdown-item" href="../articles/Enrichment.html">Enrichment Analyses</a></li>
    <li><a class="dropdown-item" href="../articles/Expression.html">Gene Expression Analysis with `myTAI`</a></li>
    <li><a class="dropdown-item" href="../articles/Intermediate.html">Intermediate Phylotranscriptomics Analyses</a></li>
    <li><a class="dropdown-item" href="../articles/Introduction.html">Introduction to the myTAI package</a></li>
    <li><a class="dropdown-item" href="../articles/Phylostratigraphy.html">Discussing Genomic Phylostratigraphy</a></li>
  </ul>
</li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
      </ul>
<ul class="navbar-nav">
<li class="nav-item"><form class="form-inline" role="search">
 <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json">
</form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/drostlab/myTAI/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul>
</div>


  </div>
</nav><div class="container template-article">




<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.png" class="logo" alt=""><h1>Enrichment Analyses</h1>
            
            <h4 data-toc-skip class="date">2024-10-03</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/drostlab/myTAI/blob/HEAD/vignettes/Enrichment.Rmd" class="external-link"><code>vignettes/Enrichment.Rmd</code></a></small>
      <div class="d-none name"><code>Enrichment.Rmd</code></div>
    </div>

    
    
<div class="section level2">
<h2 id="performing-phylostratum-and-divergence-stratum-enrichment-analyses">Performing <code>Phylostratum</code> and
<code>Divergence Stratum</code> Enrichment Analyses<a class="anchor" aria-label="anchor" href="#performing-phylostratum-and-divergence-stratum-enrichment-analyses"></a>
</h2>
<p><code>Phylostratum</code> and <code>Divergence Stratum</code>
enrichment analyses have been performed by several studies to correlate
organ or metabolic pathway evolution with the origin of organ or pathway
specific genes (Sestak and Domazet-Loso, 2015).</p>
<p>In detail, <code>Phylostratum</code> and
<code>Divergence Stratum</code> enrichment analyses can be performed
analogously to <a href="https://geneontology.github.io/page/go-enrichment-analysis/" class="external-link">Gene
Ontology</a> and <a href="https://www.genome.jp/kegg/" class="external-link">Kegg</a>
enrichment analyses to study the enrichment of evolutionary age or
sequence divergence in a set of selected genes against the entire
genome/transcriptome. In case specific age categories are significantly
over- or underrepresented in the selected gene set, assumptions or
potential correlations between the evolutionary origin of a particular
organ or metabolic pathway can be implied.</p>
<p>In this vignette we will use the data set published by Sestak and
Domazet-Loso, 2015 to demonstrate how to perform enrichment analyses
using <code>myTAI</code>.</p>
</div>
<div class="section level2">
<h2 id="enrichment-analyses-using-plotenrichment">Enrichment Analyses using <code>PlotEnrichment()</code><a class="anchor" aria-label="anchor" href="#enrichment-analyses-using-plotenrichment"></a>
</h2>
<p>The <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> function implemented in
<code>myTAI</code> computes and visualizes the significance of enriched
(over- or underrepresented) <code>Phylostrata</code> or
<code>Divergence Strata</code> within an input set of process/tissue
specific genes. In detail this function takes the
<code>Phylostratum</code> or <code>Divergence Stratum</code>
distribution of all genes stored in the input <code>ExpressionSet</code>
as background set and the <code>Phylostratum</code> or
<code>Divergence Stratum</code> distribution of the specific gene set
and performs a Fisher’s exact test for each <code>Phylostratum</code> or
<code>Divergence Stratum</code> to quantify the statistical significance
of over- or under-represented <code>Phylostrata</code> or
<code>Divergence Strata</code> within the set of selected genes. In
other words, the frequency distribution of <code>Phylostrata</code> or
<code>Divergence Strata</code> in the complete sample is compared with
the frequency distribution of <code>Phylostrata</code> or
<code>Divergence Strata</code> in the set of selected genes and over- or
under-representation is visualized by log-odds (or odds), where a
log-odd of zero means that both frequency distributions are equal (see
also Sestak and Domazet-Loso, 2015).</p>
<div class="section level3">
<h3 id="example-data-set-retrieval">Example Data Set Retrieval<a class="anchor" aria-label="anchor" href="#example-data-set-retrieval"></a>
</h3>
<p>Before using the <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> function, we need to
download the example data set from Sestak and Domazet-Loso, 2015.</p>
<p>Download the <code>Phylostratigraphic Map</code> of <em>D.
rerio</em>:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># download the Phylostratigraphic Map of Danio rerio</span></span>
<span><span class="co"># from Sestak and Domazet-Loso, 2015</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/download.file.html" class="external-link">download.file</a></span><span class="op">(</span> url      <span class="op">=</span> <span class="st">"http://mbe.oxfordjournals.org/content/suppl/2014/11/17/msu319.DC1/TableS3-2.xlsx"</span>, </span>
<span>               destfile <span class="op">=</span> <span class="st">"MBE_2015a_Drerio_PhyloMap.xlsx"</span> <span class="op">)</span></span>
<span>               </span></code></pre></div>
<p>Read the <code>*.xlsx</code> file storing the
<code>Phylostratigraphic Map</code> of <em>D. rerio</em> and format it
for the use with <code>myTAI</code>:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># install the readxl package</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"readxl"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># load package readxl</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://readxl.tidyverse.org" class="external-link">readxl</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># read the excel file</span></span>
<span><span class="va">DrerioPhyloMap.MBEa</span> <span class="op">&lt;-</span> <span class="fu">read_excel</span><span class="op">(</span><span class="st">"MBE_2015a_Drerio_PhyloMap.xlsx"</span>, sheet <span class="op">=</span> <span class="fl">1</span>, skip <span class="op">=</span> <span class="fl">4</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># format Phylostratigraphic Map for use with myTAI</span></span>
<span><span class="va">Drerio.PhyloMap</span> <span class="op">&lt;-</span> <span class="va">DrerioPhyloMap.MBEa</span><span class="op">[</span> , <span class="fl">1</span><span class="op">:</span><span class="fl">2</span><span class="op">]</span></span>
<span></span>
<span><span class="co"># have a look at the final format</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span><span class="op">)</span></span></code></pre></div>
<pre><code>  Phylostrata            ZFIN_ID
1           1 ZDB-GENE-000208-13
2           1 ZDB-GENE-000208-17
3           1 ZDB-GENE-000208-18
4           1 ZDB-GENE-000208-23
5           1  ZDB-GENE-000209-3
6           1  ZDB-GENE-000209-4</code></pre>
<p>Now, <code>Drerio.PhyloMap</code> stores the
<code>Phylostratigraphic Map</code> of <em>D. rerio</em> which is used
as background set to perform enrichment analyses with
<code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code>.</p>
</div>
<div class="section level3">
<h3 id="enrichment-analyses">Enrichment Analyses<a class="anchor" aria-label="anchor" href="#enrichment-analyses"></a>
</h3>
<p>Now, the <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> function visualizes the over-
and underrepresented <code>Phylostrata</code> of brain specific genes
when compared with the total number of genes stored in the
<code>Phylostratigraphic Map</code> of <em>D. rerio</em>.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># read expression data (organ specific genes) from Sestak and Domazet-Loso, 2015</span></span>
<span><span class="va">Drerio.OrganSpecificExpression</span> <span class="op">&lt;-</span> <span class="fu">read_excel</span><span class="op">(</span><span class="st">"MBE_2015a_Drerio_PhyloMap.xlsx"</span>, sheet <span class="op">=</span> <span class="fl">2</span>, skip <span class="op">=</span> <span class="fl">3</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># select only brain specific genes</span></span>
<span><span class="va">Drerio.Brain.Genes</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html" class="external-link">unique</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/na.fail.html" class="external-link">na.omit</a></span><span class="op">(</span><span class="va">Drerio.OrganSpecificExpression</span><span class="op">[</span> , <span class="st">"brain"</span><span class="op">]</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># visualize enriched Phylostrata of genes annotated as brain specific</span></span>
<span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure      <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>               use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName   <span class="op">=</span> <span class="st">"PS"</span><span class="op">)</span></span></code></pre></div>
<p>Here, the first argument is either a standard
<code>ExpressionSet</code> object (in case
<code>use.only.map = FALSE</code>: default) or a
<code>Phylostratigraphic Map</code> or <code>Divergence Map</code> (in
case <code>use.only.map = TRUE</code>; see <a href="Introduction.html">Introduction</a> for details). The second
argument <code>test.set</code> specifies the gene ids also stored in the
corresponding <code>ExpressionSet</code> or
<code>Phylostratigraphic Map/ Divergence Map</code> for which enrichment
shall be quantified and visualized.</p>
<p>To visualize the odds or log-odds of over- or underrepresented genes
within the <code>test.set</code> the following procedure is
performed:</p>
<ul>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">N_{ij}</annotation></semantics></math>
denotes the number of genes in group j and deriving from PS
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>i</mi><annotation encoding="application/x-tex">i</annotation></semantics></math>,
with
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>=</mo><mn>1</mn><mo>,</mo><mi>.</mi><mi>.</mi><mo>,</mo><mi>n</mi></mrow><annotation encoding="application/x-tex">i = 1, .. , n</annotation></semantics></math>
and where
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">j = 1</annotation></semantics></math>
denotes the background set and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">j = 2</annotation></semantics></math>
denotes the <code>test.set</code></p></li>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>i</mi><mi>.</mi></mrow></msub><annotation encoding="application/x-tex">N_{i.}</annotation></semantics></math>
denotes the total number of genes within PS
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>i</mi><annotation encoding="application/x-tex">i</annotation></semantics></math></p></li>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>.</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">N_{.j}</annotation></semantics></math>
denotes the total number of genes within group
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>j</mi><annotation encoding="application/x-tex">j</annotation></semantics></math></p></li>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>.</mi><mi>.</mi></mrow></msub><annotation encoding="application/x-tex">N_{..}</annotation></semantics></math>
is the total number of genes within all groups
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>j</mi><annotation encoding="application/x-tex">j</annotation></semantics></math>
and all PS
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>i</mi><annotation encoding="application/x-tex">i</annotation></semantics></math></p></li>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">f_{ij}</annotation></semantics></math>
=
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">N_{ij}</annotation></semantics></math>
/
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>N</mi><mrow><mi>.</mi><mi>.</mi></mrow></msub><annotation encoding="application/x-tex">N_{..}</annotation></semantics></math>
and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>g</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">g_{ij}</annotation></semantics></math>
=
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">f_{ij}</annotation></semantics></math>
/
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>.</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">f_{.j}</annotation></semantics></math>
denote relative frequencies between groups</p></li>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>i</mi><mi>.</mi></mrow></msub><annotation encoding="application/x-tex">f_{i.}</annotation></semantics></math>
denotes the between group sum of
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><annotation encoding="application/x-tex">f_{ij}</annotation></semantics></math></p></li>
</ul>
<p>The result is the <strong>fold-change value</strong> (odds;
<code>measure = "foldchange"</code>) denoted as
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mn>2</mn></msub><mo>=</mo><msub><mi>g</mi><mrow><mi>i</mi><mn>2</mn></mrow></msub><mi>/</mi><msub><mi>f</mi><mrow><mi>i</mi><mi>.</mi></mrow></msub></mrow><annotation encoding="application/x-tex">C_2 = g_{i2} / f_{i.}</annotation></semantics></math>
which is visualized above and below zero or the <strong>log
fold-change</strong> value (log-odds;
<code>measure = "log-foldchange"</code>), where
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">log_2</annotation></semantics></math>(C)
=
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">log_2</annotation></semantics></math>(<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>g</mi><mrow><mi>i</mi><mn>2</mn></mrow></msub><annotation encoding="application/x-tex">g_{i2}</annotation></semantics></math>)
-
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">log_2</annotation></semantics></math>(<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>f</mi><mrow><mi>i</mi><mi>.</mi></mrow></msub><annotation encoding="application/x-tex">f_{i.}</annotation></semantics></math>)
which is visualized symmetrically above and below zero by
<code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code>. Analogously,
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mn>1</mn></msub><mo>=</mo><msub><mi>g</mi><mrow><mi>i</mi><mn>1</mn></mrow></msub><mi>/</mi><msub><mi>f</mi><mrow><mi>i</mi><mi>.</mi></mrow></msub></mrow><annotation encoding="application/x-tex">C_1 = g_{i1} / f_{i.}</annotation></semantics></math>
but is not visualized by this function.</p>
<p>Internally, <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> performs a Fisher’s exact
test for each <code>Phylostratum</code> or
<code>Divergence Stratum</code> separately, to quantify the significance
of over- or under-representation of corresponding
<code>Phylostrata</code> or <code>Divergence Strata</code> within the
<code>test.set</code> when compared with the entire
<code>ExpressionSet</code>. <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> visualizes
significantly enriched (over- or underrepresented)
<code>Phylostrata</code> or <code>Divergence Strata</code> with
asterisks ’*’.</p>
<p>Notation:</p>
<ul>
<li>’*’ = P-Value
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mo>≤</mo><annotation encoding="application/x-tex">\leq</annotation></semantics></math>
0.05</li>
<li>’**’ = P-Value
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mo>≤</mo><annotation encoding="application/x-tex">\leq</annotation></semantics></math>
0.005</li>
<li>’***’ = P-Value
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mo>≤</mo><annotation encoding="application/x-tex">\leq</annotation></semantics></math>
0.0005</li>
</ul>
<p>Users will notice that when performing the
<code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> function, the p-values and the enrichment
matrix (storing
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>C</mi><mn>1</mn></msub><annotation encoding="application/x-tex">C_1</annotation></semantics></math>
and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>C</mi><mn>2</mn></msub><annotation encoding="application/x-tex">C_2</annotation></semantics></math>)
will be returned.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure      <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>               use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName   <span class="op">=</span> <span class="st">"PS"</span><span class="op">)</span></span></code></pre></div>
<pre><code>$p.values
         PS1          PS2          PS3          PS4          PS5          PS6 
8.283490e-01 8.362880e-05 6.778981e-02 1.373816e-02 7.946309e-13 6.017041e-01 
         PS7          PS8          PS9         PS10         PS11         PS12 
2.185021e-03 2.281194e-03 8.943147e-01 5.699612e-01 4.717058e-02 9.367759e-01 
        PS13         PS14 
3.929949e-03 1.593834e-05 

$enrichment.matrix
           BG_Set     Test_Set
PS1  -0.001132832  0.007668216
PS2   0.023733936 -0.172380714
PS3  -0.040879607  0.250587496
PS4  -0.048920465  0.294399729
PS5  -0.114888949  0.603817643
PS6   0.008678915 -0.060350168
PS7  -0.062948352  0.367240944
PS8   0.115630474 -1.206210187
PS9  -0.007353969  0.048964218
PS10 -0.031971192  0.200141519
PS11  0.039742253 -0.303363314
PS12 -0.002418079  0.016311853
PS13  0.101449988 -0.984621732
PS14  0.098211044 -0.938724783</code></pre>
<p>In case users are only interested in the p-values of the Fisher test
and the enrichment matrix without illustrating the bar plot, they can
specify the <code>plot.bars = FALSE</code> argument to only retrieve the
numeric results.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># specify plot.bars = FALSE to retrieve only numeric results</span></span>
<span><span class="va">EnrichmentResult</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>                                   test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>                                   measure      <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>                                   use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>                                   legendName   <span class="op">=</span> <span class="st">"PS"</span>,</span>
<span>                                   plot.bars    <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># access p-values quantifying the enrichment for each Phylostratum</span></span>
<span><span class="va">EnrichmentResult</span><span class="op">$</span><span class="va">p.values</span></span></code></pre></div>
<pre><code>         PS1          PS2          PS3          PS4          PS5          PS6 
8.283490e-01 8.362880e-05 6.778981e-02 1.373816e-02 7.946309e-13 6.017041e-01 
         PS7          PS8          PS9         PS10         PS11         PS12 
2.185021e-03 2.281194e-03 8.943147e-01 5.699612e-01 4.717058e-02 9.367759e-01 
        PS13         PS14 
3.929949e-03 1.593834e-05</code></pre>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># access enrichment matrix storing C_1 and C_2</span></span>
<span><span class="va">EnrichmentResult</span><span class="op">$</span><span class="va">enrichment.matrix</span></span></code></pre></div>
<pre><code>           BG_Set     Test_Set
PS1  -0.001132832  0.007668216
PS2   0.023733936 -0.172380714
PS3  -0.040879607  0.250587496
PS4  -0.048920465  0.294399729
PS5  -0.114888949  0.603817643
PS6   0.008678915 -0.060350168
PS7  -0.062948352  0.367240944
PS8   0.115630474 -1.206210187
PS9  -0.007353969  0.048964218
PS10 -0.031971192  0.200141519
PS11  0.039742253 -0.303363314
PS12 -0.002418079  0.016311853
PS13  0.101449988 -0.984621732
PS14  0.098211044 -0.938724783</code></pre>
</div>
<div class="section level3">
<h3 id="defining-the-background-set">Defining the Background Set<a class="anchor" aria-label="anchor" href="#defining-the-background-set"></a>
</h3>
<p>The Fisher test which is performed inside
<code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> assumes that all genes stored in the input
<code>ExpressionSet</code> or
<code>Phylostratigraphic Map</code>/<code>Divergence Map</code> are used
to define the background set for constructing the test statistic.
However, since in most cases the <code>test.set</code> is an subset of
the input <code>ExpressionSet</code> or
<code>Phylostratigraphic Map</code>/<code>Divergence Map</code> one
could also specify the <code>complete.bg</code> argument to remove all
<code>test.set</code> genes from the background set when performing the
Fisher test and visualization.</p>
<p>The following two examples allow users to compare the results when
retaining all genes as background set compared with the option to remove
<code>test.set</code> genes from the background set.</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># complete.bg = TRUE (default) -&gt; retain test.set genes in background set</span></span>
<span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure      <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>               complete.bg  <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName   <span class="op">=</span> <span class="st">"PS"</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># complete.bg = FALSE -&gt; remove test.set genes from background set</span></span>
<span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure      <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>               complete.bg  <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>               use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName   <span class="op">=</span> <span class="st">"PS"</span><span class="op">)</span></span></code></pre></div>
<p>Users will notice that although some p-values change, the qualitative
result did not change. In border line cases however, the results might
influence whether or not some <code>Phylostrata</code> or
<code>Divergence Strata</code> are denoted as significantly enriched or
not. So always be aware of the interpretation when retaining or removing
the <code>test.set</code> from the background set, because both options
are valid and have advantages and disadvantages and depend on a valid
interpretation.</p>
</div>
</div>
<div class="section level2">
<h2 id="interpretation-of-enrichment-results">Interpretation of Enrichment Results<a class="anchor" aria-label="anchor" href="#interpretation-of-enrichment-results"></a>
</h2>
<p>For the <em>D. rerio</em> brain genes example you can see that PS4,
PS5, and PS7 are significantly over-represented in the set of brain
specific genes.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set     <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure      <span class="op">=</span> <span class="st">"foldchange"</span>,</span>
<span>               complete.bg  <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               use.only.map <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName   <span class="op">=</span> <span class="st">"PS"</span><span class="op">)</span></span></code></pre></div>
<p>Again, we retrieve the <em>D. rerio</em> specific taxonomy
represented by PS1-14 using the <code>myTAI::taxonomy()</code> function
(see <a href="Introduction.html">Introduction</a> and
<code>Taxonomy</code> for details).</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># retrieve the taxonomy of D. rerio</span></span>
<span><span class="fu">myTAI</span><span class="fu">::</span><span class="fu">taxonomy</span><span class="op">(</span>organism <span class="op">=</span> <span class="st">"Danio rerio"</span><span class="op">)</span></span></code></pre></div>
<pre><code>                    id         name    rank
1   cellular organisms      no rank  131567
2            Eukaryota superkingdom    2759
3         Opisthokonta      no rank   33154
4              Metazoa      kingdom   33208
5            Eumetazoa      no rank    6072
6            Bilateria      no rank   33213
7        Deuterostomia      no rank   33511
8             Chordata       phylum    7711
9             Craniata    subphylum   89593
10          Vertebrata      no rank    7742
11       Gnathostomata      no rank    7776
12          Teleostomi      no rank  117570
13        Euteleostomi      no rank  117571
14      Actinopterygii   superclass    7898
15         Actinopteri        class  186623
16         Neopterygii     subclass   41665
17           Teleostei   infraclass   32443
18 Osteoglossocephalai      no rank 1489341
19       Clupeocephala      no rank  186625
20           Otomorpha      no rank  186634
21        Ostariophysi      no rank   32519
22            Otophysa      no rank  186626
23       Cypriniphysae   superorder  186627
24       Cypriniformes        order    7952
25         Cyprinoidea  superfamily   30727
26          Cyprinidae       family    7953
27               Danio        genus    7954
28         Danio rerio      species    7955</code></pre>
<p>Sestak and Domazet-Loso, 2015 collapsed these 28 taxonomic nodes into
14 taxonomic nodes (see <code>Figure 2</code> in Sestak and
Domazet-Loso, 2015) and labelled them as phylostrata 1 to phylostrata
14, where PS1 represents <code>cellular organisms</code> and PS14
represents <code>D. rerio</code> specific genes. Based on the
phylostratum categorization of Sestak and Domazet-Loso, 2015, PS4
represents <code>Holozoa (= Metazoa + allies)</code>, PS5 represents
<code>Metazoa</code>, and PS7 represents <code>Bilateria</code>.</p>
<p>Now, the over-representation results of brain specific genes returned
by <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> provide evidence, that brain specific
genes might indeed have originated during the emergence of the nervous
system at the metazoan-eumetazoan transition leading to the
interpretation that the vertebrate brain has a step wise adaptive
history where most of its extant organization was already present in the
chordate ancestor as argued by Sestak and Domazet-Loso, 2015.</p>
<p>This example shall illustrate how the <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code>
function can be used to trace the evolutionary origin of tissue or
process specific genes by investigating their age enrichment.</p>
<p>In case users have an <code>ExpressionSet</code> storing the
<code>Phylostratigraphic Map</code> of <em>D. rerio</em> as well as an
expression set, they can furthermore use the <code><a href="../reference/PlotGeneSet.html">PlotGeneSet()</a></code>
function implemented in <code>myTAI</code> to visualize the expression
levels of brain specific genes which have been shown to be significantly
enriched in <code>Metazoa</code> specific phylostrata.</p>
<p>Example:</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># the best parameter setting to visualize this plot:</span></span>
<span><span class="co"># png("DrerioBrainSpecificGeneExpression.png",700,400)</span></span>
<span><span class="fu"><a href="../reference/PlotGeneSet.html">PlotGeneSet</a></span><span class="op">(</span>ExpressionSet <span class="op">=</span> <span class="va">DrerioPhyloExpressionSet</span>,</span>
<span>            gene.set      <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>            plot.legend   <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>            type          <span class="op">=</span> <span class="st">"l"</span>,</span>
<span>            lty           <span class="op">=</span> <span class="fl">1</span>,</span>
<span>            lwd           <span class="op">=</span> <span class="fl">4</span>,</span>
<span>            xlab          <span class="op">=</span> <span class="st">"Ontogeny"</span>,</span>
<span>            ylab          <span class="op">=</span> <span class="st">"Expression Level"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># dev.off()</span></span></code></pre></div>
<p>Here <code>DrerioPhyloExpressionSet</code> denotes a hypothetical
<code>ExpressionSet</code> of <em>D. rerio</em> development.</p>
<p>Additionally, the <code><a href="../reference/SelectGeneSet.html">SelectGeneSet()</a></code> function allows users
to obtain the <code>ExpresisonSet</code> subset of selected genes
(<code>gene.set</code>) for subsequent analyses.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># select the ExpressionSet subset of Brain specific genes</span></span>
<span><span class="va">Brain.PhyloExpressionSet</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/SelectGeneSet.html">SelectGeneSet</a></span><span class="op">(</span> ExpressionSet <span class="op">=</span> <span class="va">DrerioPhyloExpressionSet</span>,</span>
<span>                                           gene.set      <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span> <span class="op">)</span></span>
<span>        </span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">Brain.PhyloExpressionSet</span><span class="op">)</span></span></code></pre></div>
<div class="section level3">
<h3 id="adjust-p-values-for-multiple-comparisons">Adjust P-values for Multiple Comparisons<a class="anchor" aria-label="anchor" href="#adjust-p-values-for-multiple-comparisons"></a>
</h3>
<p>In case a large number of Phylostrata or Divergence Strata is
included in the input <code>ExpressionSet</code>, p-values returned by
<code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> should be adjusted for multiple
comparisons. For this purpose <code><a href="../reference/PlotEnrichment.html">PlotEnrichment()</a></code> includes the
argument <code>p.adjust.method</code>. Here, all methods implemented in
<code><a href="https://rdrr.io/r/stats/p.adjust.html" class="external-link">?p.adjust</a></code> can be specified:</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># adjust p-values for multiple comparisons with Benjamini &amp; Hochberg (1995)</span></span>
<span><span class="fu"><a href="../reference/PlotEnrichment.html">PlotEnrichment</a></span><span class="op">(</span><span class="va">Drerio.PhyloMap</span>,</span>
<span>               test.set        <span class="op">=</span> <span class="va">Drerio.Brain.Genes</span>,</span>
<span>               measure         <span class="op">=</span> <span class="st">"log-foldchange"</span>,</span>
<span>               complete.bg     <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>               use.only.map    <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>               legendName      <span class="op">=</span> <span class="st">"PS"</span>,</span>
<span>               p.adjust.method <span class="op">=</span> <span class="st">"BH"</span><span class="op">)</span></span></code></pre></div>
<p>Please consult these reviews <a href="http://www.stat.columbia.edu/~gelman/research/published/multiple2f.pdf" class="external-link">Gelman
et al., 2008</a>, and <a href="http://www.gs.washington.edu/academics/courses/akey/56008/lecture/lecture10.pdf" class="external-link">Slides</a>)
to decide whether or not to apply p-value adjustment to your own
dataset.</p>
</div>
</div>
<div class="section level2">
<h2 id="references">References<a class="anchor" aria-label="anchor" href="#references"></a>
</h2>
<p>Sestak MS and Domazet-Loso T. <strong>Phylostratigraphic Profiles in
Zebrafish Uncover Chordate Origins of the Vertebrate Brain</strong>.
<em>Mol. Biol. Evol.</em> (2015) 32 (2): 299-312.</p>
</div>
  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside>
</div>



    <footer><div class="pkgdown-footer-left">
  <p>Developed by Hajk-Georg Drost, Jaruwatana Sodai Lotharukpong, Nikola Kalábová, Kristian K Ullrich.</p>
</div>

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

    </footer>
</div>





  </body>
</html>
