from ontquery.interlex import interlex_client
ilx_cli = interlex_client('test3.scicrunch.org')
ilx_cli.apiEndpoint
'https://test3.scicrunch.org/api/1'
ilx_cli_production = interlex_client('scicrunch.org')
ilx_cli_production.apiEndpoint
'https://scicrunch.org/api/1'
ilx_cli.ilx_cli._get('user/info').json()['data']
{'logged_in': True, 'first_name': 'troy', 'last_name': 'sincomb', 'role': 2, 'communities': [{'portalName': 'odc-sci', 'cid': 97, 'level': 1}, {'portalName': 'SPARC', 'cid': 134, 'level': 1}], 'labs': [{'cid': 97, 'id': 3, 'name': 'SciCrunch @ UCSD'}, {'cid': 97, 'id': 76, 'name': 'tmsincomb-lab'}], 'datasets': [], 'id': 34142}
# Exact Search with only 1 result back
list(ilx_cli.query(label='brain'))
[QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0101431', 'curie': 'ILX:0101431', 'label': 'Brain', 'labels': (), 'definition': 'The part of the central nervous system contained within the cranium, comprising the forebrain, midbrain, hindbrain, and metencephalon. It is derived from the anterior part of the embryonic neural tube (or the encephalon). Does not include retina. (CUMBO)The rostral topographic division of the cerebrospinal axis, while the caudal division is the spinal cord. The usual criterion for distinguishing the two divisions in the adult is that the vertebrate brain lies within the skull whereas the spinal cord lies within the spinal (vertebral) column, although this is a difficult problem. (Swanson, 2014)', 'synonyms': ({'literal': 'Encephalon', 'type': ''},), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>})]
[qr.asTerm() for qr in ilx_cli.query(label='brain')]
[QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0101431', 'curie': 'ILX:0101431', 'label': 'Brain', 'labels': (), 'definition': 'The part of the central nervous system contained within the cranium, comprising the forebrain, midbrain, hindbrain, and metencephalon. It is derived from the anterior part of the embryonic neural tube (or the encephalon). Does not include retina. (CUMBO)The rostral topographic division of the cerebrospinal axis, while the caudal division is the spinal cord. The usual criterion for distinguishing the two divisions in the adult is that the vertebrate brain lies within the skull whereas the spinal cord lies within the spinal (vertebral) column, although this is a difficult problem. (Swanson, 2014)', 'synonyms': ({'literal': 'Encephalon', 'type': ''},), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0101434', 'curie': 'ILX:0101434', 'label': 'Brain Ischemia', 'labels': (), 'definition': 'Localized reduction of blood flow to brain tissue due to arterial obstruction or systemic hypoperfusion. This frequently occurs in conjunction with brain hypoxia ( HYPOXIA, BRAIN). Prolonged ischemia is associated with BRAIN INFARCTION (MeSH).', 'synonyms': ({'literal': 'Ischemic Brain Injury', 'type': ''}, {'literal': 'Ischemic Encephalopathy', 'type': ''}), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0461406', 'curie': 'ILX:0461406', 'label': 'Brain Death', 'labels': (), 'definition': 'A state of prolonged irreversible cessation of all brain activity, including lower brain stem function with the complete absence of voluntary movements, responses to stimuli, brain stem reflexes, and spontaneous respirations. Reversible conditions which mimic this clinical state (e.g., sedative overdose, hypothermia, etc.) are excluded prior to making the determination of brain death. (From Adams et al., Principles of Neurology, 6th ed, pp348-9)', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0733041', 'curie': 'ILX:0733041', 'label': 'brain endothelium', 'labels': (), 'definition': 'Vascular endothelium found in blood vessels of the blood-brain-barrier.', 'synonyms': ({'literal': 'cerebromicrovascular endothelium', 'type': 'oboInOwl:hasRelatedSynonym'},), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0732724', 'curie': 'ILX:0732724', 'label': 'embryonic brain', 'labels': (), 'definition': 'Brain of the embryo.', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0506443', 'curie': 'ILX:0506443', 'label': 'Brain Embolism', 'labels': (), 'definition': '', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0400525', 'curie': 'ILX:0400525', 'label': 'Brain Thrombus', 'labels': (), 'definition': '', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0506479', 'curie': 'ILX:0506479', 'label': 'Brain Thrombosis', 'labels': (), 'definition': '', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0489948', 'curie': 'ILX:0489948', 'label': 'Brain Waves', 'labels': (), 'definition': 'Wave-like oscillations of electric potential between parts of the brain recorded by EEG.', 'synonyms': (), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>}), QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0730602', 'curie': 'ILX:0730602', 'label': 'brain ventricle', 'labels': (), 'definition': 'one of the system of communicating cavities in the brain that are continuous with the central canal of the spinal cord, that like it are derived from the medullary canal of the embryo, that are lined with an epithelial ependyma, and that contain a serous fluid', 'synonyms': ({'literal': 'cerebral ventricle', 'type': 'oboInOwl:hasExactSynonym'}, {'literal': 'region of ventricular system of brain', 'type': 'oboInOwl:hasExactSynonym'}, {'literal': 'brain ventricles', 'type': 'oboInOwl:hasExactSynonym'}), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>})]
# General Search through elasticsearch & SciGraph
list(ilx_cli.query(term='brain'))
QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0101431', 'curie': 'ILX:0101431', 'label': 'Brain', 'labels': (), 'definition': 'The part of the central nervous system contained within the cranium, comprising the forebrain, midbrain, hindbrain, and metencephalon. It is derived from the anterior part of the embryonic neural tube (or the encephalon). Does not include retina. (CUMBO)The rostral topographic division of the cerebrospinal axis, while the caudal division is the spinal cord. The usual criterion for distinguishing the two divisions in the adult is that the vertebrate brain lies within the skull whereas the spinal cord lies within the spinal (vertebral) column, although this is a difficult problem. (Swanson, 2014)', 'synonyms': ({'id': '1781408', 'tid': '1432', 'literal': 'Encephalon', 'type': '', 'time': '1598039945', 'version': '10'},), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>})
ilx_cli.get_entity('ilx_0101431')
QueryResult({'iri': 'http://uri.interlex.org/base/ilx_0101431', 'curie': 'ILX:0101431', 'label': 'Brain', 'labels': (), 'definition': 'The part of the central nervous system contained within the cranium, comprising the forebrain, midbrain, hindbrain, and metencephalon. It is derived from the anterior part of the embryonic neural tube (or the encephalon). Does not include retina. (CUMBO)The rostral topographic division of the cerebrospinal axis, while the caudal division is the spinal cord. The usual criterion for distinguishing the two divisions in the adult is that the vertebrate brain lies within the skull whereas the spinal cord lies within the spinal (vertebral) column, although this is a difficult problem. (Swanson, 2014)', 'synonyms': ({'id': '1781408', 'tid': '1432', 'literal': 'Encephalon', 'type': '', 'time': '1598039945', 'version': '10'},), 'deprecated': None, 'predicates': {}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fa564a27dc0>})
ilx_cli.add_entity?
Signature: ilx_cli.add_entity( label: str, type: str, subThingOf: str, definition: str = None, comment: str = None, cid: Union[str, int] = None, synonyms: Union[List[dict], List[str]] = None, existing_ids: List[dict] = None, predicates: dict = None, **kwargs, ) -> ontquery.utils.QueryResult Docstring: Add InterLex entity :param label: Preferred name of entity. :param type: Any of the following: term, TermSet, cde, pde, fde, relationship, annotation. :param cid: Community ID :param definition: Entities official definition. :param comment: A foot note regarding either the interpretation of the data or the data itself :param subThingOf: The ilx_id of the parent of this entity. Example: Organ is a superclass to Brain :param synonyms: Alternate names of the label. :param existing_ids: Alternate/source ontological iri/curies. Can only be one preferred ID. :param predicates: Annotations and/or Relationships to be added. :return: requests.Response of insert or query from existing. >>> self.add_entity( 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', synonyms=[{ 'literal': 'Brains', # label of synonym 'type': 'obo:hasExactSynonym', # Often predicate defined in ref ontology. }], existing_ids=[{ 'iri': 'http://purl.obolibrary.org/obo/UBERON_0000955', 'curie': 'UBERON:0000955', # Obeys prefix:id structure. 'preferred': '1', # Can be 0 or 1 with a type of either str or int. }], predicates={ # Annotation 'http://uri.interlex.org/base/ilx_0101432': 'sample_annotation_value', # Relationship 'http://uri.interlex.org/base/ilx_0101435': 'http://uri.interlex.org/base/ilx_0101434', }, ) File: ~/Dropbox/git/ontquery/ontquery/plugins/services/interlex.py Type: method
import string
import random
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
random_label = 'test_' + id_generator(size=12)
entity = {
'label': random_label,
'type': 'term', # broken at the moment NEEDS PDE HARDCODED
'definition': 'Part of the central nervous system',
# 'comment': 'Cannot live without it',
'subThingOf': 'http://uri.interlex.org/base/tmp_0738397', # ILX ID for Organ
'synonyms': ['Encephalon', 'Cerebro'],
'predicates': {
'http://uri.interlex.org/base/tmp_0738407': 'sample_value', # spont firing beta ID | annotation
'http://uri.interlex.org/base/tmp_0738408': 'http://uri.interlex.org/base/tmp_0738406', # relationship
}
}
result = ilx_cli.add_entity(**entity)
print(result)
[2020-08-12 13:37:20,684] - WARNING - ontquery - interlex_client.py:793 - Annotation: [test_DY0F652BGCZU -> test_K8KAGD9D0QOQ -> sample_value], already exists. [2020-08-12 13:37:22,470] - WARNING - ontquery - interlex_client.py:904 - relationship: [test_DY0F652BGCZU -> test_67M6YEYODK3V -> troy_test_term], already exists.
QueryResult({'iri': 'http://uri.interlex.org/base/tmp_0741934', 'curie': 'TMP:0741934', 'label': 'test_DY0F652BGCZU', 'labels': (), 'definition': 'Part of the central nervous system', 'synonyms': ({'id': '1780663', 'tid': '664039', 'literal': 'Encephalon', 'type': '', 'time': '1597264636', 'version': '1'}, {'id': '1780664', 'tid': '664039', 'literal': 'Cerebro', 'type': '', 'time': '1597264636', 'version': '1'}), 'deprecated': None, 'predicates': {'comment': ''}, 'type': None, 'types': (), '_graph': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7ff6b0044b80>})
ilx_cli.update_entity?
Object `ilx_cli.update_entity` not found.
entity = {
'ilx_id': result['curie'],
'label': 'label_update',
# 'type': 'term', # broken at the moment NEEDS PDE HARDCODED
'definition': 'Updated definition!',
# 'comment': 'Cannot live without it UPDATE',
'subThingOf': 'http://uri.interlex.org/base/tmp_0738406', # ILX ID for Organ
'add_synonyms': ['Encephalon', 'Cerebro_update'],
'predicates_to_add': {
# DUPCLICATE CHECK
'http://uri.interlex.org/base/tmp_0738407': 'sample_value', # spont firing beta ID | annotation
'http://uri.interlex.org/base/tmp_0738407': 'sample_value2', # spont firing beta ID | annotation
'http://uri.interlex.org/base/tmp_0738408': 'http://uri.interlex.org/base/tmp_0738409' # relationship
},
'predicates_to_delete': {
# DELETE ORIGINAL
'http://uri.interlex.org/base/tmp_0738407': 'sample_value', # spont firing beta ID | annotation
'http://uri.interlex.org/base/tmp_0738408': 'http://uri.interlex.org/base/tmp_0738409', # relationship
}
}
result = ilx_cli.update_entity(**entity)
print(result)
[2020-08-03 22:51:27,167] - WARNING - ontquery - interlex_client.py:790 - Annotation: [label_update -> test_K8KAGD9D0QOQ -> sample_value2], already exists. [2020-08-03 22:51:28,644] - WARNING - ontquery - interlex_client.py:901 - relationship: [label_update -> test_67M6YEYODK3V -> test_5YMGMUGWAKY5], already exists.
QueryResult({'iri': 'http://uri.interlex.org/base/tmp_0741837', 'curie': 'TMP:0741837', 'label': 'label_update', 'labels': (), 'definition': 'Updated definition!', 'synonyms': ('Encephalon', 'Cerebro', 'Cerebro_update'), 'deprecated': None, 'predicates': {'comment': 'Cannot live without it UPDATE'}, 'type': None, 'types': (), '_graph': None, '_blob': None, 'source': <ontquery.plugins.services.interlex.InterLexRemote object at 0x7fd3540f9a90>})
ilx_cli.ilx_cli.partial_update?
Signature: ilx_cli.ilx_cli.partial_update( curie: str = None, definition: str = None, comment: str = None, superclass: str = None, synonyms: List[dict] = None, existing_ids: List[dict] = None, ) -> dict Docstring: Update entity field only if the reference field is empty. :param curie: Curie of entity within existing ids. :param definition: Entities official definition. :param comment: A foot note regarding either the interpretation of the data or the data itself :param superclass: The ilx_id of the parent of this entity. Example: Organ is a superclass to Brain :param synonyms: Alternate names of the label. :param existing_ids: Alternate/source ontological iri/curies. Can only be one preferred ID. File: ~/Dropbox/git/ontquery/ontquery/plugins/services/interlex_client.py Type: method
partial_update = ilx_cli.ilx_cli.partial_update(curie=result['curie'], comment='updated definition!')
partial_update['comment']
'updated definition!'
partial_update = ilx_cli.ilx_cli.partial_update(curie=result['curie'], comment='updated definition please?!')
partial_update['comment']
'updated definition!'