diff --git a/README.md b/README.md index bdb0f72..52e2882 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,13 @@ ### Tools Available: -## UberOnto API -### version h-bar/2 - -``` -updates to follow -``` - ## Onto API -### To edit/execute Onto API locally: +Onto is a facility which aggregates lookup services that provide generic facts about ontologies. It leverages the Uberongraph RDB (a SPARQL-queried Uberongraph available at https://stars-app.renci.org/uberongraph/#query) for data. + +### To edit/execute/test Onto API locally: ``` +- TO EDIT: $git clone git@github.com:NCATS-Translator/reasoner-tools - make a virtual env and activate it, recommended as follows: @@ -22,21 +18,41 @@ $source YOUR_ENV_NAME/bin/activate $cd reasoner-tools +Make functionality changes in greent/services/ontology.py +Make front-end changes in greent/api/onto_gunicorn.py +The above two files should be considered in tandem. + +Add unit test cases to greent/test/test_ontology.py + + +- TO RUN: $pip install -r greent/requirements.txt $export greent_conf=greent/greent.conf -- TO RUN: $gunicorn onto_gunicorn:app --workers 1 --pythonpath=$PWD/greent/api -navigate to http://127.0.0.1:8000/apidocs +Navigate in your browser to http://127.0.0.1:8000/apidocs. + -make functionality changes in greent/services/ontology.py -make front-end changes in greent/api/onto.py -the above two files should be considered in tandem +- TO TEST: +$cd reasoner-tools + +- To run all unit tests: +pytest greent/test/test_ontology.py + +- Remove warnings and get more information as tests run: +pytest -p no:warnings -vv greent/test/test_ontology.py + +- Run a single unit test: +pytest greent/test/test_ontology.py -k +pytest greent/test/test_ontology.py -k test_label ``` ## BioNames API +BioNames is a generic facility which aggregates bio-ontology lookup services. It retrieve names from IDs or IDs based on Natural Language names. +### To edit/execute/test BioNames API locally: ``` +- TO EDIT: $git clone git@github.com:NCATS-Translator/reasoner-tools - make a virtual env and activate it, recommended as follows: @@ -45,13 +61,30 @@ $source YOUR_ENV_NAME/bin/activate $cd reasoner-tools +Make functionality changes in greent/services/bionames.py +Make front-end changes in builder/api/naming.py +The above two files should be considered in tandem. + +Add unit test cases to greent/test/test_bionames.py + + +- TO RUN: $pip install -r greent/requirements.txt -- TO RUN VIA PYTHON: $PYTHONPATH=$PWD python3 builder/api/naming.py --navigate to localhost:5000/apidocs +- Navigate in your browser to localhost:5000/apidocs. -make functionality changes in greent/services/bionames.py -make front-end changes in builder/api/naming.py -the above two files should be considered in tandem + +- TO TEST: +$cd reasoner-tools + +- To run all unit tests: +pytest greent/test/test_bionames.py + +- Remove warnings and get more information as tests run: +pytest -p no:warnings -vv greent/test/test_bionames.py + +- Run a single unit test: +pytest greent/test/test_bionames.py -k +pytest greent/test/test_bionames.py -k test_lookup_router ``` diff --git a/builder/api/naming.py b/builder/api/naming.py index f9fb557..f55e551 100644 --- a/builder/api/naming.py +++ b/builder/api/naming.py @@ -15,7 +15,7 @@ "swagger": "2.0", "info": { "title": "BioNames API", - "description": "Generic facility aggregating bio-ontology lookup services to retrieve names from IDs or IDs based on Natural Language names.", + "description": "Bionames is a generic facility which aggregates bio-ontology lookup services to retrieve names from IDs or IDs based on Natural Language names.", "contact": { "responsibleOrganization": "renci.org", "responsibleDeveloper": "scox@renci.org", @@ -125,7 +125,7 @@ def ID_to_label (ID): return jsonify(result) if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Rosetta Server') + parser = argparse.ArgumentParser(description='BioNames Server') parser.add_argument('-p', '--port', type=int, help='Port to run service on.', default=5000) parser.add_argument('-d', '--debug', help="Debug.", default=False) parser.add_argument('-c', '--conf', help='GreenT config file to use.', default="greent.conf") @@ -135,4 +135,4 @@ def ID_to_label (ID): 'config' : args.conf, 'debug' : args.debug } - app.run(host='0.0.0.0', port=args.port, debug=True, threaded=True) \ No newline at end of file + app.run(host='0.0.0.0', port=args.port, debug=True, threaded=True) diff --git a/greent/api/main.py b/greent/api/main.py deleted file mode 100644 index 35e9904..0000000 --- a/greent/api/main.py +++ /dev/null @@ -1,25 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - price: float - is_offer: bool = None - - -@app.get("/") -def read_root(): - return {"Hello": "World"} - - -@app.get("/items/{item_id}") -def read_item(item_id: int, q: str = None): - return {"item_id": item_id, "q": q} - - -@app.put("/items/{item_id}") -def create_item(item_id: int, item: Item): - return {"item_name": item.name, "item_id": item_id} \ No newline at end of file diff --git a/greent/api/onto_gunicorn.py b/greent/api/onto_gunicorn.py index d162d55..abf1d54 100644 --- a/greent/api/onto_gunicorn.py +++ b/greent/api/onto_gunicorn.py @@ -14,7 +14,7 @@ "swagger": "2.0", "info": { "title": "Generic Ontology API", - "description": "Generic facts about ontologies (Flask/Gunicorn). This interface utilizes flat file .obo files as well as leveraging the Uberongraph RDB (a SPARQL-queried Uberongraph available at https://stars-app.renci.org/uberongraph/#query)", + "description": "Onto is a facility which aggregates lookup services that provide generic facts about ontologies. It leverages the Uberongraph RDB (a SPARQL-queried Uberongraph available at https://stars-app.renci.org/uberongraph/#query) for data.", "contact": { "responsibleOrganization": "renci.org", "responsibleDeveloper": "scox@renci.org", @@ -466,10 +466,6 @@ def all_properties (curie): ont = get_ontology_service() return jsonify({"all_properties" : ont.all_properties(curie_normalize(curie))}) -################## -# start of sparkle based access to the Uberongraph RDB -################## - @app.route('/descendants/') def descendants(curie): """ Get all cascading 'is_a' descendants of an input CURIE term. @@ -565,7 +561,7 @@ def label(curie): @app.route('/uri/') def uri_from_curie(curie): - """ Exapnds a curie to uri. + """ Expands a curie to uri. --- parameters: - name: curie @@ -602,11 +598,10 @@ def get_curie_uri_map(): if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Rosetta Server') + parser = argparse.ArgumentParser(description='Onto Server') parser.add_argument('-p', '--port', type=int, help='Port to run service on.', default=5000) parser.add_argument('-d', '--debug', help="Debug.", default=False) - parser.add_argument('-t', '--data', help="Ontology data source.", default="c:/Users/powen/PycharmProjects/Reasoner/reasoner-tools/") - # parser.add_argument('-t', '--data', help="Ontology data source.", default="/projects/stars/reasoner/var/ontologies/") + parser.add_argument('-t', '--data', help="Ontology data source.", default="/projects/stars/reasoner/var/ontologies/") parser.add_argument('-c', '--conf', help='GreenT config file to use.', default="greent.conf") args = parser.parse_args () app.config['SWAGGER']['greent_conf'] = args.greent_conf = args.conf diff --git a/greent/api/onto_wsgi.py b/greent/api/onto_wsgi.py new file mode 100644 index 0000000..9d0d253 --- /dev/null +++ b/greent/api/onto_wsgi.py @@ -0,0 +1,5 @@ +# usage: gunicorn --workers=3 --timeout=120 --bind=0.0.0.0:5000 --pythonpath '../../' onto_wsgi:app +from onto_gunicorn import app + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/greent/requirements.txt b/greent/requirements.txt index 109ad60..28d490f 100644 --- a/greent/requirements.txt +++ b/greent/requirements.txt @@ -33,4 +33,4 @@ requests==2.21.0 six==1.12.0 SPARQLWrapper==1.8.2 urllib3==1.24.1 -Werkzeug==0.15.1 +Werkzeug==0.15.3 diff --git a/greent/services/bionames.py b/greent/services/bionames.py index b98b970..b090882 100644 --- a/greent/services/bionames.py +++ b/greent/services/bionames.py @@ -96,7 +96,8 @@ def _search_onto(self, q, concept=None): try: result = self.context.core.onto.search (q, is_regex=True, full=True) if concept: - result = [r for r in result if r['type'] == concept] + # Added fix for KeyException when there's no 'type' key in dict r + result = [r for r in result if 'type' in r and r['type'] == concept] except: traceback.print_exc () return result diff --git a/greent/services/ontology.py b/greent/services/ontology.py index e977303..cce878a 100644 --- a/greent/services/ontology.py +++ b/greent/services/ontology.py @@ -51,7 +51,7 @@ def query_sparql(self, query_template, inputs, outputs): def label(self,identifier): - """Return the exitlabel for an identifier""" + """Return the label for an identifier""" query_text = f""" PREFIX rdfs: SELECT DISTINCT ?labels diff --git a/greent/test/test_bionames.py b/greent/test/test_bionames.py index 02e6a13..2fdbc81 100644 --- a/greent/test/test_bionames.py +++ b/greent/test/test_bionames.py @@ -28,140 +28,86 @@ def test_lookup_router(bionames): concept_key = 'disease' lookup_no_sims_result = [ { - 'defined_by': 'http://purl.obolibrary.org/obo/mondo.owl', - 'definition': 'A bronchial disease that is characterized by chronic inflammation and narrowing of the airways, which is caused by a combination of environmental and genetic factors resulting in recurring periods of wheezing (a whistling sound while breathing), chest tightness, shortness of breath, mucus production and coughing. The symptoms appear due to a variety of triggers such as allergens, irritants, respiratory infections, weather changes, exercise, stress, reflux disease, medications, foods and emotional anxiety.', 'id': 'MONDO:0004979', - 'label': 'asthma' + 'label': 'asthma', + 'type': 'disease' } ] lookup_w_sims_result = [ { - "defined_by": "http://purl.obolibrary.org/obo/hp.owl", - "definition": "Asthma is characterized by increased responsiveness of the tracheobronchial tree to multiple stimuli, leading to narrowing of the air passages with resultant dyspnea, cough, and wheezing.", - "id": "HP:0002099", - "label": "Asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/hp.owl", - "definition": "A type of asthma in which aspirin and other nonsteroidal anti-inflammatory drugs (NSAIDs) that inhibit cyclooxygen-ase 1 (COX-1) exacerbate bronchoconstriction.", - "id": "HP:0012042", - "label": "Aspirin-induced asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/hp.owl", - "definition": "Severe asthma unresponsive to repeated courses of beta-agonist therapy such as inhaled albuterol, levalbuterol, or subcutaneous epinephrine.", - "id": "HP:0012653", - "label": "Status asthmaticus" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/hp.owl", - "definition": "Asthma attacks following exercise.", - "id": "HP:0012652", - "label": "Exercise-induced asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "A asthma with a basis in a pathological type I hypersensitivity reaction.", - "id": "MONDO:0004784", - "label": "allergic asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "A bronchial disease that is characterized by chronic inflammation and narrowing of the airways, which is caused by a combination of environmental and genetic factors resulting in recurring periods of wheezing (a whistling sound while breathing), chest tightness, shortness of breath, mucus production and coughing. The symptoms appear due to a variety of triggers such as allergens, irritants, respiratory infections, weather changes, exercise, stress, reflux disease, medications, foods and emotional anxiety.", - "id": "MONDO:0004979", - "label": "asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "An acute exacerbation of asthma, characterized by inadequate response to initial bronchodilators.", - "id": "MONDO:0004766", - "label": "status asthmaticus" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Asthma that starts in childhood.", - "id": "MONDO:0005405", - "label": "childhood onset asthma" - }, - { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0008834", - "label": "asthma, nasal polyps, and aspirin intolerance" + 'id': 'MONDO:0004979', + 'label': 'asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0008835", - "label": "asthma, short stature, and elevated IgA" + 'id': 'MONDO:0022742', + 'label': 'occupational asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Any inherited susceptibility to asthma in which the cause of the disease is a mutation in the IRAK3 gene.", - "id": "MONDO:0012607", - "label": "asthma-related traits, susceptibility to, 5" + 'id': 'MONDO:0004765', + 'label': 'intrinsic asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0012666", - "label": "asthma-related traits, susceptibility to, 6" + 'id': 'MONDO:0004784', + 'label': 'allergic asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Any inherited susceptibility to asthma in which the cause of the disease is a mutation in the CHI3L1 gene.", - "id": "MONDO:0012771", - "label": "asthma-related traits, susceptibility to, 7" + 'id': 'MONDO:0004766', + 'label': 'status asthmaticus', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0013180", - "label": "asthma-related traits, susceptibility to, 8" + 'id': 'MONDO:0012607', + 'label': 'asthma-related traits, susceptibility to, 5', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Any inherited susceptibility to asthma in which the cause of the disease is a mutation in the PTGDR gene.", - "id": "MONDO:0011805", - "label": "asthma-related traits, susceptibility to, 1" + 'id': 'MONDO:0010940', + 'label': 'inherited susceptibility to asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Any inherited susceptibility to asthma in which the cause of the disease is a mutation in the NPSR1 gene.", - "id": "MONDO:0012067", - "label": "asthma-related traits, susceptibility to, 2" + 'id': 'MONDO:0025556', + 'label': 'isocyanate induced asthma', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0012379", - "label": "asthma-related traits, susceptibility to, 3" + 'id': 'MONDO:0011805', + 'label': 'asthma-related traits, susceptibility to, 1', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "id": "MONDO:0012577", - "label": "asthma-related traits, susceptibility to, 4" + 'id': 'MONDO:0012067', + 'label': 'asthma-related traits, susceptibility to, 2', + 'type': 'disease' }, { - "defined_by": "http://purl.obolibrary.org/obo/mondo.owl", - "definition": "Asthma attacks caused, triggered, or exacerbated by OCCUPATIONAL EXPOSURE.", - "id": "MONDO:0022742", - "label": "occupational asthma" + 'id': 'MONDO:0012771', + 'label': 'asthma-related traits, susceptibility to, 7', + 'type': 'disease' }, { - "id": "MONDO:0004765", - "label": "intrinsic asthma", - "type": "disease" + 'id': 'MONDO:0001491', + 'label': 'cough variant asthma', + 'type': 'disease' }, { - "id": "MONDO:0010940", - "label": "inherited susceptibility to asthma", - "type": "disease" + 'id': 'MONDO:0005405', + 'label': 'childhood onset asthma', + 'type': 'disease' }, { - "id": "MONDO:0025556", - "label": "isocyanate induced asthma", - "type": "disease" + 'id': 'MONDO:0008835', + 'label': 'asthma, short stature, and elevated IgA', + 'type': 'disease' }, { - "id": "MONDO:0001491", - "label": "cough variant asthma", - "type": "disease" + 'id': 'MONDO:0008834', + 'label': 'asthma, nasal polyps, and aspirin intolerance', + 'type': 'disease' } ] result = bionames.lookup_router(query_key, concept_key) @@ -217,10 +163,9 @@ def test__find(bionames): """ expected = [ { - 'defined_by': 'http://purl.obolibrary.org/obo/mondo.owl', - 'definition': 'A viral hemorrhagic fever that is caused by the Ebola virus, which is transmitted by contact with infected animals or humans; it is characterized by high fever, unexplained bleeding, and a high mortality rate.', 'id': 'MONDO:0005737', - 'label': 'Ebola hemorrhagic fever' + 'label': 'Ebola hemorrhagic fever', + 'type': 'disease' } ] query_key = 'ebola' diff --git a/greent/uberonto_requirements_conda.txt b/greent/uberonto_requirements_conda.txt deleted file mode 100644 index 68398b0..0000000 --- a/greent/uberonto_requirements_conda.txt +++ /dev/null @@ -1,36 +0,0 @@ -# This file may be used to create an environment using: -# $ conda create --name --file -# platform: osx-64 -attrs=19.1.0=py_0 -ca-certificates=2018.11.29=ha4d7672_0 -certifi=2018.11.29=py37_1000 -click=7.0=py37_0 -flasgger=0.9.2=py_0 -flask=1.0.2=py37_1 -itsdangerous=1.1.0=py37_0 -jinja2=2.10=py37_0 -jsonschema=3.0.1=py37_0 -keepalive=0.5=py_1 -libcxx=4.0.1=hcfea43d_1 -libcxxabi=4.0.1=hcfea43d_1 -libedit=3.1.20181209=hb402a30_0 -libffi=3.2.1=h475c297_4 -markupsafe=1.1.1=py37h1de35cc_0 -mistune=0.8.4=py37h1de35cc_1000 -ncurses=6.1=h0a44026_1 -openssl=1.1.1b=h1de35cc_0 -pip=19.0.3=py37_0 -pyrsistent=0.14.11=py37h1de35cc_0 -python=3.7.2=haf84260_0 -pyyaml=3.13=py37h1de35cc_1001 -readline=7.0=h1de35cc_5 -setuptools=40.8.0=py37_0 -six=1.12.0=py37_1000 -sparqlwrapper=1.8.2=py37_1000 -sqlite=3.26.0=ha441bb4_0 -tk=8.6.8=ha441bb4_0 -werkzeug=0.14.1=py37_0 -wheel=0.33.1=py37_0 -xz=5.2.4=h1de35cc_4 -yaml=0.1.7=h1de35cc_1001 -zlib=1.2.11=h1de35cc_3 diff --git a/greent/util.py b/greent/util.py index c3c490e..8c02f10 100644 --- a/greent/util.py +++ b/greent/util.py @@ -145,7 +145,7 @@ def get_curie_to_uri_map(): 'MESH': 'http://purl.obolibrary.org/obo/MESH_', 'MONDO': 'http://purl.obolibrary.org/obo/MONDO_', 'NCIT' : 'http://purl.obolibrary.org/obo/NCIT_', - 'OMIM': 'https://www.omim.org/entry/', + 'OMIM': 'http://purl.obolibrary.org/obo/OMIM_', 'OMIMPS': 'http://purl.obolibrary.org/obo/OMIMPS_', 'ONCOTREE': 'http://purl.obolibrary.org/obo/ONCOTREE_', 'ORPHANET': 'http://www.orpha.net/ORDO/Orphanet_',