<!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="Po-Yuan Tung" /> <meta name="date" content="2017-11-28" /> <title>Sample QC</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/cosmo.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-1.1/textmate.css" rel="stylesheet" /> <script src="site_libs/highlightjs-1.1/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 && 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">fucci-seq</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/jdblischak/fucci-seq"> <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">Sample QC</h1> <h4 class="author"><em>Po-Yuan Tung</em></h4> <h4 class="date"><em>2017-11-28</em></h4> </div> <!-- The file analysis/chunks.R contains chunks that define default settings shared across the workflowr files. --> <!-- Update knitr chunk options --> <!-- Insert the date the file was last updated --> <p><strong>Last updated:</strong> 2018-02-06</p> <!-- Insert the code version (Git commit SHA1) if Git repository exists and R package git2r is installed --> <p><strong>Code version:</strong> fd3bf7b</p> <div id="setup" class="section level2"> <h2>Setup</h2> <pre class="r"><code>library("cowplot") library("dplyr") library("edgeR") library("ggplot2") library("reshape2") library("Biobase") source("../code/pca.R") theme_set(cowplot::theme_cowplot()) # The palette with grey: cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")</code></pre> <pre class="r"><code>fname <- Sys.glob("../data/eset/*.rds") eset <- Reduce(combine, Map(readRDS, fname)) anno <- pData(eset)</code></pre> <hr /> </div> <div id="total-mapped-reads" class="section level2"> <h2>Total mapped reads</h2> <p>Note: Using the 15% cutoff of samples with no cells excludes all the samples</p> <pre class="r"><code>## calculate the cut-off cut_off_reads <- quantile(anno[anno$cell_number == 0,"mapped"], 0.85) cut_off_reads</code></pre> <pre><code> 85% 733229.6 </code></pre> <pre class="r"><code>anno$cut_off_reads <- anno$mapped > cut_off_reads ## numbers of cells sum(anno[anno$cell_number == 1, "mapped"] > cut_off_reads)</code></pre> <pre><code>[1] 1146</code></pre> <pre class="r"><code>sum(anno[anno$cell_number == 1, "mapped"] <= cut_off_reads)</code></pre> <pre><code>[1] 161</code></pre> <pre class="r"><code>## density plots plot_reads <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = mapped, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + geom_vline(xintercept = cut_off_reads, colour="grey", linetype = "longdash") + labs(x = "Total mapped reads", title = "Number of total mapped reads", fill = "Cell number") plot_reads</code></pre> <p><img src="figure/sampleqc.Rmd/total-reads-1.png" width="672" style="display: block; margin: auto;" /></p> <hr /> </div> <div id="unmapped-ratios" class="section level2"> <h2>Unmapped ratios</h2> <p>Note: Using the 30 % cutoff of samples with no cells excludes all the samples</p> <pre class="r"><code>## calculate unmapped ratios anno$unmapped_ratios <- anno$unmapped/anno$umi ## cut off cut_off_unmapped <- quantile(anno[anno$cell_number == 0,"unmapped_ratios"], 0.3) cut_off_unmapped</code></pre> <pre><code> 30% 0.4216077 </code></pre> <pre class="r"><code>anno$cut_off_unmapped <- anno$unmapped_ratios < cut_off_unmapped ## numbers of cells sum(anno[anno$cell_number == 1, "unmapped_ratios"] >= cut_off_unmapped)</code></pre> <pre><code>[1] 254</code></pre> <pre class="r"><code>sum(anno[anno$cell_number == 1, "unmapped_ratios"] < cut_off_unmapped)</code></pre> <pre><code>[1] 1053</code></pre> <pre class="r"><code>## density plots plot_unmapped <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = unmapped_ratios *100, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + geom_vline(xintercept = cut_off_unmapped *100, colour="grey", linetype = "longdash") + labs(x = "Unmapped reads/ total reads", title = "Unmapped reads percentage") plot_unmapped</code></pre> <p><img src="figure/sampleqc.Rmd/unmapped-ratios-1.png" width="672" style="display: block; margin: auto;" /> Look at the unmapped percentage per sample by C1 experimnet and by individual.</p> <pre class="r"><code>unmapped_exp <- ggplot(anno, aes(x = as.factor(experiment), y = unmapped_ratios, color = as.factor(experiment))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "Unmapped reads/ total reads", title = "Unmapped reads percentage") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) unmapped_indi <- ggplot(anno, aes(x = chip_id, y = unmapped_ratios, color = as.factor(chip_id))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "Unmapped reads/ total reads", title = "Unmapped reads percentage") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) plot_grid(unmapped_exp + theme(legend.position = "none"), unmapped_indi + theme(legend.position = "none"), labels = letters[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/unmapped_exp-1.png" width="672" style="display: block; margin: auto;" /></p> <hr /> </div> <div id="ercc-percentage" class="section level2"> <h2>ERCC percentage</h2> <pre class="r"><code>## calculate ercc reads percentage anno$ercc_percentage <- anno$reads_ercc / anno$mapped ## cut off cut_off_ercc <- quantile(anno[anno$cell_number == 0,"ercc_percentage"], 0.15) cut_off_ercc</code></pre> <pre><code> 15% 0.1673614 </code></pre> <pre class="r"><code>anno$cut_off_ercc <- anno$ercc_percentage < cut_off_ercc ## numbers of cells sum(anno[anno$cell_number == 1, "ercc_percentage"] >= cut_off_ercc)</code></pre> <pre><code>[1] 225</code></pre> <pre class="r"><code>sum(anno[anno$cell_number == 1, "ercc_percentage"] < cut_off_ercc)</code></pre> <pre><code>[1] 1082</code></pre> <pre class="r"><code>## density plots plot_ercc <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = ercc_percentage *100, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + geom_vline(xintercept = cut_off_ercc *100, colour="grey", linetype = "longdash") + labs(x = "ERCC reads / total mapped reads", title = "ERCC reads percentage") plot_ercc</code></pre> <p><img src="figure/sampleqc.Rmd/ercc-percentage-1.png" width="672" style="display: block; margin: auto;" /></p> <p>Look at the ERCC spike-in percentage per sample by C1 experimnet and by individual.</p> <pre class="r"><code>ercc_exp <- ggplot(anno, aes(x = as.factor(experiment), y = ercc_percentage, color = as.factor(experiment))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "ERCC percentage", title = "ERCC percentage per sample") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) ercc_indi <- ggplot(anno, aes(x = chip_id, y = ercc_percentage, color = as.factor(chip_id))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "ERCC percentage", title = "ERCC percentage per sample") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) plot_grid(ercc_exp + theme(legend.position = "none"), ercc_indi + theme(legend.position = "none"), labels = letters[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/ercc_exp-1.png" width="672" style="display: block; margin: auto;" /></p> <hr /> </div> <div id="number-of-genes-detected" class="section level2"> <h2>Number of genes detected</h2> <pre class="r"><code>## cut off cut_off_genes <- quantile(anno[anno$cell_number == 0,"detect_hs"], 0.85) cut_off_genes</code></pre> <pre><code> 85% 5901.4 </code></pre> <pre class="r"><code>anno$cut_off_genes <- anno$detect_hs > cut_off_genes ## numbers of cells sum(anno[anno$cell_number == 1, "detect_hs"] > cut_off_genes)</code></pre> <pre><code>[1] 1079</code></pre> <pre class="r"><code>sum(anno[anno$cell_number == 1, "detect_hs"] <= cut_off_genes)</code></pre> <pre><code>[1] 228</code></pre> <pre class="r"><code>## density plots plot_gene <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = detect_hs, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + geom_vline(xintercept = cut_off_genes, colour="grey", linetype = "longdash") + labs(x = "Gene numbers", title = "Numbers of detected genes") plot_gene</code></pre> <p><img src="figure/sampleqc.Rmd/gene-number-1.png" width="672" style="display: block; margin: auto;" /></p> <pre class="r"><code>number_exp <- ggplot(anno, aes(x = as.factor(experiment), y = detect_hs, color = as.factor(experiment))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "Number of genes detected", title = "Number of genes per sample") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) number_indi <- ggplot(anno, aes(x = chip_id, y = detect_hs, color = as.factor(chip_id))) + geom_violin() + geom_boxplot(alpha = .01, width = .2, position = position_dodge(width = .9)) + labs(x = "C1 chip", y = "Number of genes detected", title = "Number of genes per sample") + theme(legend.title = element_blank(), axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) plot_grid(number_exp + theme(legend.position = "none"), number_indi + theme(legend.position = "none"), labels = letters[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/gene-number-exp-1.png" width="672" style="display: block; margin: auto;" /></p> <hr /> </div> <div id="fucci-transgene" class="section level2"> <h2>FUCCI transgene</h2> <pre class="r"><code>## plot molecule number of egfp and mCherry egfp_mol <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = mol_egfp, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + labs(x = "EGFP molecule numbers", title = "Numbers of EGFP molecules") mcherry_mol <- ggplot(anno[anno$cell_number == 0 | anno$cell_number == 1 , ], aes(x = mol_mcherry, fill = as.factor(cell_number))) + geom_density(alpha = 0.5) + labs(x = "mCherry molecule numbers", title = "Numbers of mCherry molecules") plot_grid(egfp_mol + theme(legend.position = c(.5,.9)), mcherry_mol + theme(legend.position = "none"), labels = letters[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/fucci-1.png" width="672" style="display: block; margin: auto;" /></p> <hr /> </div> <div id="linear-discriminat-analysis" class="section level2"> <h2>Linear Discriminat Analysis</h2> <div id="total-molecule-vs-concentration" class="section level3"> <h3>Total molecule vs concentration</h3> <pre class="r"><code>library(MASS)</code></pre> <pre><code> Attaching package: 'MASS'</code></pre> <pre><code>The following object is masked from 'package:dplyr': select</code></pre> <pre class="r"><code>## create 3 groups according to cell number group_3 <- rep("two",dim(anno)[1]) group_3[grep("0", anno$cell_number)] <- "no" group_3[grep("1", anno$cell_number)] <- "one" ## create data frame data <- anno %>% dplyr::select(experiment:concentration, mapped, molecules) data <- data.frame(data, group = group_3) ## perform lda data_lda <- lda(group ~ concentration + molecules, data = data) data_lda_p <- predict(data_lda, newdata = data[,c("concentration", "molecules")])$class ## determine how well the model fix table(data_lda_p, data[, "group"])</code></pre> <pre><code> data_lda_p no one two no 0 0 0 one 36 1297 147 two 0 11 45</code></pre> <pre class="r"><code>data$data_lda_p <- data_lda_p ## plot before and after plot_before <- ggplot(data, aes(x = concentration, y = molecules / 10^3, color = as.factor(group))) + geom_text(aes(label = cell_number, alpha = 0.5)) + labs(x = "Concentration", y = "Gene molecules (thousands)", title = "Before") + scale_color_brewer(palette = "Dark2") + theme(legend.position = "none") plot_after <- ggplot(data, aes(x = concentration, y = molecules / 10^3, color = as.factor(data_lda_p))) + geom_text(aes(label = cell_number, alpha = 0.5)) + labs(x = "Concentration", y = "Gene molecules (thousands)", title = "After") + scale_color_brewer(palette = "Dark2") + theme(legend.position = "none") plot_grid(plot_before + theme(legend.position=c(.8,.85)), plot_after + theme(legend.position = "none"), labels = LETTERS[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/lda-1.png" width="1152" style="display: block; margin: auto;" /></p> </div> <div id="reads-to-molecule-conversion" class="section level3"> <h3>Reads to molecule conversion</h3> <pre class="r"><code>## calculate convertion anno$ercc_conversion <- anno$mol_ercc / anno$reads_ercc anno$conversion <- anno$mol_hs / anno$reads_hs ## try lda data$conversion <- anno$conversion data$ercc_conversion <- anno$ercc_conversion data_ercc_lda <- lda(group ~ ercc_conversion + conversion, data = data) data_ercc_lda_p <- predict(data_ercc_lda, newdata = data[,c("ercc_conversion", "conversion")])$class ## determine how well the model fix table(data_ercc_lda_p, data[, "group"])</code></pre> <pre><code> data_ercc_lda_p no one two no 15 29 1 one 21 1275 165 two 0 4 26</code></pre> <pre class="r"><code>data$data_ercc_lda_p <- data_ercc_lda_p ## cutoff #out_ercc_con <- anno %>% filter(cell_number == "1", ercc_conversion > .094) anno$conversion_outlier <- anno$cell_number == 1 & anno$ercc_conversion > .094 ## plot before and after plot_ercc_before <- ggplot(data, aes(x = ercc_conversion, y = conversion, color = as.factor(group))) + geom_text(aes(label = cell_number, alpha = 0.5)) + labs(x = "Convertion of ERCC spike-ins", y = "Conversion of genes", title = "Before") + scale_color_brewer(palette = "Dark2") + theme(legend.position = "none") plot_ercc_after <- ggplot(data, aes(x = ercc_conversion, y = conversion, color = as.factor(data_ercc_lda_p))) + geom_text(aes(label = cell_number, alpha = 0.5)) + labs(x = "Convertion of ERCC spike-ins", y = "Conversion of genes", title = "After") + scale_color_brewer(palette = "Dark2") + theme(legend.position = "none") plot_grid(plot_ercc_before, plot_ercc_after, labels = LETTERS[3:4])</code></pre> <p><img src="figure/sampleqc.Rmd/convertion-1.png" width="1152" style="display: block; margin: auto;" /></p> </div> </div> <div id="pca" class="section level2"> <h2>PCA</h2> <pre class="r"><code>## look at human genes eset_hs <- eset[fData(eset)$source == "H. sapiens", ] head(featureNames(eset_hs))</code></pre> <pre><code>[1] "ENSG00000000003" "ENSG00000000005" "ENSG00000000419" "ENSG00000000457" [5] "ENSG00000000460" "ENSG00000000938"</code></pre> <pre class="r"><code>## remove genes of all 0s eset_hs_clean <- eset_hs[rowSums(exprs(eset_hs)) != 0, ] dim(eset_hs_clean)</code></pre> <pre><code>Features Samples 19348 1536 </code></pre> <pre class="r"><code>## convert to log2 cpm mol_hs_cpm <- cpm(exprs(eset_hs_clean), log = TRUE) mol_hs_cpm_means <- rowMeans(mol_hs_cpm) summary(mol_hs_cpm_means)</code></pre> <pre><code> Min. 1st Qu. Median Mean 3rd Qu. Max. 2.413 2.482 3.180 3.858 4.761 12.999 </code></pre> <pre class="r"><code>mol_hs_cpm <- mol_hs_cpm[mol_hs_cpm_means > median(mol_hs_cpm_means), ] dim(mol_hs_cpm)</code></pre> <pre><code>[1] 9674 1536</code></pre> <pre class="r"><code>## pca of genes with reasonable expression levels pca_hs <- run_pca(mol_hs_cpm) plot_pca_id <- plot_pca(pca_hs$PCs, pcx = 1, pcy = 2, explained = pca_hs$explained, metadata = pData(eset_hs_clean), color = "chip_id")</code></pre> </div> <div id="filter" class="section level2"> <h2>Filter</h2> <div id="final-list" class="section level3"> <h3>Final list</h3> <pre class="r"><code>## all filter anno$filter_all <- anno$cell_number == 1 & anno$mol_egfp > 0 & anno$valid_id & anno$cut_off_reads & ## anno$cut_off_unmapped & anno$cut_off_ercc & anno$cut_off_genes sort(table(anno[anno$filter_all, "chip_id"]))</code></pre> <pre><code> NA18511 NA19160 NA19101 NA18855 NA19098 NA18870 131 133 142 198 202 227 </code></pre> <pre class="r"><code>table(anno[anno$filter_all, c("experiment","chip_id")])</code></pre> <pre><code> chip_id experiment NA18511 NA18855 NA18870 NA19098 NA19101 NA19160 20170905 0 38 31 0 0 0 20170906 0 0 0 48 24 0 20170907 0 33 0 26 0 0 20170908 0 0 38 0 38 0 20170910 0 38 0 0 27 0 20170912 0 0 43 39 0 0 20170913 0 50 0 0 0 10 20170914 0 0 0 0 27 36 20170915 27 39 0 0 0 0 20170916 20 0 0 0 26 0 20170917 0 0 0 43 0 12 20170919 12 0 0 46 0 0 20170920 41 0 0 0 0 18 20170921 0 0 46 0 0 26 20170922 31 0 30 0 0 0 20170924 0 0 39 0 0 31</code></pre> </div> <div id="plots" class="section level3"> <h3>Plots</h3> <pre class="r"><code>genes_unmapped <- ggplot(anno, aes(x = detect_hs, y = unmapped_ratios * 100, col = as.factor(chip_id), label = as.character(cell_number), height = 600, width = 2000)) + scale_colour_manual(values=cbPalette) + geom_text(fontface = 3, alpha = 0.5) + geom_vline(xintercept = cut_off_genes, colour="grey", linetype = "longdash") + geom_hline(yintercept = cut_off_unmapped * 100, colour="grey", linetype = "longdash") + labs(x = "Number of detected genes / sample", y = "Percentage of unmapped reads (%)") genes_spike <- ggplot(anno, aes(x = detect_hs, y = ercc_percentage * 100, col = as.factor(chip_id), label = as.character(cell_number), height = 600, width = 2000)) + scale_colour_manual(values=cbPalette) + scale_shape_manual(values=c(1:10)) + geom_text(fontface = 3, alpha = 0.5) + geom_vline(xintercept = cut_off_genes, colour="grey", linetype = "longdash") + geom_hline(yintercept = cut_off_ercc * 100, colour="grey", linetype = "longdash") + labs(x = "Number of detected genes / samlpe", y = "Percentage of ERCC spike-in reads (%)") reads_unmapped_num <- ggplot(anno, aes(x = mapped, y = unmapped_ratios * 100, col = as.factor(experiment), label = as.character(cell_number), height = 600, width = 2000)) + geom_text(fontface = 3, alpha = 0.5) + geom_vline(xintercept = cut_off_reads, colour="grey", linetype = "longdash") + geom_hline(yintercept = cut_off_unmapped * 100, colour="grey", linetype = "longdash") + labs(x = "Total mapped reads / sample", y = "Percentage of unmapped reads (%)") reads_spike_num <- ggplot(anno, aes(x = mapped, y = ercc_percentage * 100, col = as.factor(experiment), label = as.character(cell_number), height = 600, width = 2000)) + geom_text(fontface = 3, alpha = 0.5) + geom_vline(xintercept = cut_off_reads, colour="grey", linetype = "longdash") + geom_hline(yintercept = cut_off_ercc * 100, colour="grey", linetype = "longdash") + labs(x = "Total mapped reads / sample", y = "Percentage of ERCC spike-in reads (%)") plot_grid(genes_unmapped + theme(legend.position = c(.7,.9)), genes_spike + theme(legend.position = "none"), labels = letters[1:2])</code></pre> <p><img src="figure/sampleqc.Rmd/plots-1.png" width="3600" style="display: block; margin: auto;" /></p> <pre class="r"><code>plot_grid(reads_unmapped_num + theme(legend.position = c(.7,.9)), reads_spike_num + theme(legend.position = "none"), labels = letters[3:4])</code></pre> <p><img src="figure/sampleqc.Rmd/plots-2.png" width="3600" style="display: block; margin: auto;" /></p> <hr /> </div> </div> <div id="output-filters" class="section level2"> <h2>Output filters</h2> <p><span class="math inline">\(~\)</span></p> <p>These filters are later combined with metadata in our <code>eset</code> objects.</p> <p><span class="math inline">\(~\)</span></p> <pre class="r"><code>exps <- unique(anno$experiment) for (index in 1:length(exps)) { tmp <- subset(anno, experiment == exps[index], select=c(cut_off_reads, unmapped_ratios, cut_off_unmapped, ercc_percentage, cut_off_ercc, cut_off_genes, ercc_conversion, conversion, conversion_outlier, filter_all)) tmp <- data.frame(sample_id=rownames(tmp), tmp) write.table(tmp, file = paste0("output/sampleqc.Rmd/",exps[index],".txt"), sep = "\t", quote = FALSE, col.names = TRUE, row.names = F) } # to import each text #library(data.table) #b <- fread("output/sampleqc.Rmd/20170905.txt", header=T) pheno_labels <- rbind ( c("cut_off_reads", "QC filter: number of mapped reads > 85th percentile among zero-cell samples"), c("unmapped_ratios", "QC filter: among reads with a valid UMI, number of unmapped/number of mapped (unmapped/umi)"), c("cut_off_unmapped", "QC filter: unmapped ratio < 30th percentile among zero-cell samples"), c("ercc_percentage", "QC filter: number of reads mapped to ERCC/total sample mapped reads (reads_ercc/mapped)"), c("cut_off_ercc", "QC filter: ercc percentage < 15th percentile among zero-cell samples"), c("cut_off_genes", "QC filter: number of endogeneous genes with at least one molecule (detect_hs) > 85th percentile among zero-cell samples"), c("ercc_conversion", "QC filter: among ERCC, number of molecules/number of mapped reads (mol_ercc/reads_ercc)"), c("conversion", "QC filter: among endogeneous genes, number of molecules/number of mapped reads (mol_hs/reads_hs)"), c("conversion_outlier", "QC filter: microscoy detects 1 cell AND ERCC conversion rate > .094"), c("filter_all", "QC filter: Does the sample pass all the QC filters? cell_number==1, mol_egfp >0, valid_id==1, cut_off_reads==TRUE, cut_off_ercc==TRUE, cut_off_genes=TRUE")) write.table(pheno_labels, file = paste0("../output/sampleqc.Rmd/pheno_labels.txt"), sep = "\t", quote = FALSE, col.names = F, row.names = F) #b <- fread("../output/sampleqc.Rmd/pheno_labels.txt", header=F)</code></pre> <hr /> </div> <div id="session-information" class="section level2"> <h2>Session information</h2> <pre><code>R version 3.4.1 (2017-06-30) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Scientific Linux 7.2 (Nitrogen) Matrix products: default BLAS: /project2/gilad/jdblischak/miniconda3/envs/fucci-seq/lib/R/lib/libRblas.so LAPACK: /project2/gilad/jdblischak/miniconda3/envs/fucci-seq/lib/R/lib/libRlapack.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] parallel methods stats graphics grDevices utils datasets [8] base other attached packages: [1] testit_0.6 MASS_7.3-45 Biobase_2.38.0 [4] BiocGenerics_0.24.0 reshape2_1.4.2 edgeR_3.20.7 [7] limma_3.34.6 dplyr_0.7.4 cowplot_0.9.1 [10] ggplot2_2.2.1 loaded via a namespace (and not attached): [1] Rcpp_0.12.13 RColorBrewer_1.1-2 compiler_3.4.1 [4] git2r_0.19.0 plyr_1.8.4 bindr_0.1 [7] tools_3.4.1 digest_0.6.12 evaluate_0.10.1 [10] tibble_1.3.3 gtable_0.2.0 lattice_0.20-34 [13] pkgconfig_2.0.1 rlang_0.1.2 yaml_2.1.14 [16] bindrcpp_0.2 stringr_1.2.0 knitr_1.16 [19] locfit_1.5-9.1 rprojroot_1.2 grid_3.4.1 [22] glue_1.1.1 R6_2.2.0 rmarkdown_1.6 [25] magrittr_1.5 backports_1.0.5 scales_0.5.0 [28] htmltools_0.3.6 assertthat_0.1 colorspace_1.3-2 [31] labeling_0.3 stringi_1.1.2 lazyeval_0.2.0 [34] munsell_0.4.3 </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 <a href="http://rmarkdown.rstudio.com">R Markdown</a> site was created with <a href="https://github.com/jdblischak/workflowr">workflowr</a> </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> --> </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>