8 Functional Enrichment
Once you have identified robust marker genes (using either standard DE or Pseudobulk, as discussed in the previous chapter), the next logical step is to understand the biological pathways they participate in.
sclet provides RunEnrichment() to seamlessly perform functional enrichment analysis (GO/KEGG). This function wraps the powerful clusterProfiler package and registers its results into the analysis-state contract, making it incredibly easy for downstream visualization tools to consume.
The GO example is executed during book rendering so that the book also tests this part of the workflow in CI. The KEGG example remains demonstration-only, because it is more sensitive to identifier preparation and organism-specific setup.
8.1 GO Enrichment
If you have already run RunDEtest(), RunEnrichment() is smart enough to automatically read the significant up-regulated markers from the active detest state. No need to manually extract gene lists!
library(sclet)
sce <- readRDS("data/pbmc-3k-sce.rds")
sce <- RunDEtest(sce, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)
# Ensure you have org.Mm.eg.db installed for Mouse data
# or org.Hs.eg.db for Human
library(org.Hs.eg.db)
# Run enrichment analysis based on the DEtest state
sce <- RunEnrichment(
sce,
db = "GO",
orgDb = "org.Hs.eg.db",
keyType = "SYMBOL",
ont = "BP"
)
# Visualize the enrichment results using EnrichmentPlot (wraps enrichplot::dotplot)
EnrichmentPlot(sce, showCategory=5)
8.2 KEGG Enrichment
For KEGG pathway enrichment, it is highly recommended to convert gene symbols to Entrez IDs first, or provide a column with Entrez IDs if available. This example is intentionally left as a template rather than executed in CI, because KEGG runs are more sensitive to identifier hygiene and organism-specific setup than the GO workflow above.