Skip to content

Commit

Permalink
Merge branch 'main' into refactor-set-header
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Feb 7, 2025
2 parents 49d2e47 + 0b8702c commit 0c73bd5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/ga4gh/vrs/dataproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def create_dataproxy(uri: str | None = None) -> _DataProxy:
* seqrepo+http://localhost:5000/seqrepo
* seqrepo+https://somewhere:5000/seqrepo
:raise ValueError: if URI doesn't match recognized schemes, e.g. is missing provider
prefix (`"seqrepo+"`)
"""
uri = uri or os.environ.get("GA4GH_VRS_DATAPROXY_URI", None)

Expand Down
29 changes: 5 additions & 24 deletions src/ga4gh/vrs/extras/annotator/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import pysam
from biocommons.seqrepo import SeqRepo
from pydantic import ValidationError

from ga4gh.core.identifiers import (
VrsObjectIdentifierIs,
use_ga4gh_compute_identifier_when,
)
from ga4gh.vrs.dataproxy import (
DataProxyValidationError,
SeqRepoDataProxy,
SeqRepoRESTDataProxy,
)
Expand Down Expand Up @@ -270,33 +268,16 @@ def _get_vrs_object(
assembly_name=assembly,
require_validation=require_validation,
)
except (ValidationError, DataProxyValidationError):
vrs_obj = None
_logger.exception(
"ValidationError when translating %s from gnomad", vcf_coords
)
raise
except KeyError:
vrs_obj = None
_logger.exception("KeyError when translating %s from gnomad", vcf_coords)
raise
except AssertionError:
vrs_obj = None
_logger.exception(
"AssertionError when translating %s from gnomad", vcf_coords
)
raise
except Exception:
vrs_obj = None
_logger.exception(
"Unhandled Exception when translating %s from gnomad", vcf_coords
"Exception encountered during translation of variation: %s", vcf_coords
)
raise
else:
if not vrs_obj:
_logger.debug(
"None was returned when translating %s from gnomad", vcf_coords
)
if vrs_obj is None:
_logger.debug(
"None was returned when translating %s from gnomad", vcf_coords
)

if vrs_data and vrs_obj:
key = vrs_data_key if vrs_data_key else vcf_coords
Expand Down
22 changes: 0 additions & 22 deletions tests/extras/test_dataproxy.py

This file was deleted.

67 changes: 67 additions & 0 deletions tests/test_dataproxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import re

import pytest

from ga4gh.vrs.dataproxy import create_dataproxy


@pytest.mark.parametrize("dp", ["rest_dataproxy", "dataproxy"])
@pytest.mark.vcr
def test_data_proxies(dp, request):
dataproxy = request.getfixturevalue(dp)
r = dataproxy.get_metadata("NM_000551.3")
assert r["length"] == 4560
assert "ga4gh:SQ.v_QTc1p-MUYdgrRv4LMT6ByXIOsdw3C_" in r["aliases"]

r = dataproxy.get_metadata("NC_000013.11")
assert r["length"] == 114364328
assert "ga4gh:SQ._0wi-qoDrvram155UmcSC-zA5ZK4fpLT" in r["aliases"]

seq = dataproxy.get_sequence("ga4gh:SQ.v_QTc1p-MUYdgrRv4LMT6ByXIOsdw3C_")
assert seq.startswith("CCTCGCCTCCGTTACAACGGCCTACGGTGCTGGAGGATCCTTCTGCGCAC")

seq = dataproxy.get_sequence(
"ga4gh:SQ.v_QTc1p-MUYdgrRv4LMT6ByXIOsdw3C_", start=0, end=50
)
assert seq == "CCTCGCCTCCGTTACAACGGCCTACGGTGCTGGAGGATCCTTCTGCGCAC"


def test_data_proxy_configs():
with pytest.raises(
ValueError,
match=re.escape(
"create_dataproxy scheme must include provider (e.g., `seqrepo+http:...`)"
),
):
create_dataproxy("file:///path/to/seqrepo/root")

with pytest.raises(
ValueError,
match=re.escape("SeqRepo URI scheme seqrepo+fake-scheme not implemented"),
):
create_dataproxy("seqrepo+fake-scheme://localhost:5000")

with pytest.raises(
ValueError, match="DataProxy provider fake-dataprovider not implemented"
):
create_dataproxy("fake-dataprovider+http://localhost:5000")

with pytest.raises(
ValueError,
match="No data proxy URI provided or found in GA4GH_VRS_DATAPROXY_URI",
):
create_dataproxy(None)

# check that fallback on env var works
os.environ["GA4GH_VRS_DATAPROXY_URI"] = "seqrepo+:tests/data/seqrepo/latest"
create_dataproxy(None)

# check that method arg takes precedence by passing an invalid arg
with pytest.raises(
ValueError,
match=re.escape(
"create_dataproxy scheme must include provider (e.g., `seqrepo+http:...`)"
),
):
create_dataproxy("file:///path/to/seqrepo/root")

0 comments on commit 0c73bd5

Please sign in to comment.