Skip to content

Commit ec3483c

Browse files
committed
Return 0 when there is only one exon
1 parent c73e4de commit ec3483c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/cool_seq_tool/mappers/exon_genomic_coords.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,10 @@ def _get_adjacent_exon(
11691169
:param end: Genomic coordinate of breakpoint
11701170
:return: Exon number corresponding to adjacent exon. Will be 0-based
11711171
"""
1172+
# If a transcript has only one exon, return 0
1173+
if len(tx_exons_genomic_coords) == 1:
1174+
return 0
1175+
11721176
# Check if a breakpoint occurs before/after the transcript boundaries
11731177
bp = start if start else end
11741178
exon_list_len = len(tx_exons_genomic_coords) - 1
@@ -1199,6 +1203,7 @@ def _get_adjacent_exon(
11991203
gte_exon = exon
12001204
if bp >= lte_exon.alt_end_i and bp <= gte_exon.alt_start_i:
12011205
break
1206+
12021207
# Return current exon if end position is provided, next exon if start position
12031208
# is provided.
12041209
return exon.ord if end else exon.ord + 1

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,21 @@ def nm_001105539_exons_genomic_coords():
277277
]
278278

279279

280+
@pytest.fixture(scope="session")
281+
def mm_001005183_1_exons():
282+
"""Create test fixture for NM_001005183.1 exons and genomic coordinates"""
283+
return [
284+
_ExonCoord(
285+
ord=0,
286+
tx_start_i=0,
287+
tx_end_i=939,
288+
alt_start_i=55426253,
289+
alt_end_i=55427192,
290+
alt_strand=Strand.POSITIVE,
291+
)
292+
]
293+
294+
280295
@pytest.fixture(scope="session")
281296
def tpm3_1_8_start_genomic():
282297
"""Create test fixture for genomic data for exon 1, 8"""

tests/mappers/test_exon_genomic_coords.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,10 @@ async def test_get_start_end_exon_coords(test_egc_mapper):
806806

807807
@pytest.mark.asyncio()
808808
async def test_get_adjacent_exon(
809-
test_egc_mapper, nm_152263_exons_genomic_coords, nm_001105539_exons_genomic_coords
809+
test_egc_mapper,
810+
nm_152263_exons_genomic_coords,
811+
nm_001105539_exons_genomic_coords,
812+
mm_001005183_1_exons,
810813
):
811814
"""Test that get_adjacent_exon works properly"""
812815
resp = test_egc_mapper._get_adjacent_exon(
@@ -866,6 +869,15 @@ async def test_get_adjacent_exon(
866869
)
867870
assert resp == 9
868871

872+
# Check cases where transcript only has one exon and breakpoint does not occur
873+
# exon
874+
resp = test_egc_mapper._get_adjacent_exon(
875+
tx_exons_genomic_coords=mm_001005183_1_exons,
876+
start=55411058,
877+
strand=Strand.POSITIVE,
878+
)
879+
assert resp == 0
880+
869881

870882
def test_is_exonic_breakpoint(test_egc_mapper, nm_001105539_exons_genomic_coords):
871883
"""Test is breakpoint occurs on exon"""

0 commit comments

Comments
 (0)