๐ง Gene Ontology Fundamentals
๐ฏ What is Gene Ontology (GO)?
Gene Ontology (GO) is a major bioinformatics initiative to unify the representation of gene and gene product attributes across all species. It provides a controlled vocabulary of terms describing gene functions in three domains: Biological Process (BP), Molecular Function (MF), and Cellular Component (CC). GO annotations enable functional interpretation of high-throughput data, cross-species comparison, and enrichment analysis.
Why GO Matters
Standardization: Unified vocabulary. Annotation: Functional labels. Enrichment: Find over-represented functions. Comparison: Cross-species. Integration: Multi-omics. Interpretation: Biological meaning.
# Gene Ontology (GO) โ the big picture
# Unifying gene function representation.
print("""
=== Gene Ontology (GO) ===
What it is:
- Controlled vocabulary
- Gene product attributes
- Three domains (BP, MF, CC)
- Cross-species
Why it matters:
- Standardization
- Functional annotation
- Enrichment analysis
- Cross-species comparison
- Multi-omics integration
- Biological interpretation
The three ontologies:
- Biological Process (BP)
- Molecular Function (MF)
- Cellular Component (CC)
Key concepts:
- GO term (GO:0000001)
- Annotation (gene โ GO term)
- Evidence code (IDA, IMP, etc.)
- Hierarchy (is_a, part_of)
- GO slim
- Enrichment
Applications:
- Functional genomics
- Transcriptomics
- Proteomics
- Metabolomics
- Systems biology
- Disease analysis
- Drug discovery
""")
print("=== Historical Context ===")
print("""
1998: Gene Ontology Consortium founded
2000: First GO annotation files
2006: GO slim introduced
2010: Enrichment tools (DAVID, topGO)
2015: GOATOOLS, clusterProfiler
2020: GO-CAM, knowledge graphs
2025: AI, semantic similarity, integration
""")
print("=== Why It's Hard ===")
print("""
1. CURATION
- Manual annotation
- Time-consuming
- Expert needed
2. HIERARCHY
- Complex DAG
- Multiple parents
- Relationships
3. EVIDENCE
- Different evidence codes
- Quality varies
- Trust
4. REDUNDANCY
- Similar terms
- Overlapping
5. ENRICHMENT
- Multiple testing
- Background choice
- Interpretation
""")๐ฏ Why GO Matters
๐ฏ The Value of Gene Ontology
GO provides a universal language for gene function. It enables researchers to interpret high-throughput data and compare across species.
Key Benefits
Standard: Unified. Annotation: Functional. Enrichment: Over-representation. Comparison: Species. Integration: Omics. Discovery: Hypotheses.
# Why GO Matters
print("=== 1. Standardization ===")
print("""
Standardization:
- Unified vocabulary
- Across species
- Across databases
Example:
Human "apoptosis"
Mouse "apoptosis"
Fly "apoptosis"
โ Same GO term: GO:0006915
""")
print("\n=== 2. Functional Annotation ===")
print("""
Annotation:
- Gene โ GO terms
- Functional labels
- Evidence
Example:
TP53
โ GO:0006915 (apoptosis)
โ GO:0003700 (DNA binding)
โ GO:0005634 (nucleus)
""")
print("\n=== 3. Enrichment Analysis ===")
print("""
Enrichment:
- Over-represented terms
- Differentially expressed genes
- Statistical test
Example:
100 DE genes
โ 30 involved in "immune response"
โ Enriched (p < 0.001)
""")
print("\n=== 4. Cross-Species Comparison ===")
print("""
Comparison:
- Human vs mouse
- Conserved functions
- Model organisms
Example:
Human disease genes
โ Mouse orthologs
โ GO terms
โ Conserved
""")
print("\n=== 5. Multi-Omics Integration ===")
print("""
Integration:
- Transcriptomics
- Proteomics
- Metabolomics
- All annotated with GO
Example:
RNA-seq + proteomics
โ GO enrichment
โ Integrated view
""")
print("\n=== 6. Biological Interpretation ===")
print("""
Interpretation:
- What do my genes do?
- Which processes?
- Which functions?
- Which locations?
Example:
Cancer dataset
โ GO enrichment
โ "Cell cycle" enriched
โ Hypothesis
""")
print("\n=== 7. Hypothesis Generation ===")
print("""
Hypothesis:
- Data โ GO โ hypothesis
- Unexpected findings
- New directions
Example:
Novel gene
โ GO annotation
โ Function predicted
โ Experiment
""")
print("\n=== 8. Disease Analysis ===")
print("""
Disease:
- Disease genes
- GO enrichment
- Mechanisms
Example:
Alzheimer's
โ GO enrichment
โ "Amyloid precursor"
โ Mechanism
""")
print("\n=== 9. Drug Discovery ===")
print("""
Drug:
- Target identification
- Pathway analysis
- GO enrichment
Example:
Drug targets
โ GO terms
โ Pathways
โ Repurposing
""")
print("\n=== 10. Systems Biology ===")
print("""
Systems:
- Networks
- Pathways
- GO annotation
Example:
Protein network
โ GO enrichment
โ Modules
โ Function
""")๐ Three Ontologies
๐ฏ BP, MF, CC
Gene Ontology is divided into three independent ontologies: Biological Process (BP), Molecular Function (MF), and Cellular Component (CC). Each describes a different aspect of gene function.
The Three Ontologies
BP: Biological processes. MF: Molecular activities. CC: Locations. Independent: Separate. Complementary: Together. Complete: Full picture.
# Three Ontologies
print("=== 1. Biological Process (BP) ===")
print("""
Biological Process:
- Biological objectives
- Pathways
- Processes
Examples:
- GO:0006915 โ apoptotic process
- GO:0006954 โ inflammatory response
- GO:0007049 โ cell cycle
- GO:0007165 โ signal transduction
- GO:0008150 โ biological_process (root)
Size:
- ~29,000 terms
- Largest ontology
""")
print("\n=== 2. Molecular Function (MF) ===")
print("""
Molecular Function:
- Molecular activities
- Binding
- Catalysis
Examples:
- GO:0003700 โ DNA-binding transcription factor activity
- GO:0004672 โ protein kinase activity
- GO:0005515 โ protein binding
- GO:0005524 โ ATP binding
- GO:0003674 โ molecular_function (root)
Size:
- ~13,000 terms
""")
print("\n=== 3. Cellular Component (CC) ===")
print("""
Cellular Component:
- Locations
- Complexes
- Organelles
Examples:
- GO:0005634 โ nucleus
- GO:0005739 โ mitochondrion
- GO:0005840 โ ribosome
- GO:0005886 โ plasma membrane
- GO:0005575 โ cellular_component (root)
Size:
- ~4,000 terms
""")
print("\n=== 4. Independence ===")
print("""
Independence:
- Three separate ontologies
- No cross-links
- Each has own root
Roots:
- BP: GO:0008150
- MF: GO:0003674
- CC: GO:0005575
Example:
A gene can have:
- Multiple BP terms
- Multiple MF terms
- Multiple CC terms
""")
print("\n=== 5. Complementary ===")
print("""
Together:
- BP: What process?
- MF: What activity?
- CC: Where?
Example:
TP53:
- BP: apoptosis, cell cycle
- MF: DNA binding, transcription factor
- CC: nucleus, cytoplasm
""")
print("\n=== 6. Evidence Codes ===")
print("""
Evidence:
- How annotation was made
- Quality indicator
Common codes:
- IDA: Inferred from Direct Assay
- IMP: Inferred from Mutant Phenotype
- IGI: Inferred from Genetic Interaction
- IPI: Inferred from Physical Interaction
- ISS: Inferred from Sequence Similarity
- IEA: Inferred from Electronic Annotation
- TAS: Traceable Author Statement
- NAS: Non-traceable Author Statement
""")
print("\n=== 7. Example Annotations ===")
print("""
TP53 (P04637):
GO:0006915 BP apoptosis IDA
GO:0003700 MF DNA binding IDA
GO:0005634 CC nucleus IDA
GO:0007049 BP cell cycle IMP
GO:0008283 BP cell proliferation IMP
GO:0045893 BP positive regulation of transcription IDA
""")
print("\n=== 8. Statistics ===")
print(f"{'Ontology':<25} {'Terms':<10} {'Annotations':<15}")
print("-" * 50)
print(f"{'Biological Process':<25} {'~29,000':<10} {'~500,000':<15}")
print(f"{'Molecular Function':<25} {'~13,000':<10} {'~400,000':<15}")
print(f"{'Cellular Component':<25} {'~4,000':<10} {'~300,000':<15}")
print(f"{'Total':<25} {'~46,000':<10} {'~1,200,000':<15}")
print("\n=== 9. Relationships ===")
print("""
Relationships:
- is_a: subclass
- part_of: component
- regulates: control
- positively_regulates
- negatively_regulates
- occurs_in: location
- has_part
Example:
GO:0006915 (apoptosis)
is_a GO:0012501 (programmed cell death)
is_a GO:0008219 (cell death)
is_a GO:0008150 (biological_process)
""")
print("\n=== 10. Use Cases ===")
print("""
Use cases:
- Functional annotation
- Enrichment analysis
- Cross-species comparison
- Multi-omics integration
- Disease analysis
- Drug discovery
- Systems biology
""")๐ GO Terms & IDs
๐ฏ GO Term Structure
Each GO term has a unique identifier (GO:XXXXXXX), a name, a definition, and relationships to other terms. Understanding GO term structure is essential for analysis.
GO Terms
ID: GO:XXXXXXX. Name: Term label. Definition: Description. Namespace: BP/MF/CC. Relations: is_a, part_of. Synonyms: Alternative names.
# GO Terms & IDs
print("=== GO Term Structure ===")
print("""
Example GO term:
ID: GO:0006915
Name: apoptotic process
Namespace: biological_process
Definition: A programmed cell death process which
begins when a cell receives an internal (e.g.,
DNA damage) or external signal...
Synonyms:
- apoptosis
- programmed cell death
Relationships:
- is_a GO:0012501 (programmed cell death)
- part_of GO:0008219 (cell death)
Cross-references:
- Wikipedia: Apoptosis
- Reactome: R-HSA-109581
""")
print("\n=== GO ID Format ===")
print("""
Format: GO:XXXXXXX
- GO: prefix
- 7 digits
- Zero-padded
Examples:
GO:0000001 โ mitochondrion inheritance
GO:0000002 โ mitochondrial genome maintenance
GO:0000003 โ reproduction
GO:0006915 โ apoptotic process
GO:0003700 โ DNA-binding transcription factor activity
GO:0005634 โ nucleus
""")
print("\n=== Namespaces ===")
print("""
Biological Process (BP):
- GO:0008150 (root)
- GO:0006915 (apoptosis)
- GO:0007049 (cell cycle)
Molecular Function (MF):
- GO:0003674 (root)
- GO:0003700 (DNA binding)
- GO:0004672 (protein kinase)
Cellular Component (CC):
- GO:0005575 (root)
- GO:0005634 (nucleus)
- GO:0005739 (mitochondrion)
""")
print("\n=== Relationships ===")
print("""
is_a:
- Subclass
- "A is a B"
- Inheritance
part_of:
- Component
- "A is part of B"
- Composition
regulates:
- Control
- "A regulates B"
positively_regulates:
- Positive control
negatively_regulates:
- Negative control
occurs_in:
- Location
has_part:
- Contains
""")
print("\n=== Term Hierarchy ===")
print("""
Example: Apoptosis hierarchy
GO:0008150 (biological_process)
โโโ GO:0009987 (cellular process)
โโโ GO:0008219 (cell death)
โโโ GO:0012501 (programmed cell death)
โโโ GO:0006915 (apoptotic process)
โโโ GO:0097190 (apoptotic signaling pathway)
โโโ GO:0008637 (apoptotic mitochondrial changes)
โโโ GO:0042981 (regulation of apoptotic process)
""")
print("\n=== Term Size ===")
print("""
Size:
- BP: ~29,000 terms
- MF: ~13,000 terms
- CC: ~4,000 terms
- Total: ~46,000 terms
Depth:
- Max depth: ~15
- Average depth: ~6
Annotations:
- ~1.2 million annotations
- Across ~5,000 species
""")
print("\n=== Obsolete Terms ===")
print("""
Obsolete:
- Merged
- Split
- Replaced
Example:
GO:0000000 (obsolete)
Reason:
- Redundant
- Ambiguous
- Outdated
Replacement:
- Use replacement term
- See "replaced_by"
""")
print("\n=== Term Lookup ===")
print("""
Lookup:
- AmiGO: amigo.geneontology.org
- QuickGO: ebi.ac.uk/QuickGO
- GO API
Example:
https://amigo.geneontology.org/amigo/term/GO:0006915
https://www.ebi.ac.uk/QuickGO/term/GO:0006915
""")
print("\n=== Python Lookup ===")
print("""
import requests
def get_go_term(go_id):
url = f"https://api.geneontology.org/api/ontology/term/{go_id}"
response = requests.get(url)
if response.status_code == 200:
return response.json()
return None
# Example
term = get_go_term("GO:0006915")
if term:
print(term["label"])
print(term["definition"])
""")
print("\n=== Use Cases ===")
print("""
Use cases:
- Term lookup
- Annotation retrieval
- Enrichment analysis
- Hierarchy analysis
- Semantic similarity
""")๐ GO Annotations
๐ฏ Linking Genes to GO Terms
GO annotations link genes or gene products to GO terms, with evidence codes indicating how the annotation was made. Annotations are the foundation of GO analysis.
GO Annotations
Gene: Protein/gene ID. GO term: Function. Evidence: How. Reference: Source. Assignee: Who. Date: When.
# GO Annotations
print("=== Annotation Format ===")
print("""
GAF (Gene Association File) format:
Column 1: DB (database)
Column 2: DB Object ID (gene)
Column 3: DB Object Symbol (gene name)
Column 4: Qualifier (NOT, contributes_to)
Column 5: GO ID
Column 6: DB:Reference
Column 7: Evidence Code
Column 8: With/From
Column 9: Aspect (P, F, C)
Column 10: DB Object Name
Column 11: DB Object Synonym
Column 12: DB Object Type
Column 13: Taxon
Column 14: Date
Column 15: Assigned By
Column 16: Annotation Extension
Column 17: Gene Product Form ID
Example:
UniProtKB P04637 TP53 GO:0006915 PMID:123456 IDA P tumor protein p53 ...
""")
print("\n=== Evidence Codes ===")
print("""
Evidence codes:
- IDA: Inferred from Direct Assay
- IMP: Inferred from Mutant Phenotype
- IGI: Inferred from Genetic Interaction
- IPI: Inferred from Physical Interaction
- ISS: Inferred from Sequence Similarity
- ISO: Inferred from Sequence Orthology
- ISA: Inferred from Sequence Alignment
- ISM: Inferred from Sequence Model
- IEA: Inferred from Electronic Annotation
- TAS: Traceable Author Statement
- NAS: Non-traceable Author Statement
- IC: Inferred by Curator
- ND: No Biological Data
- RCA: Inferred from Reviewed Computational Analysis
""")
print("\n=== Annotation Sources ===")
print("""
Sources:
- UniProt
- Ensembl
- FlyBase
- TAIR
- SGD
- MGI
- RGD
- ZFIN
- WormBase
- PDB
- Reactome
- InterPro
All contribute to GO Consortium.
""")
print("\n=== Annotation Statistics ===")
print("""
Statistics (2025):
- Annotations: ~1.2 million
- Species: ~5,000
- Genes: ~1 million
- Evidence: ~50% IEA
- Manual: ~50%
""")
print("\n=== Annotation Quality ===")
print("""
Quality:
- Manual > Electronic
- Experimental > Inferred
- Multiple evidence > single
Trust:
- IDA, IMP: high
- ISS, ISO: medium
- IEA: lower
Use:
- Filter by evidence
- Use manual for accuracy
- Use all for coverage
""")
print("\n=== Annotation Retrieval ===")
print("""
Retrieval:
- AmiGO
- QuickGO
- GO Consortium downloads
- API
Example:
https://www.ebi.ac.uk/QuickGO/services/annotation/search?geneProductId=P04637
""")
print("\n=== Python Retrieval ===")
print("""
import requests
def get_annotations(gene_id):
url = "https://www.ebi.ac.uk/QuickGO/services/annotation/search"
params = {"geneProductId": gene_id, "limit": 100}
response = requests.get(url, params=params, headers={"Accept": "application/json"})
if response.status_code == 200:
return response.json()
return None
# Example
ann = get_annotations("P04637")
if ann:
for result in ann["results"]:
print(result["goId"], result["goName"])
""")
print("\n=== Annotation File ===")
print("""
Download:
- GO Consortium: geneontology.org
- Format: GAF, GPAD
Example:
wget http://current.geneontology.org/annotations/human.gaf.gz
wget http://current.geneontology.org/annotations/mgi.gaf.gz
""")
print("\n=== Use Cases ===")
print("""
Use cases:
- Gene annotation
- Enrichment analysis
- Cross-species
- Quality control
- Functional prediction
""")๐ณ GO Hierarchy
๐ฏ Directed Acyclic Graph
GO is structured as a Directed Acyclic Graph (DAG), not a tree. Terms can have multiple parents, and relationships include is_a, part_of, and regulates.
Hierarchy
DAG: Multiple parents. Root: Top term. is_a: Subclass. part_of: Component. Depth: Levels. Path: Root to term.
# GO Hierarchy
print("=== DAG vs Tree ===")
print("""
Tree:
- One parent per node
- Simple
DAG:
- Multiple parents
- Directed
- Acyclic
GO is a DAG.
""")
print("\n=== Multiple Parents ===")
print("""
Example:
GO:0006915 (apoptotic process)
Parents:
- GO:0012501 (programmed cell death)
- GO:0008219 (cell death)
- GO:0009987 (cellular process)
Children:
- GO:0097190 (apoptotic signaling)
- GO:0008637 (mitochondrial changes)
- GO:0042981 (regulation)
""")
print("\n=== Root Terms ===")
print("""
Roots:
- BP: GO:0008150 (biological_process)
- MF: GO:0003674 (molecular_function)
- CC: GO:0005575 (cellular_component)
All terms trace back to root.
""")
print("\n=== Depth ===")
print("""
Depth:
- Max: ~15
- Average: ~6
Example path:
GO:0008150 (root)
โ GO:0009987 (cellular process)
โ GO:0008219 (cell death)
โ GO:0012501 (programmed cell death)
โ GO:0006915 (apoptotic process)
""")
print("\n=== Relationships ===")
print("""
is_a:
- Subclass
- Inheritance
part_of:
- Component
- Composition
regulates:
- Control
positively_regulates:
- Positive control
negatively_regulates:
- Negative control
occurs_in:
- Location
Example:
GO:0006915 is_a GO:0012501
GO:0005634 part_of GO:0005622
""")
print("\n=== True Path Rule ===")
print("""
True Path Rule:
- If gene annotated to term
- It is also annotated to all ancestors
Example:
Gene annotated to GO:0006915
โ Also GO:0012501
โ Also GO:0008219
โ Also GO:0009987
โ Also GO:0008150
This ensures consistency.
""")
print("\n=== Annotation Propagation ===")
print("""
Propagation:
- Annotations propagate up
- Not down
Example:
Gene โ GO:0006915
โ Ancestors also annotated
But:
Gene โ GO:0012501
โ Not necessarily GO:0006915
""")
print("\n=== Hierarchy Analysis ===")
print("""
Analysis:
- Depth
- Path length
- Ancestors
- Descendants
- Semantic similarity
Tools:
- GOATOOLS
- clusterProfiler
- AmiGO
""")
print("\n=== Python Hierarchy ===")
print("""
from goatools import obo_parser
def load_go(obo_file):
go = obo_parser.GODag(obo_file)
return go
def get_ancestors(go, go_id):
term = go[go_id]
return term.get_all_parents()
# Example
# go = load_go("go-basic.obo")
# ancestors = get_ancestors(go, "GO:0006915")
# for a in ancestors:
# print(a)
""")
print("\n=== Use Cases ===")
print("""
Use cases:
- Enrichment analysis
- Semantic similarity
- Annotation propagation
- Hierarchy visualization
- Functional clustering
""")โ๏ธ GO Slims
๐ฏ Reduced GO Sets
A GO slim is a curated subset of GO terms (~100-200) that provides a broad overview of annotations. GO slims are useful for summarizing large datasets and comparing across species.
GO Slims
Subset: ~100-200 terms. Broad: High-level. Summary: Overview. Comparison: Across species. Visualization: Simple. Custom: Make your own.
# GO Slims
print("=== What is a GO Slim? ===")
print("""
GO slim:
- Subset of GO terms
- ~100-200 terms
- High-level
- Broad overview
Purpose:
- Summarize annotations
- Compare across species
- Visualize
- Simplify
Example:
Generic GO slim
โ ~100 terms
โ Covers major processes
""")
print("\n=== Common GO Slims ===")
print("""
1. Generic GO slim
- ~100 terms
- Broad
2. Plant GO slim
- ~100 terms
- Plant-specific
3. Yeast GO slim
- ~100 terms
- Yeast-specific
4. Fly GO slim
- ~100 terms
- Fly-specific
5. Human GO slim
- ~100 terms
- Human-specific
6. Custom GO slim
- User-defined
- Specific
""")
print("\n=== GO Slim Mapping ===")
print("""
Mapping:
- Full GO โ slim
- Annotations mapped up
- Summary
Example:
GO:0006915 (apoptosis)
โ GO:0009987 (cellular process)
โ Slim term
GO:0003700 (DNA binding)
โ GO:0003674 (molecular_function)
โ Slim term
""")
print("\n=== GO Slim Analysis ===")
print("""
Analysis:
- Count genes per slim term
- Percentage
- Compare conditions
- Visualize
Example:
Control: 30% cellular process
Treatment: 50% cellular process
โ Difference
""")
print("\n=== Tools ===")
print("""
1. AmiGO
- Slim mapping
- Visualization
2. GOATOOLS
- Python
- Slim mapping
3. clusterProfiler
- R
- Slim
4. QuickGO
- Web
- Slim
""")
print("\n=== Python GO Slim ===")
print("""
from goatools import obo_parser
from goatools.semantic import get_info_content
from goatools.goslim import GOSlim
def map_to_slim(go, goslim, go_id):
\"\"\"Map GO term to slim term.\"\"\"
if go_id in goslim:
return go_id
term = go[go_id]
for parent in term.get_all_parents():
if parent in goslim:
return parent
return None
# Example
# go = obo_parser.GODag("go-basic.obo")
# goslim = GOSlim("goslim_generic.obo")
# slim_term = map_to_slim(go, goslim, "GO:0006915")
""")
print("\n=== Create Custom Slim ===")
print("""
Custom slim:
- Select terms
- Define mapping
- Use for analysis
Steps:
1. Choose terms
2. Map full GO
3. Analyze
Example:
Custom slim for cancer
โ Apoptosis, cell cycle, DNA repair, ...
""")
print("\n=== Visualization ===")
print("""
Visualization:
- Bar chart
- Pie chart
- Heatmap
- Network
Example:
Bar chart:
Cellular process: 30%
Metabolic process: 25%
Response to stimulus: 20%
...
""")
print("\n=== Use Cases ===")
print("""
Use cases:
- Large dataset summary
- Cross-species comparison
- Visualization
- Communication
- Teaching
""")๐ Enrichment Analysis
๐ฏ Finding Over-Represented GO Terms
GO enrichment analysis identifies GO terms that are over-represented (enriched) in a set of genes compared to a background. It's the most common application of GO.
Enrichment
Input: Gene list. Background: All genes. Test: Hypergeometric. Correction: FDR. Output: Enriched terms. Interpret: Biology.
# Enrichment Analysis
print("=== What is Enrichment? ===")
print("""
Enrichment:
- Gene list (e.g., DE genes)
- Background (all genes)
- Over-representation
Example:
100 DE genes
โ 30 involved in "immune response"
โ Expected: 5
โ Enriched (p < 0.001)
""")
print("\n=== Statistical Test ===")
print("""
Hypergeometric test:
- Probability of observing k or more
- Given N, K, n
Parameters:
- N: total genes
- K: genes in GO term
- n: gene list size
- k: overlap
Example:
N = 20,000
K = 500 (immune response)
n = 100 (DE genes)
k = 30 (overlap)
โ p-value
""")
print("\n=== Fisher's Exact Test ===")
print("""
Fisher's exact:
- 2x2 contingency table
- Alternative to hypergeometric
Table:
In list Not in list
In GO term k K-k
Not in GO n-k N-K-n+k
Example:
k = 30
K-k = 470
n-k = 70
N-K-n+k = 19,430
""")
print("\n=== Multiple Testing ===")
print("""
Multiple testing:
- Many GO terms tested
- False positives
- Correction needed
Corrections:
- Bonferroni: strict
- Benjamini-Hochberg (FDR): common
- Storey: less strict
Example:
1000 tests
โ 50 false positives at p < 0.05
โ FDR correction
""")
print("\n=== Background ===")
print("""
Background:
- All genes tested
- Or all genes in genome
- Affects results
Example:
RNA-seq: all expressed genes
Microarray: all probes
Genome: all genes
Choice matters!
""")
print("\n=== Tools ===")
print("""
1. DAVID
- Web
- Popular
2. clusterProfiler
- R
- Comprehensive
3. GOATOOLS
- Python
- Flexible
4. topGO
- R
- Classic
5. g:Profiler
- Web
- Fast
6. Enrichr
- Web
- Simple
7. PANTHER
- Web
- Classification
8. WebGestalt
- Web
- Comprehensive
""")
print("\n=== Python GOATOOLS ===")
print("""
from goatools import obo_parser
from goatools.go_enrichment import GOEnrichmentStudy
from Bio import Entrez
# Load GO
go = obo_parser.GODag("go-basic.obo")
# Load associations
# gene2go = ...
# Run enrichment
# goea = GOEnrichmentStudy(
# background_genes,
# gene2go,
# go,
# propagate_counts=True,
# alpha=0.05,
# methods=['fdr_bh']
# )
# results = goea.run_study(study_genes)
""")
print("\n=== R clusterProfiler ===")
print("""
library(clusterProfiler)
library(org.Hs.eg.db)
# Enrichment
ego <- enrichGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.05
)
# View
head(ego)
# Plot
dotplot(ego)
barplot(ego)
""")
print("\n=== Interpretation ===")
print("""
Interpretation:
- Enriched terms
- Biological meaning
- Hypotheses
Example:
Cancer dataset
โ "Cell cycle" enriched
โ Proliferation
โ Hypothesis
""")
print("\n=== Common Pitfalls ===")
print("""
Pitfalls:
- Wrong background
- Multiple testing
- Redundant terms
- Small gene lists
- Annotation bias
Best practices:
- Correct background
- FDR correction
- Filter redundant
- Min gene list (10-20)
- Consider bias
""")
print("\n=== Visualization ===")
print("""
Visualization:
- Bar plot
- Dot plot
- Enrichment map
- Network
Tools:
- clusterProfiler
- GOATOOLS
- ggplot2
- Cytoscape
""")๐ ๏ธ Tools (AmiGO, QuickGO, GOATOOLS)
๐ฏ GO Tools
Many tools exist for GO analysis. Each has strengths and is suited to different use cases.
Tools
AmiGO: Browser. QuickGO: EBI. GOATOOLS: Python. clusterProfiler: R. DAVID: Web. g:Profiler: Fast.
# Tools
print("=== AmiGO ===")
print("""
AmiGO:
- Web: amigo.geneontology.org
- GO Consortium
- Browse, search, visualize
- Free
Features:
- Term lookup
- Gene annotation
- Enrichment
- Visualization
Use:
- Browse GO
- Search genes
- Enrichment
""")
print("\n=== QuickGO ===")
print("""
QuickGO:
- Web: ebi.ac.uk/QuickGO
- EBI
- Fast
- API
Features:
- Term lookup
- Annotation
- Enrichment
- API
Use:
- Quick lookup
- API access
- Annotation
""")
print("\n=== GOATOOLS ===")
print("""
GOATOOLS:
- Python
- Flexible
- Enrichment
- Semantic similarity
Features:
- Load GO
- Enrichment
- Semantic similarity
- Visualization
Install:
pip install goatools
Use:
- Python pipeline
- Custom analysis
""")
print("\n=== clusterProfiler ===")
print("""
clusterProfiler:
- R
- Comprehensive
- Enrichment
- Visualization
Features:
- Enrichment
- GSEA
- Visualization
- Many organisms
Install:
BiocManager::install("clusterProfiler")
Use:
- R analysis
- Publication quality
""")
print("\n=== DAVID ===")
print("""
DAVID:
- Web: david.ncifcrf.gov
- Popular
- Enrichment
- Functional annotation
Features:
- Enrichment
- Clustering
- Annotation
- Visualization
Use:
- Quick enrichment
- No coding
""")
print("\n=== g:Profiler ===")
print("""
g:Profiler:
- Web: biit.cs.ut.ee/gprofiler
- Fast
- Comprehensive
- Many organisms
Features:
- Enrichment
- Multiple sources
- Visualization
- API
Use:
- Fast enrichment
- Cross-species
""")
print("\n=== Other Tools ===")
print("""
1. Enrichr
- Web
- Simple
- Many libraries
2. WebGestalt
- Web
- Comprehensive
- Many methods
3. PANTHER
- Web
- Classification
- Enrichment
4. topGO
- R
- Classic
- Enrichment
5. GOrilla
- Web
- Enrichment
- Visualization
6. REVIGO
- Web
- Summarize
- Visualization
""")
print("\n=== Tool Comparison ===")
print(f"{'Tool':<20} {'Type':<15} {'Enrichment':<15} {'Visualization':<15} {'Free':<10}")
print("-" * 75)
print(f"{'AmiGO':<20} {'Web':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print(f"{'QuickGO':<20} {'Web':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print(f"{'GOATOOLS':<20} {'Python':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print(f"{'clusterProfiler':<20} {'R':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print(f"{'DAVID':<20} {'Web':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print(f"{'g:Profiler':<20} {'Web':<15} {'Yes':<15} {'Yes':<15} {'Yes':<10}")
print("\n=== When to Use Which ===")
print("""
USE AmiGO:
โ Browse GO
โ Term lookup
โ Quick
USE QuickGO:
โ Quick lookup
โ API
โ Annotation
USE GOATOOLS:
โ Python
โ Custom
โ Flexible
USE clusterProfiler:
โ R
โ Comprehensive
โ Publication
USE DAVID:
โ Quick
โ No coding
โ Popular
USE g:Profiler:
โ Fast
โ Cross-species
โ Comprehensive
""")๐ Python Integration
๐ฏ GO Analysis with Python
Python is a powerful language for GO analysis. Here's how to use it with GOATOOLS, requests, and other libraries.
Python
GOATOOLS: Enrichment. Requests: APIs. Pandas: Data. Matplotlib: Plot. NetworkX: Graphs. Automate: Pipeline.
# Python Integration
print("=== 1. Install GOATOOLS ===")
print("""
pip install goatools
""")
print("\n=== 2. Load GO ===")
print("""
from goatools import obo_parser
# Download GO basic
# wget http://purl.obolibrary.org/obo/go/go-basic.obo
go = obo_parser.GODag("go-basic.obo")
print(f"Loaded {len(go)} GO terms")
""")
print("\n=== 3. Explore GO Terms ===")
print("""
# Get a term
term = go["GO:0006915"]
print(f"ID: {term.id}")
print(f"Name: {term.name}")
print(f"Namespace: {term.namespace}")
print(f"Definition: {term.definition}")
# Ancestors
for ancestor in term.get_all_parents():
print(f"Parent: {go[ancestor].name}")
# Children
for child in term.children:
print(f"Child: {go[child].name}")
""")
print("\n=== 4. Load Annotations ===")
print("""
from goatools.anno.genetogo_reader import Gene2GoReader
# Load gene2go
obj = Gene2GoReader("gene2go", taxids=[9606])
gene2go = obj.get_ns2assc()
""")
print("\n=== 5. Enrichment Analysis ===")
print("""
from goatools.go_enrichment import GOEnrichmentStudy
# Background genes
background = ["TP53", "BRCA1", "BRCA2", ...]
# Study genes (e.g., DE genes)
study = ["TP53", "BRCA1", "BRCA2", ...]
# Run enrichment
goea = GOEnrichmentStudy(
background,
gene2go,
go,
propagate_counts=True,
alpha=0.05,
methods=['fdr_bh']
)
results = goea.run_study(study)
# Print results
for r in results:
if r.p_fdr_bh < 0.05:
print(f"{r.GO} {r.name} p={r.p_fdr_bh:.2e}")
""")
print("\n=== 6. Semantic Similarity ===")
print("""
from goatools.semantic import TermSemanticSimilarity, get_info_content
from goatools.semantic import Resnik, Lin, JiangConrath
# Calculate similarity
# sim = Resnik(go, "GO:0006915", "GO:0012501")
# print(f"Similarity: {sim}")
""")
print("\n=== 7. Query GO API ===")
print("""
import requests
def get_go_term(go_id):
url = f"https://api.geneontology.org/api/ontology/term/{go_id}"
response = requests.get(url)
if response.status_code == 200:
return response.json()
return None
# Example
term = get_go_term("GO:0006915")
if term:
print(term["label"])
print(term["definition"])
""")
print("\n=== 8. Query QuickGO ===")
print("""
import requests
def get_annotations(gene_id):
url = "https://www.ebi.ac.uk/QuickGO/services/annotation/search"
params = {"geneProductId": gene_id, "limit": 100}
headers = {"Accept": "application/json"}
response = requests.get(url, params=params, headers=headers)
if response.status_code == 200:
return response.json()
return None
# Example
ann = get_annotations("P04637")
if ann:
for result in ann["results"]:
print(result["goId"], result["goName"])
""")
print("\n=== 9. Visualization ===")
print("""
import matplotlib.pyplot as plt
import pandas as pd
def plot_enrichment(results):
\"\"\"Plot enrichment results.\"\"\"
df = pd.DataFrame([{
"term": r.name,
"pvalue": r.p_fdr_bh,
"count": r.study_count
} for r in results if r.p_fdr_bh < 0.05])
df = df.sort_values("pvalue").head(20)
plt.figure(figsize=(10, 8))
plt.barh(df["term"], -np.log10(df["pvalue"]), color='purple')
plt.xlabel("-log10(FDR)")
plt.title("GO Enrichment")
plt.tight_layout()
plt.savefig("enrichment.png")
plt.show()
# Use
# plot_enrichment(results)
""")
print("\n=== 10. Complete Pipeline ===")
print("""
from goatools import obo_parser
from goatools.anno.genetogo_reader import Gene2GoReader
from goatools.go_enrichment import GOEnrichmentStudy
def go_enrichment(study_genes, background_genes, gene2go, go):
\"\"\"Complete GO enrichment pipeline.\"\"\"
goea = GOEnrichmentStudy(
background_genes,
gene2go,
go,
propagate_counts=True,
alpha=0.05,
methods=['fdr_bh']
)
results = goea.run_study(study_genes)
return [r for r in results if r.p_fdr_bh < 0.05]
# Use
# go = obo_parser.GODag("go-basic.obo")
# obj = Gene2GoReader("gene2go", taxids=[9606])
# gene2go = obj.get_ns2assc()
# results = go_enrichment(study, background, gene2go, go)
""")๐จ Visualization
๐ฏ Seeing GO Results
Visualization is crucial for interpreting GO enrichment results. Tools like REVIGO, clusterProfiler, and ggplot2 provide rich visualizations.
Visualization
Bar: Simple. Dot: Enrichment. Map: Network. Tree: Hierarchy. Heatmap: Comparison. Network: Relationships.
# Visualization
print("=== 1. Bar Plot ===")
print("""
Bar plot:
- Enriched terms
- -log10(p-value)
- Count
Example:
Apoptosis: โโโโโโโโโโโโ 12
Cell cycle: โโโโโโโโโโ 10
Immune: โโโโโโโโ 8
""")
print("\n=== 2. Dot Plot ===")
print("""
Dot plot:
- X: Gene ratio
- Y: Term
- Size: Count
- Color: p-value
Example:
clusterProfiler dotplot
""")
print("\n=== 3. Enrichment Map ===")
print("""
Enrichment map:
- Nodes: GO terms
- Edges: Overlap
- Clusters: Functional modules
Tools:
- Cytoscape
- EnrichmentMap
- clusterProfiler
""")
print("\n=== 4. Tree Plot ===")
print("""
Tree plot:
- GO hierarchy
- Enriched terms
- Color by p-value
Tools:
- clusterProfiler
- GOATOOLS
- AmiGO
""")
print("\n=== 5. Heatmap ===")
print("""
Heatmap:
- Terms x Samples
- Color: Enrichment
- Clustering
Example:
Term Sample1 Sample2 Sample3
Apop 0.8 0.2 0.9
Cycle 0.1 0.9 0.3
""")
print("\n=== 6. Network ===")
print("""
Network:
- Nodes: Terms
- Edges: Similarity
- Modules
Tools:
- Cytoscape
- NetworkX
- igraph
""")
print("\n=== 7. REVIGO ===")
print("""
REVIGO:
- Web: revigo.irb.hr
- Summarize GO
- Remove redundancy
- Visualization
Features:
- Treemap
- Scatterplot
- Network
- Tree
Use:
- Reduce redundancy
- Visualize
""")
print("\n=== 8. Python Visualization ===")
print("""
import matplotlib.pyplot as plt
import numpy as np
def plot_go_results(results, output="go.png"):
\"\"\"Plot GO enrichment results.\"\"\"
terms = [r.name for r in results]
pvals = [-np.log10(r.p_fdr_bh) for r in results]
plt.figure(figsize=(10, 6))
plt.barh(terms, pvals, color='purple')
plt.xlabel("-log10(FDR)")
plt.title("GO Enrichment")
plt.tight_layout()
plt.savefig(output)
plt.show()
# Use
# plot_go_results(results)
""")
print("\n=== 9. R Visualization ===")
print("""
library(clusterProfiler)
library(ggplot2)
# Dot plot
dotplot(ego, showCategory=20)
# Bar plot
barplot(ego, showCategory=20)
# Enrichment map
emapplot(ego)
# Tree plot
cnetplot(ego)
# Heatmap
heatplot(ego)
""")
print("\n=== 10. Best Practices ===")
print("""
1. Sort by p-value
2. Show top 20 terms
3. Color by p-value
4. Size by count
5. Remove redundancy
6. Cluster similar
7. Label clearly
8. Export high-quality
""")โ๏ธ Tool Comparison
๐ฏ Which Tool?
Choosing the right GO tool depends on your needs, programming skills, and analysis goals.
Comparison
AmiGO: Browse. QuickGO: API. GOATOOLS: Python. clusterProfiler: R. DAVID: Web. g:Profiler: Fast.
| Tool | Type | Enrichment | Visualization | Best For |
|---|---|---|---|---|
| AmiGO | Web | Yes | Yes | Browse, lookup |
| QuickGO | Web | Yes | Yes | API, annotation |
| GOATOOLS | Python | Yes | Yes | Custom, flexible |
| clusterProfiler | R | Yes | Yes | Publication quality |
| DAVID | Web | Yes | Yes | Quick, no coding |
| g:Profiler | Web | Yes | Yes | Fast, cross-species |
| Enrichr | Web | Yes | Yes | Simple, many libraries |
| topGO | R | Yes | Yes | Classic |
| PANTHER | Web | Yes | Yes | Classification |
# Decision Guide
print("=== Choose Tool by Skill ===")
print("""
No coding:
โ DAVID
โ g:Profiler
โ Enrichr
โ AmiGO
โ QuickGO
Python:
โ GOATOOLS
โ requests + API
R:
โ clusterProfiler
โ topGO
Publication:
โ clusterProfiler
โ GOATOOLS
""")
print("\n=== Choose Tool by Task ===")
print("""
Browse GO:
โ AmiGO
Quick lookup:
โ QuickGO
Enrichment:
โ DAVID
โ g:Profiler
โ clusterProfiler
โ GOATOOLS
Visualization:
โ clusterProfiler
โ REVIGO
โ GOATOOLS
API:
โ QuickGO
โ GO API
""")
print("\n=== Speed Comparison ===")
print(f"{'Tool':<20} {'100 genes':<15} {'1000 genes':<15} {'10000 genes':<15}")
print("-" * 65)
print(f"{'DAVID':<20} {'< 1 min':<15} {'< 5 min':<15} {'< 30 min':<15}")
print(f"{'g:Profiler':<20} {'< 10s':<15} {'< 1 min':<15} {'< 5 min':<15}")
print(f"{'clusterProfiler':<20} {'< 1 min':<15} {'< 5 min':<15} {'< 30 min':<15}")
print(f"{'GOATOOLS':<20} {'< 1 min':<15} {'< 5 min':<15} {'< 30 min':<15}")
print("\n=== When to Use Which ===")
print("""
USE AmiGO:
โ Browse
โ Lookup
โ Visualization
USE QuickGO:
โ API
โ Annotation
โ Quick
USE GOATOOLS:
โ Python
โ Custom
โ Flexible
USE clusterProfiler:
โ R
โ Comprehensive
โ Publication
USE DAVID:
โ Quick
โ No coding
โ Popular
USE g:Profiler:
โ Fast
โ Cross-species
โ Comprehensive
""")โ FAQ
๐ฏ Frequently Asked Questions
Answers to common questions about Gene Ontology.
What is Gene Ontology (GO)?
Gene Ontology (GO) is a major bioinformatics initiative to unify the representation of gene and gene product attributes across all species. It provides a controlled vocabulary of terms describing gene functions in three domains: Biological Process (BP), Molecular Function (MF), and Cellular Component (CC).
What are the three GO ontologies?
The three GO ontologies are: (1) Biological Process (BP) โ biological objectives like 'cell division' or 'immune response'; (2) Molecular Function (MF) โ molecular activities like 'ATP binding' or 'kinase activity'; (3) Cellular Component (CC) โ locations like 'nucleus', 'mitochondrion', or 'ribosome'.
What is GO enrichment analysis?
GO enrichment analysis identifies GO terms that are over-represented (enriched) in a set of genes (e.g., differentially expressed genes) compared to a background. It uses statistical tests (hypergeometric, Fisher's exact) and corrects for multiple testing (FDR/Bonferroni). Tools include DAVID, clusterProfiler, and GOATOOLS.
What is the difference between GO and GO slim?
The full Gene Ontology contains ~45,000 terms with fine-grained detail. A GO slim is a curated subset of ~100-200 high-level terms that provides a broad overview of annotations. GO slims are useful for summarizing large datasets and comparing across species.
How do I access Gene Ontology data?
Access GO data via: (1) AmiGO (web browser, amigo.geneontology.org), (2) QuickGO (EBI, ebi.ac.uk/QuickGO), (3) GO Consortium downloads (geneontology.org), (4) APIs (GO API, QuickGO API), (5) Python libraries (GOATOOLS, goatools), (6) R packages (clusterProfiler, topGO).
What is an evidence code?
An evidence code indicates how a GO annotation was made. Common codes include IDA (Inferred from Direct Assay), IMP (Inferred from Mutant Phenotype), ISS (Inferred from Sequence Similarity), and IEA (Inferred from Electronic Annotation). Evidence codes indicate annotation quality.
What is the True Path Rule?
The True Path Rule states that if a gene is annotated to a GO term, it is also annotated to all its ancestor terms. This ensures consistency in the hierarchy and allows annotations to propagate upward.
What is the best background for enrichment?
The best background is the set of all genes that could have been detected in your experiment. For RNA-seq, use all expressed genes. For microarrays, use all probes. For genome-wide, use all genes. The choice of background significantly affects results.
How many genes do I need for enrichment?
A minimum of 10-20 genes is recommended for meaningful enrichment. Smaller lists may produce unreliable results. For robust analysis, use 50-100+ genes.
What is semantic similarity?
Semantic similarity measures how similar two GO terms are based on their position in the ontology and their information content. It's used for comparing genes, clustering, and functional prediction. Tools include GOATOOLS and GOSemSim.
# Quick Reference
print("=== Quick Answers ===")
print("""
Q: What is GO?
A: Controlled vocabulary for gene function.
Q: Three ontologies?
A: BP, MF, CC.
Q: GO term?
A: GO:XXXXXXX with name, definition.
Q: Annotation?
A: Gene โ GO term + evidence.
Q: Enrichment?
A: Over-represented terms in gene list.
Q: Background?
A: All genes that could be detected.
Q: Multiple testing?
A: FDR (Benjamini-Hochberg).
Q: GO slim?
A: Subset of ~100-200 broad terms.
Q: Tools?
A: AmiGO, QuickGO, GOATOOLS, clusterProfiler.
Q: Python?
A: GOATOOLS, requests.
Q: R?
A: clusterProfiler, topGO.
Q: Free?
A: Yes โ all major tools are free.
""")๐ Future
๐ฏ Where GO Is Going
The future is AI-integrated, knowledge graphs, single-cell, spatial, and multi-omics.
Future Directions
AI: Integration. Graphs: Knowledge. Single-cell: Resolution. Spatial: Location. Multi-omics: Integrated. Real-time: Updates.
# Future of Gene Ontology
print("=== 1. AI Integration ===")
print("""
Trend: AI + GO
Ideas:
- AI-powered annotation
- Predictive GO
- NLP for literature
- Knowledge graphs
Examples:
- GO-CAM
- DeepGO
- AI curation
Future:
- Automated annotation
- Predictive
- Integrated
""")
print("\n=== 2. Knowledge Graphs ===")
print("""
Trend: Knowledge graphs
Current:
- GO + annotations
- Separate databases
Future:
- Integrated knowledge
- Linked data
- Reasoning
Examples:
- GO-CAM
- Wikidata
- SPOKE
Future:
- Unified knowledge
- Reasoning
- Discovery
""")
print("\n=== 3. Single-Cell ===")
print("""
Trend: Single-cell GO
Current:
- Bulk GO
- Average
Future:
- Single-cell GO
- Cell-type specific
- Trajectory
Examples:
- scRNA-seq + GO
- Cell atlas
- Developmental
Future:
- Cell-type resolution
- Trajectories
- Dynamics
""")
print("\n=== 4. Spatial ===")
print("""
Trend: Spatial GO
Current:
- Tissue-level
Future:
- Spatial GO
- Location-specific
- Microenvironment
Examples:
- Spatial transcriptomics
- Imaging
- Tumor
Future:
- Spatial resolution
- Microenvironment
- Context
""")
print("\n=== 5. Multi-Omics ===")
print("""
Trend: Multi-omics GO
Current:
- Single omics
Future:
- Multi-omics GO
- Integration
- Systems
Examples:
- RNA + protein + metabolite
- GO enrichment
- Integrated view
Future:
- Unified
- Integrated
- Systems-level
""")
print("\n=== 6. Real-Time ===")
print("""
Trend: Real-time GO
Current:
- Periodic updates
- Static
Future:
- Real-time
- Streaming
- Live
Examples:
- COVID-19
- Outbreak
- Surveillance
Future:
- Real-time
- Continuous
- Dynamic
""")
# TIMELINE
print("\n=== Timeline ===")
print("""
Past:
1998: GO Consortium
2000: First annotations
2006: GO slim
2010: Enrichment tools
2020: GO-CAM
Present:
2025: AI integration
2026: Knowledge graphs
Future:
2030: Single-cell
2035: Spatial
2040: Real-time?
""")
print("\n=== Final Thoughts ===")
print("""
Gene Ontology is:
- Essential for functional genomics
- Standardized
- Comprehensive
- Evolving
The future is:
- AI-integrated
- Knowledge graphs
- Single-cell
- Spatial
- Multi-omics
- Real-time
"GO is the language of gene function."
Keep exploring. Keep building.
""")