To run every example in this vignette, install knowYourCG with the packages the examples load:
if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager")
BiocManager::install(c("knowYourCG", "SummarizedExperiment", "sesame",
"gprofiler2"))There are four testing scenarios depending on the type format of the
query set and database sets. They are shown with the respective testing
scenario in the table below. testEnrichment,
testEnrichmentSEA are for Fisher’s exact test and Set
Enrichment Analysis respectively.
| Continuous Database Set | Discrete Database Set | |
|---|---|---|
| Continuous Query | Correlation-based | Set Enrichment Analysis |
| Discrete Query | Set Enrichment Analysis | Fisher’s Exact Test |
The query may be a named continuous vector. In that case, either a gene enrichment score will be calculated (if the database is discrete) or a Spearman correlation will be calculated (if the database is continuous as well). The two other cases are shown below using biologically relevant examples.
To display this functionality, let’s load two numeric database sets individually. One is a database set for CpG density and the other is a database set corresponding to the distance of the nearest transcriptional start site (TSS) to each probe.
sesameDataCache(data_titles = c("KYCG.MM285.seqContextN.20210630"))
res <- testEnrichmentSEA(query, "MM285.seqContextN")
main_stats <- c("dbname", "test", "estimate", "FDR", "nQ", "nD", "overlap")
res[,main_stats]The estimate here is enrichment score.
NOTE: Negative enrichment score suggests enrichment of the categorical database with the higher values (in the numerical database). Positive enrichment score represents enrichment with the smaller values. As expected, the designed TSS CpGs are significantly enriched in smaller TSS distance and higher CpG density.
Alternatively one can test the enrichment of a continuous query with discrete databases. Here we will use the methylation level from a sample as the query and test it against the chromHMM chromatin states.
The p-values come from permutation: each set is compared with random sets of the same size. Seed the generator to reproduce them.
library(sesame)
set.seed(1)
sesameDataCache(data_titles = c("MM285.1.SigDF"))
beta_values <- getBetas(sesameDataGet("MM285.1.SigDF"))
res <- testEnrichmentSEA(beta_values, "MM285.chromHMM")
main_stats <- c("dbname", "test", "estimate", "FDR", "nQ", "nD", "overlap")
res[,main_stats] As expected, chromatin states Tss and Enh
have positive enrichment scores, meaning these databases are associated
with small values of the query (DNA methylation level). On the contrary,
Het and most quiescent states (Quies,
QuiesG, Quies2, Quies3) have
negative scores, meaning they are associated with high methylation
level; Quies4 is the exception. Here nD is the
number of CpGs with a value and nQ the size of each
state.
## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.23-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [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
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] sesame_1.30.1 knitr_1.52
## [3] SummarizedExperiment_1.42.0 Biobase_2.72.0
## [5] GenomicRanges_1.64.0 Seqinfo_1.2.0
## [7] IRanges_2.46.0 S4Vectors_0.50.3
## [9] MatrixGenerics_1.24.0 matrixStats_1.5.0
## [11] sesameData_1.30.0 ExperimentHub_3.2.2
## [13] AnnotationHub_4.2.2 BiocFileCache_3.2.0
## [15] dbplyr_2.6.0 BiocGenerics_0.58.1
## [17] generics_0.1.4 knowYourCG_1.8.5
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 dplyr_1.2.1 farver_2.1.2
## [4] blob_1.3.0 filelock_1.0.3 Biostrings_2.80.2
## [7] S7_0.2.2 fastmap_1.2.0 digest_0.6.39
## [10] lifecycle_1.0.5 KEGGREST_1.52.2 RSQLite_3.53.3
## [13] magrittr_2.0.5 compiler_4.6.1 rlang_1.3.0
## [16] sass_0.4.10 tools_4.6.1 yaml_2.3.12
## [19] S4Arrays_1.12.1 bit_4.6.0 curl_8.1.0
## [22] DelayedArray_0.38.2 plyr_1.8.9 RColorBrewer_1.1-3
## [25] BiocParallel_1.46.0 abind_1.4-8 withr_3.0.3
## [28] purrr_1.2.2 grid_4.6.1 preprocessCore_1.74.0
## [31] wheatmap_0.2.4 colorspace_2.1-4 ggplot2_4.0.3
## [34] scales_1.4.0 dichromat_2.0-1 cli_3.6.6
## [37] rmarkdown_2.32 crayon_1.5.3 otel_0.2.0
## [40] httr_1.4.9 reshape2_1.4.5 tzdb_0.5.0
## [43] DBI_1.3.0 cachem_1.1.0 stringr_1.6.0
## [46] parallel_4.6.1 AnnotationDbi_1.74.0 BiocManager_1.30.27
## [49] XVector_0.52.0 vctrs_0.7.3 Matrix_1.7-6
## [52] jsonlite_2.0.0 hms_1.1.4 bit64_4.8.6
## [55] ggrepel_0.9.8 fontawesome_0.5.3 jquerylib_0.1.4
## [58] glue_1.8.1 codetools_0.2-20 stringi_1.8.9
## [61] gtable_0.3.6 BiocVersion_3.23.1 tibble_3.3.1
## [64] pillar_1.11.1 rappdirs_0.3.4 htmltools_0.5.9
## [67] R6_2.6.1 httr2_1.3.0 evaluate_1.0.5
## [70] lattice_0.23-1 readr_2.2.0 png_0.1-9
## [73] memoise_2.0.1 bslib_0.12.0 Rcpp_1.1.2
## [76] SparseArray_1.12.3 xfun_0.62 pkgconfig_2.0.3