Skip to content

Commit b44b262

Browse files
committed
sdfljk
1 parent 0e98274 commit b44b262

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/agct/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""Provide fast liftover in Python via the ``chainfile`` crate."""
22

33
from agct.assembly_registry import Assembly, get_assembly_from_refget_id
4-
from agct.converter import Converter, Strand
4+
from agct.converter import Converter, LiftoverResult, Strand
55

6-
__all__ = ["Assembly", "Converter", "Strand", "get_assembly_from_refget_id"]
6+
__all__ = [
7+
"Assembly",
8+
"Converter",
9+
"LiftoverResult",
10+
"Strand",
11+
"get_assembly_from_refget_id",
12+
]

src/agct/converter.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections.abc import Callable
55
from enum import Enum
66
from pathlib import Path
7+
from typing import NamedTuple
78

89
from wags_tails import CustomData
910
from wags_tails.utils.downloads import download_http, handle_gzip
@@ -22,6 +23,14 @@ class Strand(str, Enum):
2223
NEGATIVE = "-"
2324

2425

26+
class LiftoverResult(NamedTuple):
27+
"""Declare structure of liftover response"""
28+
29+
chrom: str
30+
position: int
31+
strand: Strand
32+
33+
2534
class Converter:
2635
"""Chainfile-based liftover provider for a single sequence to sequence
2736
association.
@@ -113,7 +122,7 @@ def _download_data(version: str, file: Path) -> None: # noqa: ARG001
113122

114123
def convert_coordinate(
115124
self, chrom: str, pos: int, strand: Strand = Strand.POSITIVE
116-
) -> list[tuple[str, int, Strand]]:
125+
) -> list[LiftoverResult]:
117126
"""Perform liftover for given params
118127
119128
The ``Strand`` enum provides constraints for legal strand values:
@@ -144,7 +153,7 @@ def convert_coordinate(
144153
strand,
145154
)
146155
results = []
147-
formatted_results: list[tuple[str, int, Strand]] = []
156+
formatted_results: list[LiftoverResult] = []
148157
for result in results:
149158
try:
150159
pos = int(result[1])
@@ -156,5 +165,5 @@ def convert_coordinate(
156165
except ValueError:
157166
_logger.exception("Got invalid Strand value in %s", result)
158167
continue
159-
formatted_results.append((result[0], pos, strand))
168+
formatted_results.append(LiftoverResult(result[0], pos, strand))
160169
return formatted_results

tests/test_liftover.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Run liftover tests."""
22

3-
from agct import Assembly, Converter, Strand
3+
from agct import Assembly, Converter, LiftoverResult, Strand
44

55

66
def test_hg19_to_hg38():
@@ -9,23 +9,23 @@ def test_hg19_to_hg38():
99

1010
result = converter.convert_coordinate("chr7", 140439611)
1111
assert len(result) == 1
12-
assert result[0] == ("chr7", 140739811, Strand.POSITIVE)
12+
assert result[0] == LiftoverResult("chr7", 140739811, Strand.POSITIVE)
1313

1414
result = converter.convert_coordinate("chr7", 140439746)
1515
assert len(result) == 1
16-
assert result[0] == ("chr7", 140739946, Strand.POSITIVE)
16+
assert result[0] == LiftoverResult("chr7", 140739946, Strand.POSITIVE)
1717

1818
result = converter.convert_coordinate("chr7", 140439703)
1919
assert len(result) == 1
20-
assert result[0] == ("chr7", 140739903, Strand.POSITIVE)
20+
assert result[0] == LiftoverResult("chr7", 140739903, Strand.POSITIVE)
2121

2222
result = converter.convert_coordinate("chr7", 140453136)
2323
assert len(result) == 1
24-
assert result[0] == ("chr7", 140753336, Strand.POSITIVE)
24+
assert result[0] == LiftoverResult("chr7", 140753336, Strand.POSITIVE)
2525

2626
result = converter.convert_coordinate("chr1", 206072707)
2727
assert len(result) == 1
28-
assert result[0] == ("chr1", 206268644, Strand.NEGATIVE)
28+
assert result[0] == LiftoverResult("chr1", 206268644, Strand.NEGATIVE)
2929

3030
# coordinate exceeds bounds
3131
result = converter.convert_coordinate("chr7", 14040053136)
@@ -38,12 +38,12 @@ def test_hg38_to_hg19():
3838

3939
result = converter.convert_coordinate("chr7", 140739811)
4040
assert len(result) == 1
41-
assert result[0] == ("chr7", 140439611, Strand.POSITIVE)
41+
assert result[0] == LiftoverResult("chr7", 140439611, Strand.POSITIVE)
4242

4343
result = converter.convert_coordinate("chr7", 140759820)
4444
assert len(result) == 1
45-
assert result[0] == ("chr7", 140459620, Strand.POSITIVE)
45+
assert result[0] == LiftoverResult("chr7", 140459620, Strand.POSITIVE)
4646

4747
result = converter.convert_coordinate("chr7", 60878240)
4848
assert len(result) == 1
49-
assert result[0] == ("chr7", 61646115, Strand.POSITIVE)
49+
assert result[0] == LiftoverResult("chr7", 61646115, Strand.POSITIVE)

0 commit comments

Comments
 (0)