library("EMMA")
library("macrophage")
library("DESeq2")
library("org.Hs.eg.db")
library("clusterProfiler")Supplementary Information for the EMMA package
Bioinformatics Group, IMBEI, University Medical Center Mainz
In this document, we demonstrate a concrete example of how EMMA supports transparent reporting and reproducibility of Functional Enrichment Analysis (FEA). We first perform and document enrichment analyses, freeze the corresponding software environment, and subsequently restore this environment in a clean installation to rerun the analyses using the provenance recorded by EMMA.
In this example we are using a publicly available dataset from Alasoo et al. “Shared genetic effects on chromatin and gene expression indicate a role for enhancer priming in immune response”, published in Nature Genetics, January 2018 (Alasoo et al. 2018). The data is made available via the macrophage Bioconductor package, which contains the files output from the Salmon quantification (version 0.12.0, with GENCODE v29 reference), as well as the values summarized at the gene level, which we will use to exemplify.
In the macrophage experimental setting, the samples are available from 6 different donors, in 4 different conditions (naive, treated with Interferon gamma, with SL1344, or with a combination of Interferon gamma and SL1344).
Let’s start by loading all the necessary packages:
1 Original analysis and environment capture
For demonstration purposes, we will perform Differential Expression Analysis using the DESeq2 framework.
1.1 Getting a list of Differentially Expressed Genes
# load data
data(gse, package = "macrophage")# set up design
dds_macrophage <- DESeqDataSet(gse, design = ~ line + condition)
# preprocess
rownames(dds_macrophage) <- substr(rownames(dds_macrophage), 1, 15)
keep <- rowSums(counts(dds_macrophage) >= 10) >= 6
dds_macrophage <- dds_macrophage[keep, ]
dds_macrophage#> class: DESeqDataSet
#> dim: 17806 24
#> metadata(7): tximetaInfo quantInfo ... txdbInfo version
#> assays(3): counts abundance avgTxLength
#> rownames(17806): ENSG00000000003 ENSG00000000419 ... ENSG00000285982
#> ENSG00000285994
#> rowData names(2): gene_id SYMBOL
#> colnames(24): SAMEA103885102 SAMEA103885347 ... SAMEA103885308
#> SAMEA103884949
#> colData names(15): names sample_id ... condition line
# run DESeq
dds_macrophage <- DESeq(dds_macrophage)
# contrasts
resultsNames(dds_macrophage)#> [1] "Intercept" "line_eiwy_1_vs_diku_1"
#> [3] "line_fikt_3_vs_diku_1" "line_ieki_2_vs_diku_1"
#> [5] "line_podx_1_vs_diku_1" "line_qaqx_1_vs_diku_1"
#> [7] "condition_IFNg_vs_naive" "condition_IFNg_SL1344_vs_naive"
#> [9] "condition_SL1344_vs_naive"
# get de res for 1st contrast
IFNg_vs_naive <- results(dds_macrophage,
contrast = c("condition", "IFNg", "naive"),
lfcThreshold = 1, alpha = 0.05)
IFNg_vs_naive <- lfcShrink(dds_macrophage, coef = "condition_IFNg_vs_naive",
res = IFNg_vs_naive,
type = "apeglm")
IFNg_vs_naive$SYMBOL <- rowData(dds_macrophage)$SYMBOL
# get de res for 2nd contrast
SL1344_vs_naive <- results(dds_macrophage,
contrast = c("condition", "SL1344", "naive"),
lfcThreshold = 1, alpha = 0.05)
SL1344_vs_naive <- lfcShrink(dds_macrophage, coef = "condition_SL1344_vs_naive",
res = SL1344_vs_naive,
type = "apeglm")
SL1344_vs_naive$SYMBOL <- rowData(dds_macrophage)$SYMBOL
# get de res for 3rd contrast
IFNg_SL1344_vs_naive <- results(dds_macrophage,
contrast = c("condition", "IFNg_SL1344", "naive"),
lfcThreshold = 1, alpha = 0.05)
IFNg_SL1344_vs_naive <- lfcShrink(dds_macrophage, coef = "condition_IFNg_SL1344_vs_naive",
res = IFNg_SL1344_vs_naive,
type = "apeglm")
IFNg_SL1344_vs_naive$SYMBOL <- rowData(dds_macrophage)$SYMBOL
# sort by adjusted p value
de_list <- list(
IFNg_vs_naive = IFNg_vs_naive,
SL1344_vs_naive = SL1344_vs_naive,
IFNg_SL1344_vs_naive = IFNg_SL1344_vs_naive
)
de_list <- lapply(de_list, function(df) {
df <- df[order(df$padj), ]
df <- df[!is.na(df$padj) & df$padj <= 0.05, ]
df
})# set background gene list
gene_universe <- rownames(dds_macrophage)1.2 Performing Functional Enrichment Analysis (FEA) with EMMA
Now that we have a list of DE genes for different contrasts, we can perform Functional Enrichment Analysis.
1.2.1 FEA with clusterProfiler::enrichGO()
In the following example, we will use the function enrichGO()
# 1st contrast
de_res1 <- de_list$IFNg_vs_naive
fea_res <- enrichGO(gene = rownames(de_res1),
universe = gene_universe,
keyType = "ENSEMBL",
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.1) |>
EMMA_run(args_form = "evaluated",
store_session_info = TRUE)EMMA_show(fea_res)#> Number of Pathways: 574
#> Call: enrichGO(gene = rownames(de_res1), universe = gene_universe, keyType = "ENSEMBL", OrgDb = org.Hs.eg.db, ont = "BP", pAdjustMethod = "BH", pvalueCutoff = 0.05, qvalueCutoff = 0.1)
#> Wrapper: FALSE
#> Package: clusterProfiler v. 4.21.1
#> Organism: Homo sapiens
#> Gene set library: GO
#> Gene set library version: 3.23.1
1.2.2 FEA with clusterProfiler::enrichKEGG()
For the following contrast, we will use the function enrichKEGG()
# 2nd contrast
de_res2 <- de_list$IFNg_SL1344_vs_naive
# convert ENSEMBL to ENTREZID
universe_map <- mapIds(
org.Hs.eg.db,
keys = gene_universe,
keytype = "ENSEMBL",
column = "ENTREZID",
multiVals = "first"
)
universe_entrez <- unique(na.omit(universe_map))
genes_entrez <- universe_map[rownames(de_res2)]
genes_entrez <- unique(na.omit(genes_entrez))
fea_res2 <- enrichKEGG(gene = genes_entrez,
universe = universe_entrez,
keyType = "ncbi-geneid",
organism = "hsa",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.1) |>
EMMA_run(args_form = "evaluated",
store_session_info = TRUE)EMMA_show(fea_res2)#> Number of Pathways: 76
#> Call: enrichKEGG(gene = genes_entrez, universe = universe_entrez, keyType = "ncbi-geneid", organism = "hsa", pAdjustMethod = "BH", pvalueCutoff = 0.05, qvalueCutoff = 0.1)
#> Wrapper: FALSE
#> Package: clusterProfiler v. 4.21.1
#> Organism: hsa
#> Gene set library: KEGG
#> Gene set library version: NA
Here no KEGG version is recorded because this information is not exposed by the underlying remote resource.
fea_list <- list(IFNg_vs_naive = fea_res,
IFNg_SL1344_vs_naive = fea_res2)1.3 Save analysis results
To save all the generated results, we will construct a DeeDeeExperiment object, to keep all analysis elements together. This step is optional.
library(DeeDeeExperiment)
dde <- DeeDeeExperiment(sce = dds_macrophage,
de_results = de_list,
enrich_results = fea_list)
dde#> class: DeeDeeExperiment
#> dim: 17806 24
#> metadata(8): tximetaInfo quantInfo ... version singlecontrast
#> assays(7): counts abundance ... H cooks
#> rownames(17806): ENSG00000000003 ENSG00000000419 ... ENSG00000285982
#> ENSG00000285994
#> rowData names(61): gene_id SYMBOL ... IFNg_SL1344_vs_naive_pvalue
#> IFNg_SL1344_vs_naive_padj
#> colnames(24): SAMEA103885102 SAMEA103885347 ... SAMEA103885308
#> SAMEA103884949
#> colData names(15): names sample_id ... condition line
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> dea(3): IFNg_vs_naive, SL1344_vs_naive, IFNg_SL1344_vs_naive
#> fea(2): IFNg_vs_naive, IFNg_SL1344_vs_naive
saveRDS(dde, "dde_macrophage.RDS")1.4 Capture the analysis environment with EMMA_freeze()
project_path <- getwd()
EMMA_freeze(project = project_path,
file = "EMMA_analysis.lock",
pkgs = loadedNamespaces(),
prompt = FALSE,
force = TRUE)2 Environment restoration and reproducibility check
To evaluate environment restoration independently of the original installation, the analysis was reproduced in a Docker container based on R 4.6.1.
From within the Docker container, we recreate the analysis result using the renv::restore() function. Normally, we would run this command, but to keep the demonstration simple, all packages listed in the EMMA_analysis.lock file were already installed in the container.
# do not run
library("renv")
restore(lockfile = "/home/rstudio/emma_supplement/EMMA_analysis.lock")Then we load the analysis results
library("DeeDeeExperiment")
library("EMMA")
library("org.Hs.eg.db")
library("clusterProfiler")
renv::load(project = "/home/rstudio/emma_analysis")
dde <- readRDS("/home/rstudio/emma_supplement/dde_macrophage.RDS")
# check
ddeWe extract the FEA results as well as the provenance record, i.e. EMMA_record
fea_res1 <- getFEA(dde, fea_name = "IFNg_vs_naive", format = "original")
fea_res2 <- getFEA(dde, fea_name = "IFNg_SL1344_vs_naive", format = "original")rec1 <- EMMA_get_record(fea_res1)
rec2 <- EMMA_get_record(fea_res2)2.1 Reproducing the GO enrichment analysis
rec1$method$call
gene_list <- rec1$input$arguments$gene
background <- rec1$input$arguments$universefea_res_new <- enrichGO(gene = gene_list,
universe = background,
keyType = "ENSEMBL",
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.1) |>
EMMA_run(args_form = "evaluated",
store_session_info = TRUE)# compare the FEA results
# compare all columns in FEA results (apart from the geneset column)
all.equal(fea_res1[, names(fea_res1) != "geneID"],
fea_res_new[, names(fea_res_new) != "geneID"])
# compare the genesets
all(mapply(setequal,
strsplit(fea_res1$geneID, "/"),
strsplit(fea_res_new$geneID, "/")))2.2 Reproducing the KEGG enrichment analysis
rec2$method$call
gene_list2 <- rec2$input$arguments$gene
background2 <- rec2$input$arguments$universefea_res_new2 <- enrichKEGG(gene = gene_list2,
universe = background2,
keyType = "ncbi-geneid",
organism = "hsa",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.1) |>
EMMA_run(args_form = "evaluated",
store_session_info = TRUE)# compare the FEA results
# compare all columns in FEA results (apart from the geneset column)
all.equal(fea_res2[, names(fea_res2) != "geneID"],
fea_res_new2[, names(fea_res_new2) != "geneID"])
# compare the genesets
all(mapply(setequal,
strsplit(fea_res2$geneID, "/"),
strsplit(fea_res_new2$geneID, "/")))KEGG annotations are continuously updated. As enrichKEGG() retrieves these annotations online, re-running the analysis at a later time may yield slightly different enrichment results, even when using identical input data, analysis parameters, and software versions.
3 Supported functions and captured provenance (as of Sept 2026)
Here we provide a list of the currently supported functions in EMMA and the metadata they capture
| Function | Call | Function name | Package name/version | Argument | Gene set resource | Annotation resource version |
|---|---|---|---|---|---|---|
enrichGO |
+ | + | + | + | + | + |
gseGO |
+ | + | + | + | + | + |
groupGO |
+ | + | + | + | + | + |
enrichKEGG |
+ | + | + | + | + | - |
gseKEGG |
+ | + | + | + | + | - |
gost |
+ | + | + | + | + | + |
wrappers |
+ | + | +/- | + | +/- | +/- |
custom |
+ | + | - | + | - | - |
+: captured automatically; -: not captured automatically; +/-: conditionally captured when the required information can be identified or is available
Session info
sessionInfo()#> R version 4.6.1 (2026-06-24)
#> Platform: aarch64-apple-darwin23
#> Running under: macOS Sequoia 15.7.2
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: Europe/Berlin
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] DeeDeeExperiment_1.3.0 SingleCellExperiment_1.35.2
#> [3] clusterProfiler_4.21.1 org.Hs.eg.db_3.23.1
#> [5] AnnotationDbi_1.75.2 DESeq2_1.53.3
#> [7] SummarizedExperiment_1.43.0 Biobase_2.73.2
#> [9] MatrixGenerics_1.25.0 matrixStats_1.5.0
#> [11] GenomicRanges_1.65.4 Seqinfo_1.3.2
#> [13] IRanges_2.47.5 S4Vectors_0.51.10
#> [15] BiocGenerics_0.59.12 generics_0.1.4
#> [17] macrophage_1.29.0 EMMA_0.99.6
#>
#> loaded via a namespace (and not attached):
#> [1] RColorBrewer_1.1-3 rstudioapi_0.19.0 jsonlite_2.0.0
#> [4] tidydr_0.0.6 magrittr_2.0.5 ggtangle_0.1.2
#> [7] farver_2.1.2 rmarkdown_2.32 fs_2.1.0
#> [10] vctrs_0.7.3 memoise_2.0.1 ggtree_4.3.0
#> [13] htmltools_0.5.9 S4Arrays_1.13.0 BiocBaseUtils_1.15.1
#> [16] SparseArray_1.13.2 gridGraphics_0.5-1 htmlwidgets_1.6.4
#> [19] plyr_1.8.9 httr2_1.3.0 cachem_1.1.0
#> [22] igraph_2.3.3 lifecycle_1.0.5 pkgconfig_2.0.3
#> [25] Matrix_1.7-6 R6_2.6.1 fastmap_1.2.0
#> [28] gson_0.2.1 numDeriv_2016.8-1.1 digest_0.6.39
#> [31] aplot_0.3.1 enrichplot_1.33.0 ggnewscale_0.5.2
#> [34] patchwork_1.3.2 aisdk_1.4.12 RSQLite_3.53.3
#> [37] httr_1.4.9 polyclip_1.10-7 abind_1.4-8
#> [40] compiler_4.6.1 bit64_4.8.6 fontquiver_0.2.1
#> [43] withr_3.0.3 S7_0.2.2 BiocParallel_1.47.0
#> [46] DBI_1.3.0 ggforce_0.5.0 MASS_7.3-66
#> [49] rappdirs_0.3.4 DelayedArray_0.39.6 tools_4.6.1
#> [52] otel_0.2.0 ape_5.8-1 scatterpie_0.2.6
#> [55] glue_1.8.1 callr_3.8.0 nlme_3.1-171
#> [58] GOSemSim_2.39.2 grid_4.6.1 cluster_2.1.8.3
#> [61] reshape2_1.4.5 gtable_0.3.6 tidyr_1.3.2
#> [64] XVector_0.53.0 ggrepel_0.9.8 pillar_1.11.1
#> [67] stringr_1.6.0 limma_3.99.0 emdbook_1.3.14
#> [70] yulab.utils_0.2.5 splines_4.6.1 dplyr_1.2.1
#> [73] tweenr_2.0.3 treeio_1.37.0 lattice_0.23-1
#> [76] bit_4.6.0 tidyselect_1.2.1 fontLiberation_0.1.0
#> [79] GO.db_3.23.1 locfit_1.5-9.12 Biostrings_2.81.9
#> [82] knitr_1.52 fontBitstreamVera_0.1.1 edgeR_4.99.6
#> [85] xfun_0.61 statmod_1.5.2 stringi_1.8.9
#> [88] lazyeval_0.2.3 ggfun_0.2.1 yaml_2.3.12
#> [91] evaluate_1.0.5 codetools_0.2-20 bbmle_1.0.26
#> [94] qvalue_2.45.0 gdtools_0.5.1 tibble_3.3.1
#> [97] BiocManager_1.30.27 ggplotify_0.1.3 cli_3.6.6
#> [100] systemfonts_1.3.2 processx_3.9.0 dichromat_2.0-1
#> [103] Rcpp_1.1.2 coda_0.19-4.1 png_0.1-9
#> [106] bdsmatrix_1.3-7 parallel_4.6.1 ggplot2_4.0.3
#> [109] blob_1.3.0 DOSE_4.7.3 mvtnorm_1.4-2
#> [112] apeglm_1.35.0 tidytree_0.4.8 ggiraph_0.9.6
#> [115] enrichit_0.2.4 scales_1.4.0 writexl_2.0.1
#> [118] purrr_1.2.2 crayon_1.5.3 BiocStyle_2.41.0
#> [121] rlang_1.3.0 KEGGREST_1.53.6