webservices.ols¶
Lookup of ontology terms in the Ontology Lookup Service (OLS).
OLS resolves an ontology term to its label, description, synonyms and cross
references. RDFAnnotationData uses it to fill in what an annotation actually
refers to.
from pymetadata.webservices.ols import ONTOLOGIES, OLSQuery
query = OLSQuery(ontologies=ONTOLOGIES)
info = query.query_ols(ontology="chebi", term="CHEBI:33699")
print(query.process_response(info)["label"])
ONTOLOGIES lists the ontologies used in most projects together with the IRI
pattern needed to build the term IRI OLS expects.
See https://www.ebi.ac.uk/ols4.
OLSOntology
dataclass
¶
An ontology available in OLS.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
lowercase ontology id, e.g., |
iri_pattern |
str | None
|
pattern of the term IRI with the placeholder |
OLSQuery
¶
Queries against the Ontology Lookup Service.
Responses are cached on disk for CACHE_DURATION_ONTOLOGY hours, see
pymetadata.CACHE_USE. If OLS cannot be reached, cached content is used
however old it is.
Attributes:
| Name | Type | Description |
|---|---|---|
ontologies |
dict[str, OLSOntology]
|
the queryable ontologies by name |
cache_path |
directory of the cached responses |
|
cache |
whether responses are cached |
Initialize the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontologies
|
list[OLSOntology]
|
ontologies which can be queried, e.g., |
required |
cache_path
|
Path | None
|
directory for cached responses, defaults to
|
None
|
cache
|
bool | None
|
cache responses, defaults to |
None
|
get_iri
¶
Build the term IRI which OLS expects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology
|
str
|
ontology id, e.g., |
required |
term
|
str
|
term of the ontology, e.g., |
required |
Returns:
| Type | Description |
|---|---|
str
|
The IRI of the term, or an empty string for an unknown ontology. |
query_ols
¶
Query OLS for a single term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology
|
str | None
|
ontology id, e.g., |
required |
term
|
str | None
|
term of the ontology, e.g., |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The OLS response, with |
dict
|
with the query. |
process_response
¶
Reduce an OLS response to the information used for annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term
|
dict
|
OLS response from |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |