From 50343dc75a04b0decb4a16747d98843bf56ec5d5 Mon Sep 17 00:00:00 2001 From: AndiMajore <andi.majore@googlemail.com> Date: Mon, 11 Jul 2022 17:05:30 +0200 Subject: [PATCH] updated nedrex package; added get_licence route --- data/license.txt | 56 +++++++++ drugstone/management/commands/populate_db.py | 13 +++ .../management/includes/DatasetLoader.py | 47 +++++++- drugstone/urls.py | 5 +- drugstone/views.py | 6 + python_nedrex/.github/ISSUE_TEMPLATE.md | 15 --- python_nedrex/.gitignore | 106 ------------------ python_nedrex/python_nedrex/common.py | 2 +- python_nedrex/python_nedrex/neo4j.py | 27 +++++ python_nedrex/python_nedrex/static.py | 4 +- python_nedrex/requirements.txt | 1 + python_nedrex/tests/test_python_nedrex.py | 68 ++++++++++- scripts/docker-entrypoint.sh | 1 + 13 files changed, 219 insertions(+), 132 deletions(-) create mode 100644 data/license.txt delete mode 100644 python_nedrex/.github/ISSUE_TEMPLATE.md delete mode 100644 python_nedrex/.gitignore create mode 100644 python_nedrex/python_nedrex/neo4j.py diff --git a/data/license.txt b/data/license.txt new file mode 100644 index 0000000..9196305 --- /dev/null +++ b/data/license.txt @@ -0,0 +1,56 @@ +==== End User License Agreement ==== + + +The authors wish to make the NeDRex platform available on a nonexclusive basis for non-commercial internal research purposes, subject to agreeing with terms of use described in the following: + +By using the NeDRex platform you are entering a legally binding agreement. Using the NeDRex platform implies that you agree to the Terms of Use. If you do not agree with the Terms of Use, do not use the platform. + +The NeDRex platform incorporates material contributed or licensed by individuals, companies, or organizations that may be protected by copyright laws. These include, but are not limited to, DrugBank (see DrugBank Terms of Use: https://go.drugbank.com/legal/terms_of_use) and OMIM (see the custom licence included in this document). All persons reproducing, redistributing, or making commercial use of this information are expected to adhere to the terms and conditions asserted by the copyright holder. + +Through a license agreement between Hamburg University (UH) and Johns Hopkins University (JHU), the NeDRex platform contains OMIM® Data. This license agreement enables us to sublicense OMIM® Data to End-User(s) of the NeDRex platform for the End-User(s)' internal research purposes. This sublicensing does not grant the End-User(s) any right to copy OMIM® Data for the purpose of providing the OMIM® data, and derivatives thereof, to any other party, or in any other way grant a sublicense or other similar rights to OMIM® Data or distribute NeDRexDB containing any part of the OMIM® Data. The rights granted to End-Users under the terms of this sublicense do not extend to affiliates of End-Users. + + 1. UH AND END-USERS OF THE NEDREX PLATFORM AGREE THAT THE OMIM® DATA AND THE OMIM® DATABASE IS PROVIDED "AS IS", AND THAT JHU MAKES NO REPRESENTATION OR WARRANTY WITH RESPECT TO THE PERFORMANCE OF THE OMIM® DATA OR THE OMIM® DATABASE INCLUDING ITS ACCURACY OR COMMERCIAL VIABILITY, USE IN RESEARCH, OR OTHER USES. JHU MAKES NO REPRESENTATIONS THAT IT WILL PROVIDE UPDATES OR IN ANY WAY MAINTAIN OR SUPPORT THE OMIM® DATABASE. JHU DISCLAIMS ALL WARRANTIES WITH REGARD TO THE OMIM® DATA AND OMIM® DATABASE, INCLUDING, BUT NOT LIMITED TO, ALL WARRANTIES, EXPRESS OR IMPLIED, OF MERCHANTABILITY AND FITNESS FOR ANY PARTICULAR PURPOSE. JHU DOES NOT WARRANT THAT THE OMIM® DATA OR OMIM® DATABASE MAY BE USED, COPIED, OR REDISTRIBUTED WITHOUT INFRINGING THE COPYRIGHTS, PATENT RIGHTS OR PROPERTY RIGHTS OF THIRD PARTIES. + + 2. UH and end-users of the NeDRex platform shall defend and hold JHU, The Johns Hopkins Health Systems, their present and former trustees, officers, authors of the OMIM® Data and the OMIM® Database, agents, faculty, employees and students (“JHU Partiesâ€) harmless as against any judgments, fees, expenses, or other costs arising from or incidental to any lawsuit, claim, demand or other action brought against JHU Parties as a consequence of the use or sublicensing of the OMIM® Data or OMIM® Database by UH, End-User(s), or other third parties that may otherwise gain access to the OMIM® Data or OMIM® Database through UH. Use of the OMIM Data and the OMIM Database by a third party on behalf of or for the account of UH or by an End-User(s), shall be considered UH’s use of the OMIM® Database for purposes of this Paragraph. The obligation of UH and end-users to defend and indemnify as set out in this Paragraph shall survive the termination of this Agreement. + + 3. Term and Termination: + + 3.1 The term of the sublicense Agreement shall be the same as the term of UH’s agreement with JHU, commencing on the date our license fee is received at Johns Hopkins Technology Ventures, and continuing for a period of three (3) years. + + 3.2 UH may terminate this Agreement and the licence granted herein, for any reason, upon giving JHU sixty (60) days written notice. + + 3.3 The agreement between UH and JHU (and, by extension, this sublicense agreement) may be terminated by JHU, in the event that UH breaches any material term of obligation hereunder including, but limited to, UH’s obligations with regard to licence fees and payments, reporting, and quality control, and fails to cure such breach within thirty (30) days of written notice thereof. In no event, however, shall such notice of intention to terminate be deemed to waive any rights to damages or any other remedy that JHU may have as a consequence of such failure or breach by UH. + + 3.4 Upon termination of the agreement between UH and JHU, UH will remove any Mirror Database from its server/computers and any part of OMIM® Data and/or any OMIM® Database from any of its non-profit proprietary derivative database(s) whether on its server/computers or not and from any other non-profit proprietary licensed product(s), and shall cease using OMIM® Data and the OMIM® Database, song with any applicable trademark(s), for any purpose. + + 3.5 UH shall further terminate the sublicense agreements with End-User(s) with respect to OMIM® Data and the OMIM® Database and any applicable trademarks by providing notice of such to End-User(s) and by providing substitute non-profit proprietary databases or non-profit proprietary products, either of which do not contain any part of OMIM® Data and/or OMIM® Database. UH shall provide JHU with a notarized certification of compliance with this agreement within sixty (60) days of termination of this agreement. + + 3.6 Termination of the agreement between UH and OMIM, for whatever reason, shall not affect the obligation of UH to make any payments for which it is liable prior to or upon such termination. Termination shall not affect JHU’s right to recover unpaid fees incurred prior to termination. Upon termination, all rights in and to the OMIM® Data and OMIM® Database and any applicable trademarks shall revert to JHU at no cost to JHU. + + 4. Except as expressly stated herein, UH and End-Users of the NeDRex platform shall not use the name of The Johns Hopkins University or The Johns Hopkins Health System or any of its constituent parts, such as the Johns Hopkins Hospital or any contraction thereof or the name of the authors of the OMIM Data or OMIM Database in any advertising, promotional, sales literature or fundraising documents without prior written consent from an officer of JHU. UH and End-Users of NeDRex shall allow at least seven (7) business days notice of any proposed public disclosure for JHU's review and comment and/or to provide written consent. + + 5. Prior to first commercial access to and/or distribution of any Mirror Database, Non-profit Proprietary Derivative Database(s) or Non-profit Proprietary Licensed Product(s) as the case may be in any particular country, UH shall establish and maintain, in each country in which Non-profit shall permit access to and/or distribution of any Mirror Database, Non-profit Proprietary Derivative Database(s) or Non-profit Proprietary Licensed Product(s), product liability or other appropriate insurance coverage appropriate to the risks involved in marketing any Mirror Database, Non-profit Proprietary Derivative Database(s) or Non-profit Proprietary Licensed Product(s) and will annually present evidence to JHU that such coverage is being maintained. Upon JHU's request, Non-profit will furnish JHU with a Certificate of Insurance of each product liability insurance policy obtained. JHU shall be listed as an additional insured in Non-profit's said insurance policies. If such Product Liability insurance is underwritten on a ‘claims made’ basis, Non-profit agrees that any change in underwriters during the term of this Agreement will require the purchase of ‘prior acts’ coverage to ensure that coverage will be continuous throughout the term of this Agreement. + + 6. In the licence agreement between UH and JHU, UH is required to provide the following exact provisions: + + 6.1 UH shall include, in a place conspicuous to End-Users(s), and with all copies of the OMIM® Database, OMIM® Data, any Mirror Database or Non-profit Proprietary Derivative Database(s) or other Non-Profit Proprietary Licensed Product(s), or any portion thereof located on UH’s server / computer, the following copyright notice: Copyright © [1966 - Present Year], Johns Hopkins University All rights reserved. + + 6.2 UH shall include the following legend in any advertising, promotional, or other marketing materials, and any documentation describing the OMIM Data®, OMIM® Database, any Mirror Database or Non-profit Proprietary Derivative Database(s), or other Non-profit Proprietary Licensed Product(s): This database/product contains information obtained from the Online Mendelian Inheritance in Man® (OMIM®) database, which has been obtained through a license from the Johns Hopkins University, which owns the copyright thereto. + + 6.3 In addition to the copyright notice and legend required in Paragraphs 6.1 and 6.2 above, UH shall use one or both of the following OMIM Trademarks in reference to a Mirror Database: a) OMIM®; or b)Online Mendelian Inheritance in Man® + UH is not permitted to use any other marks or derivatives of the OMIM Trademarks in association with a Mirror Database. + + 6.4 In addition to the copyright notice and legend required in Paragraphs 6.1 and 6.2 above, UH shall use the following legend in any reference to any Non-profit Proprietary Derivative Database(S) or Non-profit Proprietary Licensed Product(s): This database/product contains information from the Online Mendelian Inheritance in Man® (OMIM®) database, which has been obtained under a license from the Johns Hopkins University. This database/product does not represent the entire, unmodified OMIM® database, which is available in its entirety at http://omim.org/downloads. + + 6.5 UH agrees that no other name, trademark, inscription, or designation whatsoever shall be affixed to the OMIM® or Online Mendelian Inheritance in Man® trademarks; furthermore, UH agrees not to use such trademarks in any advertising or promotional material, except as expressly stated in Section 6, without the express written consent of JHU. + + 6.6 UH shall at no time adopt or use, without JHU’s prior written consent, any variation of the OMIM® or Online Mendelian Inheritance in Man® trademarks or any word or mark likely to be similar or confusingly similar with such trademarks. + + 6.7 UH will provide JHU with copies of Non-profit documents that reflect the copyright notices and legends specified in paragraphs 6.1 to 6.4 upon incorporation into documents and thereafter, on an annual basis. Such documents may be provided to JHU in conjunction with the written reports that UH provides as required by our license with JHU. + + 6.8 UH agrees to download OMIM® Data from the OMIM® Database at a minimum of once per week during the term of our Agreement with JHU, and incorporate such updated data so that UH is utilising the most recent version of the OMIM® Database. UH also agrees to indicate on all links to the OMIM® Data, any Mirror Database, any Non-profit Proprietary Derivative Database(s) and any other Non-profit Proprietary Licensed Product(s), the date that such data was last downloaded. + + +==== Acknowledgements ==== + +NeDRexDB contains information from the Online Mendelian Inheritance in Man® (OMIM®) database, which has been obtained under a license from the Johns Hopkins University. NeDRexDB does not represent the entire, unmodified OMIM® database, which is available in its entirety at https://omim.org/downloads. diff --git a/drugstone/management/commands/populate_db.py b/drugstone/management/commands/populate_db.py index fd9f6f3..df60c86 100755 --- a/drugstone/management/commands/populate_db.py +++ b/drugstone/management/commands/populate_db.py @@ -104,6 +104,8 @@ def populate(kwargs): populator = DataPopulator(cache) total_n = 0 + nedrex_update = False + if 'all' in kwargs and kwargs['all']: kwargs['drugs'] = True kwargs['disorders'] = True @@ -118,18 +120,21 @@ def populate(kwargs): print('Populating Drugs...') n = NedrexImporter.import_drugs(importer, update) total_n +=n + nedrex_update = True print(f'Populated {n} Drugs.') if kwargs['disorders']: print('Populating Disorders...') n = NedrexImporter.import_disorders(importer, update) total_n += n + nedrex_update = True print(f'Populated {n} Disorders.') if kwargs['proteins']: print('Populating Proteins...') n = NedrexImporter.import_proteins(importer, update) total_n += n + nedrex_update = True print(f'Populated {n} Proteins.') print('Populating ENSG IDs...') n = DataPopulator.populate_ensg(populator, update) @@ -149,6 +154,7 @@ def populate(kwargs): DatasetLoader.get_drug_target_nedrex(nedrex_api_url), update) total_n += n + nedrex_update = True print(f'Imported {n} PDIs from NeDRexDB') print('Populating PDIs from Chembl...') @@ -168,6 +174,7 @@ def populate(kwargs): nedrex_api_url), update) total_n += n + nedrex_update = True print(f'Imported {n} PDis from NeDRexDB') if kwargs['drug_disorder']: @@ -176,6 +183,7 @@ def populate(kwargs): DatasetLoader.get_drug_disorder_nedrex(nedrex_api_url), update) total_n += n + nedrex_update = True print(f'Imported {n} DrDis from NeDRexDB') print('Populating DrDi indications from DrugBank...') n = DataPopulator.populate_drdis_drugbank(populator, DatasetLoader.get_drug_disorder_drugbank(), update) @@ -188,6 +196,7 @@ def populate(kwargs): DatasetLoader.get_ppi_nedrex(nedrex_api_url), update) total_n += n + nedrex_update = True print(f'Imported {n} PPIs from NeDRexDB') print('Populating PPIs from STRING...') n = DataPopulator.populate_ppi_string(populator, DatasetLoader.get_ppi_string(), update) @@ -199,5 +208,9 @@ def populate(kwargs): total_n += n print(f'Populated {n} PPIs from APID.') + if nedrex_update: + from drugstone.management.includes.DatasetLoader import update_license + update_license() + cache.clear() return total_n diff --git a/drugstone/management/includes/DatasetLoader.py b/drugstone/management/includes/DatasetLoader.py index 8238a6a..6d2ade8 100644 --- a/drugstone/management/includes/DatasetLoader.py +++ b/drugstone/management/includes/DatasetLoader.py @@ -1,9 +1,9 @@ from requests.exceptions import RetryError from drugstone import models -from python_nedrex.static import get_metadata +from python_nedrex.static import get_metadata, get_license -ppi_nedrex_datasets = dict() +LICENSE_FILE = "./data/license.txt" def get_ppi_string(): @@ -123,6 +123,33 @@ def get_protein_disorder_nedrex(url): return dataset +def write_license(text): + with open(LICENSE_FILE,'w') as fh: + fh.write(text) + + +def update_license(): + try: + license = get_license() + write_license(license) + return license + except RetryError: + print(f'License could not be retreived.') + return "" + + +def import_license(): + try: + license = "" + with open(LICENSE_FILE, 'r') as fh: + for line in fh: + license += line + return license + except FileNotFoundError: + print(f'No lincense doc there yet! Make sure to run an update first!') + return "" + + def get_drug_disorder_nedrex(url): version = get_today_version() try: @@ -182,12 +209,14 @@ def get_drug_disorder_drugbank(): ) return dataset + def get_today_version(): import datetime now = datetime.date.today() version = f'{now.year}-{now.month}-{now.day}_temp' return version + def get_dis_prot_nedrex_disgenet(url): version = get_today_version() try: @@ -232,6 +261,7 @@ def get_drdis_nedrex_drugcentral(url): ) return dataset + def get_drdis_nedrex_ctd(url): version = get_today_version() try: @@ -246,6 +276,7 @@ def get_drdis_nedrex_ctd(url): ) return dataset + def get_pdr_nedrex_drugcentral(url): version = get_today_version() try: @@ -260,6 +291,7 @@ def get_pdr_nedrex_drugcentral(url): ) return dataset + def get_pdr_nedrex_drugbank(url): version = get_today_version() try: @@ -274,14 +306,19 @@ def get_pdr_nedrex_drugbank(url): ) return dataset + def get_pdr_nedrex_datasets(url): return {'drugbank': get_pdr_nedrex_drugbank(url), 'drugcentral': get_pdr_nedrex_drugcentral(url)} + def get_drdis_nedrex_datasets(url): - return {'ctd':get_drdis_nedrex_ctd(url), 'drugcentral':get_drdis_nedrex_drugcentral(url)} + return {'ctd': get_drdis_nedrex_ctd(url), 'drugcentral': get_drdis_nedrex_drugcentral(url)} + def get_ppi_nedrex_datasets(url): - return {'biogrid':get_ppi_nedrex_biogrid(url), 'iid':get_ppi_nedrex_iid(url), 'intact':get_ppi_nedrex_intact(url)} + return {'biogrid': get_ppi_nedrex_biogrid(url), 'iid': get_ppi_nedrex_iid(url), + 'intact': get_ppi_nedrex_intact(url)} + def get_dis_prot_nedrex_datasets(url): - return {'disgenet': get_dis_prot_nedrex_disgenet(url), 'omim': get_dis_prot_nedrex_omim(url)} \ No newline at end of file + return {'disgenet': get_dis_prot_nedrex_disgenet(url), 'omim': get_dis_prot_nedrex_omim(url)} diff --git a/drugstone/urls.py b/drugstone/urls.py index 4de3852..a44eeb9 100755 --- a/drugstone/urls.py +++ b/drugstone/urls.py @@ -18,7 +18,7 @@ from django.urls import path from drugstone.views import map_nodes, tasks_view, result_view, \ graph_export, query_proteins, TissueView, TissueExpressionView, query_tissue_proteins, TaskView, \ - adjacent_drugs, adjacent_disorders, fetch_edges, create_network, load_network + adjacent_drugs, adjacent_disorders, fetch_edges, create_network, load_network, get_license # cache time is 6 hours urlpatterns = [ @@ -38,5 +38,6 @@ urlpatterns = [ path('tissues/', TissueView.as_view()), path('admin/', admin.site.urls), path('create_network', create_network), - path('load_network', load_network) + path('load_network', load_network), + path('get_license', get_license) ] diff --git a/drugstone/views.py b/drugstone/views.py index b4351d6..5ccbc9b 100755 --- a/drugstone/views.py +++ b/drugstone/views.py @@ -166,6 +166,12 @@ class TaskView(APIView): 'stats': task_stats(task), }) +@api_view(['GET']) +def get_license(request) -> Response: + from drugstone.management.includes.DatasetLoader import import_license + return Response({'license': import_license()}) + + @api_view(['POST']) def fetch_edges(request) -> Response: diff --git a/python_nedrex/.github/ISSUE_TEMPLATE.md b/python_nedrex/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index af31396..0000000 --- a/python_nedrex/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,15 +0,0 @@ -* python-nedrex version: -* Python version: -* Operating System: - -### Description - -Describe what you were trying to get done. -Tell us what happened, what went wrong, and what you expected to happen. - -### What I Did - -``` -Paste the command(s) you ran and the output. -If there was a crash, please include the traceback here. -``` diff --git a/python_nedrex/.gitignore b/python_nedrex/.gitignore deleted file mode 100644 index 4c915d1..0000000 --- a/python_nedrex/.gitignore +++ /dev/null @@ -1,106 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# IDE settings -.vscode/ -.idea/ diff --git a/python_nedrex/python_nedrex/common.py b/python_nedrex/python_nedrex/common.py index 5a0adfd..6e3fdba 100644 --- a/python_nedrex/python_nedrex/common.py +++ b/python_nedrex/python_nedrex/common.py @@ -44,7 +44,7 @@ def check_response(resp: requests.Response, return_type: str = "json") -> Any: if data["detail"] == "An API key is required to access the requested data": raise ConfigError("no API key set in the configuration") - if resp.status_code == 422: + if resp.status_code in {102, 400, 422}: data = resp.json() raise NeDRexError(data["detail"]) diff --git a/python_nedrex/python_nedrex/neo4j.py b/python_nedrex/python_nedrex/neo4j.py new file mode 100644 index 0000000..0a1e48b --- /dev/null +++ b/python_nedrex/python_nedrex/neo4j.py @@ -0,0 +1,27 @@ +import json as _json +from typing import Any as _Any +from typing import Dict as _Dict +from typing import Generator as _Generator + +from requests.exceptions import ChunkedEncodingError # type: ignore + +from python_nedrex import config as _config +from python_nedrex.common import http as _http +from python_nedrex.exceptions import NeDRexError + + +def neo4j_query(query: str) -> _Generator[_Dict[str, _Any], None, None]: + url = f"{_config.url_base}/neo4j/query" + params = {"query": query} + + resp = _http.get(url, params=params, headers={"x-api-key": _config.api_key}, stream=True) + if resp.status_code != 200: + raise NeDRexError("Querying Neo4j returned a non-200 status code.") + + try: + for line in resp.iter_lines(): + data = _json.loads(line.decode()) + for item in data: + yield item + except ChunkedEncodingError as exc: + raise NeDRexError("cypher query could not be executed") from exc diff --git a/python_nedrex/python_nedrex/static.py b/python_nedrex/python_nedrex/static.py index 3f492f8..00bf86c 100644 --- a/python_nedrex/python_nedrex/static.py +++ b/python_nedrex/python_nedrex/static.py @@ -16,9 +16,9 @@ def get_metadata() -> _Dict[str, _Any]: def get_license() -> str: - url = f"{_config.url_base}/static/license" + url = f"{_config.url_base}/static/licence" resp = _http.get(url) - result: str = _check_response(resp) + result: str = _check_response(resp=resp, return_type='text') return result diff --git a/python_nedrex/requirements.txt b/python_nedrex/requirements.txt index 2c15053..0e89273 100644 --- a/python_nedrex/requirements.txt +++ b/python_nedrex/requirements.txt @@ -2,4 +2,5 @@ attrs==21.4.0 cachetools==4.2.4 more-itertools==8.13.0 pytest==7.0.1 +pytest-xdist==2.5.0 requests==2.27.1 diff --git a/python_nedrex/tests/test_python_nedrex.py b/python_nedrex/tests/test_python_nedrex.py index 262a41d..e86cb19 100644 --- a/python_nedrex/tests/test_python_nedrex.py +++ b/python_nedrex/tests/test_python_nedrex.py @@ -2,6 +2,7 @@ """Tests for `python_nedrex` package.""" +from email import quoprimime import os import re from pathlib import Path @@ -48,6 +49,7 @@ from python_nedrex.graph import ( download_graph, ) from python_nedrex.must import must_request, check_must_status +from python_nedrex.neo4j import neo4j_query from python_nedrex.ppi import ppis from python_nedrex.relations import ( get_encoded_proteins, @@ -661,4 +663,68 @@ class TestDominoRoutes: uid = domino_submit(SEEDS) status = check_domino_status(uid) assert isinstance(status, dict) - assert "status" in status.keys() \ No newline at end of file + assert "status" in status.keys() + + +class TestNeo4j: + def test_general_node_query(self, set_base_url, set_api_key): + query = """ + MATCH (n: Gene) + RETURN n + LIMIT 25 + """ + + assert all(i[0]["type"] == "Gene" for i in neo4j_query(query)) + + def test_general_edge_query(self, set_base_url, set_api_key): + query = """ + MATCH ()-[n:GeneAssociatedWithDisorder]-() + RETURN n + LIMIT 25 + """ + + assert all(i[0]["type"] == "GeneAssociatedWithDisorder" for i in neo4j_query(query)) + + def test_general_node_query_with_attributes(self, set_base_url, set_api_key): + query = """ + MATCH (n: Gene {approvedSymbol: 'A1BG'}) + RETURN n + """ + + x = list(neo4j_query(query)) + assert len(x) == 1 + assert x[0][0]['chromosome'] == '19' + + + def test_general_edge_query_with_attributes(self, set_base_url, set_api_key): + query = """ + MATCH ()-[n: GeneAssociatedWithDisorder {score: 1.0}]-() + RETURN n + LIMIT 1000 + """ + + results = list(neo4j_query(query)) + assert len(results) != 0 + assert all(i[0]['score'] == 1.0 for i in results) + + + def test_gene_associated_with_disorder(self, set_base_url, set_api_key): + query = """ + MATCH (g: Gene)-[gawd: GeneAssociatedWithDisorder]-(d: Disorder) + RETURN g, d, gawd + LIMIT 50 + """ + + for gene, disorder, assoc in neo4j_query(query): + assert gene['type'] == 'Gene' + assert disorder['type'] == "Disorder" + assert assoc['type'] == "GeneAssociatedWithDisorder" + + def test_write_fails(self, set_base_url, set_api_key): + query = """ + CREATE (n: SomeRandomNode) + """ + + with pytest.raises(NeDRexError): + for _ in neo4j_query(query): + pass \ No newline at end of file diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index db7a2d3..efb99a9 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -4,6 +4,7 @@ python3 manage.py makemigrations drugstone python3 manage.py migrate python3 manage.py createfixtures python3 manage.py cleanuptasks +python3 manage.py populate_db --update -p #python3 manage.py populate_db --update -a #python3 manage.py make_graphs -- GitLab