From 3d0f71839539f15e59ff40f63e8795f65160f38d Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 14:42:53 -0400 Subject: [PATCH 1/7] updating packing and adding github actions for pypi --- .github/workflows/pypi.yml | 70 ++++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 ++ setup.py | 16 ++++++--- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/pypi.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..9fb2a27 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,70 @@ +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI + +on: + release: + types: [published] + +jobs: + build: + name: Build Python 🐍 distributions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.9" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/robokop-genetics + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + needs: + - publish-to-testpypi + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/robokop-genetics + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7fd26b9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py index c1914e9..fdc0963 100644 --- a/setup.py +++ b/setup.py @@ -5,19 +5,25 @@ setuptools.setup( name="robokop-genetics", - version="0.4.1", + version="0.5.0", author="Evan Morris", author_email="evandietzmorris@gmail.com", + maintainer="Evan Morris", + maintainer_email="evandietzmorris@gmail.com", description="A package for Robokop genetics tools and services.", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/ObesityHub/robokop-genetics", + url="https://github.com/RobokopU24/robokop-genetics", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], - python_requires='>=3.8', - install_requires=["requests", "redis"] -) \ No newline at end of file + python_requires='>=3.9', + license="CC-0", + install_requires=[ + "requests>=2.32.3", + "redis>=5.0.4" + ] +) From 385fd50ebb77cdbab1be751842f27e9332801a2c Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:15:27 -0400 Subject: [PATCH 2/7] adding check for and ignoring protein allele ids --- robokop_genetics/services/clingen.py | 15 +++++++++++++-- tests/test_normalization.py | 13 +++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/robokop_genetics/services/clingen.py b/robokop_genetics/services/clingen.py index 8cb8776..2ea8d6f 100644 --- a/robokop_genetics/services/clingen.py +++ b/robokop_genetics/services/clingen.py @@ -81,7 +81,9 @@ def get_batch_of_synonyms(self, variant_curie_list: list): query_response: ClinGenQueryResponse = self.query_service(query_url, data=variant_pseudo_file) if query_response.success: for allele_json in query_response.response_json: - normalization_results.append(self.parse_result(allele_json)) + parsed_result = self.parse_result(allele_json) + if parsed_result is not None: + normalization_results.append(parsed_result) else: for j in range(len(variant_subset)): normalization_results.append(ClinGenSynonymizationResult(success=False, @@ -131,7 +133,9 @@ def get_synonyms_by_parameter_matching(self, url_param: str, url_param_value: st error_message='Clingen returned a 200 status but no results.')) else: for response_item in query_response.response_json: - synonymization_results.append(self.parse_result(response_item)) + parsed_result = self.parse_result(response_item) + if parsed_result is not None: + synonymization_results.append(parsed_result) if allele_preference: filtered_syn_results = [] for syn_result in synonymization_results: @@ -159,6 +163,13 @@ def parse_result(self, allele_json: dict): error_message=cg_error_description) try: variant_caid = allele_json['@id'].rsplit('/', 1)[1] + # clingen added Protein Allele IDs but we don't want them (for now) + if variant_caid.startswith('PA'): + return None + # we could do something like the following, but it's not really an error, let's just ignore them + # return ClinGenSynonymizationResult(success=False, + # error_type='UnsupportedIdentifier', + # error_message=f'Protein Allele IDs not supported {variant_caid}') except KeyError: return ClinGenSynonymizationResult(success=False, error_type='MissingIdentifier', diff --git a/tests/test_normalization.py b/tests/test_normalization.py index 04d8af0..bbb2533 100644 --- a/tests/test_normalization.py +++ b/tests/test_normalization.py @@ -41,10 +41,15 @@ def test_one_at_a_time_normalization(genetics_normalizer): assert normalization_result['error_type'] == 'InefficientUsage' node_id = "CLINVARVARIANT:18390" - normalization_info = genetics_normalizer.get_sequence_variant_normalization(node_id).pop() - assert normalization_info["id"] == 'CAID:CA128085' - assert normalization_info["name"] == 'rs671' - assert 'DBSNP:rs671' in normalization_info["equivalent_identifiers"] + synonymization_results = genetics_normalizer.get_sequence_variant_normalization(node_id) + found_result = False + for normalization_info in synonymization_results: + if 'id' in normalization_info: + assert normalization_info["id"] == 'CAID:CA128085' + assert normalization_info["name"] == 'rs671' + assert 'DBSNP:rs671' in normalization_info["equivalent_identifiers"] + found_result = True + assert found_result # rs369602258 is tri-allelic - the following tests show how a specific allele can be normalized from a DBSNP # if no allele specified return all CAID and their synonym sets From eb37afbdad28ec13bbdc5b57b2763e0cfb25c1bd Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:26:04 -0400 Subject: [PATCH 3/7] adding test workflow --- .github/workflows/test.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..08c7ce2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run pytest + run: | + python -m pytest tests/ From 590d2684d0bae869c83d0b4af85c6f7237147009 Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:27:36 -0400 Subject: [PATCH 4/7] adding requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fd50096 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests>=2.32.3 +redis>=5.0.4 From eb41834a36db1475b132278ef61e55f1d4710a88 Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:36:54 -0400 Subject: [PATCH 5/7] fixing pytest for testing actions --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 08c7ce2..5dadc38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + pip install pytest - name: Run pytest run: | python -m pytest tests/ From ab09defe322b1e803f97f5d4900800236cd68c92 Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:41:50 -0400 Subject: [PATCH 6/7] skip the cache tests --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5dadc38..878973c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install pytest + pip install pytest tests/test_normalization.py tests/test_services.py - name: Run pytest run: | python -m pytest tests/ From e9f49a2da6daf6f80057e90640b0549a53e46c87 Mon Sep 17 00:00:00 2001 From: Evan Morris Date: Tue, 4 Jun 2024 15:45:00 -0400 Subject: [PATCH 7/7] fixing pytest typo --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 878973c..ca24a95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install pytest tests/test_normalization.py tests/test_services.py + pip install pytest - name: Run pytest run: | - python -m pytest tests/ + python -m pytest tests/test_normalization.py tests/test_services.py