Skip to content

Commit

Permalink
fix: Check to see if there is only one exon in a transcript when sele…
Browse files Browse the repository at this point in the history
…cting the adjacent exon (#386)
  • Loading branch information
jarbesfeld authored Dec 12, 2024
1 parent c73e4de commit 78ab113
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/cool_seq_tool/mappers/exon_genomic_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,10 @@ def _get_adjacent_exon(
:param end: Genomic coordinate of breakpoint
:return: Exon number corresponding to adjacent exon. Will be 0-based
"""
# If a transcript has only one exon, return 0
if len(tx_exons_genomic_coords) == 1:
return 0

# Check if a breakpoint occurs before/after the transcript boundaries
bp = start if start else end
exon_list_len = len(tx_exons_genomic_coords) - 1
Expand Down Expand Up @@ -1199,6 +1203,7 @@ def _get_adjacent_exon(
gte_exon = exon
if bp >= lte_exon.alt_end_i and bp <= gte_exon.alt_start_i:
break

# Return current exon if end position is provided, next exon if start position
# is provided.
return exon.ord if end else exon.ord + 1
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ def nm_001105539_exons_genomic_coords():
]


@pytest.fixture(scope="session")
def mm_001005183_1_exons():
"""Create test fixture for NM_001005183.1 exons and genomic coordinates"""
return [
_ExonCoord(
ord=0,
tx_start_i=0,
tx_end_i=939,
alt_start_i=55426253,
alt_end_i=55427192,
alt_strand=Strand.POSITIVE,
)
]


@pytest.fixture(scope="session")
def tpm3_1_8_start_genomic():
"""Create test fixture for genomic data for exon 1, 8"""
Expand Down
14 changes: 13 additions & 1 deletion tests/mappers/test_exon_genomic_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,10 @@ async def test_get_start_end_exon_coords(test_egc_mapper):

@pytest.mark.asyncio()
async def test_get_adjacent_exon(
test_egc_mapper, nm_152263_exons_genomic_coords, nm_001105539_exons_genomic_coords
test_egc_mapper,
nm_152263_exons_genomic_coords,
nm_001105539_exons_genomic_coords,
mm_001005183_1_exons,
):
"""Test that get_adjacent_exon works properly"""
resp = test_egc_mapper._get_adjacent_exon(
Expand Down Expand Up @@ -866,6 +869,15 @@ async def test_get_adjacent_exon(
)
assert resp == 9

# Check cases where transcript only has one exon and breakpoint does not occur
# exon
resp = test_egc_mapper._get_adjacent_exon(
tx_exons_genomic_coords=mm_001005183_1_exons,
start=55411058,
strand=Strand.POSITIVE,
)
assert resp == 0


def test_is_exonic_breakpoint(test_egc_mapper, nm_001105539_exons_genomic_coords):
"""Test is breakpoint occurs on exon"""
Expand Down

0 comments on commit 78ab113

Please sign in to comment.