Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make methods in ManeTranscript public #326

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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