Last updated: 2021-04-13

Checks: 7 0

Knit directory: mage_2020_marker-gene-benchmarking/

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(20190102) 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 b5b2a88. 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:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    .snakemake/
    Ignored:    config/
    Ignored:    data/sim_data/
    Ignored:    logs/
    Ignored:    results/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   code/analysis-utils.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/roc.Rmd) and HTML (public/roc.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 b5b2a88 Jeffrey Pullin 2021-04-13 Add new results
Rmd 33746c6 Jeffrey Pullin 2021-04-09 Add more ROC analysis
Rmd ee6c83a Jeffrey Pullin 2021-04-08 Add initial analysis of ROC curves

library(ROCR)
library(ggplot2)
library(dplyr)
library(forcats)
library(pals)
library(SingleCellExperiment)
library(tidyr)
source(here::here("code", "top-genes.R"))
source(here::here("code", "find-marker-genes.R"))
source(here::here("code", "analysis-utils.R"))

create_predictions <- function(sel_mgs, true_mgs) {
  scores <- sel_mgs$score
  labels <- as.numeric(sel_mgs$gene  %in% true_mgs$gene)
  # FIXME: Is this HACK a good idea?
  # I added it to prevent prediction breaking when no correct genes are found.
  # It's impact should be minor as we are averaging across groups and reps
  if (length(unique(labels)) == 1) {
    if (unique(labels == 1)) {
      labels[[length(labels)]] <- 0
    } else {
      labels[[length(labels)]] <- 1
    }
  }
  ROCR::prediction(scores, labels) 
}
config <- yaml::read_yaml(here::here("config.yaml"))

res_paths <- here::here(list.files(config$results_folder, full.names = TRUE))

# FIXME: Consider separate folders for umg, sumg and simulated data.
umg_paths <- here::here(
  list.files(config$sim_data_folder, pattern = "^umg", full.names = TRUE)
)
umgs <- lapply(umg_paths, readRDS)

sumg_paths <- here::here(
  list.files(config$sim_data_folder, pattern = "^sumg", full.names = TRUE)
)
sumgs <- lapply(sumg_paths, readRDS)

# FIXME: Hack...
sim_names <- substr(basename(umg_paths), 5, nchar(basename(umg_paths)) - 4)
mgs <- tibble(sim_name = sim_names, umg = umgs, sumg = sumgs)

sel_genes <- list()
for (i in seq_along(res_paths)) {
  if (!isTRUE(getOption("knitr.in.progress"))) {
    print(i)
  }
  res <- readRDS(res_paths[[i]])
  # Some (DESeq2 runs lead to convergence issues.)
  if (!(length(res$result) == 0)) {
    # We select 700 as there are never more than around 650 true marker genes.
    sel_genes[[i]] <- reformat_found_mgs(res, top_n = 700)
  }
  rm(res)
}

res_names <- substr(basename(res_paths), 1, nchar(basename(res_paths)) - 4)
selected_genes <- tibble(res_name = res_names, sel_genes = sel_genes)

pars <- retrive_simulation_parameters() %>% 
  mutate(res_name = substr(file_name, 1, nchar(file_name) - 4)) %>% 
  left_join(mgs, by = "sim_name") %>% 
  left_join(selected_genes, by = "res_name") %>% 
  pivot_longer(cols = c(umg, sumg), 
               names_to = "mg_type", 
               values_to = "mgs")

metrics_data <- pars %>% 
  mutate(clusters = if_else(sim_label == "prop", list(1), list(NULL))) %>% 
  dplyr::rename(sel_mgs = sel_genes, true_mgs = mgs) %>% 
  rowwise() %>% 
  mutate(group_id = list(names(true_mgs))) %>% 
  unchop(c(sel_mgs, true_mgs, group_id))

Standard simulation AUC

metrics_data %>% 
  filter(sim_label == "standard_sim" & mg_type == "umg") %>% 
  expand_grid(n_sel = 20, n_true = c(20, 100, 700)) %>% 
  rowwise() %>% 
  mutate(
    sel_mgs = list(get_top_sel_mgs(sel_mgs, n = n_sel)), 
    true_mgs = list(get_top_true_mgs(true_mgs, n = n_true)),
    pred = list(create_predictions(sel_mgs, true_mgs)), 
    auc = performance(pred, "auc")@y.values[[1]],
  ) %>% 
  ungroup() %>% 
  mutate(pars = fct_reorder(factor(pars), auc)) %>% 
  ggplot(aes(pars, y = auc)) + 
  geom_boxplot() + 
  facet_wrap(~n_true) + 
  coord_flip(ylim = c(0, 1)) +
  labs(y = "AUC", 
       x = "Method") + 
  theme_bw()

Standard simulation ROC curves

metrics_data %>% 
  filter(sim_label == "standard_sim" & mg_type == "umg") %>% 
  rowwise() %>% 
  mutate(
    sel_mgs = list(get_top_sel_mgs(sel_mgs, n = 20)), 
    true_mgs = list(get_top_true_mgs(true_mgs, n = 400)),
    pred = list(create_predictions(sel_mgs, true_mgs)), 
    perf = list(performance(pred, measure = "tpr", x.measure = "fpr")),
    x_value = list(perf@x.values[[1]]), 
    y_value = list(perf@y.values[[1]]), 
    ind = list(1:length(x_value))
  ) %>% 
  unnest(cols = c(x_value, y_value, ind)) %>% 
  group_by(pars, ind) %>% 
  summarise(
    x_value = mean(x_value), 
    y_value = mean(y_value), 
    .groups = "drop"
  ) %>% 
  ggplot(aes(x = x_value, y = y_value, colour = factor(pars))) + 
  geom_line() + 
  scale_colour_manual(values = unname(polychrome(20))) +
  labs(
    x = "False Postive Rate",
    y = "True Positive Rate",
    colour = "Method"
  ) +
  theme_bw()

Number of cells AUC

metrics_data %>% 
  filter(sim_label == "num_cells" & mg_type == "umg") %>% 
  expand_grid(n_sel = 20, n_true = 100) %>% 
  rowwise() %>%  
  # FIXME: Why are there NULL values?
  filter(!is.null(sel_mgs))  %>% 
  mutate(
    sel_mgs = list(get_top_sel_mgs(sel_mgs, n = n_sel)), 
    true_mgs = list(get_top_true_mgs(true_mgs, n = n_true)),
    pred = list(create_predictions(sel_mgs, true_mgs)), 
    auc = performance(pred, "auc")@y.values[[1]],
  ) %>% 
  ungroup() %>% 
  mutate(pars = fct_reorder(factor(pars), auc)) %>% 
  ggplot(aes(pars, y = auc)) + 
  geom_boxplot() + 
  facet_wrap(~batchCells) + 
  coord_flip(ylim = c(0, 1)) +
  labs(y = "AUC", 
       x = "Method") + 
  theme_bw()

Number of clusters AUC

metrics_data %>% 
  filter(sim_label == "num_clusters" & mg_type == "umg") %>% 
  expand_grid(n_sel = 20, n_true = 700) %>% 
  rowwise() %>%  
  # FIXME: Why are there NULL values?
  filter(!is.null(sel_mgs))  %>% 
  mutate(
    sel_mgs = list(get_top_sel_mgs(sel_mgs, n = n_sel)), 
    true_mgs = list(get_top_true_mgs(true_mgs, n = n_true)),
    pred = list(create_predictions(sel_mgs, true_mgs)), 
    auc = performance(pred, "auc")@y.values[[1]],
  ) %>% 
  ungroup() %>% 
  mutate(pars = fct_reorder(factor(pars), auc)) %>% 
  ggplot(aes(pars, y = auc)) + 
  geom_boxplot() + 
  facet_wrap(~n_clus) + 
  coord_flip(ylim = c(0, 1)) +
  labs(y = "AUC", 
       x = "Method") + 
  theme_bw()

Mean AUC

metrics_data %>% 
  filter(sim_label == "mean" & mg_type == "umg") %>% 
  expand_grid(n_sel = 20, n_true = 700) %>% 
  rowwise() %>%  
  # FIXME: Why are there NULL values?
  filter(!is.null(sel_mgs))  %>% 
  mutate(
    sel_mgs = list(get_top_sel_mgs(sel_mgs, n = n_sel)), 
    true_mgs = list(get_top_true_mgs(true_mgs, n = n_true)),
    pred = list(create_predictions(sel_mgs, true_mgs)), 
    auc = performance(pred, "auc")@y.values[[1]],
  ) %>% 
  ungroup() %>% 
  mutate(pars = fct_reorder(factor(pars), auc)) %>% 
  ggplot(aes(pars, y = auc)) + 
  geom_boxplot() + 
  facet_wrap(~mean.rate) + 
  coord_flip(ylim = c(0, 1)) +
  labs(y = "AUC", 
       x = "Method") + 
  theme_bw()


devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.3 (2020-10-10)
 os       CentOS Linux 7 (Core)       
 system   x86_64, linux-gnu           
 ui       X11                         
 language (EN)                        
 collate  en_AU.UTF-8                 
 ctype    en_AU.UTF-8                 
 tz       UTC                         
 date     2021-04-13                  

─ Packages ───────────────────────────────────────────────────────────────────
 package              * version  date       lib source        
 assertthat             0.2.1    2019-03-21 [2] CRAN (R 4.0.3)
 Biobase              * 2.50.0   2020-10-27 [1] Bioconductor  
 BiocGenerics         * 0.36.0   2020-10-27 [2] Bioconductor  
 bitops                 1.0-6    2013-08-17 [2] CRAN (R 4.0.3)
 bslib                  0.2.4    2021-01-25 [1] CRAN (R 4.0.0)
 callr                  3.5.1    2020-10-13 [2] CRAN (R 4.0.3)
 cli                    2.2.0    2020-11-20 [2] CRAN (R 4.0.3)
 colorspace             2.0-0    2020-11-11 [2] CRAN (R 4.0.3)
 crayon                 1.3.4    2017-09-16 [2] CRAN (R 4.0.3)
 DBI                    1.1.1    2021-01-15 [1] CRAN (R 4.0.0)
 DelayedArray           0.16.2   2021-02-26 [1] Bioconductor  
 desc                   1.2.0    2018-05-01 [2] CRAN (R 4.0.3)
 devtools               2.3.2    2020-09-18 [2] CRAN (R 4.0.3)
 dichromat              2.0-0    2013-01-24 [1] CRAN (R 4.0.0)
 digest                 0.6.27   2020-10-24 [2] CRAN (R 4.0.3)
 dplyr                * 1.0.5    2021-03-05 [1] CRAN (R 4.0.0)
 ellipsis               0.3.1    2020-05-15 [2] CRAN (R 4.0.3)
 evaluate               0.14     2019-05-28 [2] CRAN (R 4.0.3)
 fansi                  0.4.1    2020-01-08 [2] CRAN (R 4.0.3)
 farver                 2.0.3    2020-01-16 [2] CRAN (R 4.0.3)
 forcats              * 0.5.1    2021-01-27 [1] CRAN (R 4.0.3)
 fs                     1.5.0    2020-07-31 [2] CRAN (R 4.0.3)
 generics               0.1.0    2020-10-31 [2] CRAN (R 4.0.3)
 GenomeInfoDb         * 1.26.2   2020-12-08 [2] Bioconductor  
 GenomeInfoDbData       1.2.4    2020-12-30 [2] Bioconductor  
 GenomicRanges        * 1.42.0   2020-10-27 [2] Bioconductor  
 ggplot2              * 3.3.3    2020-12-30 [1] CRAN (R 4.0.0)
 git2r                  0.28.0   2021-01-10 [1] CRAN (R 4.0.3)
 glue                   1.4.2    2020-08-27 [2] CRAN (R 4.0.3)
 gtable                 0.3.0    2019-03-25 [2] CRAN (R 4.0.3)
 here                   1.0.1    2020-12-13 [1] CRAN (R 4.0.0)
 htmltools              0.5.1.1  2021-01-22 [1] CRAN (R 4.0.0)
 httpuv                 1.5.5    2021-01-13 [1] CRAN (R 4.0.0)
 IRanges              * 2.24.1   2020-12-12 [2] Bioconductor  
 jquerylib              0.1.3    2020-12-17 [1] CRAN (R 4.0.0)
 jsonlite               1.7.2    2020-12-09 [2] CRAN (R 4.0.3)
 knitr                  1.30     2020-09-22 [2] CRAN (R 4.0.3)
 labeling               0.4.2    2020-10-20 [2] CRAN (R 4.0.3)
 later                  1.1.0.1  2020-06-05 [2] CRAN (R 4.0.3)
 lattice                0.20-41  2020-04-02 [2] CRAN (R 4.0.3)
 lifecycle              1.0.0    2021-02-15 [1] CRAN (R 4.0.0)
 magrittr               2.0.1    2020-11-17 [2] CRAN (R 4.0.3)
 mapproj                1.2.7    2020-02-03 [1] CRAN (R 4.0.0)
 maps                   3.3.0    2018-04-03 [1] CRAN (R 4.0.0)
 Matrix                 1.2-18   2019-11-27 [2] CRAN (R 4.0.3)
 MatrixGenerics       * 1.2.1    2021-01-30 [1] Bioconductor  
 matrixStats          * 0.58.0   2021-01-29 [1] CRAN (R 4.0.0)
 memoise                1.1.0    2017-04-21 [2] CRAN (R 4.0.3)
 munsell                0.5.0    2018-06-12 [2] CRAN (R 4.0.3)
 pals                 * 1.6      2019-12-04 [1] CRAN (R 4.0.0)
 pillar                 1.4.7    2020-11-20 [2] CRAN (R 4.0.3)
 pkgbuild               1.2.0    2020-12-15 [2] CRAN (R 4.0.3)
 pkgconfig              2.0.3    2019-09-22 [2] CRAN (R 4.0.3)
 pkgload                1.1.0    2020-05-29 [2] CRAN (R 4.0.3)
 prettyunits            1.1.1    2020-01-24 [2] CRAN (R 4.0.3)
 processx               3.4.5    2020-11-30 [2] CRAN (R 4.0.3)
 promises               1.1.1    2020-06-09 [2] CRAN (R 4.0.3)
 ps                     1.5.0    2020-12-05 [2] CRAN (R 4.0.3)
 purrr                  0.3.4    2020-04-17 [1] CRAN (R 4.0.0)
 R6                     2.5.0    2020-10-28 [2] CRAN (R 4.0.3)
 Rcpp                   1.0.6    2021-01-15 [1] CRAN (R 4.0.0)
 RCurl                  1.98-1.2 2020-04-18 [2] CRAN (R 4.0.3)
 remotes                2.2.0    2020-07-21 [2] CRAN (R 4.0.3)
 rlang                  0.4.10   2020-12-30 [1] CRAN (R 4.0.0)
 rmarkdown              2.7      2021-02-19 [1] CRAN (R 4.0.3)
 ROCR                 * 1.0-11   2020-05-02 [1] CRAN (R 4.0.0)
 rprojroot              2.0.2    2020-11-15 [1] CRAN (R 4.0.0)
 rstudioapi             0.13     2020-11-12 [2] CRAN (R 4.0.3)
 S4Vectors            * 0.28.1   2020-12-09 [2] Bioconductor  
 sass                   0.3.1    2021-01-24 [1] CRAN (R 4.0.0)
 scales                 1.1.1    2020-05-11 [2] CRAN (R 4.0.3)
 sessioninfo            1.1.1    2018-11-05 [2] CRAN (R 4.0.3)
 SingleCellExperiment * 1.12.0   2020-10-27 [1] Bioconductor  
 stringi                1.5.3    2020-09-09 [2] CRAN (R 4.0.3)
 stringr                1.4.0    2019-02-10 [2] CRAN (R 4.0.3)
 SummarizedExperiment * 1.20.0   2020-10-27 [1] Bioconductor  
 testthat               3.0.1    2020-12-17 [2] CRAN (R 4.0.3)
 tibble                 3.0.4    2020-10-12 [2] CRAN (R 4.0.3)
 tidyr                * 1.1.3    2021-03-03 [1] CRAN (R 4.0.0)
 tidyselect             1.1.0    2020-05-11 [2] CRAN (R 4.0.3)
 usethis                2.0.0    2020-12-10 [2] CRAN (R 4.0.3)
 vctrs                  0.3.6    2020-12-17 [1] CRAN (R 4.0.0)
 whisker                0.4      2019-08-28 [2] CRAN (R 4.0.3)
 withr                  2.3.0    2020-09-22 [2] CRAN (R 4.0.3)
 workflowr              1.6.2    2020-04-30 [1] CRAN (R 4.0.3)
 xfun                   0.19     2020-10-30 [2] CRAN (R 4.0.3)
 XVector                0.30.0   2020-10-27 [2] Bioconductor  
 yaml                   2.2.1    2020-02-01 [2] CRAN (R 4.0.3)
 zlibbioc               1.36.0   2020-10-27 [2] Bioconductor  

[1] /home/jpullin/R_libs
[2] /opt/R/4.0.3/lib/R/library