ontquery


Nameontquery JSON
Version 0.2.11 PyPI version JSON
download
home_pagehttps://github.com/tgbugs/ontquery
Summarya framework querying ontology terms
upload_time2022-12-23 06:18:11
maintainer
docs_urlNone
authorTom Gillespie
requires_python>=3.6
licenseMIT
keywords ontology terminology scigraph interlex term lookup ols
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            # ontquery
[![PyPI version](https://badge.fury.io/py/ontquery.svg)](https://pypi.org/project/ontquery/)
[![Build Status](https://travis-ci.com/tgbugs/ontquery.svg?branch=master)](https://travis-ci.com/tgbugs/ontquery)
[![Coverage Status](https://coveralls.io/repos/github/tgbugs/ontquery/badge.svg?branch=master)](https://coveralls.io/github/tgbugs/ontquery?branch=master)

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](https://packaging.python.org/tutorials/installing-packages/#installing-setuptools-extras) 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](https://scicrunch.org/register) and then [get an api key](https://scicrunch.org/account/developer).

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
```python
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
```
```python
list(query('mouse'))
```
3 potential matches are shown:
```python
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:

```python
from ontquery.interlex import interlex_client
```

##### Setup for **TEST**:
*This Should be used to test if your code works first*

```python
ilx_cli = interlex_client('test3.scicrunch.org')
```

##### Setup for **PRODUCTION**:

```python
ilx_cli = interlex_client('scicrunch.org')
```

##### Adding Entity Needed:

```python
added_entity_data = ilx_cli.add_entity(
    label = '',
    type = '', # term, fde, cde, pde, relationship, annotation
)
```

#### Adding Entity Example

```python
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

```python
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 
)
```
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tgbugs/ontquery",
    "name": "ontquery",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "ontology terminology scigraph interlex term lookup ols",
    "author": "Tom Gillespie",
    "author_email": "tgbugs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6e/fe/51445344fdac9ef69063ca69bccc03f0dc743f9490b91b765e23a865ce88/ontquery-0.2.11.tar.gz",
    "platform": null,
    "description": "# ontquery\n[![PyPI version](https://badge.fury.io/py/ontquery.svg)](https://pypi.org/project/ontquery/)\n[![Build Status](https://travis-ci.com/tgbugs/ontquery.svg?branch=master)](https://travis-ci.com/tgbugs/ontquery)\n[![Coverage Status](https://coveralls.io/repos/github/tgbugs/ontquery/badge.svg?branch=master)](https://coveralls.io/github/tgbugs/ontquery?branch=master)\n\na framework querying ontology terms\n\n# Installation\nOntquery supports two different use cases each with their own installation instructions.  \n\nBy default ontquery installs only the stripped down core libraries so that it can be embedded an reused in\nother applications that need to reduce their dependnecies. For this use case packages can include ontquery\nas a dependency in their package requirements without any special changes e.g. `ontquery>=0.0.6`.  \n\nThe second use case enables remote services via a plugin infrastructure.\nTo install this version you should install or require using the [pip extras syntax](https://packaging.python.org/tutorials/installing-packages/#installing-setuptools-extras) e.g. `pip install \"ontquery[services]\"`.\n\n# SciCrunch api key\nIf 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`).\n\nTo do this go to SciCrunch and [register for an account](https://scicrunch.org/register) and then [get an api key](https://scicrunch.org/account/developer).\n\nYou can then set the `SCICRUNCH_API_KEY` environment variable.\nFor example in bash `export SCICRUNCH_API_KEY=my-api-key`.\n\nSee https://github.com/tgbugs/ontquery/blob/db8cad7463704bce9010651c3744452aa5370114/ontquery/__init__.py#L557-L558 for how to pass the key in.\n\n# SciGraphRemote Usage\n```python\nfrom ontquery import OntQuery, OntTerm, OntCuries\nfrom ontquery.plugins.namespaces.nifstd import CURIE_MAP\nfrom ontquery.plugins.services.scigraph import SciGraphRemote\n\ncuries = OntCuries(CURIE_MAP)\nquery = OntQuery(SciGraphRemote(), instrumented=OntTerm)\nOntTerm.query = query\n```\n```python\nlist(query('mouse'))\n```\n3 potential matches are shown:\n```python\nQuery {'term': 'mouse', 'limit': 10} returned more than one result. Please review.\n\nOntTerm('NCBITaxon:10090', label='Mus musculus', synonyms=['mouse', 'house mouse', 'mice C57BL/6xCBA/CaJ hybrid', 'Mus muscaris'])\n\nOntTerm('NCBITaxon:10088', label='Mus <mouse, genus>', synonyms=['mouse', 'Mus', 'mice'])\n\nOntTerm('BIRNLEX:167', label='Mouse', synonyms=['mouse', 'Mus musculus', 'house mouse'])\n```\n\nThe one we are looking for is `Mus musculus`, and we can select that with\n`OntTerm('NCBITaxon:10090', label='Mus musculus')` or with `OntTerm(curie='NCBITaxon:10090')`.\n\nThis workflow works for a variety of categories:\n* species (e.g. 'mouse', 'rat', 'rhesus macaque')\n* brain area (e.g. 'hippocampus', 'CA1', 'S1')\n* cell type (e.g. 'mossy cell', 'pyramidal cell')\n* institution (e.g. 'UC San Francisco', 'Brown University')\n* disease (e.g. \"Parkinson's Disease\", 'ALS')\n\n# Building for release\n`python setup.py sdist --release && python setup.py bdist_wheel --universal --release`\nBuilding a release requires a working install of pyontutils in order to build the\nscigraph client library. The `--release` tells setup to build the scigraph client.\n\n# Related issues\n\nhttps://github.com/NeurodataWithoutBorders/nwb-schema/issues/1#issuecomment-368741867\n\nhttps://github.com/NeurodataWithoutBorders/nwb-schema/issues/1#issuecomment-369215854\n\n# InterlexRemote Notes\nilx_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.\n\n# InterLexRemote Usage\nTo access InterLex programatically you can set `SCICRUNCH_API_KEY` or\nyou can set `INTERLEX_API_KEY` either will work, but `INTERLEX_API_KEY`\nhas priority if both are set.\n\n##### Importing:\n\n```python\nfrom ontquery.interlex import interlex_client\n```\n\n##### Setup for **TEST**:\n*This Should be used to test if your code works first*\n\n```python\nilx_cli = interlex_client('test3.scicrunch.org')\n```\n\n##### Setup for **PRODUCTION**:\n\n```python\nilx_cli = interlex_client('scicrunch.org')\n```\n\n##### Adding Entity Needed:\n\n```python\nadded_entity_data = ilx_cli.add_entity(\n    label = '',\n    type = '', # term, fde, cde, pde, relationship, annotation\n)\n```\n\n#### Adding Entity Example\n\n```python\nadded_entity_data = ilx_cli.add_entity(\n    label = 'Label of entity you wish to create',\n    type = 'A type that should be one of the following: term, relationship, annotation, cde, fde, pde',\n    # subThingOf can take either iri or curie form of ID\n    subThingOf = 'http://uri.interlex.org/base/ilx_0108124', # superclass or subClassOf ILX ID\n    definition = 'Entities definition',\n    comment = 'A comment to help understand entity',\n    synonyms = ['synonym1', {'literal': 'synonym2', 'type': 'hasExactSynonym'}, 'etc'],\n    # exisiting IDs are List[dict] with keys iri & curie\n    existing_ids = [{'iri':'https://example.org/example_1', 'curie':'EXAMPLE:1'}],\n    cid = 504,  # community ID\n    predicates = {\n        # annotation_entity_ilx_id : 'annotation_value',\n        'http://uri.interlex.org/base/tmp_0381624': 'PMID:12345', # annotation\n        # relationship_entity_ilx_id : 'entity2_ilx_id',\n        'http://uri.interlex.org/base/ilx_0112772': 'http://uri.interlex.org/base/ilx_0100001', # relationship\n    }\n)\n```\n\n#### Updating Entity Example\n\n```python\nupdated_entity = update_entity( \n    ilx_id='ilx_1234567', \n    label='Brain', \n    type='term',  # options: term, pde, fde, cde, annotation, or relationship \n    definition='Official definition for entity.', \n    comment='Additional casual notes for the next person.', \n    superclass='ilx_1234567', \n    add_synonyms=[{ \n        'literal': 'Better Brains',  # label of synonym \n        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. \n    }], \n    delete_synonyms=[{ \n        'literal': 'Brains',  # label of synonym \n        'type': 'obo:hasExactSynonym',  # Often predicate defined in ref ontology. \n    }], \n    add_existing_ids=[{ \n        'iri': 'http://purl.obolibrary.org/obo/UBERON_0000956', \n        'curie': 'UBERON:0000956',  # Obeys prefix:id structure. \n        'preferred': '1',  # Can be 0 or 1 with a type of either str or int. \n    }], \n    delet_existing_ids=[{ \n        'iri': 'http://purl.obolibrary.org/obo/UBERON_0000955', \n        'curie': 'UBERON:0000955',  # Obeys prefix:id structure. \n    }], \n    cid='504',  # SPARC Community, \n    status='0',  # remove delete \n)\n```\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "a framework querying ontology terms",
    "version": "0.2.11",
    "split_keywords": [
        "ontology",
        "terminology",
        "scigraph",
        "interlex",
        "term",
        "lookup",
        "ols"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "62f92a69cbdabf965ec281178b404d4d",
                "sha256": "ceb7f14b586221d4b5139f39e337186659a8ccb3ce6cc3182d496ebef92e9eee"
            },
            "downloads": -1,
            "filename": "ontquery-0.2.11-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62f92a69cbdabf965ec281178b404d4d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 63534,
            "upload_time": "2022-12-23T06:18:09",
            "upload_time_iso_8601": "2022-12-23T06:18:09.224196Z",
            "url": "https://files.pythonhosted.org/packages/7a/c8/14887867b41274f90d6ba6368b8a0fc5b333909013e05464793ac6980239/ontquery-0.2.11-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "956573f3b5e758cbb09d59b3c2a5e6f6",
                "sha256": "2bd1e4934a165689bcca609def5f3ecc62369519e42838816d01ed4ddaf79841"
            },
            "downloads": -1,
            "filename": "ontquery-0.2.11.tar.gz",
            "has_sig": false,
            "md5_digest": "956573f3b5e758cbb09d59b3c2a5e6f6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 81605,
            "upload_time": "2022-12-23T06:18:11",
            "upload_time_iso_8601": "2022-12-23T06:18:11.048432Z",
            "url": "https://files.pythonhosted.org/packages/6e/fe/51445344fdac9ef69063ca69bccc03f0dc743f9490b91b765e23a865ce88/ontquery-0.2.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-23 06:18:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "tgbugs",
    "github_project": "ontquery",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "lcname": "ontquery"
}
        
Elapsed time: 0.02144s