Exercise 11 — Pathway and Functional Enrichment Analysis

In Exercise 8, we identified thousands of differentially expressed genes.

In Exercise 10, we confirmed that the dataset is high quality and biologically structured.

Now we answer the most important question:

What biological processes are changing?


Key Idea

A gene list alone is not interpretable.

We need to ask:

Are certain biological processes over-represented in my gene list?

This is called:

  • Gene Ontology (GO) enrichment
  • pathway enrichment analysis

Packages

We will use:

  • :contentReference[oaicite:0]{index=0}
  • :contentReference[oaicite:1]{index=1}
  • :contentReference[oaicite:2]{index=2}

Part 1 — Prepare Gene List

Task 1.1 — Load DE results

res <- results(dds)
res_df <- as.data.frame(res)

Task 1.2 — Define significant genes

sig_genes <- subset(
  res_df,
  padj < 0.05 & abs(log2FoldChange) > 1
)

Task 1.3 — Extract gene IDs

genes <- rownames(sig_genes)

Task 1.4 — Question

Why do we not use all genes for enrichment?


Part 2 — Gene ID Conversion

RNA-seq datasets often use Ensembl IDs.

We must convert them.

Task 2.1

library(clusterProfiler)
library(org.Hs.eg.db)

Task 2.2 — Convert IDs

gene_df <- bitr(
  genes,
  fromType = "ENSEMBL",
  toType = "ENTREZID",
  OrgDb = org.Hs.eg.db
)

Task 2.3 — Question

Why do some genes fail conversion?


Part 3 — GO Enrichment Analysis

Task 3.1 — Run GO enrichment

ego <- enrichGO(
  gene = gene_df$ENTREZID,
  OrgDb = org.Hs.eg.db,
  keyType = "ENTREZID",
  ont = "BP",
  pAdjustMethod = "BH",
  pvalueCutoff = 0.05,
  qvalueCutoff = 0.2
)

Task 3.2 — Inspect results

head(ego)

Task 3.3 — Question

What do these columns mean?

  • GeneRatio
  • Count
  • p.adjust

Task 3.4 — Visualization

dotplot(ego)

Part 4 — KEGG Pathway Analysis

Task 4.1

ekegg <- enrichKEGG(
  gene = gene_df$ENTREZID,
  organism = "hsa",
  pvalueCutoff = 0.05
)

Task 4.2

dotplot(ekegg)

Task 4.3 — Question

What is the difference between GO and KEGG?


Part 5 — Biological Interpretation

Task 5.1 — Interpretation Questions

From your enrichment results:

  1. Which biological processes are enriched?
  2. Are immune pathways activated or suppressed?
  3. Do results match dexamethasone biology?

Task 5.2 — Key Insight

Dexamethasone is a glucocorticoid.

Think about:

  • inflammation
  • immune regulation
  • transcriptional repression

Do your results match this?


Part 6 — Enrichment Plot Interpretation

Task 6.1

Look at dotplot:

Questions:

  • What does dot size represent?
  • What does dot color represent?
  • Which pathways are most significant?

Part 7 — Leading Edge Genes

Task 7.1

geneInPathway <- ego@result

Task 7.2 — Question

Why do multiple genes contribute to the same pathway signal?


Part 8 — Common Pitfalls

Task 8.1

Why can enrichment be misleading?

Think about:

  • gene list bias
  • pathway size bias
  • redundancy between GO terms

Part 9 — Biological Summary

Write a short interpretation:

  • What pathways are enriched?
  • What does this tell you about dexamethasone?
  • How does this connect to gene-level results?

Bonus

B1 — Compare upregulated vs downregulated genes separately

Split gene list:

up_genes
down_genes

Run enrichment separately.


B2 — Visualize enriched network

library(enrichplot)
cnetplot(ego)

B3 — Simplify GO terms

simplify(ego)

Key Takeaways

  • Gene lists are not biologically meaningful until interpreted
  • GO and KEGG reveal biological processes behind expression changes
  • Enrichment analysis bridges statistics and biology
  • Interpretation is more important than the code itself

⬅️ Previous Exercise 🏠 Home ➡️ Coming soon