Ontology API¶
Ontology loading and traversal functions.
Core functions¶
load_go_terms(path=None)
Loads GO terms from an OBO file.
If
pathis omitted, GO3 downloadsgo-basic.obo.Replaces the in-process ontology cache.
get_term_by_id(go_id)
Returns a
go3.PyGOTermobject.Raises
ValueErrorif the term does not exist.
ancestors(go_id)
Returns all ancestors of
go_id(including the term itself).
common_ancestor(go_id1, go_id2)
Returns common ancestors between two terms.
deepest_common_ancestor(go_id1, go_id2)
Returns the deepest common ancestor (MICA-like depth criterion).
Raises
ValueErrorif either GO ID is missing.
Example¶
import go3
go3.load_go_terms("go-basic.obo")
term = go3.get_term_by_id("GO:0006397")
print(term.name)
ancs = go3.ancestors("GO:0006397")
print(len(ancs))
common = go3.common_ancestor("GO:0006397", "GO:0008380")
print(len(common))
dca = go3.deepest_common_ancestor("GO:0006397", "GO:0008380")
print(dca)
Notes for developers¶
Ontology data is cached globally within the Python process.
Loading a new ontology refreshes dependent internal caches.
For reproducible analyses, keep ontology version fixed across runs.
API reference¶
- ancestors(go_id)
Returns the list of all ancestors in the ontology for the given GO Term.
- Parameters:
go_id (str) – GO term ID.
- Returns:
List of IDs of all the ancestors in the ontology.
- Return type:
list of str
- common_ancestor(go_id1, go_id2)
Returns the list of all the common ancestors in the ontology for the given GO Terms.
- Parameters:
go_id1 (str) – GO term ID 1.
go_id2 (str) – GO term ID 2.
- Returns:
List of IDs of all the common ancestors in the ontology.
- Return type:
list of str
- deepest_common_ancestor(go_id1, go_id2)
Returns the deepest common ancestor in the ontology for the given GO Terms.
- Parameters:
go_id1 (str) – GO term ID 1.
go_id2 (str) – GO term ID 2.
- Returns:
ID of the deepest common ancestor in the ontology.
- Return type:
Option<String>
- get_term_by_id(go_id)
Get the PyGOTerm object for a given GO term ID.
- Raises:
ValueError – If the GO term does not exist in the ontology.
- load_go_terms(path=None)
Load GO terms from an OBO file and cache them globally.
- Parameters:
path (Optional[str]) – Optional path to the OBO file.
- Returns:
List of GO terms as Python objects.
- Return type:
list of PyGOTerm