Skip to content

Commit 13f1f90

Browse files
committed
add cassettes etc
1 parent 05cea72 commit 13f1f90

13 files changed

+988
-59
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test = [
3737
"httpx",
3838
"jsonschema",
3939
"pyyaml",
40-
"responses",
40+
"pytest-recording",
4141
]
4242
dev = [
4343
"ruff==0.12.8",

src/anyvlm/anyvar/base_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
from anyvar.utils.types import VrsVariation
66

7-
# define constant to use as AnyVar annotation type
8-
AF_ANNOTATION_TYPE = "cohort_allele_frequency"
97

10-
11-
class AmbiguousAnnotationError(Exception):
12-
"""Raise if multiple candidate annotations exist on a variation"""
8+
class AnyVarConnectionError(Exception):
9+
"""Raise for network/communication failures when making calls to AnyVar instance"""
1310

1411

1512
class BaseAnyVarClient(abc.ABC):
@@ -21,6 +18,7 @@ def put_objects(self, objects: list[VrsVariation]) -> list[VrsVariation]:
2118
2219
:param objects: variation objects to register
2320
:return: completed VRS objects
21+
:raise AnyVarConnectionError: if connection is unsuccessful during registration request
2422
"""
2523

2624
@abc.abstractmethod
@@ -33,6 +31,7 @@ def search_by_interval(
3331
:param start: start position for genomic region
3432
:param end: end position for genomic region
3533
:return: list of matching variant objects
34+
:raise AnyVarConnectionError: if connection is unsuccessful during search query
3635
"""
3736

3837
@abc.abstractmethod

src/anyvlm/anyvar/http_client.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from anyvar.utils.types import VrsVariation
55
from ga4gh.vrs import models
66

7-
from anyvlm.anyvar.base_client import BaseAnyVarClient
7+
from anyvlm.anyvar.base_client import AnyVarConnectionError, BaseAnyVarClient
88

99

1010
class HttpAnyVarClient(BaseAnyVarClient):
@@ -30,6 +30,7 @@ def put_objects(self, objects: list[VrsVariation]) -> list[VrsVariation]:
3030
3131
:param objects: variation objects to register
3232
:return: completed VRS objects
33+
:raise AnyVarConnectionError: if connection is unsuccessful during registration request
3334
"""
3435
results = []
3536
url = f"{self.hostname}/vrs_variation"
@@ -39,7 +40,10 @@ def put_objects(self, objects: list[VrsVariation]) -> list[VrsVariation]:
3940
json=vrs_object.model_dump(exclude_none=True, mode="json"),
4041
timeout=self.request_timeout,
4142
)
42-
response.raise_for_status()
43+
try:
44+
response.raise_for_status()
45+
except requests.HTTPError as e:
46+
raise AnyVarConnectionError from e
4347
result_object = response.json()["object"]
4448
if result_object.get("type") == "Allele":
4549
results.append(models.Allele(**result_object))
@@ -58,13 +62,17 @@ def search_by_interval(
5862
:param start: start position for genomic region
5963
:param end: end position for genomic region
6064
:return: list of matching variant objects
65+
:raise AnyVarConnectionError: if connection is unsuccessful during search query
6166
"""
6267
response = requests.get(
63-
f"{self.hostname}/search?accession={accession}&start={start}&end{end}",
68+
f"{self.hostname}/search?accession={accession}&start={start}&end={end}",
6469
timeout=self.request_timeout,
6570
)
66-
response.raise_for_status()
67-
return response.json()["variations"]
71+
try:
72+
response.raise_for_status()
73+
except requests.HTTPError as e:
74+
raise AnyVarConnectionError from e
75+
return [models.Allele(**v) for v in response.json()["variations"]]
6876

6977
def close(self) -> None:
7078
"""Clean up AnyVar connection.

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import json
12
from pathlib import Path
23

34
import pytest
45
from dotenv import load_dotenv
6+
from ga4gh.vrs import models
7+
from pydantic import BaseModel
58

69

710
@pytest.fixture(scope="session", autouse=True)
@@ -17,3 +20,19 @@ def load_env():
1720
def test_data_dir() -> Path:
1821
"""Provide Path instance pointing to test data directory"""
1922
return Path(__file__).parent / "data"
23+
24+
25+
@pytest.fixture(scope="session")
26+
def alleles(test_data_dir: Path):
27+
class _AlleleFixture(BaseModel):
28+
"""Validate data structure in variations.json"""
29+
30+
variation: models.Allele
31+
comment: str | None = None
32+
33+
with (test_data_dir / "variations.json").open() as f:
34+
data = json.load(f)
35+
alleles = data["alleles"]
36+
for allele in alleles.values():
37+
assert _AlleleFixture(**allele), f"Not a valid allele fixture: {allele}"
38+
return alleles

tests/data/variations.json

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"alleles": {
3+
"ga4gh:VA.d6ru7RcuVO0-v3TtPFX5fZz-GLQDhMVb": {
4+
"variation": {
5+
"id": "ga4gh:VA.d6ru7RcuVO0-v3TtPFX5fZz-GLQDhMVb",
6+
"type": "Allele",
7+
"digest": "d6ru7RcuVO0-v3TtPFX5fZz-GLQDhMVb",
8+
"location": {
9+
"id": "ga4gh:SL.JOFKL4nL5mRUlO_xLwQ8VOD1v7mxhs3I",
10+
"type": "SequenceLocation",
11+
"digest": "JOFKL4nL5mRUlO_xLwQ8VOD1v7mxhs3I",
12+
"sequenceReference": {
13+
"type": "SequenceReference",
14+
"refgetAccession": "SQ.IW78mgV5Cqf6M24hy52hPjyyo5tCCd86"
15+
},
16+
"start": 36561661,
17+
"end": 36561663
18+
},
19+
"state": {
20+
"type": "ReferenceLengthExpression",
21+
"length": 0,
22+
"sequence": "",
23+
"repeatSubunitLength": 2
24+
}
25+
},
26+
"comment": "NC_000007.13:g.36561662_36561663del"
27+
},
28+
"ga4gh:VA.Otc5ovrw906Ack087o1fhegB4jDRqCAe": {
29+
"variation": {
30+
"id": "ga4gh:VA.Otc5ovrw906Ack087o1fhegB4jDRqCAe",
31+
"type": "Allele",
32+
"digest": "Otc5ovrw906Ack087o1fhegB4jDRqCAe",
33+
"location": {
34+
"id": "ga4gh:SL.nhul5x5P_fKjGEpY9PEkMIekJfZaKom2",
35+
"type": "SequenceLocation",
36+
"digest": "nhul5x5P_fKjGEpY9PEkMIekJfZaKom2",
37+
"start": 140753335,
38+
"end": 140753336,
39+
"sequenceReference": {
40+
"type": "SequenceReference",
41+
"refgetAccession": "SQ.F-LrLMe1SRpfUZHkQmvkVKFEGaoDeHul"
42+
}
43+
},
44+
"state": { "type": "LiteralSequenceExpression", "sequence": "T" }
45+
},
46+
"comment": "BRAF V600E (genomic)"
47+
},
48+
"ga4gh:VA.ruQCmfXJrEylHmOQF-1PG6bLwQesDU2g": {
49+
"variation": {
50+
"id": "ga4gh:VA.ruQCmfXJrEylHmOQF-1PG6bLwQesDU2g",
51+
"type": "Allele",
52+
"digest": "ruQCmfXJrEylHmOQF-1PG6bLwQesDU2g",
53+
"location": {
54+
"id": "ga4gh:SL.JqeJ3V-75edWj03xbzw1gtSw3qPQVV2D",
55+
"digest": "JqeJ3V-75edWj03xbzw1gtSw3qPQVV2D",
56+
"type": "SequenceLocation",
57+
"start": 2781703,
58+
"end": 2781704,
59+
"sequenceReference": {
60+
"type": "SequenceReference",
61+
"refgetAccession": "SQ.8_liLu1aycC0tPQPFmUaGXJLDs5SbPZ5"
62+
}
63+
},
64+
"state": {
65+
"type": "LiteralSequenceExpression",
66+
"sequence": "G"
67+
}
68+
},
69+
"comment": "Y-2781704-G-G"
70+
},
71+
"ga4gh:VA.IM4QyU9D2kTJzeftUBBD4Vcd1peq0dn1": {
72+
"variation": {
73+
"id": "ga4gh:VA.IM4QyU9D2kTJzeftUBBD4Vcd1peq0dn1",
74+
"digest": "IM4QyU9D2kTJzeftUBBD4Vcd1peq0dn1",
75+
"type": "Allele",
76+
"location": {
77+
"id": "ga4gh:SL.sWfeTXwGUkfIuYRAkiFGPjkSk_mIDuXG",
78+
"digest": "sWfeTXwGUkfIuYRAkiFGPjkSk_mIDuXG",
79+
"type": "SequenceLocation",
80+
"start": 2781760,
81+
"end": 2781762,
82+
"sequenceReference": {
83+
"type": "SequenceReference",
84+
"refgetAccession": "SQ.8_liLu1aycC0tPQPFmUaGXJLDs5SbPZ5"
85+
}
86+
},
87+
"state": {
88+
"type": "LiteralSequenceExpression",
89+
"sequence": "CA"
90+
}
91+
},
92+
"comment": "Y-2781761-C-C"
93+
},
94+
"ga4gh:VA.xbX035HgURWIUAjn6x3cS26jafP8Q_bk": {
95+
"variation": {
96+
"id": "ga4gh:VA.xbX035HgURWIUAjn6x3cS26jafP8Q_bk",
97+
"digest": "xbX035HgURWIUAjn6x3cS26jafP8Q_bk",
98+
"type": "Allele",
99+
"location": {
100+
"id": "ga4gh:SL.sYiBcbbgF-1CANNCTfQ6zwZOU0iHhymR",
101+
"digest": "sYiBcbbgF-1CANNCTfQ6zwZOU0iHhymR",
102+
"type": "SequenceLocation",
103+
"start": 2781760,
104+
"end": 2781761,
105+
"sequenceReference": {
106+
"type": "SequenceReference",
107+
"refgetAccession": "SQ.8_liLu1aycC0tPQPFmUaGXJLDs5SbPZ5"
108+
}
109+
},
110+
"state": { "type": "LiteralSequenceExpression", "sequence": "C" }
111+
},
112+
"comment": "Y-2781761-C-C"
113+
},
114+
"ga4gh:VA.9VDxL0stMBOZwcTKw3yb3UoWQkpaI9OD": {
115+
"variation": {
116+
"id": "ga4gh:VA.9VDxL0stMBOZwcTKw3yb3UoWQkpaI9OD",
117+
"digest": "9VDxL0stMBOZwcTKw3yb3UoWQkpaI9OD",
118+
"type": "Allele",
119+
"location": {
120+
"id": "ga4gh:SL.sYiBcbbgF-1CANNCTfQ6zwZOU0iHhymR",
121+
"digest": "sYiBcbbgF-1CANNCTfQ6zwZOU0iHhymR",
122+
"type": "SequenceLocation",
123+
"start": 2781760,
124+
"end": 2781761,
125+
"sequenceReference": {
126+
"type": "SequenceReference",
127+
"refgetAccession": "SQ.8_liLu1aycC0tPQPFmUaGXJLDs5SbPZ5"
128+
}
129+
},
130+
"state": { "type": "LiteralSequenceExpression", "sequence": "A" }
131+
},
132+
"comment": "Y-2781761-C-A"
133+
},
134+
"ga4gh:VA.yi7A2l0uIUMaInQaJnHU_B2Cf_OuZRJg": {
135+
"variation": {
136+
"id": "ga4gh:VA.yi7A2l0uIUMaInQaJnHU_B2Cf_OuZRJg",
137+
"type": "Allele",
138+
"digest": "yi7A2l0uIUMaInQaJnHU_B2Cf_OuZRJg",
139+
"location": {
140+
"id": "ga4gh:SL.JsFGLKlUDocinf7oWTXAvVT2WOso7R9u",
141+
"digest": "JsFGLKlUDocinf7oWTXAvVT2WOso7R9u",
142+
"type": "SequenceLocation",
143+
"start": 2781761,
144+
"end": 2781785,
145+
"sequenceReference": {
146+
"type": "SequenceReference",
147+
"refgetAccession": "SQ.8_liLu1aycC0tPQPFmUaGXJLDs5SbPZ5"
148+
}
149+
},
150+
"state": {
151+
"type": "ReferenceLengthExpression",
152+
"length": 23,
153+
"sequence": "AAAAAAAAAAAAAAAAAAAAAAA",
154+
"repeatSubunitLength": 1
155+
}
156+
},
157+
"comment": "Y-2781761-CA-C"
158+
}
159+
}
160+
}

0 commit comments

Comments
 (0)