Last updated: 2022-09-09
Checks: 7 0
Knit directory: rare-mutation-detection/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
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.
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.
The command set.seed(20210916)
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.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 62e155d. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
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 wflow_publish
or
wflow_git_commit
). 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:
Ignored files:
Ignored: .DS_Store
Ignored: .Rapp.history
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/.DS_Store
Ignored: scripts/
Untracked files:
Untracked: ._.DS_Store
Untracked: DOCNAME
Untracked: analysis/._.DS_Store
Untracked: analysis/cache/
Untracked: analysis/calc_nanoseq_metrics.Rmd
Untracked: data/._metrics.rds
Untracked: data/ecoli/
Untracked: data/ecoli_k12_metrics.rds
Untracked: data/metadata/
Untracked: data/metrics_efficiency_nossc.rds
Untracked: data/mixtures
Untracked: data/ref/
Untracked: prototype_code/
Unstaged changes:
Modified: analysis/ecoli_K12.Rmd
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.
These are the previous versions of the repository in which changes were
made to the R Markdown (analysis/downsampling.Rmd
) and HTML
(docs/downsampling.html
) files. If you’ve configured a
remote Git repository (see ?wflow_git_remote
), click on the
hyperlinks in the table below to view the files as they were in that
past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 62e155d | Marek Cmero | 2022-09-09 | Added NanoSeq MB2 Rep1 downsampling experiment |
html | 2a208e6 | Marek Cmero | 2022-08-24 | Build site. |
Rmd | e66471e | Marek Cmero | 2022-08-24 | Added replicate to downsampling experiment; separated gc_both and gc_single stats |
html | 4ae6aec | Marek Cmero | 2022-08-19 | Build site. |
Rmd | a06f97c | Marek Cmero | 2022-08-19 | Added extra 1-6% samples |
html | f90d40a | Marek Cmero | 2022-08-18 | Build site. |
Rmd | 7ff227e | Marek Cmero | 2022-08-18 | Added downsampling experiments and some presentation-only plots. |
The E. Coli sample 1-K12Rep1 (1% spike-in) was selected as a representative sample. We down-sampled to 1-6% in 1% increments and 10-50% in 10% increments to determine the optimal duplicate rate (highest efficiency).
library(ggplot2)
library(data.table)
library(dplyr)
library(here)
library(tibble)
library(stringr)
library(Rsamtools)
library(GenomicRanges)
library(seqinr)
library(parallel)
library(readxl)
library(patchwork)
library(RColorBrewer)
library(UpSetR)
library(vcfR)
library(tidyr)
source(here('code/load_data.R'))
source(here('code/plot.R'))
source(here('code/efficiency_nanoseq_functions.R'))
genome_max <- 4528118
cores <- 8
genomeFile <- here('data/ref/Escherichia_coli_strain_BL21_TaKaRa.fasta')
rinfo_dir <- here('data/ecoli/downsampling/QC/read_info')
markdup_dir <- here('data/ecoli/downsampling/QC/mark_duplicates')
qualimap_dir <- here('data/ecoli/downsampling/QC/qualimap')
qualimap_cons_dir <- here('data/ecoli/downsampling/QC/consensus/qualimap')
variant_dir <- here('data/ecoli/downsampling/variants')
sample_names <- list.files(rinfo_dir, pattern = '\\.txt\\.gz') %>%
str_split('\\.txt\\.gz') %>%
lapply(., dplyr::first) %>%
unlist() %>%
str_split('_') %>%
lapply(., head, 2) %>%
lapply(., paste, collapse='-') %>%
unlist()
# load variant data
var_sample_names <- list.files(variant_dir) %>%
str_split('_HFVGHDSX3') %>%
lapply(., dplyr::first) %>%
unlist()
var_df <- load_variants(variant_dir, var_sample_names) %>% calculate_vafs()
# load and fetch duplicate rate from MarkDuplicates output
mdup <- load_markdup_data(markdup_dir, sample_names)
# get mean coverage for pre and post-consensus reads
qmap_cov <- get_qmap_coverage(qualimap_dir, sample_names)
qmap_cons_cov <- get_qmap_coverage(qualimap_cons_dir, sample_names)
# uncomment below to calculate metrics
# calculate metrics for nanoseq
rlen <- 151; skips <- 5
metrics <- calc_metrics_new_rbs(rinfo_dir, cores = cores) %>% bind_rows()
metrics$duplicate_rate <- mdup
metrics$duplex_coverage_ratio <- qmap_cov$coverage / qmap_cons_cov$coverage
metrics$duplex_coverage_ratio[qmap_cons_cov$coverage < 1] <- 0 # fix when < 1 duplex cov
metrics$sample <- gsub('-HFVGHDSX3', '', sample_names)
# cache metrics object
# saveRDS(metrics, file = here('data/metrics.rds'))
# prepare for plotting
mm <- data.frame(reshape2::melt(metrics))
colnames(mm)[2] <- 'metric'
mm$group <- gsub('-0\\.[0-9]+-mix', '', mm$sample)
ggplot(mm, aes(sample, value, shape = group)) +
geom_point() +
theme_bw() +
theme(axis.text.x = element_text(angle = 90)) +
facet_wrap(~metric, scales = 'free') +
scale_colour_brewer(palette = 'Dark2')
Fraction of duplicate reads calculated by Picard’s MarkDuplicates. This is based on barcode-aware aligned duplicates mapping to the same 5’ positions for both read pairs. The NanoSeq Analysis pipeline states the optimal empirical duplicate rate is 75-76% (marked in the plot).
metric <- 'duplicate_rate'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
geom_hline(yintercept = 0.81, alpha = 0.4) +
scale_fill_brewer(palette = 'Set2') +
ggtitle(metric)
Shows the number of single-read families divided by the total number of reads. As suggested by Stoler et al. 2016, this metric can server as a proxy for error rate, as (uncorrected) barcode mismatches will manifest as single-read families. The lower the fraction of singletons, the better.
metric <- 'frac_singletons'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
scale_fill_brewer(palette = 'Set2') +
ggtitle(metric)
This is the same calculation as F-EFF in the NanoSeq Analysis pipeline:
“This shows the fraction of read bundles missing one of the two original strands beyond what would be expected under random sampling (assuming a binomial process). Good values are between 0.10-0.30, and larger values are likely due to DNA damage such as modified bases or internal nicks that prevent amplification of one of the two strands. Larger values do not impact the quality of the results, just reduce the efficiency of the protocol.”
This is similar to the singleton fraction, but taking into account loss of pairs due to sampling. The optimal range is shown by the lines.
metric <- 'drop_out_rate'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
scale_fill_brewer(palette = 'Set2') +
geom_hline(yintercept = c(0.1, 0.3), alpha = 0.4) +
ggtitle(metric)
Efficiency is the number of duplex bases divided by the number of sequenced bases. According the NanoSeq Analysis pipeline, this value is maximised at ~0.07 when duplicate rates and strand drop-outs are optimal.
metric <- 'efficiency'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
scale_fill_brewer(palette = 'Set2') +
geom_hline(yintercept = c(0.07), alpha = 0.4) +
ggtitle(metric)
GC deviation is the absolute difference between GC_BOTH
and GC_SINGLE
calculated by the NanoSeq Analysis
pipeline. The lower this deviation, the better.
“GC_BOTH and GC_SINGLE: the GC content of RBs with both strands and with just one strand. The two values should be similar between them and similar to the genome average. If there are large deviations that is possibly due to biases during PCR amplification. If GC_BOTH is substantially larger than GC_SINGLE, DNA denaturation before dilution may have taken place.”
metric <- 'gc_deviation'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
scale_fill_brewer(palette = 'Set2') +
ggtitle(metric)
The mean sequence (pre-duplex) coverage divided by mean duplex coverage. Indicates the yield of how much duplex coverage we get at each sample’s sequence coverage. Abascal et al. report that their yield was approximately 30x (marked on the plot).
metric <- 'duplex_coverage_ratio'
ggplot(mm[mm$metric == metric,], aes(sample, value, fill = group)) +
geom_histogram(stat = 'identity', position = 'dodge') +
theme_bw() +
coord_flip() +
scale_fill_brewer(palette = 'Set2') +
geom_hline(yintercept = 30, alpha = 0.4) +
ggtitle(metric)
Comparison of family pair sizes between samples (these are calculated from total reads of paired AB and BA families).
ggplot(mm[mm$metric %like% 'family', ], aes(value, sample, colour = metric)) +
geom_point() +
coord_trans(x='log2') +
scale_x_continuous(breaks=seq(0, 94, 8)) +
theme(axis.text.x = element_text(size=5)) +
theme_bw() +
ggtitle('Family pair sizes')
The following plot shows:
ggplot(mm[mm$metric %like% 'pair|gt1', ], aes(value, sample, fill = metric)) +
geom_bar(stat='identity', position='dodge') +
theme_bw() +
ggtitle('Family statistics')
dvf <- mm[mm$metric %in% c('duplicate_rate', 'efficiency'),] %>%
reshape2::dcast(., sample ~ metric) %>%
mutate(group = gsub('-0\\.[0-9]+-mix', '', sample),
sample = gsub('p[0-9]|-|mix', '', sample))
ggplot(dvf, aes(duplicate_rate, efficiency, label = sample, colour = group)) +
geom_text(vjust = -0.5) +
geom_point() +
theme_bw() +
geom_smooth(method = 'lm', formula = y ~ x + I(x^2), alpha = 0.2) +
scale_x_continuous(breaks = seq(0.3, 0.9, 0.1))
print(dvf)
sample efficiency duplicate_rate group
1 0.01 0.009357879 0.344995 p1
2 0.02 0.023186215 0.530327 p1
3 0.03 0.028731789 0.639217 p1
4 0.04 0.029026991 0.708232 p1
5 0.05 0.027242919 0.755368 p1
6 0.06 0.024912201 0.788894 p1
7 0.1 0.017276748 0.861301 p1
8 0.2 0.009495706 0.920186 p1
9 0.3 0.006573071 0.940894 p1
10 0.4 0.005042973 0.951593 p1
11 0.5 0.004093100 0.958179 p1
12 0.01 0.017112062 0.456862 p2
13 0.02 0.027572392 0.644464 p2
14 0.03 0.026600260 0.737295 p2
15 0.04 0.023353433 0.791547 p2
16 0.05 0.020244512 0.826472 p2
17 0.06 0.017763446 0.850733 p2
18 0.1 0.011633367 0.901799 p2
19 0.2 0.006205110 0.942477 p2
20 0.3 0.004245127 0.956784 p2
21 0.4 0.003238568 0.964124 p2
22 0.5 0.002620392 0.968663 p2
23 0.1 0.007324807 0.223345 p3
24 0.2 0.025883250 0.372871 p3
25 0.3 0.042500643 0.477532 p3
26 0.4 0.052752617 0.553370 p3
27 0.5 0.057747730 0.610244 p3
28 0.6 0.059300720 0.654287 p3
29 0.7 0.058824472 0.689125 p3
30 0.8 0.057309689 0.717307 p3
31 0.9 0.055289137 0.740505 p3
sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS: /stornext/System/data/apps/R/R-4.0.5/lib64/R/lib/libRblas.so
LAPACK: /stornext/System/data/apps/R/R-4.0.5/lib64/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] stats4 parallel stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] tidyr_1.1.3 vcfR_1.12.0 UpSetR_1.4.0
[4] RColorBrewer_1.1-3 patchwork_1.1.1 readxl_1.3.1
[7] seqinr_4.2-8 Rsamtools_2.6.0 Biostrings_2.58.0
[10] XVector_0.30.0 GenomicRanges_1.42.0 GenomeInfoDb_1.26.7
[13] IRanges_2.24.1 S4Vectors_0.28.1 BiocGenerics_0.36.1
[16] stringr_1.4.0 tibble_3.1.7 here_1.0.1
[19] dplyr_1.0.7 data.table_1.14.0 ggplot2_3.3.6
[22] workflowr_1.6.2
loaded via a namespace (and not attached):
[1] nlme_3.1-152 bitops_1.0-7 fs_1.5.0
[4] rprojroot_2.0.2 tools_4.0.5 bslib_0.3.0
[7] utf8_1.2.2 R6_2.5.1 vegan_2.5-7
[10] DBI_1.1.1 mgcv_1.8-35 colorspace_2.0-3
[13] permute_0.9-5 ade4_1.7-18 withr_2.5.0
[16] tidyselect_1.1.1 gridExtra_2.3 compiler_4.0.5
[19] git2r_0.28.0 cli_3.3.0 labeling_0.4.2
[22] sass_0.4.0 scales_1.2.0 digest_0.6.29
[25] rmarkdown_2.11 pkgconfig_2.0.3 htmltools_0.5.2
[28] highr_0.9 fastmap_1.1.0 rlang_1.0.2
[31] rstudioapi_0.13 farver_2.1.0 jquerylib_0.1.4
[34] generics_0.1.1 jsonlite_1.7.2 BiocParallel_1.24.1
[37] RCurl_1.98-1.3 magrittr_2.0.3 GenomeInfoDbData_1.2.4
[40] Matrix_1.3-2 Rcpp_1.0.7 munsell_0.5.0
[43] fansi_1.0.3 ape_5.5 lifecycle_1.0.1
[46] stringi_1.7.5 whisker_0.4 yaml_2.2.1
[49] MASS_7.3-53.1 zlibbioc_1.36.0 plyr_1.8.6
[52] pinfsc50_1.2.0 grid_4.0.5 promises_1.2.0.1
[55] crayon_1.5.1 lattice_0.20-44 splines_4.0.5
[58] knitr_1.33 pillar_1.7.0 reshape2_1.4.4
[61] glue_1.6.2 evaluate_0.14 memuse_4.2-1
[64] vctrs_0.4.1 httpuv_1.6.3 cellranger_1.1.0
[67] gtable_0.3.0 purrr_0.3.4 assertthat_0.2.1
[70] xfun_0.22 later_1.3.0 viridisLite_0.4.0
[73] cluster_2.1.2 ellipsis_0.3.2