Download tests/test_variant_service.py from OpenVar/backend: direct link, hf CLI and curl.
- Browser
- Download file 4.27 kB
-
https://huggingface.co/spaces/OpenVar/backend/resolve/main/tests/test_variant_service.py
- Command line
-
hf download hf://spaces/OpenVar/backend/tests/test_variant_service.py
-
curl -L -o test_variant_service.py https://huggingface.co/spaces/OpenVar/backend/resolve/main/tests/test_variant_service.py
4.27 kB
| import asyncio | |
| from unittest.mock import AsyncMock, Mock | |
| from app.services.variant_service import parse_variant_query, hgvs_to_coordinates, _parse_vep_to_coordinates | |
| class TestVariantService: | |
| def test_parse_coordinates_with_chr(self): | |
| result = parse_variant_query("chr9-135800978-A-G") | |
| assert result["type"] == "coordinates" | |
| assert result["chromosome"] == "9" | |
| assert result["position"] == 135800978 | |
| assert result["ref"] == "A" | |
| assert result["alt"] == "G" | |
| def test_parse_coordinates_without_chr(self): | |
| result = parse_variant_query("9-135800978-A-G") | |
| assert result["type"] == "coordinates" | |
| assert result["chromosome"] == "9" | |
| def test_parse_rsid(self): | |
| result = parse_variant_query("rs123456") | |
| assert result["type"] == "rsid" | |
| assert result["value"] == "rs123456" | |
| def test_parse_structural_variant_dup(self): | |
| result = parse_variant_query("DUP:Chr5:125423848-128107072") | |
| assert result["type"] == "sv" | |
| assert result["chromosome"] == "5" | |
| assert result["start"] == 125423848 | |
| assert result["end"] == 128107072 | |
| assert result["sv_type"] == "DUP" | |
| def test_parse_structural_variant_franklin_style_id(self): | |
| result = parse_variant_query("chr5-125423848-128107072-DUP-hg38") | |
| assert result["type"] == "sv" | |
| assert result["chromosome"] == "5" | |
| assert result["start"] == 125423848 | |
| assert result["end"] == 128107072 | |
| assert result["sv_type"] == "DUP" | |
| assert result["reference_version"] == "hg38" | |
| def test_parse_invalid(self): | |
| result = parse_variant_query("invalid") | |
| assert result["type"] == "unknown" | |
| def test_hgvs_to_coordinates_parses_spdi_and_converts_to_1_based(self): | |
| mock_client = AsyncMock() | |
| mock_response = Mock() | |
| mock_response.status_code = 200 | |
| mock_response.text = "ok" | |
| mock_response.json = Mock(return_value=[ | |
| { | |
| "input": "TSC1:c.359T>C", | |
| "TSC1": { | |
| "spdi": ["NC_000009.12:135786501:A:G"] | |
| }, | |
| } | |
| ]) | |
| mock_client.get.return_value = mock_response | |
| result = asyncio.run(hgvs_to_coordinates("TSC1:c.359T>C", mock_client)) | |
| assert result is not None | |
| assert result["chromosome"] == "9" | |
| assert result["position"] == 135786502 | |
| assert result["ref"] == "A" | |
| assert result["alt"] == "G" | |
| def test_hgvs_to_coordinates_parses_genomic_hgvs_string(self): | |
| mock_client = AsyncMock() | |
| mock_response = Mock() | |
| mock_response.status_code = 200 | |
| mock_response.text = "ok" | |
| mock_response.json = Mock(return_value=[ | |
| { | |
| "hgvsg": ["9:g.135800978A>G"], | |
| } | |
| ]) | |
| mock_client.get.return_value = mock_response | |
| result = asyncio.run(hgvs_to_coordinates("TSC1:c.359T>C", mock_client)) | |
| assert result is not None | |
| assert result["chromosome"] == "9" | |
| assert result["position"] == 135800978 | |
| assert result["ref"] == "A" | |
| assert result["alt"] == "G" | |
| def test_parse_vep_to_coordinates_negative_strand_complements_alleles(self): | |
| data = [ | |
| { | |
| "seq_region_name": "9", | |
| "start": 132925591, | |
| "allele_string": "T/C", | |
| "strand": -1, | |
| } | |
| ] | |
| result = _parse_vep_to_coordinates(data, "TSC1:c.359T>C") | |
| assert result is not None | |
| assert result["chromosome"] == "9" | |
| assert result["position"] == 132925591 | |
| assert result["ref"] == "A" | |
| assert result["alt"] == "G" | |
| def test_parse_vep_to_coordinates_positive_strand_uses_alleles_as_is(self): | |
| data = [ | |
| { | |
| "seq_region_name": "9", | |
| "start": 132925591, | |
| "allele_string": "A/G", | |
| "strand": 1, | |
| } | |
| ] | |
| result = _parse_vep_to_coordinates(data, "chr9:g.132925591A>G") | |
| assert result is not None | |
| assert result["chromosome"] == "9" | |
| assert result["position"] == 132925591 | |
| assert result["ref"] == "A" | |
| assert result["alt"] == "G" | |