Last updated: 2022-01-05
Checks: 7 0
Knit directory: single-cell-topics/analysis/
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(1)
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 95017e4. 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: analysis/figure/
Ignored: data/droplet.RData
Ignored: data/pbmc_68k.RData
Ignored: data/pbmc_purified.RData
Ignored: data/pulseseq.RData
Ignored: output/droplet/diff-count-droplet.RData
Ignored: output/droplet/fits-droplet.RData
Ignored: output/droplet/rds/
Ignored: output/pbmc-68k/fits-pbmc-68k.RData
Ignored: output/pbmc-68k/rds/
Ignored: output/pbmc-purified/fits-pbmc-purified.RData
Ignored: output/pbmc-purified/rds/
Ignored: output/pulseseq/diff-count-pulseseq.RData
Ignored: output/pulseseq/fits-pulseseq.RData
Ignored: output/pulseseq/rds/
Ignored: output/sims/
Untracked files:
Untracked: analysis/de_analysis_detailed_look_cache/
Untracked: analysis/de_analysis_detailed_look_more_cache/
Untracked: plots/
Unstaged changes:
Modified: analysis/de_analysis_mast_deseq2.R
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/de_analysis_mast_deseq2.Rmd
) and HTML (docs/de_analysis_mast_deseq2.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 | 95017e4 | Peter Carbonetto | 2022-01-05 | workflowr::wflow_publish(“de_analysis_mast_deseq2.Rmd”, verbose = TRUE) |
html | c05700c | Peter Carbonetto | 2022-01-05 | Added p-value and s-value histograms to de_analysis_mast_deseq2 analysis. |
Rmd | 2a2d9b1 | Peter Carbonetto | 2022-01-05 | workflowr::wflow_publish(“de_analysis_mast_deseq2.Rmd”, verbose = TRUE) |
html | 10fc0dc | Peter Carbonetto | 2022-01-05 | Added scatterplots to de_analysis_mast_deseq2 analysis. |
Rmd | 85eeed0 | Peter Carbonetto | 2022-01-05 | workflowr::wflow_publish(“de_analysis_mast_deseq2.Rmd”, verbose = TRUE) |
Rmd | 283c7ba | Peter Carbonetto | 2022-01-05 | Working on de_analysis_mast_deseq2 R Markdown. |
html | 283c7ba | Peter Carbonetto | 2022-01-05 | Working on de_analysis_mast_deseq2 R Markdown. |
html | 4ff98f4 | Peter Carbonetto | 2022-01-05 | Built de_analysis_mast_deseq2 page. |
html | e164b8f | Peter Carbonetto | 2022-01-05 | Added link to overview page. |
Rmd | 3de0e0c | Peter Carbonetto | 2022-01-05 | workflowr::wflow_publish(“index.Rmd”) |
This is a more systematic comparison of the new fastTopics DE analysis with MAST and DESeq2 based on an initial smaller simulation. The results were generated using the run_sims.R
script, and here we summarize the results of these simulations.
Load the packages needed for this analysis, and some additional functions used to compile the results and generate the plots.
library(Matrix)
library(Seurat)
library(DESeq2)
library(MAST)
library(fastTopics)
library(ggplot2)
library(cowplot)
source("../code/de_analysis_functions.R")
Load the results of the simulations.
load("../output/sims/sims-k=2-alpha=0.01.RData")
These were the R packages used to run the simulations:
res$session.info
# R version 4.1.0 (2021-05-18)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Scientific Linux 7.4 (Nitrogen)
#
# Matrix products: default
# BLAS/LAPACK: /software/openblas-0.3.13-el7-x86_64/lib/libopenblas_haswellp-r0.3.13.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 tools stats graphics grDevices utils datasets
# [8] methods base
#
# other attached packages:
# [1] fastTopics_0.6-97 MAST_1.20.0
# [3] SeuratObject_4.0.2 Seurat_4.0.3
# [5] DESeq2_1.34.0 scran_1.22.1
# [7] scuttle_1.4.0 SingleCellExperiment_1.16.0
# [9] SummarizedExperiment_1.24.0 Biobase_2.54.0
# [11] GenomicRanges_1.46.0 GenomeInfoDb_1.30.0
# [13] IRanges_2.28.0 S4Vectors_0.32.0
# [15] BiocGenerics_0.40.0 MatrixGenerics_1.6.0
# [17] matrixStats_0.60.1 Matrix_1.3-3
#
# loaded via a namespace (and not attached):
# [1] utf8_1.2.1 reticulate_1.20
# [3] tidyselect_1.1.1 RSQLite_2.2.8
# [5] AnnotationDbi_1.56.1 htmlwidgets_1.5.3
# [7] grid_4.1.0 BiocParallel_1.28.0
# [9] Rtsne_0.15 munsell_0.5.0
# [11] ScaledMatrix_1.2.0 codetools_0.2-18
# [13] ica_1.0-2 statmod_1.4.36
# [15] future_1.21.0 miniUI_0.1.1.1
# [17] colorspace_2.0-2 rstudioapi_0.13
# [19] ROCR_1.0-11 tensor_1.5
# [21] listenv_0.8.0 GenomeInfoDbData_1.2.7
# [23] mixsqp_0.3-43 polyclip_1.10-0
# [25] MCMCpack_1.6-0 bit64_4.0.5
# [27] coda_0.19-4 parallelly_1.26.1
# [29] vctrs_0.3.8 generics_0.1.0
# [31] R6_2.5.0 rsvd_1.0.5
# [33] invgamma_1.1 locfit_1.5-9.4
# [35] bitops_1.0-7 spatstat.utils_2.2-0
# [37] cachem_1.0.5 DelayedArray_0.20.0
# [39] assertthat_0.2.1 promises_1.2.0.1
# [41] scales_1.1.1 gtable_0.3.0
# [43] beachmat_2.10.0 globals_0.14.0
# [45] conquer_1.0.2 goftest_1.2-2
# [47] mcmc_0.9-7 rlang_0.4.11
# [49] MatrixModels_0.5-0 genefilter_1.76.0
# [51] splines_4.1.0 lazyeval_0.2.2
# [53] spatstat.geom_2.2-0 reshape2_1.4.4
# [55] abind_1.4-5 httpuv_1.6.1
# [57] ggplot2_3.3.5 ellipsis_0.3.2
# [59] spatstat.core_2.2-0 RColorBrewer_1.1-2
# [61] ggridges_0.5.3 Rcpp_1.0.7
# [63] plyr_1.8.6 sparseMatrixStats_1.6.0
# [65] progress_1.2.2 zlibbioc_1.40.0
# [67] purrr_0.3.4 RCurl_1.98-1.5
# [69] prettyunits_1.1.1 rpart_4.1-15
# [71] deldir_0.2-10 pbapply_1.4-3
# [73] ashr_2.2-51 cowplot_1.1.1
# [75] zoo_1.8-9 ggrepel_0.9.1
# [77] cluster_2.1.2 magrittr_2.0.1
# [79] data.table_1.14.0 scattermore_0.7
# [81] SparseM_1.81 lmtest_0.9-38
# [83] RANN_2.6.1 truncnorm_1.0-8
# [85] SQUAREM_2021.1 fitdistrplus_1.1-5
# [87] hms_1.1.0 patchwork_1.1.1
# [89] mime_0.11 xtable_1.8-4
# [91] XML_3.99-0.6 gridExtra_2.3
# [93] compiler_4.1.0 tibble_3.1.2
# [95] KernSmooth_2.23-20 crayon_1.4.1
# [97] htmltools_0.5.1.1 mgcv_1.8-35
# [99] later_1.2.0 tidyr_1.1.3
# [101] geneplotter_1.72.0 RcppParallel_5.1.4
# [103] DBI_1.1.1 MASS_7.3-54
# [105] quadprog_1.5-8 parallel_4.1.0
# [107] metapod_1.2.0 igraph_1.2.6
# [109] pkgconfig_2.0.3 plotly_4.9.4.1
# [111] spatstat.sparse_2.0-0 annotate_1.72.0
# [113] dqrng_0.3.0 XVector_0.34.0
# [115] stringr_1.4.0 digest_0.6.27
# [117] sctransform_0.3.2 RcppAnnoy_0.0.18
# [119] spatstat.data_2.1-0 Biostrings_2.62.0
# [121] leiden_0.3.8 uwot_0.1.10
# [123] edgeR_3.36.0 DelayedMatrixStats_1.16.0
# [125] shiny_1.6.0 quantreg_5.86
# [127] lifecycle_1.0.0 nlme_3.1-152
# [129] jsonlite_1.7.2 BiocNeighbors_1.12.0
# [131] viridisLite_0.4.0 limma_3.50.0
# [133] fansi_0.5.0 pillar_1.6.1
# [135] lattice_0.20-44 KEGGREST_1.34.0
# [137] fastmap_1.1.0 httr_1.4.2
# [139] survival_3.2-11 glue_1.4.2
# [141] png_0.1-7 bluster_1.4.0
# [143] bit_4.0.4 stringi_1.6.2
# [145] blob_1.2.1 BiocSingular_1.10.0
# [147] memoise_2.0.0 dplyr_1.0.7
# [149] irlba_2.3.3 future.apply_1.7.0
Since we are comparing with MAST and DESeq2, two methods that do not allow for partial membership to groups, we have simulated count data from a topic model in which the true topic proportions are all 0 or 1, or mostly very close to 0 or 1.
res["session.info"] <- NULL
x <- combine_sim_res(res,function (x) apply(x$dat$L,1,max))
mean(x > 0.99)
# [1] 0.98625
Before comparing the methods, first we assess accuracy of the Monte Carlo computations by comparing the estimates from two independent MCMC simulations. The estimates from the two independent simulations are largely consistent.
pdat <- data.frame(lfc1 = combine_sim_res(res,function (x) x$de1$postmean[,2]),
lfc2 = combine_sim_res(res,function (x) x$de2$postmean[,2]),
z1 = combine_sim_res(res,function (x) x$de1$z[,2]),
z2 = combine_sim_res(res,function (x) x$de2$z[,2]))
p1 <- ggplot(pdat,aes(x = lfc1,y = lfc2)) +
geom_point(color = "dodgerblue",shape = 4,size = 0.75) +
geom_abline(intercept = 0,slope = 1,linetype = "dotted") +
labs(x = "first posterior mean",y = "second posterior mean") +
theme_cowplot(font_size = 12)
p2 <- ggplot(pdat,aes(x = z1,y = z2)) +
geom_point(color = "dodgerblue",shape = 4,size = 0.75) +
geom_abline(intercept = 0,slope = 1,linetype = "dotted") +
labs(x = "first z-score estimate",y = "second z-score estimate") +
xlim(-45,42) +
ylim(-45,42) +
theme_cowplot(font_size = 12)
plot_grid(p1,p2)
Version | Author | Date |
---|---|---|
10fc0dc | Peter Carbonetto | 2022-01-05 |
Now we compare LFC estimates for the second topic:
j <- paste0("g",1:10000)
lfc.deseq <- combine_sim_res(res,function (x) x$deseq$log2FoldChange)
lfc.fasttopics <- combine_sim_res(res,function (x) x$de1$postmean[,2])
lfc.mast <- combine_sim_res(res,function (x) x$mast[j,"avg_log2FC"])
z.deseq <- combine_sim_res(res,function (x) with(x$deseq,log2FoldChange/lfcSE))
z.fasttopics <- combine_sim_res(res,function (x) x$de1$z[,2])
pdat <- data.frame(lfc.deseq = lfc.deseq,
lfc.fasttopics = lfc.fasttopics,
lfc.mast = clamp(lfc.mast,-6,+6),
z.deseq = z.deseq,
z.fasttopics = z.fasttopics)
p1 <- ggplot(pdat,aes(x = lfc.mast,y = lfc.fasttopics)) +
geom_point(color = "dodgerblue",shape = 4,size = 0.75) +
geom_abline(intercept = 0,slope = 1,linetype = "dotted") +
labs(x = "MAST",y = "fastTopics",title = "LFC estimates") +
theme_cowplot(font_size = 12)
p2 <- ggplot(pdat,aes(x = lfc.deseq,y = lfc.fasttopics)) +
geom_point(color = "dodgerblue",shape = 4,size = 0.75) +
geom_abline(intercept = 0,slope = 1,linetype = "dotted") +
labs(x = "DESeq2",y = "fastTopics",title = "LFC estimates") +
theme_cowplot(font_size = 12)
p3 <- ggplot(pdat,aes(x = z.deseq,y = z.fasttopics)) +
geom_point(color = "dodgerblue",shape = 4,size = 0.75) +
geom_abline(intercept = 0,slope = 1,linetype = "dotted") +
labs(x = "DESeq2",y = "fastTopics",title = "z-scores") +
theme_cowplot(font_size = 12)
plot_grid(p1,p2,p3,nrow = 1,ncol = 3)
Version | Author | Date |
---|---|---|
10fc0dc | Peter Carbonetto | 2022-01-05 |
The fastTopics and DESeq2 estimates are very similar across the board, whereas the MAST estimare are broadly correlated, but show a number of large differences.
Compare the MAST, DESeq2 and fastTopics p-values (or s-values), separately for all true positives (dark blue) and true negatives (orange). Not surprisingly, the DESeq2 and fastTopics s-value distributions are also very similar.
deseq <- combine_sim_res(res,function (x) x$deseq$svalue)
fasttopics <- combine_sim_res(res,function (x) x$de1$svalue[,2])
mast <- combine_sim_res(res,function (x) x$mast[j,"p_val"])
nonzero_lfc <-
combine_sim_res(res,function (x) with(x$dat,abs(F[,1] - F[,2]) > 1e-8))
pdat <- data.frame(deseq = deseq,
fasttopics = fasttopics,
mast = mast,
nonzero_lfc = factor(nonzero_lfc))
p4 <- ggplot(pdat,aes(x = mast,color = nonzero_lfc,fill = nonzero_lfc)) +
geom_histogram(bins = 64,show.legend = FALSE) +
scale_color_manual(values = c("darkorange","darkblue")) +
scale_fill_manual(values = c("darkorange","darkblue")) +
labs(x = "p-value",y = "genes",title = "MAST") +
theme_cowplot(font_size = 12)
p5 <- ggplot(pdat,aes(x = deseq,color = nonzero_lfc,fill = nonzero_lfc)) +
geom_histogram(bins = 64,show.legend = FALSE) +
scale_color_manual(values = c("darkorange","darkblue")) +
scale_fill_manual(values = c("darkorange","darkblue")) +
labs(x = "s-value",y = "genes",title = "DESeq2") +
theme_cowplot(font_size = 12)
p6 <- ggplot(pdat,aes(x = fasttopics,color = nonzero_lfc,fill = nonzero_lfc)) +
geom_histogram(bins = 64,show.legend = FALSE) +
scale_color_manual(values = c("darkorange","darkblue")) +
scale_fill_manual(values = c("darkorange","darkblue")) +
labs(x = "s-value",y = "genes",title = "fastTopics") +
theme_cowplot(font_size = 12)
plot_grid(p4,p5,p6,nrow = 1,ncol = 3)
Version | Author | Date |
---|---|---|
c05700c | Peter Carbonetto | 2022-01-05 |
Finally, we plot, for each method, FDR vs. power for identifying genes that are differentially expressed between among the two topics or groups.
v1 <- create_fdr_vs_power_curve(pdat$deseq,nonzero_lfc,length.out = 200)
v2 <- create_fdr_vs_power_curve(combine_sim_res(res,function(x)x$de1$lfsr[,2]),
nonzero_lfc,length.out = 200)
v3 <- create_fdr_vs_power_curve(pdat$mast,nonzero_lfc,length.out = 200)
dat <- rbind(cbind(v1,method = "deseq2"),
cbind(v2,method = "fastTopics"),
cbind(v3,method = "mast"))
p <- ggplot(dat,aes(x = fdr,y = power,color = method)) +
geom_line(size = 0.65,orientation = "y") +
scale_color_manual(values = c("dodgerblue","darkorange","darkblue")) +
theme_cowplot(font_size = 12)
print(p)
At low false discovery rates, DESeq2 has a slight edge, but otherwise the performance of all three methods is very close.
sessionInfo()
# R version 3.6.2 (2019-12-12)
# Platform: x86_64-apple-darwin15.6.0 (64-bit)
# Running under: macOS Catalina 10.15.7
#
# Matrix products: default
# BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] parallel stats4 stats graphics grDevices utils datasets
# [8] methods base
#
# other attached packages:
# [1] cowplot_1.0.0 ggplot2_3.3.5
# [3] fastTopics_0.6-96 MAST_1.12.0
# [5] SingleCellExperiment_1.8.0 DESeq2_1.33.5
# [7] SummarizedExperiment_1.16.1 DelayedArray_0.12.3
# [9] BiocParallel_1.18.1 matrixStats_0.61.0
# [11] Biobase_2.46.0 GenomicRanges_1.38.0
# [13] GenomeInfoDb_1.22.1 IRanges_2.20.2
# [15] S4Vectors_0.24.4 BiocGenerics_0.32.0
# [17] Seurat_3.2.3 Matrix_1.2-18
#
# loaded via a namespace (and not attached):
# [1] backports_1.1.5 workflowr_1.6.2 systemfonts_1.0.2
# [4] plyr_1.8.5 igraph_1.2.5 lazyeval_0.2.2
# [7] splines_3.6.2 listenv_0.8.0 scattermore_0.7
# [10] digest_0.6.23 invgamma_1.1 htmltools_0.4.0
# [13] SQUAREM_2017.10-1 fansi_0.4.0 magrittr_2.0.1
# [16] memoise_1.1.0 tensor_1.5 cluster_2.1.0
# [19] ROCR_1.0-11 globals_0.13.0 annotate_1.64.0
# [22] RcppParallel_4.4.2 MCMCpack_1.4-5 prettyunits_1.1.1
# [25] colorspace_1.4-1 blob_1.2.1 ggrepel_0.9.1
# [28] xfun_0.11 dplyr_1.0.7 crayon_1.4.1
# [31] RCurl_1.98-1.2 jsonlite_1.7.2 genefilter_1.68.0
# [34] spatstat_1.64-1 spatstat.data_1.4-3 survival_3.1-8
# [37] zoo_1.8-7 glue_1.4.2 polyclip_1.10-0
# [40] gtable_0.3.0 zlibbioc_1.32.0 XVector_0.26.0
# [43] MatrixModels_0.4-1 leiden_0.3.3 future.apply_1.6.0
# [46] SparseM_1.78 abind_1.4-5 scales_1.1.0
# [49] DBI_1.1.0 miniUI_0.1.1.1 Rcpp_1.0.7
# [52] progress_1.2.2 viridisLite_0.3.0 xtable_1.8-4
# [55] reticulate_1.16 bit_1.1-15.2 rsvd_1.0.2
# [58] truncnorm_1.0-8 htmlwidgets_1.5.1 httr_1.4.2
# [61] RColorBrewer_1.1-2 ellipsis_0.3.2 ica_1.0-2
# [64] farver_2.0.1 pkgconfig_2.0.3 XML_3.99-0.3
# [67] uwot_0.1.10 deldir_0.1-29 locfit_1.5-9.4
# [70] utf8_1.1.4 labeling_0.3 tidyselect_1.1.1
# [73] rlang_0.4.11 reshape2_1.4.3 later_1.0.0
# [76] AnnotationDbi_1.48.0 munsell_0.5.0 tools_3.6.2
# [79] generics_0.0.2 RSQLite_2.2.0 ggridges_0.5.2
# [82] evaluate_0.14 stringr_1.4.0 fastmap_1.0.1
# [85] ragg_0.3.1 yaml_2.2.0 goftest_1.2-2
# [88] mcmc_0.9-6 knitr_1.26 bit64_0.9-7
# [91] fs_1.3.1 fitdistrplus_1.1-1 purrr_0.3.4
# [94] RANN_2.6.1 pbapply_1.5-1 future_1.18.0
# [97] nlme_3.1-142 quantreg_5.54 whisker_0.4
# [100] mime_0.8 compiler_3.6.2 plotly_4.9.2
# [103] png_0.1-7 spatstat.utils_1.17-0 tibble_3.1.3
# [106] geneplotter_1.64.0 stringi_1.4.3 lattice_0.20-38
# [109] vctrs_0.3.8 pillar_1.6.2 lifecycle_1.0.0
# [112] lmtest_0.9-38 RcppAnnoy_0.0.18 data.table_1.12.8
# [115] bitops_1.0-6 irlba_2.3.3 httpuv_1.5.2
# [118] patchwork_1.0.1 R6_2.4.1 promises_1.1.0
# [121] KernSmooth_2.23-16 gridExtra_2.3 codetools_0.2-16
# [124] MASS_7.3-51.4 assertthat_0.2.1 rprojroot_1.3-2
# [127] withr_2.4.2 sctransform_0.3.2 GenomeInfoDbData_1.2.2
# [130] hms_1.1.0 mgcv_1.8-31 quadprog_1.5-8
# [133] grid_3.6.2 rpart_4.1-15 coda_0.19-3
# [136] tidyr_1.1.3 rmarkdown_2.3 ashr_2.2-51
# [139] Rtsne_0.15 git2r_0.26.1 mixsqp_0.3-46
# [142] shiny_1.4.0