From 78ab1136805b9d99c000ceeccca21aff523301fc Mon Sep 17 00:00:00 2001 From: Jeremy Arbesfeld <50678786+jarbesfeld@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:19:11 -0500 Subject: [PATCH] fix: Check to see if there is only one exon in a transcript when selecting the adjacent exon (#386) --- src/cool_seq_tool/mappers/exon_genomic_coords.py | 5 +++++ tests/conftest.py | 15 +++++++++++++++ tests/mappers/test_exon_genomic_coords.py | 14 +++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/cool_seq_tool/mappers/exon_genomic_coords.py b/src/cool_seq_tool/mappers/exon_genomic_coords.py index 82d4a72..056d1d7 100644 --- a/src/cool_seq_tool/mappers/exon_genomic_coords.py +++ b/src/cool_seq_tool/mappers/exon_genomic_coords.py @@ -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 @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index d37c2ec..d44f391 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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""" diff --git a/tests/mappers/test_exon_genomic_coords.py b/tests/mappers/test_exon_genomic_coords.py index c779953..5cdfb1f 100644 --- a/tests/mappers/test_exon_genomic_coords.py +++ b/tests/mappers/test_exon_genomic_coords.py @@ -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( @@ -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"""