From 9b58c5cf3eb5aa21399679c8049bd09d2f67d05c Mon Sep 17 00:00:00 2001 From: korikuzma Date: Tue, 26 Mar 2024 13:36:03 -0400 Subject: [PATCH] chore: move VariationNormalizerRESTDataProxy to notebooks * This dp is only for notebooks, so it should live within the notebook dir --- notebooks/Extras.ipynb | 2 +- notebooks/HGVS Translation.ipynb | 6 +++--- .../variation_normalizer_rest_dp.py | 14 ++++++-------- .../test_variation_normalizer_rest_dp.py | 18 ------------------ 4 files changed, 10 insertions(+), 30 deletions(-) rename {src/ga4gh/vrs/extras => notebooks}/variation_normalizer_rest_dp.py (71%) delete mode 100644 tests/extras/test_variation_normalizer_rest_dp.py diff --git a/notebooks/Extras.ipynb b/notebooks/Extras.ipynb index 0bb04b88..209a8f16 100644 --- a/notebooks/Extras.ipynb +++ b/notebooks/Extras.ipynb @@ -210,7 +210,7 @@ } ], "source": [ - "from ga4gh.vrs.extras.variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", + "from variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", "vnorm = VariationNormalizerRESTDataProxy()\n", "vnorm.to_hgvs(a)" ] diff --git a/notebooks/HGVS Translation.ipynb b/notebooks/HGVS Translation.ipynb index 7d0052d5..a1a0b128 100644 --- a/notebooks/HGVS Translation.ipynb +++ b/notebooks/HGVS Translation.ipynb @@ -287,7 +287,7 @@ "metadata": {}, "outputs": [], "source": [ - "from ga4gh.vrs.extras.variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", + "from variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", "vnorm = VariationNormalizerRESTDataProxy()" ] }, @@ -423,10 +423,10 @@ "source": [ "import tabulate\n", "from ga4gh.vrs.normalize import normalize\n", - "from ga4gh.vrs.extras.variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", + "from variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy\n", "vnorm = VariationNormalizerRESTDataProxy()\n", "\n", - "#The postgres default port of 5432 is blocked outbound by binder and potentially other institutions. \n", + "#The postgres default port of 5432 is blocked outbound by binder and potentially other institutions.\n", "#To circumvent users having to install UTA themsleves we created a rest data proxy for variation normalizer for the to_hgvs endpoint.\n", "\n", "# todo: this example should get changed to use normalized hgvs_g as input.\n", diff --git a/src/ga4gh/vrs/extras/variation_normalizer_rest_dp.py b/notebooks/variation_normalizer_rest_dp.py similarity index 71% rename from src/ga4gh/vrs/extras/variation_normalizer_rest_dp.py rename to notebooks/variation_normalizer_rest_dp.py index 14dd6ddc..44f4c604 100644 --- a/src/ga4gh/vrs/extras/variation_normalizer_rest_dp.py +++ b/notebooks/variation_normalizer_rest_dp.py @@ -1,18 +1,16 @@ import requests class VariationNormalizerRESTDataProxy: - """ - Rest data proxy for Variation Normalizer API - """ + """Rest data proxy for Variation Normalizer API""" def __init__(self) -> None: """ Initialize class with the API URL """ self.api = "https://normalize.cancervariants.org/variation" - def to_hgvs(self, vo, namespace="refseq"): - """ - tranlsate vrs allele object (vo) to hgvs format + def to_hgvs(self, vo, namespace="refseq") -> list[str]: + """Translate vrs allele object (vo) to hgvs format + Use this method if you don't have UTA installed locally or are unable to reach the public UTA database due to port issues. """ @@ -29,5 +27,5 @@ def to_hgvs(self, vo, namespace="refseq"): if r.status_code == 200: return r.json().get("variations", []) else: - raise requests.HTTPError(f"Variation normalizer returned the status code: {r.status_code}.") - + err_msg = f"Variation normalizer returned the status code: {r.status_code}." + raise requests.HTTPError(err_msg) diff --git a/tests/extras/test_variation_normalizer_rest_dp.py b/tests/extras/test_variation_normalizer_rest_dp.py deleted file mode 100644 index 03aad933..00000000 --- a/tests/extras/test_variation_normalizer_rest_dp.py +++ /dev/null @@ -1,18 +0,0 @@ -import pytest - -from ga4gh.vrs import models -from ga4gh.vrs.extras.variation_normalizer_rest_dp import VariationNormalizerRESTDataProxy -from tests.extras.test_allele_translator import hgvs_tests, hgvs_tests_to_hgvs_map - - -@pytest.fixture(scope="module") -def variation_norm_rest_dp(): - return VariationNormalizerRESTDataProxy() - - -@pytest.mark.parametrize("expected,vo_as_dict", hgvs_tests) -@pytest.mark.vcr -def test_rest_dp_to_hgvs(variation_norm_rest_dp, expected, vo_as_dict): - vo = models.Allele(**vo_as_dict) - resp = variation_norm_rest_dp.to_hgvs(vo) - assert resp == [hgvs_tests_to_hgvs_map.get(expected, expected)]