Skip to content

Commit

Permalink
fixing nomenclature bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Aug 3, 2024
1 parent 8031f47 commit c3d2ac6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 80 deletions.
27 changes: 19 additions & 8 deletions server/src/curfu/routers/nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from curfu import logger
from curfu.schemas import NomenclatureResponse, ResponseDict, RouteTag
from curfu.sequence_services import get_strand

router = APIRouter()

Expand Down Expand Up @@ -47,7 +48,7 @@ def generate_regulatory_element_nomenclature(
logger.warning(
f"Encountered ValidationError: {error_msg} for regulatory element: {regulatory_element}"
)
return {"warnings": [error_msg]}
return {"nomenclature": "", "warnings": [error_msg]}
try:
nomenclature = reg_element_nomenclature(
structured_reg_element, request.app.state.fusor.seqrepo
Expand All @@ -57,9 +58,10 @@ def generate_regulatory_element_nomenclature(
f"Encountered parameter errors for regulatory element: {regulatory_element}"
)
return {
"nomenclature": "",
"warnings": [
f"Unable to validate regulatory element with provided parameters: {regulatory_element}"
]
],
}
return {"nomenclature": nomenclature}

Expand Down Expand Up @@ -87,7 +89,7 @@ def generate_tx_segment_nomenclature(tx_segment: dict = Body()) -> ResponseDict:
logger.warning(
f"Encountered ValidationError: {error_msg} for tx segment: {tx_segment}"
)
return {"warnings": [error_msg]}
return {"nomenclature": "", "warnings": [error_msg]}
nomenclature = tx_segment_nomenclature(structured_tx_segment)
return {"nomenclature": nomenclature}

Expand All @@ -110,13 +112,20 @@ def generate_templated_seq_nomenclature(
:return: response with nomenclature if successful and warnings otherwise
"""
try:
# convert client input of +/- for strand
strand = (
get_strand(templated_sequence.get("strand"))
if templated_sequence.get("strand") is not None
else None
)
templated_sequence["strand"] = strand
structured_templated_seq = TemplatedSequenceElement(**templated_sequence)
except ValidationError as e:
error_msg = str(e)
logger.warning(
f"Encountered ValidationError: {error_msg} for templated sequence element: {templated_sequence}"
)
return {"warnings": [error_msg]}
return {"nomenclature": "", "warnings": [error_msg]}
try:
nomenclature = templated_seq_nomenclature(
structured_templated_seq, request.app.state.fusor.seqrepo
Expand All @@ -126,9 +135,10 @@ def generate_templated_seq_nomenclature(
f"Encountered parameter errors for templated sequence: {templated_sequence}"
)
return {
"nomenclature": "",
"warnings": [
f"Unable to validate templated sequence with provided parameters: {templated_sequence}"
]
],
}
return {"nomenclature": nomenclature}

Expand All @@ -155,15 +165,16 @@ def generate_gene_nomenclature(gene_element: dict = Body()) -> ResponseDict:
logger.warning(
f"Encountered ValidationError: {error_msg} for gene element: {gene_element}"
)
return {"warnings": [error_msg]}
return {"nomenclature": "", "warnings": [error_msg]}
try:
nomenclature = gene_nomenclature(valid_gene_element)
except ValueError:
logger.warning(f"Encountered parameter errors for gene element: {gene_element}")
return {
"nomenclature": "",
"warnings": [
f"Unable to validate gene element with provided parameters: {gene_element}"
]
],
}
return {"nomenclature": nomenclature}

Expand All @@ -188,6 +199,6 @@ def generate_fusion_nomenclature(
try:
valid_fusion = request.app.state.fusor.fusion(**fusion)
except FUSORParametersException as e:
return {"warnings": [str(e)]}
return {"nomenclature": "", "warnings": [str(e)]}
nomenclature = request.app.state.fusor.generate_nomenclature(valid_fusion)
return {"nomenclature": nomenclature}
4 changes: 2 additions & 2 deletions server/tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import re

import pytest
import pytest_asyncio


@pytest.mark.asyncio()
@pytest_asyncio.fixture(scope="session")
async def test_service_info(async_client):
"""Test /service_info endpoint
Expand Down
111 changes: 41 additions & 70 deletions server/tests/integration/test_nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ def regulatory_element():
"""Provide regulatory element fixture."""
return {
"regulatoryClass": "promoter",
"associatedGene": {
"id": "gene:G1",
"gene": {"gene_id": "hgnc:9339"},
"label": "G1",
},
"associatedGene": {"id": "hgnc:9339", "label": "G1", "type": "Gene"},
}


Expand All @@ -24,26 +20,21 @@ def epcam_5_prime():
return {
"type": "TranscriptSegmentElement",
"transcript": "refseq:NM_002354.2",
"exon_end": 5,
"exon_end_offset": 0,
"exonEnd": 5,
"exonEndOffset": 0,
"gene": {
"id": "normalize.gene:EPCAM",
"type": "Gene",
"label": "EPCAM",
"gene_id": "hgnc:11529",
"id": "hgnc:11529",
},
"element_genomic_end": {
"elementGenomicEnd": {
"id": "fusor.location_descriptor:NC_000002.12",
"type": "SequenceLocation",
"label": "NC_000002.12",
"location": {
"type": "SequenceLocation",
"sequence_id": "refseq:NC_000002.12",
"interval": {
"type": "SequenceInterval",
"start": {"type": "Number", "value": 47377013},
"end": {"type": "Number", "value": 47377014},
},
"start": 47377013,
"end": 47377014,
},
},
}
Expand All @@ -55,27 +46,18 @@ def epcam_3_prime():
return {
"type": "TranscriptSegmentElement",
"transcript": "refseq:NM_002354.2",
"exon_start": 5,
"exon_start_offset": 0,
"exonStart": 5,
"exonStartOffset": 0,
"gene": {
"id": "normalize.gene:EPCAM",
"type": "Gene",
"label": "EPCAM",
"gene_id": "hgnc:11529",
"id": "hgnc:11529",
},
"element_genomic_start": {
"elementGenomicStart": {
"id": "fusor.location_descriptor:NC_000002.12",
"type": "SequenceLocation",
"label": "NC_000002.12",
"location": {
"type": "SequenceLocation",
"sequence_id": "refseq:NC_000002.12",
"interval": {
"type": "SequenceInterval",
"start": {"type": "Number", "value": 47377013},
"end": {"type": "Number", "value": 47377014},
},
},
"start": 47377013,
"end": 47377014,
},
}

Expand All @@ -85,27 +67,18 @@ def epcam_invalid():
"""Provide invalidly-constructed EPCAM transcript segment element."""
return {
"type": "TranscriptSegmentElement",
"exon_end": 5,
"exon_end_offset": 0,
"exonEnd": 5,
"exonEndOffset": 0,
"gene": {
"id": "normalize.gene:EPCAM",
"type": "Gene",
"label": "EPCAM",
"gene_id": "hgnc:11529",
"id": "hgnc:11529",
},
"element_genomic_end": {
"elementGenomicEnd": {
"id": "fusor.location_descriptor:NC_000002.12",
"type": "SequenceLocation",
"label": "NC_000002.12",
"location": {
"type": "SequenceLocation",
"sequence_id": "refseq:NC_000002.12",
"interval": {
"type": "SequenceInterval",
"start": {"type": "Number", "value": 47377013},
"end": {"type": "Number", "value": 47377014},
},
},
"start": 47377013,
"end": 47377014,
},
}

Expand All @@ -117,17 +90,15 @@ def templated_sequence_element():
"type": "TemplatedSequenceElement",
"strand": "-",
"region": {
"id": "NC_000001.11:15455-15566",
"id": "ga4gh:SL.sKl255JONKva_LKJeyfkmlmqXTaqHcWq",
"type": "SequenceLocation",
"location": {
"sequence_id": "refseq:NC_000001.11",
"interval": {
"start": {"type": "Number", "value": 15455},
"end": {"type": "Number", "value": 15566},
},
"type": "SequenceLocation",
"sequenceReference": {
"id": "refseq:NC_000001.11",
"refgetAccession": "SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO",
"type": "SequenceReference",
},
"label": "NC_000001.11:15455-15566",
"start": 15455,
"end": 15566,
},
}

Expand Down Expand Up @@ -176,9 +147,12 @@ async def test_tx_segment_nomenclature(
"/api/nomenclature/transcript_segment?first=true&last=false", json=epcam_invalid
)
assert response.status_code == 200
assert response.json().get("warnings", []) == [
"1 validation error for TranscriptSegmentElement\ntranscript\n field required (type=value_error.missing)"
expected_warnings = [
"validation error for TranscriptSegmentElement",
"Field required",
]
for expected in expected_warnings:
assert expected in response.json().get("warnings", [])[0]


@pytest.mark.asyncio()
Expand All @@ -195,9 +169,9 @@ async def test_gene_element_nomenclature(
json={"type": "GeneElement", "associatedGene": {"id": "hgnc:427"}},
)
assert response.status_code == 200
assert response.json().get("warnings", []) == [
"2 validation errors for GeneElement\ngene\n field required (type=value_error.missing)\nassociatedGene\n extra fields not permitted (type=value_error.extra)"
]
expected_warnings = ["validation error for GeneElement", "Field required"]
for expected in expected_warnings:
assert expected in response.json().get("warnings", [])[0]


@pytest.mark.asyncio()
Expand All @@ -221,21 +195,18 @@ async def test_templated_sequence_nomenclature(
"region": {
"id": "NC_000001.11:15455-15566",
"type": "SequenceLocation",
"location": {
"interval": {
"start": {"type": "Number", "value": 15455},
"end": {"type": "Number", "value": 15566},
},
"sequence_id": "refseq:NC_000001.11",
"type": "SequenceLocation",
},
"start": 15455,
"end": 15566,
},
},
)
assert response.status_code == 200
assert response.json().get("warnings", []) == [
"1 validation error for TemplatedSequenceElement\nstrand\n field required (type=value_error.missing)"
expected_warnings = [
"validation error for TemplatedSequenceElement",
"Input should be a valid integer",
]
for expected in expected_warnings:
assert expected in response.json().get("warnings", [])[0]


@pytest.mark.asyncio()
Expand Down

0 comments on commit c3d2ac6

Please sign in to comment.