<!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="Briana Mittleman" /> <title>deNovo peak callling</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> <link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" /> <script src="site_libs/highlightjs-9.12.0/highlight.js"></script> <link href="site_libs/font-awesome-4.5.0/css/font-awesome.min.css" rel="stylesheet" /> <style type="text/css">code{white-space: pre;}</style> <style type="text/css"> pre:not([class]) { background-color: white; } </style> <script type="text/javascript"> if (window.hljs) { hljs.configure({languages: []}); hljs.initHighlightingOnLoad(); if (document.readyState && document.readyState === "complete") { window.setTimeout(function() { hljs.initHighlighting(); }, 0); } } </script> <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; } 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 --> <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">Three Prime Sequencing in Human LCLs</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/brimittleman/threeprimeseq"> <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"> <h1 class="title toc-ignore">deNovo peak callling</h1> <h4 class="author"><em>Briana Mittleman</em></h4> <h4 class="date"><em>6/28/2018</em></h4> </div> <p><strong>Last updated:</strong> 2018-07-09</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(12345)</code> </summary></p> <p>The command <code>set.seed(12345)</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/brimittleman/threeprimeseq/tree/4348871eae879ece3e83fb7f33fc65d868af2b98" target="_blank">4348871</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: output/.DS_Store Untracked files: Untracked: data/18486.genecov.txt Untracked: data/YL-SP-18486-T_S9_R1_001-genecov.txt Untracked: data/bedgraph_peaks/ Untracked: data/bin200.5.T.nuccov.bed Untracked: data/bin200.Anuccov.bed Untracked: data/bin200.nuccov.bed Untracked: data/gene_cov/ Untracked: data/leafcutter/ Untracked: data/nuc6up/ Untracked: data/reads_mapped_three_prime_seq.csv Untracked: data/ssFC200.cov.bed Untracked: output/picard/ Untracked: output/plots/ Untracked: output/qual.fig2.pdf Unstaged changes: Modified: analysis/dif.iso.usage.leafcutter.Rmd Modified: analysis/explore.filters.Rmd Modified: analysis/test.max2.Rmd Modified: code/Snakefile </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;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/brimittleman/threeprimeseq/blob/4348871eae879ece3e83fb7f33fc65d868af2b98/analysis/deNovopeakcalling.Rmd" target="_blank">4348871</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-09 </td> <td style="text-align:left;"> call peaks on nuclear </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/f4f19189e372c610cb22b8020035ea9dadc99bf5/docs/deNovopeakcalling.html" target="_blank">f4f1918</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </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/brimittleman/threeprimeseq/blob/2522654f0e90864f429121515856254655ae0d85/analysis/deNovopeakcalling.Rmd" target="_blank">2522654</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </td> <td style="text-align:left;"> fix axis </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/a0541e37d08c94cb1df9592aca3537ed38406b91/docs/deNovopeakcalling.html" target="_blank">a0541e3</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </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/brimittleman/threeprimeseq/blob/df5cfe4942df2cf4fcc82dffd8d5b3a7d1fdfe02/analysis/deNovopeakcalling.Rmd" target="_blank">df5cfe4</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </td> <td style="text-align:left;"> add Yangs peaks </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/9de36772e8b1b166540211cc7fcf5c076f223070/docs/deNovopeakcalling.html" target="_blank">9de3677</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </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/brimittleman/threeprimeseq/blob/c619183e1288ef8f31ace4ee51fc3056d258d830/analysis/deNovopeakcalling.Rmd" target="_blank">c619183</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </td> <td style="text-align:left;"> examine long peaks </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/2d67ec51a1081d45a630bef20fac1692948657b8/docs/deNovopeakcalling.html" target="_blank">2d67ec5</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </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/brimittleman/threeprimeseq/blob/15c79674071d2330e1f4289e9eb7d611eed63b24/analysis/deNovopeakcalling.Rmd" target="_blank">15c7967</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </td> <td style="text-align:left;"> add split analysis </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/deNovopeakcalling.html" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </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/brimittleman/threeprimeseq/blob/776fc62d1c6ee9e6f9dbb1511b64741aafe36a6a/analysis/deNovopeakcalling.Rmd" target="_blank">776fc62</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> <td style="text-align:left;"> genome cov stats </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/brimittleman/threeprimeseq/b48f27c0e5bb534650122f0ef716de2f8ff23795/docs/deNovopeakcalling.html" target="_blank">b48f27c</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-02 </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/brimittleman/threeprimeseq/blob/1e2ff4cbb34548e49fa92559fabe46615954324d/analysis/deNovopeakcalling.Rmd" target="_blank">1e2ff4c</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-02 </td> <td style="text-align:left;"> evaluate bedgraph regions </td> </tr> </tbody> </table> </ul> <p></details></p> <hr /> <div id="create-bedgraph" class="section level2"> <h2>Create Bedgraph</h2> <p>I will call peaks de novo in the combined total and nuclear fraction 3’ Seq. The data is reletevely clean so I will start with regions that have continuous coverage. I will first create a bedgraph.</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=Tbedgraph #SBATCH --account=pi-yangili1 #SBATCH --time=24:00:00 #SBATCH --output=Tbedgraph.out #SBATCH --error=Tbedgraph.err #SBATCH --partition=broadwl #SBATCH --mem=40G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env samtools sort -o /project2/gilad/briana/threeprimeseq/data/macs2/TotalBamFiles.sort.bam /project2/gilad/briana/threeprimeseq/data/macs2/TotalBamFiles.bam bedtools genomecov -ibam /project2/gilad/briana/threeprimeseq/data/macs2/TotalBamFiles.sort.bam -bga > /project2/gilad/briana/threeprimeseq/data/bedgraph/TotalBamFiles.bedgraph </code></pre> <p>Next I will create the file without the 0 places in the genome. I will be able to use this for the bedtools merge function.</p> <pre class="bash"><code>awk '{if ($4 != 0) print}' TotalBamFiles.bedgraph >TotalBamFiles_no0.bedgraph </code></pre> <p>I can merge the regions with consequtive reads using the bedtools merge function.</p> <ul> <li><p>-i input bed</p></li> <li><p>-c colomn to act on</p></li> <li><p>-o collapse, print deliminated list of the counts from -c call</p></li> <li><p>-delim “,”</p></li> </ul> <p>This is the mergeBedgraph.sh script. It takes in the no 0 begraph filename without the path.</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=merge #SBATCH --account=pi-yangili1 #SBATCH --time=8:00:00 #SBATCH --output=merge.out #SBATCH --error=merge.err #SBATCH --partition=broadwl #SBATCH --mem=16G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env bedgraph=$1 describer=$(echo ${bedgraph} | sed -e "s/.bedgraph$//") bedtools merge -c 4,4,4 -o count,mean,collapse -delim "," -i /project2/gilad/briana/threeprimeseq/data/bedgraph/$1 > /project2/gilad/briana/threeprimeseq/data/bedgraph/${describer}.peaks.bed </code></pre> <p>Run this first on the total bedgraph, TotalBamFiles_no0.bedgraph. The file has chromosome, start, end, number of regions, mean, and a string of the values.</p> <p>This is not exaclty what I want. I need to go back and do genome cov not collapsing with bedgraph.</p> <p>To evaluate this I will bring the file into R and plot some statistics about it.</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=Tgencov #SBATCH --account=pi-yangili1 #SBATCH --time=24:00:00 #SBATCH --output=Tgencov.out #SBATCH --error=Tgencov.err #SBATCH --partition=broadwl #SBATCH --mem=40G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env bedtools genomecov -ibam /project2/gilad/briana/threeprimeseq/data/macs2/TotalBamFiles.sort.bam -d > /project2/gilad/briana/threeprimeseq/data/bedgraph/TotalBamFiles.genomecov.bed </code></pre> <p>I will now remove the bases with 0 coverage.</p> <pre class="bash"><code>awk '{if ($3 != 0) print}' TotalBamFiles.genomecov.bed > TotalBamFiles.genomecov.no0.bed awk '{print $1 "\t" $2 "\t" $2 "\t" $3}' TotalBamFiles.genomecov.no0.bed > TotalBamFiles.genomecov.no0.fixed.bed</code></pre> <p>I will now merge the genomecov_no0 file with mergeGencov.sh</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=mergegc #SBATCH --account=pi-yangili1 #SBATCH --time=8:00:00 #SBATCH --output=mergegc.out #SBATCH --error=mergegc.err #SBATCH --partition=broadwl #SBATCH --mem=16G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env gencov=$1 describer=$(echo ${gencov} | sed -e "s/.genomecov.no0.fixed.bed$//") bedtools merge -c 4,4,4 -o count,mean,collapse -delim "," -i /project2/gilad/briana/threeprimeseq/data/bedgraph/$1 > /project2/gilad/briana/threeprimeseq/data/bedgraph/${describer}.gencovpeaks.bed </code></pre> <p>This method gives us 811,637 regions.</p> </div> <div id="evaluate-regions" class="section level2"> <h2>Evaluate regions</h2> <div id="bedgraph-results" class="section level3"> <h3>Bedgraph results</h3> <pre class="r"><code>library(dplyr)</code></pre> <pre><code>Warning: package 'dplyr' was built under R version 3.4.4</code></pre> <pre><code> Attaching package: 'dplyr'</code></pre> <pre><code>The following objects are masked from 'package:stats': filter, lag</code></pre> <pre><code>The following objects are masked from 'package:base': intersect, setdiff, setequal, union</code></pre> <pre class="r"><code>library(ggplot2) library(readr) library(workflowr)</code></pre> <pre><code>Loading required package: rmarkdown</code></pre> <pre><code>This is workflowr version 1.0.1 Run ?workflowr for help getting started</code></pre> <pre class="r"><code>library(tidyr)</code></pre> <p>First I will look at the bedgraph file. This is not as imformative becuase it combined regions with the same counts.</p> <pre class="r"><code>total_bedgraph=read.table("../data/bedgraph_peaks/TotalBamFiles_no0.peaks.bed",col.names = c("chr", "start", "end", "regions", "mean", "counts"))</code></pre> <p>Plot the mean:</p> <pre class="r"><code>plot(sort(log10(total_bedgraph$mean), decreasing=T), xlab="Region", ylab="log10 of bedgraph region bin", main="Distribution of log10 region means from bedgraph")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-9-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-9-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/brimittleman/threeprimeseq/blob/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-9-1.png" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> </tr> </tbody> </table> <p></details></p> <p>I want to look at the distribution of how many bases are included in the regions.</p> <pre class="r"><code>Tregion_bases=total_bedgraph %>% mutate(bases=end-start) %>% select(bases)</code></pre> <pre><code>Warning: package 'bindrcpp' was built under R version 3.4.4</code></pre> <pre class="r"><code>plot(sort(log10(Tregion_bases$bases), decreasing = T), xlab="Region", ylab="log10 of region size", main="Distribution of bases in regions- log10")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-10-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-10-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/brimittleman/threeprimeseq/blob/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-10-1.png" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> </tr> </tbody> </table> <p></details></p> <p>Given the reads are abotu 60bp this is probably pretty good.</p> </div> <div id="genomecov-results" class="section level3"> <h3>GenomeCov results</h3> <p>I am only going to look at the number of bases in region and mean coverage columns here because the file is really big.</p> <pre class="r"><code>total_gencov=read.table("../data/bedgraph_peaks/TotalBamFiles.gencovpeaks_noregstring.bed",col.names = c("chr", "start", "end", "regions", "mean"))</code></pre> <p>Plot the mean:</p> <pre class="r"><code>plot(sort(log10(total_gencov$mean), decreasing=T), xlab="Region", ylab="log10 of mean bin count", main="Distribution of log10 region means")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-12-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-12-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/brimittleman/threeprimeseq/blob/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-12-1.png" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> </tr> </tbody> </table> <p></details></p> <pre class="r"><code>plot(sort(log10(total_gencov$regions), decreasing = T), xlab="Region", ylab="log10 of region size", main="Distribution of bases in regions- log10")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-13-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-13-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/brimittleman/threeprimeseq/blob/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-13-1.png" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> </tr> </tbody> </table> <p></details></p> <p>Plot number of bases against the mean:</p> <pre class="r"><code>ggplot(total_gencov, aes(y=log10(regions), x=log10(mean))) + geom_point(na.rm = TRUE, size = 0.1) + geom_density2d(na.rm = TRUE, size = 1, colour = 'red') + ylab('Log10 Region size') + xlab('Log10 Mean region coverage') + ggtitle("Region size vs Region Coverage: Combined Total Libraries")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-14-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-14-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/brimittleman/threeprimeseq/blob/24c6663bafcc674ca7aba33d1eb674018ce6f623/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-14-1.png" target="_blank">24c6663</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-03 </td> </tr> </tbody> </table> <p></details></p> </div> </div> <div id="troubleshooting" class="section level2"> <h2>Troubleshooting</h2> <div id="account-for-split-reads" class="section level3"> <h3>Account for split reads</h3> <p>In the previous analysis I did not account for split reads in the genome coveragre step. This may explain some of the long regions that are an effect of splicing. This script is</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=Tgencovsplit #SBATCH --account=pi-yangili1 #SBATCH --time=24:00:00 #SBATCH --output=Tgencovsplit.out #SBATCH --error=Tgencovaplit.err #SBATCH --partition=broadwl #SBATCH --mem=40G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env bedtools genomecov -ibam /project2/gilad/briana/threeprimeseq/data/macs2/TotalBamFiles.sort.bam -d -split > /project2/gilad/briana/threeprimeseq/data/bedgraph/TotalBamFiles.split.genomecov.bed</code></pre> <p>Now I need to remove the 0s and merge.</p> <pre class="bash"><code>awk '{if ($3 != 0) print}' TotalBamFiles.split.genomecov.bed > TotalBamFiles.split.genomecov.no0.bed awk '{print $1 "\t" $2 "\t" $2 "\t" $3}' TotalBamFiles.split.genomecov.no0.bed > TotalBamFiles.split.genomecov.no0.fixed.bed</code></pre> <p>Use this file to run mergeGencov.sh.</p> <pre class="r"><code>total_gencov_split=read.table("../data/bedgraph_peaks/TotalBamFiles.split.gencovpeaks.noregstring.bed",col.names = c("chr", "start", "end", "regions", "mean"))</code></pre> <p>Plot the region size. I expect some of the long regions are gone.</p> <pre class="r"><code>plot(sort(log10(total_gencov_split$regions), decreasing = T), xlab="Region", ylab="log10 of region size", main="Distribution of bases in regions- log10 SPLIT")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-18-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-18-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/brimittleman/threeprimeseq/blob/2d67ec51a1081d45a630bef20fac1692948657b8/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-18-1.png" target="_blank">2d67ec5</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </td> </tr> </tbody> </table> <p></details></p> <p>Plot the region size against the mean:</p> <p>Plot number of bases against the mean:</p> <pre class="r"><code>splitplot=ggplot(total_gencov_split, aes(y=log10(regions), x=log10(mean))) + geom_point(na.rm = TRUE, size = 0.1) + geom_density2d(na.rm = TRUE, size = 1, colour = 'red') + ylab('Log10 Region size') + xlab('Log10 Mean region coverage') + scale_y_continuous(limits = c(0, 3)) + ggtitle("Combined Total Libraries SPLIT")</code></pre> </div> <div id="investigate-long-regions" class="section level3"> <h3>Investigate long regions</h3> <p>Some of the regions are long and probably represent 2 or more sites. This is evident in highly expressed genes such as actB. I will look at some of the long regions and make histograms with the strings of coverage in the region.</p> <p>First I am going to look at chr11:65266512-65268654, this is peak 580475 I will go into the otalBamFiles.split.gencovpeaks.bed file and use:</p> <pre class="bash"><code> grep -n 65266512 TotalBamFiles.split.gencovpeaks.bed | awk '{print $6}' > loc_ch11_65266512_65268654.txt</code></pre> <pre class="r"><code>loc_ch11_65266512_65268654=read.csv("../data/bedgraph_peaks/loc_ch11_65266512_65268654.txt", header=F) %>% t loc_ch11_65266512_65268654_df= as.data.frame(loc_ch11_65266512_65268654) loc_ch11_65266512_65268654_df$loc= seq(1:nrow(loc_ch11_65266512_65268654_df)) colnames(loc_ch11_65266512_65268654_df)= c("count", "loc") ggplot(loc_ch11_65266512_65268654_df, aes(x=loc, y=count)) + geom_line() + labs(y="Read Count", x="Peak Location", title="Example of long region called as 1 peak \n ch11 65266512-65268654")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-21-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-21-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/brimittleman/threeprimeseq/blob/9de36772e8b1b166540211cc7fcf5c076f223070/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-21-1.png" target="_blank">9de3677</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </td> </tr> </tbody> </table> <p></details></p> <p>Try one more. Example. line 816811, chr:17- 79476983- 79477761</p> <pre class="bash"><code> grep -n 79476983 TotalBamFiles.split.gencovpeaks.bed | awk '{print $6}' > loc_ch17_79476983_79477761.txt</code></pre> <pre class="r"><code>loc_ch17_79476983_79477761=read.csv("../data/bedgraph_peaks/loc_ch17_79476983_79477761.txt", header=F) %>% t loc_ch17_79476983_79477761_df= as.data.frame(loc_ch17_79476983_79477761) loc_ch17_79476983_79477761_df$loc= seq(1:nrow(loc_ch17_79476983_79477761_df)) colnames(loc_ch17_79476983_79477761_df)= c("count", "loc") ggplot(loc_ch17_79476983_79477761_df, aes(x=loc, y=count)) + geom_line() + labs(y="Read Count", x="Peak Location", title="Example of long region called as 1 peak \n ch17 79476983:79477761")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-23-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-23-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/brimittleman/threeprimeseq/blob/9de36772e8b1b166540211cc7fcf5c076f223070/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-23-1.png" target="_blank">9de3677</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-05 </td> </tr> </tbody> </table> <p></details></p> <p>This one is not multiple peaks but it does need to be trimmed.</p> </div> </div> <div id="compare-to-adhoc-method-by-yang" class="section level2"> <h2>Compare to adhoc method by Yang</h2> <p>Yang created an adhoc method to do this.</p> <pre class="python"><code>def main(inFile, outFile, ctarget): fout = open(outFile,'w') mincount = 10 ov = 20 current_peak = [] currentChrom = None for ln in open(inFile): chrom, pos, count = ln.split() if chrom != ctarget: continue count = float(count) if currentChrom == None: currentChrom = chrom if count == 0 or currentChrom != chrom: if len(current_peak) > 0: M = max([x[1] for x in current_peak]) if M > mincount: all_peaks = refine_peak(current_peak, M, M*0.1,M*0.05) #refined_peaks = [(x[0][0],x[-1][0], np.mean([y[1] for y in x])) for x in all_peaks] rpeaks = [(int(x[0][0])-ov,int(x[-1][0])+ov, np.mean([y[1] for y in x])) for x in all_peaks] if len(rpeaks) > 1: for clu in cluster_intervals(rpeaks)[0]: M = max([x[2] for x in clu]) merging = [] for x in clu: if x[2] > M *0.5: #print x, M merging.append(x) c, s,e,mean = chrom, min([x[0] for x in merging])+ov, max([x[1] for x in merging])-ov, np.mean([x[2] for x in merging]) #print c,s,e,mean fout.write("chr%s\t%d\t%d\t%d\t+\t.\n"%(c,s,e,mean)) fout.flush() elif len(rpeaks) == 1: s,e,mean = rpeaks[0] fout.write("chr%s\t%d\t%d\t%f\t+\t.\n"%(chrom,s+ov,e-ov,mean)) print ("chr%s"%chrom+"\t%d\t%d\t%f\t+\t.\n"%rpeaks[0]) #print refined_peaks current_peak = [] else: current_peak.append((pos,count)) currentChrom = chrom def refine_peak(current_peak, M, thresh, noise, minpeaksize=30): cpeak = [] opeak = [] allcpeaks = [] allopeaks = [] for pos, count in current_peak: if count > thresh: cpeak.append((pos,count)) opeak = [] continue elif count > noise: opeak.append((pos,count)) else: if len(opeak) > minpeaksize: allopeaks.append(opeak) opeak = [] if len(cpeak) > minpeaksize: allcpeaks.append(cpeak) cpeak = [] if len(cpeak) > minpeaksize: allcpeaks.append(cpeak) if len(opeak) > minpeaksize: allopeaks.append(opeak) allpeaks = allcpeaks for opeak in allopeaks: M = max([x[1] for x in opeak]) allpeaks += refine_peak(opeak, M, M*0.3, noise) #print [(x[0],x[-1]) for x in allcpeaks], [(x[0],x[-1]) for x in allopeaks], [(x[0],x[-1]) for x in allpeaks] #print '---\n' return allpeaks if __name__ == "__main__": import numpy as np from misc_helper import * import sys chrom = sys.argv[1] inFile = "/project2/yangili1/threeprimeseq/gencov/TotalBamFiles.split.genomecov.bed" outFile = "APApeaks_chr%s.bed"%chrom main(inFile, outFile, chrom)</code></pre> <p>This is done by chromosome and takes in the TotalBam Split genome coverage file I made.I am going to look at the stats for these peaks.</p> <pre class="r"><code>YL_peaks=read.table("../data/bedgraph_peaks/APApeaks.bed", col.names = c("chr", "start", "end", "count", "strand", "score")) %>% mutate(length=end-start)</code></pre> <p>Plot the lengths</p> <pre class="r"><code>plot(sort(log10(YL_peaks$length), decreasing = T), xlab="Region", ylab="log10 of region size", main="Distribution of bases in YL regions- log10 ")</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-26-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-26-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/brimittleman/threeprimeseq/blob/a0541e37d08c94cb1df9592aca3537ed38406b91/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-26-1.png" target="_blank">a0541e3</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </td> </tr> </tbody> </table> <p></details></p> <p>Plot number of bases against the mean:</p> <pre class="r"><code>YLplot=ggplot(YL_peaks, aes(y=log10(length), x=log10(count))) + geom_point(na.rm = TRUE, size = 0.1) + geom_density2d(na.rm = TRUE, size = 1, colour = 'red') + ylab('Log10 Region size') + xlab('Log10 Mean region coverage') + scale_y_continuous(limits = c(0, 3)) + ggtitle("YL Peaks Combined Total Libraries")</code></pre> <pre class="r"><code>library(cowplot)</code></pre> <pre><code>Warning: package 'cowplot' was built under R version 3.4.3</code></pre> <pre><code> Attaching package: 'cowplot'</code></pre> <pre><code>The following object is masked from 'package:ggplot2': ggsave</code></pre> <pre class="r"><code>plot_grid(splitplot, YLplot)</code></pre> <p><img src="figure/deNovopeakcalling.Rmd/unnamed-chunk-28-1.png" width="672" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of unnamed-chunk-28-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/brimittleman/threeprimeseq/blob/f4f19189e372c610cb22b8020035ea9dadc99bf5/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-28-1.png" target="_blank">f4f1918</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </td> </tr> <tr> <td style="text-align:left;"> <a href="https://github.com/brimittleman/threeprimeseq/blob/a0541e37d08c94cb1df9592aca3537ed38406b91/docs/figure/deNovopeakcalling.Rmd/unnamed-chunk-28-1.png" target="_blank">a0541e3</a> </td> <td style="text-align:left;"> Briana Mittleman </td> <td style="text-align:left;"> 2018-07-06 </td> </tr> </tbody> </table> <p></details></p> </div> <div id="run-this-on-the-nuclear-fraction-bam" class="section level2"> <h2>Run this on the Nuclear Fraction Bam</h2> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=Ngencov_s #SBATCH --account=pi-yangili1 #SBATCH --time=24:00:00 #SBATCH --output=Ngencov_s.out #SBATCH --error=Ngencov_s.err #SBATCH --partition=broadwl #SBATCH --mem=40G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env samtools sort -o /project2/gilad/briana/threeprimeseq/data/macs2/NuclearBamFiles.sort.bam /project2/gilad/briana/threeprimeseq/data/macs2/NuclearBamFiles.bam bedtools genomecov -ibam /project2/gilad/briana/threeprimeseq/data/macs2/NuclearBamFiles.sort.bam -d -split > /project2/gilad/briana/threeprimeseq/data/bedgraph/NuclearBamFiles.split.genomecov.bed </code></pre> <p>I modified Yang’s script to take the nuclear gencov and put the output in the data/peaks directory. I will create a wrapper to call this on chromosomes 1-22.</p> <pre class="bash"><code>#!/bin/bash #SBATCH --job-name=w_getpeakYL #SBATCH --account=pi-yangili1 #SBATCH --time=24:00:00 #SBATCH --output=w_getpeakYL.out #SBATCH --error=w_getpeakYL.err #SBATCH --partition=broadwl #SBATCH --mem=12G #SBATCH --mail-type=END module load Anaconda3 source activate three-prime-env for i in $(seq 1 22); do sbatch callPeaksYL_Nuc.py $i done </code></pre> <p>I can now concatenate all of these into one file:</p> <pre class="bash"><code>cat * | sort -k 1,1 -k2,2n > APApeaks_nuclear_all.bed </code></pre> <p>Thoughts:</p> <ul> <li><p>Remove peaks outside 1kb of the genes</p></li> <li><p>Remove peaks with low expression</p></li> </ul> </div> <div id="session-information" class="section level2"> <h2>Session information</h2> <pre class="r"><code>sessionInfo()</code></pre> <pre><code>R version 3.4.2 (2017-09-28) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.6 Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] cowplot_0.9.2 bindrcpp_0.2.2 tidyr_0.7.2 workflowr_1.0.1 [5] rmarkdown_1.8.5 readr_1.1.1 ggplot2_2.2.1 dplyr_0.7.5 loaded via a namespace (and not attached): [1] Rcpp_0.12.17 compiler_3.4.2 pillar_1.1.0 [4] git2r_0.21.0 plyr_1.8.4 bindr_0.1.1 [7] R.methodsS3_1.7.1 R.utils_2.6.0 tools_3.4.2 [10] digest_0.6.15 jsonlite_1.5 evaluate_0.10.1 [13] tibble_1.4.2 gtable_0.2.0 pkgconfig_2.0.1 [16] rlang_0.2.1 yaml_2.1.19 stringr_1.3.1 [19] knitr_1.18 hms_0.4.1 rprojroot_1.3-2 [22] grid_3.4.2 tidyselect_0.2.4 reticulate_1.4 [25] glue_1.2.0 R6_2.2.2 purrr_0.2.5 [28] magrittr_1.5 whisker_0.3-2 MASS_7.3-48 [31] backports_1.1.2 scales_0.5.0 htmltools_0.3.6 [34] assertthat_0.2.0 colorspace_1.3-2 labeling_0.3 [37] stringi_1.2.2 lazyeval_0.2.1 munsell_0.4.3 [40] R.oo_1.22.0 </code></pre> </div> <hr> <p> </p> <hr> <!-- To enable disqus, uncomment the section below and provide your disqus_shortname --> <!-- disqus <div id="disqus_thread"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'rmarkdown'; // required: replace example with your forum shortname /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> --> <!-- 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.0.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>