Last updated: 2022-02-17
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 7cfe3e4. 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: .Rhistory
Ignored: .Rproj.user/
Ignored: scripts/
Untracked files:
Untracked: ._.DS_Store
Untracked: DOCNAME
Untracked: analysis/calc_nanoseq_metrics.Rmd
Untracked: code/count_family_metrics.sh
Untracked: data/ecoli/
Untracked: data/nanoseq_results
Untracked: prototype_code/
Untracked: quali
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/model.Rmd
) and HTML (docs/model.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 | 7cfe3e4 | Marek Cmero | 2022-02-17 | Updated/simplified model |
html | e5ed9a7 | Marek Cmero | 2021-12-15 | Build site. |
html | 5a3c6b1 | Marek Cmero | 2021-12-15 | Build site. |
html | cbb4886 | mcmero | 2021-09-22 | Build site. |
Rmd | cf87608 | mcmero | 2021-09-22 | Added equation |
Rmd | 5cb4f4d | mcmero | 2021-09-22 | Fix probability of selecting mutant fragment |
html | 5cb4f4d | mcmero | 2021-09-22 | Fix probability of selecting mutant fragment |
html | 2f677c2 | mcmero | 2021-09-22 | Build site. |
Rmd | de62c5c | mcmero | 2021-09-22 |
|
html | de62c5c | mcmero | 2021-09-22 |
|
html | b680ba0 | mcmero | 2021-09-17 | Build site. |
Rmd | ebb9d74 | mcmero | 2021-09-17 | initial commit |
html | ebb9d74 | mcmero | 2021-09-17 | initial commit |
library(ggplot2)
Q: how many cells (or “cell equivalents”) do we need to sequence to detect variants down to a VAF of X%
Let \(p\) be the probability of selecting a mutant cell from a pool of \(n\) cells.
\(p = v / 2\)
Where:
We assume the probability of selecting a mutant cell is binomially distributed. We want to know the probability of selecting at least one mutant:
\(P(Bin(n, p)) > 0)\) = 0.95
This is equivalent to:
\(P(Bin(n, p)) = 0)\) = 0.05
Where \(n\) is the number of sequenced cells. We note that the number of mutant cells will, on average, will be \(2nv\).
Let’s consider how many input cells (\(n\)) are required to select at least one mutant cell at 1% VAF (95% confidence).
We’ll consider 100 cell increments from \(n = \{100, 200..2000\}\). Using these values, we can plot the probability selecting of sequencing at least one cell.
v = 0.01
n = seq(100, 2000, 100)
vafs <- data.frame(vaf=v,
p=pbinom(0, n, v / 2),
input_cells=n,
mutant_cells=(n * v * 2))
ggplot(vafs, aes(input_cells, p)) +
geom_point() +
theme_bw() +
geom_hline(yintercept=0.05, alpha=0.4)
We can also plot this as mutant cells instead of VAF:
ggplot(vafs, aes(mutant_cells, p)) +
geom_point() +
theme_bw() +
geom_hline(yintercept=0.05, alpha=0.4)
This shows that for a VAF target of 1%, we should sequence at least 600 cells (12 are mutants).
deviation <- abs(0.05 - vafs$p)
print(vafs[which(deviation == min(deviation)),])
vaf p input_cells mutant_cells
6 0.01 0.04941382 600 12
If we select 1000 input cells, what’s the lowest VAF we can sequence down to, where \(v = {0.0002, 0.0004..0.01}\).
v = seq(0.0002, 0.01, 0.0002)
n = 1000
vafs <- data.frame(vaf=v,
p=pbinom(0, n, v / 2),
input_cells=n,
mutant_cells=(n * v * 2))
ggplot(vafs, aes(vaf, p)) +
geom_point() +
theme_bw() +
geom_hline(yintercept=0.05, alpha=0.4)
We can sequence down to approx 0.6% VAF.
deviation <- abs(0.05 - vafs$p)
print(vafs[which(deviation == min(deviation)),])
vaf p input_cells mutant_cells
30 0.006 0.04956308 1000 12
We can look at the relationship between input cells and allele frequency:
cells_vs_vaf = NULL
n = seq(100, 10000, 100)
V = seq(0.001, 0.01, 0.001)
for (v in V) {
toadd <- data.frame(
vaf=as.factor(v),
p=pbinom(0, n, v / 2),
total_cells=n
)
cells_vs_vaf <- rbind(cells_vs_vaf, toadd)
}
ggplot(cells_vs_vaf, aes(total_cells, p, colour=vaf)) +
geom_line() +
theme_bw() +
theme(legend.position = 'bottom') +
geom_hline(yintercept=0.05, alpha=0.4)
We can define an equation based on the binomial probability calculation, of obtaining the number of cells to sequence, to be 95% confident of sequencing the mutation based on the target VAF:
\((1 – v / 2) ^ n = 0.05\)
The above thought experiment won’t tell us the probability of sequencing the variant, as sequencing involves a whole host of other factors. Coverage is one of the most important. Given that approximately 30x duplex coverage is required to yield 1x of high quality duplex coverage, we can look at the relationship between coverage and VAF (need the variant to be at least 1x to detect).
Here we can see that at VAF = 0.01 (line), we need to sequence to approx 3000x, and this gets exponentially deeper as we go down in target VAF.
v = seq(0.001, 0.1, 0.001)
ccov <- data.frame(d = 30 / v,
v = v)
ggplot(ccov, aes(d, v)) +
geom_line() +
theme_bw() +
geom_hline(yintercept=0.01, alpha=0.4)
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] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.5 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 highr_0.9 pillar_1.6.4 compiler_4.0.5
[5] bslib_0.3.0 later_1.3.0 jquerylib_0.1.4 git2r_0.28.0
[9] tools_4.0.5 digest_0.6.27 jsonlite_1.7.2 evaluate_0.14
[13] lifecycle_1.0.1 tibble_3.1.5 gtable_0.3.0 pkgconfig_2.0.3
[17] rlang_0.4.12 DBI_1.1.1 yaml_2.2.1 xfun_0.22
[21] fastmap_1.1.0 withr_2.4.2 dplyr_1.0.7 stringr_1.4.0
[25] knitr_1.33 generics_0.1.1 fs_1.5.0 vctrs_0.3.8
[29] sass_0.4.0 tidyselect_1.1.1 rprojroot_2.0.2 grid_4.0.5
[33] glue_1.4.2 R6_2.5.1 fansi_0.5.0 rmarkdown_2.11
[37] farver_2.1.0 purrr_0.3.4 magrittr_2.0.1 whisker_0.4
[41] scales_1.1.1 promises_1.2.0.1 ellipsis_0.3.2 htmltools_0.5.2
[45] assertthat_0.2.1 colorspace_2.0-0 httpuv_1.6.3 labeling_0.4.2
[49] utf8_1.2.2 stringi_1.7.5 munsell_0.5.0 crayon_1.4.2