From 60fc027ce4649848951445e15c97bb276339b49d Mon Sep 17 00:00:00 2001 From: Pradeep Bashyal Date: Tue, 29 Aug 2023 13:30:07 -0500 Subject: [PATCH] Rename endpoints and names (#17) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename endpoints and names - Change to *IPD-IMGT/HLA* - Change endpoint to `ipd-imgt-hla-versions` * Upgrade Docker python to 3.10 * Fix quotes * Fix quotes * Bump version: 0.0.1 → 1.0.0 * Bump version: 1.0.0 → 2.0.0 * Fix name * Fix keyname * Fix package copy --- CONTRIBUTING.rst | 4 +-- Dockerfile | 4 +-- HEADER.txt | 2 +- api-spec.yaml | 44 ++++++++++++++++---------------- api.py | 12 ++++----- gfe_service/__init__.py | 6 ++--- gfe_service/gfe_service.py | 2 +- query.py => gfe_service/query.py | 16 ++++++------ neo4j.yaml | 3 +-- requirements-tests.txt | 4 +-- requirements.txt | 1 + setup.cfg | 13 +++++----- setup.py | 6 ++--- tests/unit/test_sample.py | 2 +- 14 files changed, 59 insertions(+), 60 deletions(-) rename query.py => gfe_service/query.py (57%) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f6216dc..e48cc43 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -38,8 +38,8 @@ and "help wanted" is open to whoever wants to implement it. Write Documentation ~~~~~~~~~~~~~~~~~~~ -My Project Template could always use more documentation, whether as part of the -official My Project Template docs, in docstrings, or even on the web in blog posts, +GFE Service could always use more documentation, whether as part of the +official GFE Service docs, in docstrings, or even on the web in blog posts, articles, and such. Submit Feedback diff --git a/Dockerfile b/Dockerfile index 5884656..f335313 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8-slim-buster +FROM python:3.10-slim-buster LABEL MAINTAINER="Pradeep Bashyal" @@ -13,7 +13,7 @@ RUN pip install --no-cache-dir -r requirements-deploy.txt COPY api-spec.yaml /app/ COPY app.py /app/ COPY api.py /app/ -COPY query.py /app/ +COPY gfe_service /app/gfe_service/ COPY neo4j.yaml /app/ CMD ["gunicorn" , "--bind", "0.0.0.0:8080", "--worker-tmp-dir", "/dev/shm", "app:app"] diff --git a/HEADER.txt b/HEADER.txt index b3783e4..dcdafe3 100644 --- a/HEADER.txt +++ b/HEADER.txt @@ -1,5 +1,5 @@ # -# gfe_service My Project Template. +# gfe_service GFE Service. # Copyright (c) 2021 Be The Match operated by National Marrow Donor Program. All Rights Reserved. # # This library is free software; you can redistribute it and/or modify it diff --git a/api-spec.yaml b/api-spec.yaml index 4b124be..8b811d3 100644 --- a/api-spec.yaml +++ b/api-spec.yaml @@ -13,30 +13,30 @@ servers: - url: 'http://localhost:8080' tags: - name: IMGT - description: "Available IMGT DB releases" + description: "Available IPD-IMGT/HLA Database releases" - name: GFE description: Create and Retrieve GFE - name: "Sequence Annotation" description: Annotation by sequence (Coming Soon) paths: - /imgt-versions: + /ipd-imgt-hla-versions: get: - summary: IMGT DB versions in the DB + summary: IPD-IMGT/HLA Database versions in the GFE-DB tags: - IMGT operationId: api.imgt_versions - description: Versions of IMGT DB Alleles in GFE DB + description: Versions of IPD-IMGT/HLA Database Alleles in GFE DB responses: 200: - description: Version Numbers of Available IMGT DB + description: Version Numbers of Available IPD-IMGT/HLA Database content: application/json: schema: type: object properties: imgt_versions: - description: IMGT DB Versions + description: IPD-IMGT/HLA Database Versions type: array items: type: string @@ -56,17 +56,17 @@ paths: type: string example: "Database Unreachable" - /who/{who_name}: + /ipd/{ipd_name}: get: - summary: Get GFE for a WHO name + summary: Get GFE for a IPD-IMGT/HLA HLA name tags: - GFE - operationId: api.gfe_from_who - description: For a given WHO Allele name, return the corresponding GFE + operationId: api.gfe_from_ipd + description: For a given IPD-IMGT/HLA Allele name, return the corresponding GFE parameters: - - name: who_name + - name: ipd_name in: path - description: WHO Allele name + description: IPD-IMGT/HLA Database Allele name required: true schema: type: string @@ -74,7 +74,7 @@ paths: example: "HLA-A*01:01:01:08" responses: 200: - description: GFE from WHO allele name + description: GFE from IPD-IMGT/HLA allele name content: application/json: schema: @@ -88,12 +88,12 @@ paths: description: GFE Name type: string example: "HLA-Aw878-8-363-912-830-2901-1044-581-151-324-198-9-316-80-508-43-151" - who: - description: WHO Name + allele: + description: IPD-IMGT/HLA Allele Name type: string example: "HLA-A*01:01:01:08" imgt_versions: - description: IMGT Versions + description: IPD-IMGT/HLA Database Versions type: array items: type: string @@ -103,15 +103,15 @@ paths: /gfe/locus/{gene}: get: - summary: GFEs and WHO Names for a gene + summary: GFEs and IPD Allele Names for a gene tags: - GFE operationId: api.all_locus_gfe - description: Get all GFEs and WHO Names for a gene + description: Get all GFEs and IPD Allele Names for a gene parameters: - name: gene in: path - description: WHO Gene Name + description: IPD Allele Gene Name required: true schema: type: string @@ -119,7 +119,7 @@ paths: example: "HLA-A" responses: 200: - description: List of WHO allele names and their corresponding GFEs + description: List of IPD Allele names and their corresponding GFEs content: application/json: schema: @@ -130,7 +130,7 @@ paths: type: string example: "HLA-A" GFEs: - description: List of WHO alleles and GFE + description: List of IPD Alleles and GFE type: array items: type: object @@ -140,7 +140,7 @@ paths: type: string example: "HLA-Aw878-8-363-912-830-2901-1044-581-151-324-198-9-316-80-508-43-151" who: - description: WHO Allele Name + description: IPD Allele Name type: string example: "HLA-A*01:01:01:08" diff --git a/api.py b/api.py index 74c81b4..ed0fa54 100644 --- a/api.py +++ b/api.py @@ -1,7 +1,7 @@ import yaml from py2neo import Graph -import query +from gfe_service import query with open("neo4j.yaml", "r") as neo4j_file: neo_dict = yaml.safe_load(neo4j_file) @@ -20,14 +20,14 @@ def imgt_versions(): return {"imgt_versions": dbs}, 200 -def gfe_from_who(who_name: str): - cypher = query.gfe_from_who() - response = graph.run(cypher, {"who_name": who_name}) +def gfe_from_ipd(ipd_name: str): + cypher = query.gfe_from_ipd() + response = graph.run(cypher, {"ipd_name": ipd_name}) result = response.next() return { "locus": result["locus"], "gfe": result["gfe"], - "who": result["who"], + "allele": result["allele"], "imgt_versions": result["imgt_versions"], }, 200 @@ -37,7 +37,7 @@ def all_locus_gfe(gene: str): response = graph.run(cypher, {"locus": gene}) allele_gfe_list = [] for result in response: - allele_gfe_list.append({"allele": result["who"], "GFE": result["gfe"]}) + allele_gfe_list.append({"allele": result["allele"], "GFE": result["gfe"]}) return {"gene": gene, "GFEs": allele_gfe_list} diff --git a/gfe_service/__init__.py b/gfe_service/__init__.py index 741e7c3..45e3551 100644 --- a/gfe_service/__init__.py +++ b/gfe_service/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# gfe_service My Project Template. +# gfe_service GFE Service. # Copyright (c) 2021 Be The Match operated by National Marrow Donor Program. All Rights Reserved. # # This library is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ # -"""Top-level package for My Project Template.""" +"""Top-level package for gfe-service.""" __organization__ = "NMDP/CIBMTR Bioinformatics" -__version__ = "2.0.1" +__version__ = "2.0.0" diff --git a/gfe_service/gfe_service.py b/gfe_service/gfe_service.py index ce8859f..66cf730 100644 --- a/gfe_service/gfe_service.py +++ b/gfe_service/gfe_service.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# gfe_service My Project Template. +# gfe_service GFE Service. # Copyright (c) 2021 Be The Match operated by National Marrow Donor Program. All Rights Reserved. # # This library is free software; you can redistribute it and/or modify it diff --git a/query.py b/gfe_service/query.py similarity index 57% rename from query.py rename to gfe_service/query.py index 8452341..21b8bc4 100644 --- a/query.py +++ b/gfe_service/query.py @@ -1,6 +1,6 @@ def imgt_db_versions(): query = """ - MATCH (g:GFE)-[e:HAS_WHO]-(w:WHO) + MATCH (g:GFE)-[e:HAS_IPD_Allele]-(a:IPD_Allele) WITH COLLECT(DISTINCT e.releases) AS releases UNWIND REDUCE(output=[], r IN releases| output + r) as dbs RETURN COLLECT(DISTINCT dbs) as HLA_DB_VERSIONS @@ -9,20 +9,20 @@ def imgt_db_versions(): return query -def gfe_from_who(): +def gfe_from_ipd(): query = """ - MATCH (g:GFE)-[r:HAS_WHO]-(w:WHO) - WHERE w.name = $who_name - RETURN g.locus AS locus, g.gfe_name AS gfe, w.name AS who, r.releases AS imgt_versions + MATCH (g:GFE)-[r:HAS_IPD_Allele]-(a:IPD_Allele) + WHERE a.name = $allele + RETURN g.locus AS locus, g.gfe_name AS gfe, a.name AS allele, r.releases AS imgt_versions """ return query def all_gfe_from_locus(): query = """ - MATCH (g:GFE)-[:HAS_WHO]-(w:WHO) + MATCH (g:GFE)-[:HAS_IPD_Allele]-(a:IPD_Allele) WHERE g.locus = $locus - RETURN g.gfe_name AS gfe, w.name AS who + RETURN g.gfe_name AS gfe, a.name AS allele limit 100 """ return query @@ -31,6 +31,6 @@ def all_gfe_from_locus(): def sequence_from_gfe(): query = """ MATCH (g:GFE)-[:HAS_SEQUENCE]-(s:Sequence) - WHERE g.gfe_name = $gfe return s.sequence as sequence; + WHERE g.name = $gfe return s.sequence as sequence; """ return query diff --git a/neo4j.yaml b/neo4j.yaml index ba84202..2ad823e 100644 --- a/neo4j.yaml +++ b/neo4j.yaml @@ -1,5 +1,4 @@ --- user: "neo4j" password: "gfedb" -# neo4j_url: "http://0.0.0.0:7474" - neo4j_url: "http://dev-gfedb.b12x.org:7474" + neo4j_url: "http://workshop-gfedb.b12x.org:7474" diff --git a/requirements-tests.txt b/requirements-tests.txt index d36e916..77d53a7 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,3 +1,3 @@ -pytest==6.2.5 +pytest==7.1.2 behave==1.2.6 -PyHamcrest==2.0.2 +PyHamcrest==2.0.3 diff --git a/requirements.txt b/requirements.txt index e69de29..60c2920 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +py2neo==2021.2.3 diff --git a/setup.cfg b/setup.cfg index 91b50fa..96a12cb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,15 +1,15 @@ [bumpversion] -current_version = 0.0.1 +current_version = 2.0.0 commit = True tag = True [bumpversion:file:setup.py] -search = version='{current_version}' -replace = version='{new_version}' +search = version="{current_version}" +replace = version="{new_version}" -[bumpversion:file:my_project_template/__init__.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' +[bumpversion:file:gfe_service/__init__.py] +search = __version__ = "{current_version}" +replace = __version__ = "{new_version}" [bdist_wheel] universal = 1 @@ -18,5 +18,4 @@ universal = 1 exclude = docs [aliases] -# Define setup.py command aliases here test = pytest diff --git a/setup.py b/setup.py index e06e8c6..3526125 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # -# gfe_service My Project Template. +# gfe_service GFE Service. # Copyright (c) 2021 Be The Match operated by National Marrow Donor Program. All Rights Reserved. # # This library is free software; you can redistribute it and/or modify it @@ -57,12 +57,12 @@ license="LGPL 3.0", long_description=readme + "\n\n" + history, include_package_data=True, - keywords="gfe_service", + keywords="GFE,HLA", name="gfe_service", packages=find_packages(include=["gfe_service"]), test_suite="tests", tests_require=test_requirements, url="https://github.com/nmdp-bioinformatics/my_project_template", - version="0.0.1", + version="2.0.0", zip_safe=False, ) diff --git a/tests/unit/test_sample.py b/tests/unit/test_sample.py index 2cda8e5..6a42ef6 100644 --- a/tests/unit/test_sample.py +++ b/tests/unit/test_sample.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# gfe_service My Project Template. +# gfe_service GFE Service. # Copyright (c) 2021 Be The Match operated by National Marrow Donor Program. All Rights Reserved. # # This library is free software; you can redistribute it and/or modify it