Ontology
The Ontology is provided as a singleton. It must be instantiated once to load all terms and annotations. Afterwards, the complete Ontology is available from the global scope across all submodules.
Instantiation
The Ontology must be instantiated once in every running program. This loads all HPO terms, their connections and annotation into memory.
Arguments
- data_folder: str
Path to the source files (default: None) Leave blank to load the builtin Ontology (recommended)
- from_obo_file: bool
Whether the input format is the standard from Jax HPO (default True)
Examples
from pyhpo import Ontology
Ontology()
term = Ontology.hpo(11968)
term.name() # ==> 'Feeding difficulties'
term.id() # ==> 'HP:0011968'
int(tern) # ==> 11968
# Altenatively, you can use direct access to HPOTerms:
term = Ontology[11968]
# ...
The following code with multiple modules works, because the Ontology must only be loaded once:
File main.py
from pyhpo import Ontology
import submodule
from submodule import foo
Ontology()
foo()
submodule.bar()
File submodule.py
from pyhpo import Ontology
def foo():
print(len(Ontology))
def bar():
print(len(Ontology))
Attributes
- __class__.genes
A list of all genes included in the ontology
- Returns
All genes that are associated to the
pyhpo.HPOTerm
in the ontology- Return type
list[
pyhpo.Gene
]
Important
The return type of this method will very likely change into an Iterator of
Gene
. (Info about likely API changes)- Raises
NameError – Ontology not yet constructed:
- __class__.omim_diseases
A list of all Omim Diseases included in the ontology
- Returns
All Omim diseases that are associated to the
pyhpo.HPOTerm
in the ontology- Return type
list[
pyhpo.Omim
]
Important
The return type of this method will very likely change into an Iterator of
Omim
. (Info about likely API changes)- Raises
NameError – Ontology not yet constructed:
Methods
- get_hpo_object(self, /, query)
Returns a single HPOTerm based on its name, synonym or id
- Parameters
query (str or int) –
str HPO term (e.g.:
Scoliosis
)str HPO-ID (e.g.:
HP:0002650
)int HPO term id (e.g.:
2650
)
- Returns
A single matching HPO term instance
- Return type
- Raises
NameError – Ontology not yet constructed
RuntimeError – No HPO term is found for the provided query
TypeError – The provided query is an unsupported type and can’t be properly converted
ValueError – The provided HPO ID cannot be converted to the correct integer representation
Examples
from pyhpo import Ontology Ontology() # Search by ID (int) Ontology.get_hpo_object(3) # >> HP:0000003 | Multicystic kidney dysplasia # Search by HPO-ID (string) Ontology.get_hpo_object('HP:0000003') # >> HP:0000003 | Multicystic kidney dysplasia # Search by term (string) Ontology.get_hpo_object('Multicystic kidney dysplasia') # >> HP:0000003 | Multicystic kidney dysplasia
- match(self, /, query)
Returns a single HPOTerm based on its name
- Parameters
query (str) – Name of the HPO term, e.g.
Scoliosis
- Returns
A single matching HPO term instance
- Return type
- Raises
NameError – Ontology not yet constructed
RuntimeError – No HPO term is found for the provided query
Examples
from pyhpo import Ontology Ontology() Ontology.match('Multicystic kidney dysplasia') # >>> HP:0000003 | Multicystic kidney dysplasia
- path(self, /, query1, query2)
Returns the shortest path from one to another HPO Term
- Parameters
query1 (str or int) – Name, HPO-ID (HP:0040064) or integer ID of source term e.g:
Abnormality of the nervous system
query2 (str or int) – Name, HPO-ID (HP:0040064) or integer ID of target term e.g:
Abnormality of the nervous system
- Returns
int – Length of path
list – List of HPOTerms in the path
int – Number of steps from term1 to the common parent (Not implemented. Returns
0
)int – Number of steps from term2 to the common parent (Not implemented. Returns
0
)
- Raises
NameError – Ontology not yet constructed
RuntimeError – No HPO term is found for the provided query
TypeError – The provided query is an unsupported type and can’t be properly converted
ValueError – The provided HPO ID cannot be converted to the correct integer representation
Examples
from pyhpo import Ontology Ontology() Ontology.path(40064, 'Multicystic kidney dysplasia') # >> ( # >> 8, # >> [ # >> <HpoTerm (HP:0040064)>, <HpoTerm (HP:0000118)>, # >> <HpoTerm (HP:0000119)>, <HpoTerm (HP:0000079)>, # >> <HpoTerm (HP:0010935)>, <HpoTerm (HP:0000077)>, # >> <HpoTerm (HP:0012210)>, <HpoTerm (HP:0000107)>, # >> <HpoTerm (HP:0000003)> # >> ], # >> 0, # >> 0 # >> )
- search(self, /, query)
Returns a list of HPOTerms that match the query
- Parameters
query (str) – Query for substring search of HPOTerms
- Returns
All terms matching the query string
- Return type
list[
HPOTerm
]
Important
The return type of this method will very likely change into an Iterator of
HPOTerm
. (Info about likely API changes)- Raises
NameError – Ontology not yet constructed
Examples
from pyhpo import Ontology Ontology() for term in Ontology.search("kidney dis"): print(term) # >> HP:0003774 | Stage 5 chronic kidney disease # >> HP:0012622 | Chronic kidney disease # >> HP:0012623 | Stage 1 chronic kidney disease # >> HP:0012624 | Stage 2 chronic kidney disease # >> HP:0012625 | Stage 3 chronic kidney disease # >> HP:0012626 | Stage 4 chronic kidney disease
- hpo(self, /, id)
Returns the HpoTerm with the provided id
- Parameters
id (int) – ID of the term as int (
HP:0000123
–>123
)- Returns
The HPO-Term
- Return type
- Raises
NameError – Ontology not yet constructed
KeyError – No HPO term is found for the provided query
Examples
from pyhpo import Ontology Ontology() term = Ontology.hpo(11968) term.name() # >> 'Feeding difficulties' term.id() # >> 'HP:0011968' int(tern) # >> 11968
- version(self, /)
Returns the HPO version
- Returns
The HPO version, e.g.
2023-04-05
- Return type
str
- Raises
NameError – Ontology not yet constructed
Examples
from pyhpo import Ontology Ontology() Ontology.version() # >> "2023-04-05"