Skip to content

Commit

Permalink
add reusable function for checking valid sequence locations
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Aug 3, 2024
1 parent d28870f commit be13369
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 19 additions & 3 deletions server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ async def check_response(
return check_response


@pytest.fixture(scope="session")
def check_sequence_location():
"""Check that a sequence location is valid
:param dict sequence_location: sequence location structure
"""

def check_sequence_location(sequence_location):
assert "ga4gh:SL." in sequence_location.get("id")
sequence_reference = sequence_location.get("sequenceReference", {})
assert "refseq:" in sequence_reference.get("id")
assert sequence_reference.get("refgetAccession")
assert sequence_reference.get("type") == "SequenceReference"

return check_sequence_location


@pytest.fixture(scope="module")
def alk_descriptor():
"""Gene descriptor for ALK gene"""
Expand Down Expand Up @@ -128,9 +144,9 @@ def tpm3_tx_t_element(tpm3_descriptor):
"type": "TranscriptSegmentElement",
"transcript": "refseq:NM_152263.4",
"exonStart": 6,
"exonStartOffset": 72,
"exonStartOffset": 71,
"exonEnd": 6,
"exonEndOffset": -5,
"exonEndOffset": -4,
"gene": tpm3_descriptor,
"elementGenomicStart": {
"id": "fusor.location_descriptor:NC_000001.11",
Expand Down Expand Up @@ -158,7 +174,7 @@ def tpm3_tx_g_element(tpm3_descriptor):
"exonStart": 6,
"exonStartOffset": 5,
"exonEnd": 6,
"exonEndOffset": -70,
"exonEndOffset": -71,
"gene": tpm3_descriptor,
"elementGenomicStart": {
"id": "fusor.location_descriptor:NC_000001.11",
Expand Down
16 changes: 8 additions & 8 deletions server/tests/integration/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def check_gene_element_response(


@pytest.fixture(scope="session")
def check_tx_element_response():
def check_tx_element_response(check_sequence_location):
"""Provide callback function to check correctness of transcript element constructor."""

def check_tx_element_response(response: dict, expected_response: dict):
Expand All @@ -64,12 +64,12 @@ def check_tx_element_response(response: dict, expected_response: dict):
assert response_element.get("exonEndOffset") == expected_element.get(
"exonEndOffset"
)
assert response_element.get("elementGenomicStart") == expected_element.get(
"elementGenomicStart"
)
assert response_element.get("elementGenomicEnd") == expected_element.get(
"elementGenomicEnd"
)
genomic_start = response_element.get("elementGenomicStart", {})
genomic_end = response_element.get("elementGenomicEnd", {})
if genomic_start:
check_sequence_location(genomic_start)
if genomic_end:
check_sequence_location(genomic_end)

return check_tx_element_response

Expand Down Expand Up @@ -143,7 +143,7 @@ async def test_build_tx_segment_ect(
# test require exonStart or exonEnd
await check_response(
"/api/construct/structural_element/tx_segment_ect?transcript=NM_002529.3",
{"warnings": ["Must provide either `exonStart` or `exonEnd`"]},
{"warnings": ["Must provide either `exon_start` or `exon_end`"]},
check_tx_element_response,
)

Expand Down

0 comments on commit be13369

Please sign in to comment.