Skip to content

Commit

Permalink
feat: make methods in ManeTranscript public (#326)
Browse files Browse the repository at this point in the history
close #229

* `ManeTranscript._validate_index` -> `ManeTranscript.validate_index`
* `ManeTranscript._get_reading_frame` -> `ManeTranscript.get_reading_frame`
  • Loading branch information
korikuzma authored Jul 23, 2024
1 parent ab31d98 commit 1710fb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
24 changes: 10 additions & 14 deletions src/cool_seq_tool/mappers/mane_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
self.liftover = liftover

@staticmethod
def _get_reading_frame(pos: int) -> int:
def get_reading_frame(pos: int) -> int:
"""Return reading frame number. Only used on c. coordinate.
:param pos: cDNA position
Expand Down Expand Up @@ -531,8 +531,8 @@ def _validate_reading_frames(
"""
for pos, pos_index in [(start_pos, 0), (end_pos, 1)]:
if pos is not None:
og_rf = self._get_reading_frame(pos)
new_rf = self._get_reading_frame(transcript_data.pos[pos_index])
og_rf = self.get_reading_frame(pos)
new_rf = self.get_reading_frame(transcript_data.pos[pos_index])

if og_rf != new_rf:
_logger.warning(
Expand Down Expand Up @@ -618,7 +618,7 @@ def _validate_references(

return True

def _validate_index(
def validate_index(
self, ac: str, pos: tuple[int, int], coding_start_site: int
) -> bool:
"""Validate that positions actually exist on accession
Expand Down Expand Up @@ -910,7 +910,7 @@ def _get_protein_rep(
ac = lcr_result.refseq or lcr_result.ensembl
pos = lcr_result.pos

if not self._validate_index(ac, pos, coding_start_site):
if not self.validate_index(ac, pos, coding_start_site):
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
pos,
Expand All @@ -936,7 +936,7 @@ def _get_protein_rep(
cds = lcr_result_dict[k].get("coding_start_site", 0)
ac = lcr_result_dict[k]["refseq"] or lcr_result_dict[k]["ensembl"]
pos = lcr_result_dict[k]["pos"]
if not self._validate_index(ac, pos, cds):
if not self.validate_index(ac, pos, cds):
valid = False
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
Expand Down Expand Up @@ -1114,7 +1114,7 @@ async def g_to_grch38(self, ac: str, start_pos: int, end_pos: int) -> dict | Non
descr = await self.uta_db.get_chr_assembly(ac)
if not descr:
# Already GRCh38 assembly
if self._validate_index(ac, (start_pos, end_pos), 0):
if self.validate_index(ac, (start_pos, end_pos), 0):
return {"ac": ac, "pos": (start_pos, end_pos)}
return None
chromosome, assembly = descr
Expand Down Expand Up @@ -1145,7 +1145,7 @@ async def g_to_grch38(self, ac: str, start_pos: int, end_pos: int) -> dict | Non
newest_ac = await self.uta_db.get_newest_assembly_ac(ac)
if newest_ac:
ac = newest_ac[0]
if self._validate_index(ac, (start_pos, end_pos), 0):
if self.validate_index(ac, (start_pos, end_pos), 0):
return {"ac": ac, "pos": (start_pos, end_pos)}
return None

Expand Down Expand Up @@ -1261,9 +1261,7 @@ async def g_to_mane_c(
mane_tx_genomic_data, coding_start_site
)

if not self._validate_index(
mane_c_ac, mane_c_pos_change, coding_start_site
):
if not self.validate_index(mane_c_ac, mane_c_pos_change, coding_start_site):
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
mane_c_pos_change,
Expand Down Expand Up @@ -1351,9 +1349,7 @@ async def grch38_to_mane_c_p(
)

# Validate MANE C positions
if not self._validate_index(
mane_c_ac, mane_c_pos_change, coding_start_site
):
if not self.validate_index(mane_c_ac, mane_c_pos_change, coding_start_site):
_logger.warning(
"%s are not valid positions on %s with coding start site %s",
mane_c_pos_change,
Expand Down
12 changes: 6 additions & 6 deletions tests/mappers/test_mane_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ def mybpc3_s236g():


def test_get_reading_frame(test_mane_transcript):
"""Test that _get_reading_frame works correctly."""
rf = test_mane_transcript._get_reading_frame(1797)
"""Test that get_reading_frame works correctly."""
rf = test_mane_transcript.get_reading_frame(1797)
assert rf == 3

rf = test_mane_transcript._get_reading_frame(1798)
rf = test_mane_transcript.get_reading_frame(1798)
assert rf == 1

rf = test_mane_transcript._get_reading_frame(1799)
rf = test_mane_transcript.get_reading_frame(1799)
assert rf == 2

rf = test_mane_transcript._get_reading_frame(1800)
rf = test_mane_transcript.get_reading_frame(1800)
assert rf == 3

rf = test_mane_transcript._get_reading_frame(2573)
rf = test_mane_transcript.get_reading_frame(2573)
assert rf == 2


Expand Down

0 comments on commit 1710fb0

Please sign in to comment.