Skip to main content

ontquery

PyPI version Build Status Coverage Status

a framework querying ontology terms

Installation

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]".

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 __init__.py).

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 https://github.com/tgbugs/ontquery/blob/db8cad7463704bce9010651c3744452aa5370114/ontquery/__init__.py#L557-L558 for how to pass the key in.

SciGraphRemote Usage

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

curies = OntCuries(CURIE_MAP)
query = OntQuery(SciGraphRemote(), instrumented=OntTerm)
OntTerm.query = query
list(query('mouse'))

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 setup.py sdist --release && python setup.py 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

https://github.com/NeurodataWithoutBorders/nwb-schema/issues/1#issuecomment-368741867

https://github.com/NeurodataWithoutBorders/nwb-schema/issues/1#issuecomment-369215854

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.

Importing:
from ontquery.interlex import interlex_client
Setup for TEST:

This Should be used to test if your code works first

ilx_cli = interlex_client('test3.scicrunch.org')
Setup for PRODUCTION:
ilx_cli = interlex_client('scicrunch.org')
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 = 'http://uri.interlex.org/base/ilx_0108124', # 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':'https://example.org/example_1', 'curie':'EXAMPLE:1'}],
    cid = 504,  # community ID
    predicates = {
        # annotation_entity_ilx_id : 'annotation_value',
        'http://uri.interlex.org/base/tmp_0381624': 'PMID:12345', # annotation
        # relationship_entity_ilx_id : 'entity2_ilx_id',
        'http://uri.interlex.org/base/ilx_0112772': 'http://uri.interlex.org/base/ilx_0100001', # relationship
    }
)

Updating Entity Example

updated_entity = update_entity( 
    ilx_id='ilx_1234567', 
    label='Brain', 
    type='term',  # options: term, pde, fde, cde, annotation, or relationship 
    definition='Official definition for entity.', 
    comment='Additional casual notes for the next person.', 
    superclass='ilx_1234567', 
    add_synonyms=[{ 
        'literal': 'Better Brains',  # label of synonym 
        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. 
    }], 
    delete_synonyms=[{ 
        'literal': 'Brains',  # label of synonym 
        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. 
    }], 
    add_existing_ids=[{ 
        'iri': 'http://purl.obolibrary.org/obo/UBERON_0000956', 
        'curie': 'UBERON:0000956',  # Obeys prefix:id structure. 
        'preferred': '1',  # Can be 0 or 1 with a type of either str or int. 
    }], 
    delet_existing_ids=[{ 
        'iri': 'http://purl.obolibrary.org/obo/UBERON_0000955', 
        'curie': 'UBERON:0000955',  # Obeys prefix:id structure. 
    }], 
    cid='504',  # SPARC Community, 
    status='0',  # remove delete 
)

Release files for ontquery 0.2.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ontquery 0.2.12
File Size Uploaded
ontquery-0.2.12.tar.gz 82.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ontquery 0.2.12
File Interpreter ABI Platform
ontquery-0.2.12-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 146.0 kB

Release files / ontquery-0.2.12.tar.gz

Download URL ontquery-0.2.12.tar.gz
Size 82.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c81a0cea9612787f90d55b01b0045da5cf7b0d18e48be1a9799abf2d9d93f698
BLAKE2b-256 checksum
How to use checksums
adef7a09386312ae86176af96058a380b5bd415fd27d7bad8c25abdb3eece171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / ontquery-0.2.12-py2.py3-none-any.whl

Download URL ontquery-0.2.12-py2.py3-none-any.whl
Size 63.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4df8b4b5623ad2e796f02966a2247437c71814697aca3164d3714a3abef77f8c
BLAKE2b-256 checksum
How to use checksums
252d7ceba858b53543556791aae543d07c5aa3b47884377acae4398ade3b2fbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.2.12 This release

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page