<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />


<meta name="author" content="Yuanhua Huang &amp; Davis J. McCarthy" />


<title>Simulation analysis for all lines</title>

<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/journal.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/navigation-1.1/codefolding.js"></script>
<link href="site_libs/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" />
<script src="site_libs/font-awesome-5.0.13/js/fontawesome-all.min.js"></script>
<script src="site_libs/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script>


<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
div.sourceCode {
  overflow-x: visible;
}
</style>
<style type="text/css">
  pre:not([class]) {
    background-color: white;
  }
</style>


<style type="text/css">
h1 {
  font-size: 34px;
}
h1.title {
  font-size: 38px;
}
h2 {
  font-size: 30px;
}
h3 {
  font-size: 24px;
}
h4 {
  font-size: 18px;
}
h5 {
  font-size: 16px;
}
h6 {
  font-size: 12px;
}
.table th:not([align]) {
  text-align: left;
}
</style>


</head>

<body>

<style type = "text/css">
.main-container {
  max-width: 940px;
  margin-left: auto;
  margin-right: auto;
}
code {
  color: inherit;
  background-color: rgba(0, 0, 0, 0.04);
}
img {
  max-width:100%;
  height: auto;
}
.tabbed-pane {
  padding-top: 12px;
}
.html-widget {
  margin-bottom: 20px;
}
button.code-folding-btn:focus {
  outline: none;
}
</style>


<style type="text/css">
/* padding for bootstrap navbar */
body {
  padding-top: 51px;
  padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar)  */
.section h1 {
  padding-top: 56px;
  margin-top: -56px;
}

.section h2 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h3 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h4 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h5 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h6 {
  padding-top: 56px;
  margin-top: -56px;
}
</style>

<script>
// manage active state of menu based on current page
$(document).ready(function () {
  // active menu anchor
  href = window.location.pathname
  href = href.substr(href.lastIndexOf('/') + 1)
  if (href === "")
    href = "index.html";
  var menuAnchor = $('a[href="' + href + '"]');

  // mark it active
  menuAnchor.parent().addClass('active');

  // if it's got a parent navbar menu mark it active as well
  menuAnchor.closest('li.dropdown').addClass('active');
});
</script>


<div class="container-fluid main-container">

<!-- tabsets -->
<script>
$(document).ready(function () {
  window.buildTabsets("TOC");
});
</script>

<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<script>
$(document).ready(function () {
  window.initializeCodeFolding("hide" === "show");
});
</script>




<script>
$(document).ready(function ()  {

    // move toc-ignore selectors from section div to header
    $('div.section.toc-ignore')
        .removeClass('toc-ignore')
        .children('h1,h2,h3,h4,h5').addClass('toc-ignore');

    // establish options
    var options = {
      selectors: "h1,h2,h3",
      theme: "bootstrap3",
      context: '.toc-content',
      hashGenerator: function (text) {
        return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
      },
      ignoreSelector: ".toc-ignore",
      scrollTo: 0
    };
    options.showAndHide = true;
    options.smoothScroll = true;

    // tocify
    var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>

<style type="text/css">

#TOC {
  margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
  position: relative;
  width: 100%;
}
}


.toc-content {
  padding-left: 30px;
  padding-right: 40px;
}

div.main-container {
  max-width: 1200px;
}

div.tocify {
  width: 20%;
  max-width: 260px;
  max-height: 85%;
}

@media (min-width: 768px) and (max-width: 991px) {
  div.tocify {
    width: 25%;
  }
}

@media (max-width: 767px) {
  div.tocify {
    width: 100%;
    max-width: none;
  }
}

.tocify ul, .tocify li {
  line-height: 20px;
}

.tocify-subheader .tocify-item {
  font-size: 0.90em;
  padding-left: 25px;
  text-indent: 0;
}

.tocify .list-group-item {
  border-radius: 0px;
}


</style>

<!-- setup 3col/9col grid for toc_float and main content  -->
<div class="row-fluid">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>

<div class="toc-content col-xs-12 col-sm-8 col-md-9">




<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">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.html">fibroblast-clonality</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="index.html">Home</a>
</li>
<li>
  <a href="about.html">About</a>
</li>
<li>
  <a href="license.html">License</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/davismcc/fibroblast-clonality">
    <span class="fa fa-github"></span>
     
  </a>
</li>
      </ul>
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

<!-- Add a small amount of space between sections. -->
<style type="text/css">
div.section {
  padding-top: 12px;
}
</style>

<div class="fluid-row" id="header">

<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>



<h1 class="title toc-ignore">Simulation analysis for all lines</h1>
<h4 class="author"><em>Yuanhua Huang &amp; Davis J. McCarthy</em></h4>

</div>


<p><strong>Last updated:</strong> 2018-08-24</p>
<strong>workflowr checks:</strong> <small>(Click a bullet for more information)</small>
<ul>
<li>
<p><details> <summary> <strong style="color:blue;">✔</strong> <strong>R Markdown file:</strong> up-to-date </summary></p>
<p>Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.</p>
</details>
</li>
<li>
<p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Environment:</strong> empty </summary></p>
<p>Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.</p>
</details>
</li>
<li>
<p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Seed:</strong> <code>set.seed(20180807)</code> </summary></p>
<p>The command <code>set.seed(20180807)</code> was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.</p>
</details>
</li>
<li>
<p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Session information:</strong> recorded </summary></p>
<p>Great job! Recording the operating system, R version, and package versions is critical for reproducibility.</p>
</details>
</li>
<li>
<p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Repository version:</strong> <a href="https://github.com/davismcc/fibroblast-clonality/tree/b1cf8d0eef10df2c1e6788afd6b656eca881e7f9" target="_blank">b1cf8d0</a> </summary></p>
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated. <br><br> Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use <code>wflow_publish</code> or <code>wflow_git_commit</code>). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
<pre><code>
Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/raw/
    Ignored:    src/.DS_Store
    Ignored:    src/.ipynb_checkpoints/
    Ignored:    src/Rmd/.Rhistory

Untracked files:
    Untracked:  Snakefile_clonality
    Untracked:  Snakefile_somatic_calling
    Untracked:  code/analysis_for_garx.Rmd
    Untracked:  code/yuanhua/
    Untracked:  data/canopy/
    Untracked:  data/cell_assignment/
    Untracked:  data/de_analysis_FTv62/
    Untracked:  data/donor_info_070818.txt
    Untracked:  data/donor_info_core.csv
    Untracked:  data/donor_neutrality.tsv
    Untracked:  data/fdr10.annot.txt.gz
    Untracked:  data/high-vs-low-exomes.v62.ft.alldonors-filt_lenient.all_filt_sites.vep_most_severe_csq.txt
    Untracked:  data/high-vs-low-exomes.v62.ft.filt_lenient-alldonors.txt.gz
    Untracked:  data/human_H_v5p2.rdata
    Untracked:  data/human_c2_v5p2.rdata
    Untracked:  data/human_c6_v5p2.rdata
    Untracked:  data/neg-bin-rsquared-petr.csv
    Untracked:  data/neutralitytestr-petr.tsv
    Untracked:  data/sce_merged_donors_cardelino_donorid_all_qc_filt.rds
    Untracked:  data/sce_merged_donors_cardelino_donorid_all_with_qc_labels.rds
    Untracked:  data/sce_merged_donors_cardelino_donorid_unstim_qc_filt.rds
    Untracked:  data/sces/
    Untracked:  data/simulations/
    Untracked:  data/variance_components/
    Untracked:  docs/figure/overview_lines.Rmd/
    Untracked:  figures/
    Untracked:  metadata/
    Untracked:  output/differential_expression/
    Untracked:  output/donor_specific/
    Untracked:  output/line_info.tsv
    Untracked:  output/nvars_by_category_by_donor.tsv
    Untracked:  output/nvars_by_category_by_line.tsv
    Untracked:  output/variance_components/
    Untracked:  references/

</code></pre>
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes. </details>
</li>
</ul>
<details> <summary> <small><strong>Expand here to see past versions:</strong></small> </summary>
<ul>
<table style="border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
File
</th>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
<th style="text-align:left;">
Message
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/davismcc/fibroblast-clonality/02a8343abed931029fae740e8e0877331bfae02b/docs/simulations.html" target="_blank">02a8343</a>
</td>
<td style="text-align:left;">
davismcc
</td>
<td style="text-align:left;">
2018-08-24
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/davismcc/fibroblast-clonality/blob/43f15d6d291c1d17bd298c810f97397e2d309a3c/analysis/simulations.Rmd" target="_blank">43f15d6</a>
</td>
<td style="text-align:left;">
davismcc
</td>
<td style="text-align:left;">
2018-08-24
</td>
<td style="text-align:left;">
Adding data pre-processing workflow and updating analyses.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/davismcc/fibroblast-clonality/43f15d6d291c1d17bd298c810f97397e2d309a3c/docs/simulations.html" target="_blank">43f15d6</a>
</td>
<td style="text-align:left;">
davismcc
</td>
<td style="text-align:left;">
2018-08-24
</td>
<td style="text-align:left;">
Adding data pre-processing workflow and updating analyses.
</td>
</tr>
</tbody>
</table>
</ul>
<p></details></p>
<hr />
<div id="load-libraries-and-simulation-results" class="section level2">
<h2>Load libraries and simulation results</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggpubr)
<span class="kw">library</span>(tidyverse)
<span class="kw">library</span>(cardelino)
<span class="kw">library</span>(viridis)
<span class="kw">library</span>(cowplot)
lines &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="st">&quot;euts&quot;</span>, <span class="st">&quot;fawm&quot;</span>, <span class="st">&quot;feec&quot;</span>, <span class="st">&quot;fikt&quot;</span>, <span class="st">&quot;garx&quot;</span>, <span class="st">&quot;gesg&quot;</span>, <span class="st">&quot;heja&quot;</span>, <span class="st">&quot;hipn&quot;</span>, 
            <span class="st">&quot;ieki&quot;</span>, <span class="st">&quot;joxm&quot;</span>, <span class="st">&quot;kuco&quot;</span>, <span class="st">&quot;laey&quot;</span>, <span class="st">&quot;lexy&quot;</span>, <span class="st">&quot;naju&quot;</span>, <span class="st">&quot;nusw&quot;</span>, <span class="st">&quot;oaaz&quot;</span>, 
            <span class="st">&quot;oilg&quot;</span>, <span class="st">&quot;pipw&quot;</span>, <span class="st">&quot;puie&quot;</span>, <span class="st">&quot;qayj&quot;</span>, <span class="st">&quot;qolg&quot;</span>, <span class="st">&quot;qonc&quot;</span>, <span class="st">&quot;rozh&quot;</span>, <span class="st">&quot;sehl&quot;</span>, 
            <span class="st">&quot;ualf&quot;</span>, <span class="st">&quot;vass&quot;</span>, <span class="st">&quot;vuna&quot;</span>, <span class="st">&quot;wahn&quot;</span>, <span class="st">&quot;wetu&quot;</span>, <span class="st">&quot;xugn&quot;</span>, <span class="st">&quot;zoxy&quot;</span>, <span class="st">&quot;vils&quot;</span>)</code></pre></div>
<div id="load-simulation-results" class="section level3">
<h3>Load simulation results</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">all_files &lt;-<span class="st"> </span><span class="kw">paste0</span>(lines, <span class="st">&quot;.simulate.rds&quot;</span>)
assign_<span class="dv">0</span> &lt;-<span class="st"> </span><span class="kw">matrix</span>(<span class="dv">0</span>, <span class="dt">nrow =</span> <span class="dv">500</span>, <span class="dt">ncol =</span> <span class="kw">length</span>(lines))
assign_<span class="dv">1</span> &lt;-<span class="st"> </span><span class="kw">matrix</span>(<span class="dv">0</span>, <span class="dt">nrow =</span> <span class="dv">500</span>, <span class="dt">ncol =</span> <span class="kw">length</span>(lines))
prob_all &lt;-<span class="st"> </span><span class="kw">matrix</span>(<span class="dv">0</span>, <span class="dt">nrow =</span> <span class="dv">500</span>, <span class="dt">ncol =</span> <span class="kw">length</span>(lines))

<span class="cf">for</span> (i <span class="cf">in</span> <span class="kw">seq_len</span>(<span class="kw">length</span>(all_files))) {
  afile &lt;-<span class="st"> </span>all_files[i]
  sim_dat &lt;-<span class="st"> </span><span class="kw">readRDS</span>(<span class="kw">file.path</span>(<span class="st">&quot;data&quot;</span>, <span class="st">&quot;simulations&quot;</span>, afile))
  assign_<span class="dv">0</span>[, i] &lt;-<span class="st"> </span><span class="kw">get_prob_label</span>(sim_dat<span class="op">$</span>I_sim)
  assign_<span class="dv">1</span>[, i] &lt;-<span class="st"> </span><span class="kw">get_prob_label</span>(sim_dat<span class="op">$</span>prob_Gibbs)
  prob_all[, i] &lt;-<span class="st"> </span><span class="kw">get_prob_value</span>(sim_dat<span class="op">$</span>prob_Gibbs, <span class="dt">mode =</span> <span class="st">&quot;best&quot;</span>)
}</code></pre></div>
</div>
<div id="load-results-from-real-data" class="section level3">
<h3>Load results from real data</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">all_files &lt;-<span class="st"> </span><span class="kw">paste0</span>(<span class="st">&quot;cardelino_results.&quot;</span>, lines, 
                    <span class="st">&quot;.filt_lenient.cell_coverage_sites.rds&quot;</span>)
n_sites &lt;-<span class="st"> </span><span class="kw">rep</span>(<span class="dv">0</span>, <span class="kw">length</span>(lines))
n_clone &lt;-<span class="st"> </span><span class="kw">rep</span>(<span class="dv">0</span>, <span class="kw">length</span>(lines))
recall_all &lt;-<span class="st"> </span><span class="kw">rep</span>(<span class="dv">0</span>, <span class="kw">length</span>(lines))
<span class="cf">for</span> (i <span class="cf">in</span> <span class="kw">seq_len</span>(<span class="kw">length</span>(all_files))) {
  afile &lt;-<span class="st"> </span>all_files[i]
  carde_dat &lt;-<span class="st"> </span><span class="kw">readRDS</span>(<span class="kw">file.path</span>(<span class="st">&quot;data&quot;</span>, <span class="st">&quot;cell_assignment&quot;</span>, afile))
  n_sites[i] &lt;-<span class="st"> </span><span class="kw">nrow</span>(carde_dat<span class="op">$</span>D)
  n_clone[i] &lt;-<span class="st"> </span><span class="kw">ncol</span>(carde_dat<span class="op">$</span>prob_mat)
  recall_all[i] &lt;-<span class="st"> </span><span class="kw">mean</span>(<span class="kw">get_prob_value</span>(carde_dat<span class="op">$</span>prob_mat, <span class="dt">mode =</span> <span class="st">&quot;best&quot;</span>) <span class="op">&gt;</span><span class="st"> </span><span class="fl">0.5</span>)
}</code></pre></div>
<p>Overall correlation in assignment rates (recall) from simulated and observed data is 0.959.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">precision_simu &lt;-<span class="st"> </span><span class="kw">rep</span>(<span class="dv">0</span>, <span class="kw">length</span>(lines))
<span class="cf">for</span> (i <span class="cf">in</span> <span class="kw">seq_len</span>(<span class="kw">length</span>(lines))) {
  idx &lt;-<span class="st"> </span>prob_all[, i] <span class="op">&gt;</span><span class="st"> </span><span class="fl">0.5</span>
  precision_simu[i] &lt;-<span class="st"> </span><span class="kw">mean</span>(assign_<span class="dv">0</span>[idx, i] <span class="op">==</span><span class="st"> </span>assign_<span class="dv">1</span>[idx, i])
}

df &lt;-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">line =</span> lines, <span class="dt">n_sites =</span> n_sites, <span class="dt">n_clone =</span> n_clone, 
                 <span class="dt">recall_real =</span> recall_all, <span class="dt">recall_simu =</span> <span class="kw">colMeans</span>(prob_all <span class="op">&gt;</span><span class="st"> </span><span class="fl">0.5</span>),
                 <span class="dt">precision_simu =</span> precision_simu)</code></pre></div>
</div>
</div>
<div id="plot-observed-vs-simulated-assignment-rates-recall" class="section level2">
<h2>Plot observed vs simulated assignment rates (recall)</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">df <span class="op">%&gt;%</span>
<span class="st">  </span>dplyr<span class="op">::</span><span class="kw">mutate</span>(<span class="dt">sites_per_clone =</span> <span class="kw">cut</span>(n_sites <span class="op">/</span><span class="st"> </span><span class="kw">pmax</span>(n_clone <span class="op">-</span><span class="st"> </span><span class="dv">1</span>, <span class="dv">1</span>), 
                                      <span class="dt">breaks =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">8</span>, <span class="dv">15</span>, <span class="dv">25</span>, <span class="dv">60</span>))) <span class="op">%&gt;%</span>
<span class="st">  </span><span class="kw">ggplot</span>(
         <span class="kw">aes</span>(<span class="dt">x =</span> recall_simu, <span class="dt">y =</span> recall_real, 
             <span class="dt">fill =</span> sites_per_clone)) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_abline</span>(<span class="dt">slope =</span> <span class="dv">1</span>, <span class="dt">intercept =</span> <span class="dv">0</span>, <span class="dt">colour =</span> <span class="st">&quot;gray40&quot;</span>, <span class="dt">linetype =</span> <span class="dv">2</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_smooth</span>(<span class="kw">aes</span>(<span class="dt">group =</span> <span class="dv">1</span>), <span class="dt">method =</span> <span class="st">&quot;lm&quot;</span>, <span class="dt">colour =</span> <span class="st">&quot;firebrick&quot;</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_point</span>(<span class="dt">size =</span> <span class="dv">3</span>, <span class="dt">shape =</span> <span class="dv">21</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">xlim</span>(<span class="dv">0</span>, <span class="dv">1</span>) <span class="op">+</span><span class="st"> </span><span class="kw">ylim</span>(<span class="dv">0</span>, <span class="dv">1</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">scale_fill_manual</span>(<span class="dt">name =</span> <span class="st">&quot;mean</span><span class="ch">\n</span><span class="st"># variants</span><span class="ch">\n</span><span class="st">per clonal</span><span class="ch">\n</span><span class="st">branch&quot;</span>, 
                    <span class="dt">values =</span> <span class="kw">magma</span>(<span class="dv">6</span>)[<span class="op">-</span><span class="dv">1</span>]) <span class="op">+</span>
<span class="st">  </span><span class="kw">guides</span>(<span class="dt">colour =</span> <span class="ot">FALSE</span>, <span class="dt">group =</span> <span class="ot">FALSE</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">xlab</span>(<span class="st">&quot;Assignment rate: simulated&quot;</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">ylab</span>(<span class="st">&quot;Assignment rate: observed&quot;</span>)</code></pre></div>
<p><img src="figure/simulations.Rmd/unnamed-chunk-4-1.png" width="672" style="display: block; margin: auto;" /></p>
<details> <summary><em>Expand here to see past versions of unnamed-chunk-4-1.png:</em></summary>
<table style="border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
<a href="https://github.com/davismcc/fibroblast-clonality/blob/02a8343abed931029fae740e8e0877331bfae02b/docs/figure/simulations.Rmd/unnamed-chunk-4-1.png" target="_blank">02a8343</a>
</td>
<td style="text-align:left;">
davismcc
</td>
<td style="text-align:left;">
2018-08-24
</td>
</tr>
</tbody>
</table>
<p></details></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggsave</span>(<span class="st">&quot;figures/simulations/assign_rate_obs_v_sim.png&quot;</span>, 
       <span class="dt">height =</span> <span class="fl">4.5</span>, <span class="dt">width =</span> <span class="dv">5</span>)
<span class="kw">ggsave</span>(<span class="st">&quot;figures/simulations/assign_rate_obs_v_sim.pdf&quot;</span>, 
       <span class="dt">height =</span> <span class="fl">4.5</span>, <span class="dt">width =</span> <span class="dv">5</span>)</code></pre></div>
</div>
<div id="plot-simulation-precision-recall-curve" class="section level2">
<h2>Plot simulation precision-recall curve</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">df <span class="op">%&gt;%</span>
<span class="st">  </span>dplyr<span class="op">::</span><span class="kw">mutate</span>(<span class="dt">sites_per_clone =</span> <span class="kw">cut</span>(n_sites <span class="op">/</span><span class="st"> </span>n_clone, 
                                      <span class="dt">breaks =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">5</span>, <span class="dv">10</span>, <span class="dv">20</span>, <span class="dv">40</span>))) <span class="op">%&gt;%</span>
<span class="st">  </span><span class="kw">ggplot</span>(
         <span class="kw">aes</span>(<span class="dt">x =</span> recall_simu, <span class="dt">y =</span> precision_simu, 
             <span class="dt">fill =</span> sites_per_clone)) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_hline</span>(<span class="dt">yintercept =</span> <span class="fl">0.85</span>, <span class="dt">colour =</span> <span class="st">&quot;gray40&quot;</span>, <span class="dt">linetype =</span> <span class="dv">2</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_smooth</span>(<span class="kw">aes</span>(<span class="dt">group =</span> <span class="dv">1</span>), <span class="dt">method =</span> <span class="st">&quot;lm&quot;</span>, <span class="dt">colour =</span> <span class="st">&quot;firebrick&quot;</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_point</span>(<span class="dt">size =</span> <span class="dv">3</span>, <span class="dt">shape =</span> <span class="dv">21</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">xlim</span>(<span class="dv">0</span>, <span class="dv">1</span>) <span class="op">+</span><span class="st"> </span><span class="kw">ylim</span>(<span class="dv">0</span>, <span class="dv">1</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">scale_fill_manual</span>(<span class="dt">name =</span> <span class="st">&quot;mean</span><span class="ch">\n</span><span class="st"># variants</span><span class="ch">\n</span><span class="st">per clone&quot;</span>, 
                    <span class="dt">values =</span> <span class="kw">magma</span>(<span class="dv">5</span>)[<span class="op">-</span><span class="dv">1</span>]) <span class="op">+</span>
<span class="st">  </span><span class="kw">guides</span>(<span class="dt">colour =</span> <span class="ot">FALSE</span>, <span class="dt">group =</span> <span class="ot">FALSE</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">xlab</span>(<span class="st">&quot;Assignment rate (recall)&quot;</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">ylab</span>(<span class="st">&quot;Precision&quot;</span>)</code></pre></div>
<p><img src="figure/simulations.Rmd/unnamed-chunk-5-1.png" width="672" style="display: block; margin: auto;" /></p>
<details> <summary><em>Expand here to see past versions of unnamed-chunk-5-1.png:</em></summary>
<table style="border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
<a href="https://github.com/davismcc/fibroblast-clonality/blob/02a8343abed931029fae740e8e0877331bfae02b/docs/figure/simulations.Rmd/unnamed-chunk-5-1.png" target="_blank">02a8343</a>
</td>
<td style="text-align:left;">
davismcc
</td>
<td style="text-align:left;">
2018-08-24
</td>
</tr>
</tbody>
</table>
<p></details></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggsave</span>(<span class="st">&quot;figures/simulations/sim_precision_v_recall.png&quot;</span>, 
       <span class="dt">height =</span> <span class="fl">4.5</span>, <span class="dt">width =</span> <span class="fl">5.5</span>)
<span class="kw">ggsave</span>(<span class="st">&quot;figures/simulations/sim_precision_v_recall.pdf&quot;</span>, 
       <span class="dt">height =</span> <span class="fl">4.5</span>, <span class="dt">width =</span> <span class="fl">5.5</span>)</code></pre></div>
</div>
<div id="clone-statistics" class="section level2">
<h2>Clone statistics</h2>
<p>Table showing the number of lines with 2, 3 and 4 clones.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">table</span>(df<span class="op">$</span>n_clone)</code></pre></div>
<pre><code>
 2  3  4 
 4 24  4 </code></pre>
<p>Summary of the average number of mutations per clonal branch across lines.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(df<span class="op">$</span>n_sites <span class="op">/</span><span class="st"> </span>(df<span class="op">$</span>n_clone <span class="op">-</span><span class="st"> </span><span class="dv">1</span>))</code></pre></div>
<pre><code>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   3.00    8.50   11.50   18.69   25.00   57.50 </code></pre>
</div>
<div id="session-information" class="section level2">
<h2>Session information</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">devtools<span class="op">::</span><span class="kw">session_info</span>()</code></pre></div>
<pre><code>Session info -------------------------------------------------------------</code></pre>
<pre><code> setting  value                       
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, darwin15.6.0        
 ui       X11                         
 language (EN)                        
 collate  en_GB.UTF-8                 
 tz       Europe/London               
 date     2018-08-24                  </code></pre>
<pre><code>Packages -----------------------------------------------------------------</code></pre>
<pre><code> package              * version   date       source        
 AnnotationDbi          1.42.1    2018-05-08 Bioconductor  
 ape                    5.1       2018-04-04 CRAN (R 3.5.0)
 assertthat             0.2.0     2017-04-11 CRAN (R 3.5.0)
 backports              1.1.2     2017-12-13 CRAN (R 3.5.0)
 base                 * 3.5.1     2018-07-05 local         
 bindr                  0.1.1     2018-03-13 CRAN (R 3.5.0)
 bindrcpp             * 0.2.2     2018-03-29 CRAN (R 3.5.0)
 Biobase                2.40.0    2018-05-01 Bioconductor  
 BiocGenerics           0.26.0    2018-05-01 Bioconductor  
 BiocParallel           1.14.2    2018-07-08 Bioconductor  
 biomaRt                2.36.1    2018-05-24 Bioconductor  
 Biostrings             2.48.0    2018-05-01 Bioconductor  
 bit                    1.1-14    2018-05-29 CRAN (R 3.5.0)
 bit64                  0.9-7     2017-05-08 CRAN (R 3.5.0)
 bitops                 1.0-6     2013-08-17 CRAN (R 3.5.0)
 blob                   1.1.1     2018-03-25 CRAN (R 3.5.0)
 broom                  0.5.0     2018-07-17 CRAN (R 3.5.0)
 BSgenome               1.48.0    2018-05-01 Bioconductor  
 cardelino            * 0.1.2     2018-08-21 Bioconductor  
 cellranger             1.1.0     2016-07-27 CRAN (R 3.5.0)
 cli                    1.0.0     2017-11-05 CRAN (R 3.5.0)
 colorspace             1.3-2     2016-12-14 CRAN (R 3.5.0)
 compiler               3.5.1     2018-07-05 local         
 cowplot              * 0.9.3     2018-07-15 CRAN (R 3.5.0)
 crayon                 1.3.4     2017-09-16 CRAN (R 3.5.0)
 datasets             * 3.5.1     2018-07-05 local         
 DBI                    1.0.0     2018-05-02 CRAN (R 3.5.0)
 DelayedArray           0.6.5     2018-08-15 Bioconductor  
 devtools               1.13.6    2018-06-27 CRAN (R 3.5.0)
 digest                 0.6.15    2018-01-28 CRAN (R 3.5.0)
 dplyr                * 0.7.6     2018-06-29 CRAN (R 3.5.1)
 evaluate               0.11      2018-07-17 CRAN (R 3.5.0)
 forcats              * 0.3.0     2018-02-19 CRAN (R 3.5.0)
 GenomeInfoDb           1.16.0    2018-05-01 Bioconductor  
 GenomeInfoDbData       1.1.0     2018-04-25 Bioconductor  
 GenomicAlignments      1.16.0    2018-05-01 Bioconductor  
 GenomicFeatures        1.32.2    2018-08-13 Bioconductor  
 GenomicRanges          1.32.6    2018-07-20 Bioconductor  
 ggplot2              * 3.0.0     2018-07-03 CRAN (R 3.5.0)
 ggpubr               * 0.1.7     2018-06-23 CRAN (R 3.5.0)
 ggtree                 1.12.7    2018-08-07 Bioconductor  
 git2r                  0.23.0    2018-07-17 CRAN (R 3.5.0)
 glue                   1.3.0     2018-07-17 CRAN (R 3.5.0)
 graphics             * 3.5.1     2018-07-05 local         
 grDevices            * 3.5.1     2018-07-05 local         
 grid                   3.5.1     2018-07-05 local         
 gridExtra              2.3       2017-09-09 CRAN (R 3.5.0)
 gtable                 0.2.0     2016-02-26 CRAN (R 3.5.0)
 haven                  1.1.2     2018-06-27 CRAN (R 3.5.0)
 hms                    0.4.2     2018-03-10 CRAN (R 3.5.0)
 htmltools              0.3.6     2017-04-28 CRAN (R 3.5.0)
 httr                   1.3.1     2017-08-20 CRAN (R 3.5.0)
 IRanges                2.14.10   2018-05-16 Bioconductor  
 jsonlite               1.5       2017-06-01 CRAN (R 3.5.0)
 knitr                  1.20      2018-02-20 CRAN (R 3.5.0)
 labeling               0.3       2014-08-23 CRAN (R 3.5.0)
 lattice                0.20-35   2017-03-25 CRAN (R 3.5.1)
 lazyeval               0.2.1     2017-10-29 CRAN (R 3.5.0)
 lubridate              1.7.4     2018-04-11 CRAN (R 3.5.0)
 magrittr             * 1.5       2014-11-22 CRAN (R 3.5.0)
 Matrix                 1.2-14    2018-04-13 CRAN (R 3.5.1)
 matrixStats            0.54.0    2018-07-23 CRAN (R 3.5.0)
 memoise                1.1.0     2017-04-21 CRAN (R 3.5.0)
 methods              * 3.5.1     2018-07-05 local         
 modelr                 0.1.2     2018-05-11 CRAN (R 3.5.0)
 munsell                0.5.0     2018-06-12 CRAN (R 3.5.0)
 nlme                   3.1-137   2018-04-07 CRAN (R 3.5.1)
 parallel               3.5.1     2018-07-05 local         
 pheatmap               1.0.10    2018-05-19 CRAN (R 3.5.0)
 pillar                 1.3.0     2018-07-14 CRAN (R 3.5.0)
 pkgconfig              2.0.2     2018-08-16 CRAN (R 3.5.0)
 plyr                   1.8.4     2016-06-08 CRAN (R 3.5.0)
 prettyunits            1.0.2     2015-07-13 CRAN (R 3.5.0)
 progress               1.2.0     2018-06-14 CRAN (R 3.5.0)
 purrr                * 0.2.5     2018-05-29 CRAN (R 3.5.0)
 R.methodsS3            1.7.1     2016-02-16 CRAN (R 3.5.0)
 R.oo                   1.22.0    2018-04-22 CRAN (R 3.5.0)
 R.utils                2.6.0     2017-11-05 CRAN (R 3.5.0)
 R6                     2.2.2     2017-06-17 CRAN (R 3.5.0)
 RColorBrewer           1.1-2     2014-12-07 CRAN (R 3.5.0)
 Rcpp                   0.12.18   2018-07-23 CRAN (R 3.5.0)
 RCurl                  1.95-4.11 2018-07-15 CRAN (R 3.5.0)
 readr                * 1.1.1     2017-05-16 CRAN (R 3.5.0)
 readxl                 1.1.0     2018-04-20 CRAN (R 3.5.0)
 rlang                  0.2.2     2018-08-16 CRAN (R 3.5.0)
 rmarkdown              1.10      2018-06-11 CRAN (R 3.5.0)
 rprojroot              1.3-2     2018-01-03 CRAN (R 3.5.0)
 Rsamtools              1.32.2    2018-07-03 Bioconductor  
 RSQLite                2.1.1     2018-05-06 CRAN (R 3.5.0)
 rstudioapi             0.7       2017-09-07 CRAN (R 3.5.0)
 rtracklayer            1.40.4    2018-08-10 Bioconductor  
 rvcheck                0.1.0     2018-05-23 CRAN (R 3.5.0)
 rvest                  0.3.2     2016-06-17 CRAN (R 3.5.0)
 S4Vectors              0.18.3    2018-06-08 Bioconductor  
 scales                 1.0.0     2018-08-09 CRAN (R 3.5.0)
 snpStats               1.30.0    2018-05-01 Bioconductor  
 splines                3.5.1     2018-07-05 local         
 stats                * 3.5.1     2018-07-05 local         
 stats4                 3.5.1     2018-07-05 local         
 stringi                1.2.4     2018-07-20 CRAN (R 3.5.0)
 stringr              * 1.3.1     2018-05-10 CRAN (R 3.5.0)
 SummarizedExperiment   1.10.1    2018-05-11 Bioconductor  
 survival               2.42-6    2018-07-13 CRAN (R 3.5.0)
 tibble               * 1.4.2     2018-01-22 CRAN (R 3.5.0)
 tidyr                * 0.8.1     2018-05-18 CRAN (R 3.5.0)
 tidyselect             0.2.4     2018-02-26 CRAN (R 3.5.0)
 tidytree               0.1.9     2018-06-13 CRAN (R 3.5.0)
 tidyverse            * 1.2.1     2017-11-14 CRAN (R 3.5.0)
 tools                  3.5.1     2018-07-05 local         
 treeio                 1.4.3     2018-08-13 Bioconductor  
 utils                * 3.5.1     2018-07-05 local         
 VariantAnnotation      1.26.1    2018-07-04 Bioconductor  
 viridis              * 0.5.1     2018-03-29 CRAN (R 3.5.0)
 viridisLite          * 0.3.0     2018-02-01 CRAN (R 3.5.0)
 whisker                0.3-2     2013-04-28 CRAN (R 3.5.0)
 withr                  2.1.2     2018-03-15 CRAN (R 3.5.0)
 workflowr              1.1.1     2018-07-06 CRAN (R 3.5.0)
 XML                    3.98-1.16 2018-08-19 CRAN (R 3.5.1)
 xml2                   1.2.0     2018-01-24 CRAN (R 3.5.0)
 XVector                0.20.0    2018-05-01 Bioconductor  
 yaml                   2.2.0     2018-07-25 CRAN (R 3.5.1)
 zlibbioc               1.26.0    2018-05-01 Bioconductor  </code></pre>
</div>

<!-- Adjust MathJax settings so that all math formulae are shown using
TeX fonts only; see
http://docs.mathjax.org/en/latest/configuration.html.  This will make
the presentation more consistent at the cost of the webpage sometimes
taking slightly longer to load. Note that this only works because the
footer is added to webpages before the MathJax javascript. -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    "HTML-CSS": { availableFonts: ["TeX"] }
  });
</script>

<hr>
<p>
  This reproducible <a href="http://rmarkdown.rstudio.com">R Markdown</a>
  analysis was created with
  <a href="https://github.com/jdblischak/workflowr">workflowr</a> 1.1.1
</p>
<hr>


</div>
</div>

</div>

<script>

// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
  $('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
  bootstrapStylePandocTables();
});


</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>