Skip to main content

a framework querying ontology terms

Project description


PyPI version Build Status Coverage Status

a framework querying ontology terms


Ontquery supports two different use cases each with their own installation instructions.

By default ontquery installs only the stripped down core libraries so that it can be embedded an reused in other applications that need to reduce their dependnecies. For this use case packages can include ontquery as a dependency in their package requirements without any special changes e.g. ontquery>=0.0.6.

The second use case enables remote services via a plugin infrastructure. To install this version you should install or require using the pip extras syntax e.g. pip install ontquery[services]>=0.6.0.

SciCrunch api key

If you don't have your own SciGraph instance you will need a SciCunch API key in order to run the demos (e.g. python

To do this go to SciCrunch and register for an account and then get an api key.

You can then set the SCICRUNCH_API_KEY environment variable. For example in bash export SCICRUNCH_API_KEY=my-api-key.

See for how to pass the key in.

SciGraphRemote Usage

from ontquery import OntQuery, SciGraphRemote, OntTerm, OntCuries
from ontquery.plugins.namespaces import CURIE_MAP

curies = OntCuries(CURIE_MAP)
query = OntQuery(SciGraphRemote())
OntTerm.query = query

3 potential matches are shown:

Query {'term': 'mouse', 'limit': 10} returned more than one result. Please review.

OntTerm('NCBITaxon:10090', label='Mus musculus', synonyms=['mouse', 'house mouse', 'mice C57BL/6xCBA/CaJ hybrid', 'Mus muscaris'])

OntTerm('NCBITaxon:10088', label='Mus <mouse, genus>', synonyms=['mouse', 'Mus', 'mice'])

OntTerm('BIRNLEX:167', label='Mouse', synonyms=['mouse', 'Mus musculus', 'house mouse'])

The one we are looking for is Mus musculus, and we can select that with OntTerm('NCBITaxon:10090', label='Mus musculus') or with OntTerm(curie='NCBITaxon:10090').

This workflow works for a variety of categories:

  • species (e.g. 'mouse', 'rat', 'rhesus macaque')
  • brain area (e.g. 'hippocampus', 'CA1', 'S1')
  • cell type (e.g. 'mossy cell', 'pyramidal cell')
  • institution (e.g. 'UC San Francisco', 'Brown University')
  • disease (e.g. "Parkinson's Disease", 'ALS')

Building for release

python sdist --release && python bdist_wheel --universal --release Building a release requires a working install of pyontutils in order to build the scigraph client library. The --release tells setup to build the scigraph client.

Related issues

InterlexRemote Notes

ilx_id and any key that takes a uri value can also be given a curie of that uri or a fragment and it will still work.

InterLexRemote Usage

To access InterLex programatically you can set SCICRUNCH_API_KEY or you can set INTERLEX_API_KEY either will work, but INTERLEX_API_KEY has priority if both are set.

from ontquery.interlex import interlex_client
Setup for TEST:

This Should be used to test if your code works first

ilx_cli = interlex_client('')
ilx_cli = interlex_client('')
Adding Entity Needed:
added_entity_data = ilx_cli.add_entity(
    label = '',
    type = '', # term, fde, cde, pde, relationship, annotation

Adding Entity Example

added_entity_data = ilx_cli.add_entity(
    label = 'Label of entity you wish to create',
    type = 'A type that should be one of the following: term, relationship, annotation, cde, fde, pde',
    # subThingOf can take either iri or curie form of ID
    subThingOf = '', # superclass or subClassOf ILX ID
    definition = 'Entities definition',
    comment = 'A comment to help understand entity',
    synonyms = ['synonym1', {'literal': 'synonym2', 'type': 'hasExactSynonym'}, 'etc'],
    # exisiting IDs are List[dict] with keys iri & curie
    existing_ids = [{'iri':'', 'curie':'EXAMPLE:1'}],
    cid = 504,  # community ID
    predicates = {
        # annotation_entity_ilx_id : 'annotation_value',
        '': 'PMID:12345', # annotation
        # relationship_entity_ilx_id : 'entity2_ilx_id',
        '': '', # relationship

Updating Entity Example

updated_entity = update_entity( 
    type='term',  # options: term, pde, fde, cde, annotation, or relationship 
    definition='Official definition for entity.', 
    comment='Additional casual notes for the next person.', 
        'literal': 'Better Brains',  # label of synonym 
        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. 
        'literal': 'Brains',  # label of synonym 
        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. 
        'iri': '', 
        'curie': 'UBERON:0000956',  # Obeys prefix:id structure. 
        'preferred': '1',  # Can be 0 or 1 with a type of either str or int. 
        'iri': '', 
        'curie': 'UBERON:0000955',  # Obeys prefix:id structure. 
    cid='504',  # SPARC Community, 
    status='0',  # remove delete 

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ontquery, version 0.2.8
Filename, size File type Python version Upload date Hashes
Filename, size ontquery-0.2.8-py2.py3-none-any.whl (63.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size ontquery-0.2.8.tar.gz (80.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page