| name | bio-pathway-go-enrichment |
| description | Gene Ontology over-representation analysis using clusterProfiler enrichGO. Use when identifying biological functions enriched in a gene list from differential expression or other analyses. Supports all three ontologies (BP, MF, CC), multiple ID types, and customizable statistical thresholds. |
| tool_type | r |
| primary_tool | clusterProfiler |
Version Compatibility
Reference examples tested with: R stats (base), clusterProfiler 4.10+
Before using code patterns, verify installed versions match. If versions differ:
- R:
packageVersion('<pkg>') then ?function_name to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
GO Over-Representation Analysis
Core Pattern
Goal: Identify enriched Gene Ontology terms in a gene list from differential expression or similar analyses.
Approach: Test for over-representation of GO terms using the hypergeometric test via clusterProfiler enrichGO.
"Run GO enrichment on my gene list" → Test whether biological process, molecular function, or cellular component terms are over-represented among significant genes.
library(clusterProfiler)
library(org.Hs.eg.db)
ego <- enrichGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
keyType = 'ENTREZID',
ont = 'BP',
pAdjustMethod = 'BH',
pvalueCutoff = 0.05,
qvalueCutoff = 0.2
)
Prepare Gene List from DE Results
Goal: Extract significant gene IDs from differential expression results and convert to the format required by enrichGO.
Approach: Filter DE results by adjusted p-value and fold change, then convert gene symbols to Entrez IDs using bitr.
library(dplyr)
de_results <- read.csv('de_results.csv')
sig_genes <- de_results %>%
filter(padj < 0.05, abs(log2FoldChange) > 1) %>%
pull(gene_id)
gene_ids <- bitr(sig_genes, fromType = 'SYMBOL', toType = 'ENTREZID', OrgDb = org.Hs.eg.db)
gene_list <- gene_ids$ENTREZID
ID Conversion with bitr
Goal: Convert between gene identifier types (Ensembl, Symbol, Entrez) for compatibility with enrichment tools.
Approach: Use clusterProfiler bitr to map between ID types using organism annotation databases.
keytypes(org.Hs.eg.db)
converted <- bitr(genes, fromType = 'ENSEMBL', toType = 'ENTREZID', OrgDb = org.Hs.eg.db)
converted <- bitr(genes, fromType = 'SYMBOL', toType = c('ENTREZID', 'ENSEMBL'), OrgDb = org.Hs.eg.db)
With Background Universe
Goal: Improve enrichment specificity by restricting the background to genes actually tested in the experiment.
Approach: Pass all expressed genes (not just significant ones) as the universe parameter to enrichGO.
all_genes <- de_results$gene_id
universe_ids <- bitr(all_genes, fromType = 'SYMBOL', toType = 'ENTREZID', OrgDb = org.Hs.eg.db)
ego <- enrichGO(
gene = gene_list,
universe = universe_ids$ENTREZID,
OrgDb = org.Hs.eg.db,
keyType = 'ENTREZID',
ont = 'BP',
pAdjustMethod = 'BH',
pvalueCutoff = 0.05
)
All Three Ontologies
ego_all <- enrichGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
keyType = 'ENTREZID',
ont = 'ALL',
pAdjustMethod = 'BH',
pvalueCutoff = 0.05
)
head(as.data.frame(ego_all))
Make Results Readable
ego_readable <- setReadable(ego, OrgDb = org.Hs.eg.db, keyType = 'ENTREZID')
ego <- enrichGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
keyType = 'ENTREZID',
ont = 'BP',
readable = TRUE
)
Extract and Export Results
head(ego)
results_df <- as.data.frame(ego)
write.csv(results_df, 'go_enrichment_results.csv', row.names = FALSE)
sig_terms <- results_df[results_df$p.adjust < 0.01 & results_df$Count >= 5, ]
Simplify Redundant Terms
Goal: Remove highly similar GO terms to reduce redundancy in enrichment results.
Approach: Cluster GO terms by semantic similarity and retain representative terms using the simplify function.
ego_simplified <- simplify(ego, cutoff = 0.7, by = 'p.adjust', select_fun = min)
Different Organisms
library(org.Mm.eg.db)
ego_mouse <- enrichGO(gene = genes, OrgDb = org.Mm.eg.db, ont = 'BP')
library(org.Dr.eg.db)
ego_zfish <- enrichGO(gene = genes, OrgDb = org.Dr.eg.db, ont = 'BP')
library(org.Sc.sgd.db)
ego_yeast <- enrichGO(gene = genes, OrgDb = org.Sc.sgd.db, ont = 'BP', keyType = 'ORF')
Group GO Terms by Ancestor
Goal: Classify genes by broad GO slim categories for a high-level functional overview.
Approach: Use groupGO to assign genes to GO terms at a specific hierarchy level.
ggo <- groupGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
ont = 'BP',
level = 3,
readable = TRUE
)
Key Parameters
| Parameter | Default | Description |
|---|
| gene | required | Vector of gene IDs |
| OrgDb | required | Organism database |
| keyType | ENTREZID | Input ID type |
| ont | BP | BP, MF, CC, or ALL |
| pvalueCutoff | 0.05 | P-value threshold |
| qvalueCutoff | 0.2 | Q-value (FDR) threshold |
| pAdjustMethod | BH | BH, bonferroni, etc. |
| universe | NULL | Background genes |
| minGSSize | 10 | Min genes per term |
| maxGSSize | 500 | Max genes per term |
| readable | FALSE | Convert to symbols |
Related Skills
- kegg-pathways - KEGG pathway enrichment
- gsea - Gene Set Enrichment Analysis for GO
- enrichment-visualization - Visualize enrichment results
- differential-expression - Generate input gene lists