<!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>Marker Identification &amp; Cluster Annotation Helpers • scCustomize</title>
<!-- 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/flatly/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="Marker Identification &amp; Cluster Annotation Helpers">
<meta property="og:description" content="scCustomize">
<!-- 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">scCustomize</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">2.1.2</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">Getting Started</a>
</li>
<li>
  <a href="../articles/Installation.html">Install</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Vignettes
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Plotting Vignettes</li>
    <li>
      <a href="../articles/Gene_Expression_Plotting.html">Plotting #1: General Analysis Plots</a>
    </li>
    <li>
      <a href="../articles/QC_Plots.html">Plotting #2: QC Plots</a>
    </li>
    <li>
      <a href="../articles/Sequencing_QC_Plots.html">Plotting #3: Sequencing QC Plots/Analysis</a>
    </li>
    <li>
      <a href="../articles/Iterative_Plotting.html">Plotting #4: Iterative Plotting Functions</a>
    </li>
    <li>
      <a href="../articles/Color_Palettes.html">Customized Color Palettes &amp; Themes</a>
    </li>
    <li class="divider">
    </li>
<li class="dropdown-header">Helpers &amp; Utilities</li>
    <li>
      <a href="../articles/Helpers_and_Utilities.html">General Helpers &amp; Utilities</a>
    </li>
    <li>
      <a href="../articles/Read_and_Write_Functions.html">Read &amp; Write Data Functions</a>
    </li>
    <li>
      <a href="../articles/Object_Conversion.html">Object/Assay Format Conversion</a>
    </li>
    <li>
      <a href="../articles/Markers_and_Cluster_Annotation.html">Marker Identification &amp; Cluster Annotation Helpers</a>
    </li>
    <li>
      <a href="../articles/Statistics.html">Statistics Functions</a>
    </li>
    <li>
      <a href="../articles/Update_Gene_Symbols.html">Updating Gene Symbols</a>
    </li>
    <li>
      <a href="../articles/Misc_Functions.html">Misc Functions</a>
    </li>
    <li class="divider">
    </li>
<li class="dropdown-header">Other Package Interactivity/Functions</li>
    <li>
      <a href="../articles/LIGER_Functions.html">LIGER Plotting &amp; Functionality</a>
    </li>
    <li>
      <a href="../articles/Cell_Bender_Functions.html">Cell Bender Functionality &amp; Plotting</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">News/Changelog</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../articles/FAQ.html">FAQ</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/samuel-marsh/scCustomize/" class="external-link">
    <span class="fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><script src="Markers_and_Cluster_Annotation_files/kePrint-0.0.1/kePrint.js"></script><link href="Markers_and_Cluster_Annotation_files/lightable-0.0.1/lightable.css" rel="stylesheet">
<div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Marker Identification &amp; Cluster Annotation
Helpers</h1>
            
            <h4 data-toc-skip class="date">Compiled: February 28,
2024</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/samuel-marsh/scCustomize/blob/HEAD/vignettes/articles/Markers_and_Cluster_Annotation.Rmd" class="external-link"><code>vignettes/articles/Markers_and_Cluster_Annotation.Rmd</code></a></small>
      <div class="hidden name"><code>Markers_and_Cluster_Annotation.Rmd</code></div>

    </div>

    
    
<hr>
<style>
p.caption {
  font-size: 0.9em;
}
</style>
<div class="section level2">
<h2 id="marker-identification-cluster-annotation">Marker Identification &amp; Cluster Annotation<a class="anchor" aria-label="anchor" href="#marker-identification-cluster-annotation"></a>
</h2>
<p>scCustomize has several helper functions to assist with
identification of marker genes and annotation of clusters. Load packages
&amp; Data</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Load Packages</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://ggplot2.tidyverse.org" class="external-link">ggplot2</a></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>
<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://magrittr.tidyverse.org" class="external-link">magrittr</a></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://satijalab.org/seurat" class="external-link">Seurat</a></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://github.com/samuel-marsh/scCustomize" class="external-link">scCustomize</a></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://github.com/traversc/qs" class="external-link">qs</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Load example dataset for tutorial</span></span>
<span><span class="va">pbmc</span> <span class="op">&lt;-</span> <span class="fu">pbmc3k.SeuratData</span><span class="fu">::</span><span class="va"><a href="https://rdrr.io/pkg/pbmc3k.SeuratData/man/pbmc3k.final.html" class="external-link">pbmc3k.final</a></span></span></code></pre></div>
<div class="section level3">
<h3 id="helper-functions-available-are">Helper functions available are:<a class="anchor" aria-label="anchor" href="#helper-functions-available-are"></a>
</h3>
<ul>
<li>
<code><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers()</a></code>: Extract either a filtered
data.frame or vector of gene IDs (with option to export named vector)
containing top N markers from data.frame.</li>
<li>
<code><a href="../reference/Create_Cluster_Annotation_File.html">Create_Cluster_Annotation_File()</a></code>: Create simple csv
file for use in annotating clusters.</li>
<li>
<code><a href="../reference/Pull_Cluster_Annotation.html">Pull_Cluster_Annotation()</a></code>: Pull cluster annotation
information quickly from data.frame/tibble or annotation csv file.</li>
<li>
<code><a href="../reference/Rename_Clusters.html">Rename_Clusters()</a></code>: Wrapper function to easily rename
clusters.</li>
</ul>
<p>We will use pbmc3K dataset from SeuratData package as example for
this vignette.</p>
</div>
<div class="section level3">
<h3 id="percent-difference-in-expression">Percent Difference in Expression<a class="anchor" aria-label="anchor" href="#percent-difference-in-expression"></a>
</h3>
<p>If we run <code><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">FindAllMarkers()</a></code> like normal, this is the
output.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Run basic FindAllMarkers DE test</span></span>
<span><span class="va">all_markers</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">FindAllMarkers</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, verbose <span class="op">=</span> <span class="cn">F</span><span class="op">)</span></span>
<span></span>
<span><span class="va">all_markers</span> <span class="op">&lt;-</span> <span class="va">all_markers</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">cluster</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/desc.html" class="external-link">desc</a></span><span class="op">(</span><span class="va">avg_log2FC</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>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="va">cluster</span><span class="op">)</span></span></code></pre></div>
<table class="table table table-bordered table-condensed table-responsive table-striped" style="margin-left: auto; margin-right: auto;">
<thead><tr>
<th style="text-align:left;">
</th>
<th style="text-align:right;">
p_val
</th>
<th style="text-align:right;">
avg_log2FC
</th>
<th style="text-align:right;">
pct.1
</th>
<th style="text-align:right;">
pct.2
</th>
<th style="text-align:right;">
p_val_adj
</th>
<th style="text-align:left;">
cluster
</th>
<th style="text-align:left;">
gene
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
1
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
7.115580
</td>
<td style="text-align:right;">
0.016
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.0004033
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
GTSCR1
</td>
</tr>
<tr>
<td style="text-align:left;">
2
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
5.853999
</td>
<td style="text-align:right;">
0.022
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
0.0000122
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
REG4
</td>
</tr>
<tr>
<td style="text-align:left;">
3
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
4.791871
</td>
<td style="text-align:right;">
0.034
</td>
<td style="text-align:right;">
0.003
</td>
<td style="text-align:right;">
0.0000001
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
NOG
</td>
</tr>
<tr>
<td style="text-align:left;">
4
</td>
<td style="text-align:right;">
8.71e-05
</td>
<td style="text-align:right;">
4.425698
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
ST6GALNAC1
</td>
</tr>
<tr>
<td style="text-align:left;">
5
</td>
<td style="text-align:right;">
8.67e-05
</td>
<td style="text-align:right;">
4.423395
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
AXIN2
</td>
</tr>
</tbody>
</table>
<p>While <code><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">Seurat::FindAllMarkers()</a></code>returns the percent of
cells in identity 1 (pct.1) and identity 2 (pct.2) that express a marker
it can be helpful to view the difference in these two measures in
addition to the values alone.</p>
<p>scCustomize contains helper function: <code><a href="../reference/Add_Pct_Diff.html">Add_Pct_Diff()</a></code> to
add the percent difference between two clusters.
<code>Add_Pct_Diff</code> can be used with any output from Seurat,
SeuratWrappers, or other DE tests and can be piped with the function
itself.</p>
<div class="section level4">
<h4 id="use-add_pct_diff-piped-with-the-marker-function-">Use <code>Add_Pct_Diff</code> piped with the marker function.<a class="anchor" aria-label="anchor" href="#use-add_pct_diff-piped-with-the-marker-function-"></a>
</h4>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># run piped with Seurat command</span></span>
<span><span class="va">all_markers_pct</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">FindAllMarkers</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, verbose <span class="op">=</span> <span class="cn">F</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="../reference/Add_Pct_Diff.html">Add_Pct_Diff</a></span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="va">all_markers_pct</span> <span class="op">&lt;-</span> <span class="va">all_markers_pct</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">cluster</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/desc.html" class="external-link">desc</a></span><span class="op">(</span><span class="va">avg_log2FC</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>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="va">cluster</span><span class="op">)</span></span></code></pre></div>
<table class="table table table-bordered table-condensed table-responsive table-striped" style="margin-left: auto; margin-right: auto;">
<thead><tr>
<th style="text-align:left;">
</th>
<th style="text-align:right;">
p_val
</th>
<th style="text-align:right;">
avg_log2FC
</th>
<th style="text-align:right;">
pct.1
</th>
<th style="text-align:right;">
pct.2
</th>
<th style="text-align:right;">
p_val_adj
</th>
<th style="text-align:left;">
cluster
</th>
<th style="text-align:left;">
gene
</th>
<th style="text-align:right;">
pct_diff
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
1
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
7.115580
</td>
<td style="text-align:right;">
0.016
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.0004033
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
GTSCR1
</td>
<td style="text-align:right;">
0.016
</td>
</tr>
<tr>
<td style="text-align:left;">
2
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
5.853999
</td>
<td style="text-align:right;">
0.022
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
0.0000122
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
REG4
</td>
<td style="text-align:right;">
0.021
</td>
</tr>
<tr>
<td style="text-align:left;">
3
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
4.791871
</td>
<td style="text-align:right;">
0.034
</td>
<td style="text-align:right;">
0.003
</td>
<td style="text-align:right;">
0.0000001
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
NOG
</td>
<td style="text-align:right;">
0.031
</td>
</tr>
<tr>
<td style="text-align:left;">
4
</td>
<td style="text-align:right;">
8.71e-05
</td>
<td style="text-align:right;">
4.425698
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
ST6GALNAC1
</td>
<td style="text-align:right;">
0.009
</td>
</tr>
<tr>
<td style="text-align:left;">
5
</td>
<td style="text-align:right;">
8.67e-05
</td>
<td style="text-align:right;">
4.423395
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
AXIN2
</td>
<td style="text-align:right;">
0.009
</td>
</tr>
</tbody>
</table>
</div>
<div class="section level4">
<h4 id="use-add_pct_diff-post-hoc">Use <code>Add_Pct_Diff</code> post-hoc<a class="anchor" aria-label="anchor" href="#use-add_pct_diff-post-hoc"></a>
</h4>
<p><code>Add_Pct_Diff</code> can also simply be run after generating
marker data.frame:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">all_markers_pct</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Add_Pct_Diff.html">Add_Pct_Diff</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="use-with-non-seurat-data-frames">Use with non-Seurat data.frames<a class="anchor" aria-label="anchor" href="#use-with-non-seurat-data-frames"></a>
</h4>
<p><code>Add_Pct_Diff</code> can be used with any data.frame as long as
the column names that specify percent expressed in the 2 groups are
provided</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">all_markers_pct</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Add_Pct_Diff.html">Add_Pct_Diff</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, pct.1_name <span class="op">=</span> <span class="st">"percent1"</span>, pct.2_name <span class="op">=</span> <span class="st">"percent2"</span><span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level3">
<h3 id="extract-the-top-n-marker-genes-per-cluster-identity-treatment-etc">Extract the top N marker genes per cluster, identity, treatment
etc<a class="anchor" aria-label="anchor" href="#extract-the-top-n-marker-genes-per-cluster-identity-treatment-etc"></a>
</h3>
<p>scCustomize contains function <code>Extract_Top_Markers</code> to get
the top N genes from each cluster (or other group of choice). It has the
option to return either a vector of genes or a filtered data.frame.</p>
<div class="section level4">
<h4 id="returns-a-named-vector-default">Returns a Named Vector (Default)<a class="anchor" aria-label="anchor" href="#returns-a-named-vector-default"></a>
</h4>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># By default it returns a named vector of genes (each gene named for cluster it was associated</span></span>
<span><span class="co"># with)</span></span>
<span><span class="va">top_5</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, num_genes <span class="op">=</span> <span class="fl">5</span>, rank_by <span class="op">=</span> <span class="st">"avg_log2FC"</span><span class="op">)</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">top_5</span>, <span class="fl">10</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">##   Naive CD4 T   Naive CD4 T   Naive CD4 T   Naive CD4 T   Naive CD4 T </span></span>
<span><span class="co">##      "GTSCR1"        "REG4"         "NOG"  "ST6GALNAC1"       "AXIN2" </span></span>
<span><span class="co">##  Memory CD4 T  Memory CD4 T  Memory CD4 T  Memory CD4 T  Memory CD4 T </span></span>
<span><span class="co">##     "HSD11B1" "RP11-90D4.3"       "RFPL2"       "CCL27"       "CCR10"</span></span></code></pre>
</div>
<div class="section level4">
<h4 id="return-data-frame-optional">Return data.frame (Optional)<a class="anchor" aria-label="anchor" href="#return-data-frame-optional"></a>
</h4>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">top_5_df</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, num_genes <span class="op">=</span> <span class="fl">5</span>, data_frame <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    rank_by <span class="op">=</span> <span class="st">"avg_log2FC"</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">top_5_df</span>, <span class="fl">10</span><span class="op">)</span></span></code></pre></div>
<table class="table table table-bordered table-condensed table-responsive table-striped" style="margin-left: auto; margin-right: auto;">
<thead><tr>
<th style="text-align:left;">
</th>
<th style="text-align:right;">
p_val
</th>
<th style="text-align:right;">
avg_log2FC
</th>
<th style="text-align:right;">
pct.1
</th>
<th style="text-align:right;">
pct.2
</th>
<th style="text-align:right;">
p_val_adj
</th>
<th style="text-align:left;">
cluster
</th>
<th style="text-align:left;">
gene
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
1
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
7.115580
</td>
<td style="text-align:right;">
0.016
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.0004033
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
GTSCR1
</td>
</tr>
<tr>
<td style="text-align:left;">
2
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
5.853999
</td>
<td style="text-align:right;">
0.022
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
0.0000122
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
REG4
</td>
</tr>
<tr>
<td style="text-align:left;">
3
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
4.791871
</td>
<td style="text-align:right;">
0.034
</td>
<td style="text-align:right;">
0.003
</td>
<td style="text-align:right;">
0.0000001
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
NOG
</td>
</tr>
<tr>
<td style="text-align:left;">
4
</td>
<td style="text-align:right;">
8.71e-05
</td>
<td style="text-align:right;">
4.425698
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
ST6GALNAC1
</td>
</tr>
<tr>
<td style="text-align:left;">
5
</td>
<td style="text-align:right;">
8.67e-05
</td>
<td style="text-align:right;">
4.423395
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
1.0000000
</td>
<td style="text-align:left;">
Naive CD4 T
</td>
<td style="text-align:left;">
AXIN2
</td>
</tr>
<tr>
<td style="text-align:left;">
2584
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
7.049508
</td>
<td style="text-align:right;">
0.017
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.0000302
</td>
<td style="text-align:left;">
Memory CD4 T
</td>
<td style="text-align:left;">
HSD11B1
</td>
</tr>
<tr>
<td style="text-align:left;">
2585
</td>
<td style="text-align:right;">
2.30e-06
</td>
<td style="text-align:right;">
6.574363
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.0313519
</td>
<td style="text-align:left;">
Memory CD4 T
</td>
<td style="text-align:left;">
RP11-90D4.3
</td>
</tr>
<tr>
<td style="text-align:left;">
2586
</td>
<td style="text-align:right;">
3.30e-05
</td>
<td style="text-align:right;">
5.049954
</td>
<td style="text-align:right;">
0.012
</td>
<td style="text-align:right;">
0.001
</td>
<td style="text-align:right;">
0.4521838
</td>
<td style="text-align:left;">
Memory CD4 T
</td>
<td style="text-align:left;">
RFPL2
</td>
</tr>
<tr>
<td style="text-align:left;">
2587
</td>
<td style="text-align:right;">
3.78e-05
</td>
<td style="text-align:right;">
4.002013
</td>
<td style="text-align:right;">
0.010
</td>
<td style="text-align:right;">
0.000
</td>
<td style="text-align:right;">
0.5180331
</td>
<td style="text-align:left;">
Memory CD4 T
</td>
<td style="text-align:left;">
CCL27
</td>
</tr>
<tr>
<td style="text-align:left;">
2588
</td>
<td style="text-align:right;">
0.00e+00
</td>
<td style="text-align:right;">
3.725109
</td>
<td style="text-align:right;">
0.039
</td>
<td style="text-align:right;">
0.004
</td>
<td style="text-align:right;">
0.0000000
</td>
<td style="text-align:left;">
Memory CD4 T
</td>
<td style="text-align:left;">
CCR10
</td>
</tr>
</tbody>
</table>
</div>
<div class="section level4">
<h4 id="use-with-non-seurat-data-frames-1">Use with non-Seurat data.frames<a class="anchor" aria-label="anchor" href="#use-with-non-seurat-data-frames-1"></a>
</h4>
<p><code>Extract_Top_Markers</code> uses the data.frame output of
<code><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">Seurat::FindAllMarkers()</a></code> by default but can be used with
any data.frame by supplying few extra parameters. Let’s use the function
on the output from <a href="https://github.com/immunogenomics/presto" class="external-link">presto package</a> and
order the results by auc instead of log2FC.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Read in pre-computed data.frame results</span></span>
<span><span class="va">presto_markers</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/qs/man/qread.html" class="external-link">qread</a></span><span class="op">(</span><span class="st">"assets/presto_markers.qs"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Extract top markers</span></span>
<span><span class="va">top_5_presto</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">presto_markers</span>, num_genes <span class="op">=</span> <span class="fl">5</span>, group_by <span class="op">=</span> <span class="st">"cluster"</span>,</span>
<span>    rank_by <span class="op">=</span> <span class="st">"auc"</span>, gene_column <span class="op">=</span> <span class="st">"gene"</span><span class="op">)</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">top_5_presto</span>, <span class="fl">10</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">##  Naive CD4 T  Naive CD4 T  Naive CD4 T  Naive CD4 T  Naive CD4 T Memory CD4 T </span></span>
<span><span class="co">##      "RPS12"      "RPS27"       "RPS6"      "RPL32"      "RPS14"        "LTB" </span></span>
<span><span class="co">## Memory CD4 T Memory CD4 T Memory CD4 T Memory CD4 T </span></span>
<span><span class="co">##       "IL32"       "LDHB"       "CD3D"       "IL7R"</span></span></code></pre>
</div>
<div class="section level4">
<h4 id="unique-vectors">Unique Vectors<a class="anchor" aria-label="anchor" href="#unique-vectors"></a>
</h4>
<p>When returning an unnamed vector you may want to return a unique list
without any duplicate features. This is often true when supplying a list
of features to plotting function like <code><a href="https://satijalab.org/seurat/reference/DoHeatmap.html" class="external-link">DoHeatmap()</a></code> or
<code>Cluster_DotPlot()</code>. You can do this by setting parameter
<code>make_unique = TRUE</code>.</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Default parameters</span></span>
<span><span class="va">top_5</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, num_genes <span class="op">=</span> <span class="fl">5</span>, rank_by <span class="op">=</span> <span class="st">"avg_log2FC"</span>,</span>
<span>    named_vector <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/any.html" class="external-link">any</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/duplicated.html" class="external-link">duplicated</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">top_5</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [1] FALSE</span></span></code></pre>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Set `make_unique = TRUE`</span></span>
<span><span class="va">top_5_unique</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, num_genes <span class="op">=</span> <span class="fl">5</span>, rank_by <span class="op">=</span> <span class="st">"avg_log2FC"</span>,</span>
<span>    named_vector <span class="op">=</span> <span class="cn">FALSE</span>, make_unique <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/any.html" class="external-link">any</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/duplicated.html" class="external-link">duplicated</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">top_5_unique</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## [1] FALSE</span></span></code></pre>
</div>
</div>
<div class="section level3">
<h3 id="pairing-extract_top_markers-with-iterate_featureplot_sccustom">Pairing <code>Extract_Top_Markers</code> with
<code>Iterate_FeaturePlot_scCustom()</code><a class="anchor" aria-label="anchor" href="#pairing-extract_top_markers-with-iterate_featureplot_sccustom"></a>
</h3>
<p>The advantage of exporting a named vector from
<code>Extract_Top_Markers</code> is that
<code>Iterate_FeaturePlot_scCustom</code> can detect the names and
either add those to the title of the plot (if
<code>single_pdf = TRUE</code>) or the file names if
<code>FALSE</code>.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Iterate_FeaturePlot_scCustom.html">Iterate_FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, gene_list <span class="op">=</span> <span class="va">top_5_presto</span>, single_pdf <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span></code></pre></div>
<center>
<p><img src="../reference/figures/assets/Iterate_named_plots.png" width="49%"></p>
<em>Example plot showing the gene name and additional name of the
plot.</em>
</center>
</div>
<div class="section level3">
<h3 id="create-simple-annotation-files">Create simple annotation files<a class="anchor" aria-label="anchor" href="#create-simple-annotation-files"></a>
</h3>
<p>Now for a simple helper we can use
<code>Create_Cluster_Annotation_File</code> to create simple csv file to
use for annotation.</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Create_Cluster_Annotation_File.html">Create_Cluster_Annotation_File</a></span><span class="op">(</span>file_path <span class="op">=</span> <span class="st">"data/"</span>, file_name <span class="op">=</span> <span class="st">"ExpXX_Round01_Annotation"</span><span class="op">)</span></span></code></pre></div>
<p>Here is an example that has already been filled out (using Excel,
Numbers, or other editor program).</p>
<table class="table table table-bordered table-condensed table-responsive table-striped" style="margin-left: auto; margin-right: auto;">
<thead><tr>
<th style="text-align:left;">
</th>
<th style="text-align:right;">
cluster
</th>
<th style="text-align:left;">
cell_type
</th>
<th style="text-align:left;">
sub_type
</th>
<th style="text-align:left;">
notes
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
1
</td>
<td style="text-align:right;">
0
</td>
<td style="text-align:left;">
oligo
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Olig2+
</td>
</tr>
<tr>
<td style="text-align:left;">
2
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
micro
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Proliferating
</td>
</tr>
<tr>
<td style="text-align:left;">
3
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
micro
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
</tr>
<tr>
<td style="text-align:left;">
4
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
oligo
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Newly formed
</td>
</tr>
<tr>
<td style="text-align:left;">
5
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
oligo
</td>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
</td>
</tr>
</tbody>
</table>
</div>
<div class="section level3">
<h3 id="extract-annotation-information">Extract annotation information<a class="anchor" aria-label="anchor" href="#extract-annotation-information"></a>
</h3>
<p>There is also complementary function to pull information back out of
the this (or other) csv files or data.frames regarding clustering
annotation.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">annotation_info</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Pull_Cluster_Annotation.html">Pull_Cluster_Annotation</a></span><span class="op">(</span>annotation <span class="op">=</span> <span class="st">"assets/ExpXX_Round01_Annotation_Completed.csv"</span><span class="op">)</span></span></code></pre></div>
<p>By default the function expects data.frame or file in same format as
<code>Create_Cluster_Annotation_File</code> but has optional parameters
that can be adjusted to file/data.frame with different column headers
(see <code>cluster_name_col</code> and <code>cell_type_col</code>).</p>
<div class="section level4">
<h4 id="pull_cluster_annotation-results">
<code>Pull_Cluster_Annotation</code> results<a class="anchor" aria-label="anchor" href="#pull_cluster_annotation-results"></a>
</h4>
<p>The result of <code>Pull_Cluster_Annotation</code> is a list that
contains:</p>
<ul>
<li>One entry for each unique cell type. The entry is named for the cell
type and is a vector of the numbered clustered that correspond to that
cell type.</li>
<li>One entry called “new_cluster_idents” containing a vector of idents
in order that can be used for renaming clusters either using
<code>Rename_Clusters</code> function (see below) or manually.</li>
<li>One entry containing vector of cell sub-types (if present).</li>
</ul>
<center>
<img src="../reference/figures/assets/annotation_info.png"><em>Example
output of `Pull_Cluster_Annotation</em>
</center>
</div>
</div>
<div class="section level3">
<h3 id="renaming-clusters">Renaming Clusters<a class="anchor" aria-label="anchor" href="#renaming-clusters"></a>
</h3>
<p>Finally can use <code>Rename_Clusters</code> to easily rename and set
active.ident in Seurat Object. This is simple wrapper around Seurat
commands but adds additional checks/warnings and is simple
one-liner.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">obj_renamed</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Rename_Clusters.html">Rename_Clusters</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">obj</span>, new_idents <span class="op">=</span> <span class="va">annotation_info</span><span class="op">$</span><span class="va">new_cluster_idents</span><span class="op">)</span></span></code></pre></div>
<p><code>Rename_Clusters</code> can take input from either
<code>Pull_Cluster_Annotation</code> “new_cluster_idents” or any
correctly ordered vector of new idents.</p>
<ul>
<li>If vector is not yet named (with the current levels of the Seurat
Object) then <code>Rename_Clusters</code> will perform that step. If
already named this step will be omitted.</li>
<li>
<code>Rename_Clusters</code> contains optional parameter to create
new column in meta.data slot to store the old idents. Simply supply
desired meta.data column name to <code>meta_col_name</code>
parameter.</li>
</ul>
</div>
</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 Samuel Marsh.</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.7.</p>
</div>

      </footer>
</div>

  


  

  </body>
</html>
