OLS wrapper¶
OLS API wrapper
- Original code borrowed from
- https://github.com/cthoyt/ols-client/blob/master/src/ols_client/client.py
- Removed ontology and term methods.
- Added details/parameters for all search methods
TODO: check input parameters are valid TODO: handle requests.exceptions.ConnectionError when traffic is too high and API goes down
-
class
ontoma.ols.
OlsClient
(ols_base=None, ontology=None, field_list=None, query_fields=None)[source]¶ Wraps the functions to query the Ontology Lookup Service.
>>> ols = OlsClient() >>> ols.search('asthma')[0]['iri'] 'http://purl.obolibrary.org/obo/NCIT_C28397'
You can search in other ontologies and pass all other parameters accepted by OLS
>>> ols.search('lung',ontology='uberon')[0]['iri'] 'http://purl.obolibrary.org/obo/UBERON_0002048'
besthit() simply returns the first element:
>>> ols.besthit('lung',ontology='uberon')['iri'] 'http://purl.obolibrary.org/obo/UBERON_0002048'
exact=True forces an exact match:
>>> ols.besthit('hypogammaglobulinemia',ontology='efo')['label'] 'Osteopetrosis - hypogammaglobulinemia'
>>> ols.besthit('hypogammaglobulinemia',ontology='efo',exact=True) is None True
>>> r = ols.search('asthma',ontology=['efo'],query_fields=['synonym'],field_list=['iri','label']) >>> r[0]['iri'] 'http://www.ebi.ac.uk/efo/EFO_0004591'
Find the label of its first ancestor:
>>> a = ols.get_ancestors('efo',r[0]['iri']) >>> a[0]['label'] 'asthma'
>>> r = ols.suggest('asthma', ontology=['efo','ordo','hpo']) >>> r[0]['autosuggest'] 'asthma'
>>> r= ols.select('asthma', ontology=['efo','ordo','hpo'],field_list=['iri']) >>> r[0]['iri'] 'http://www.ebi.ac.uk/efo/EFO_0000270'
>>> ols.search('Myofascial Pain Syndrome',ontology=['efo'])[0]['short_form'] 'EFO_1001054'
>>> [x['short_form'] for x in ols.select('alzheimer')[:2]] ['NCIT_C2866', 'NCIT_C38778']
You can also pass your favourite parameters at class instantiation:
>>> ot_ols = OlsClient(ontology=['efo'],field_list=['short_form']) >>> ot_ols.search('asthma')[0]['short_form'] 'EFO_0000270' >>> ot_ols.besthit('asthma')['short_form'] 'EFO_0000270'
-
get_ancestors
(ont, iri)[source]¶ Gets the data for a given term
Parameters: - ontology – The name of the ontology
- iri – The IRI of a term
-
get_term
(ontology, iri)[source]¶ Gets the data for a given term
Parameters: - ontology – The name of the ontology
- iri – The IRI of a term
-
search
(name, query_fields=None, ontology=None, field_list=None, exact=None, bytype='class')[source]¶ Searches the OLS with the given term
Parameters: - query_fields – By default the search is performed over term labels, synonyms, descriptions, identifiers and annotation properties. This option allows to specify the fields to query, the defaults are {label, synonym, description, short_form, obo_id, annotations, logical_description, iri}
- exact – Forces exact match if not None
- bytype – restrict to terms one of {class,property,individual,ontology}
-