Skip to content

Commit

Permalink
Merge branch 'rename-exon-coord' into organize-mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Aug 20, 2024
2 parents ca268d1 + a1a78c2 commit 18b9118
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/cool_seq_tool/mappers/exon_genomic_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _check_errors(
required_fields: list[str],
either_or_fields: list[tuple[str, str]] | None = None,
) -> dict:
"""Ensure that required fields are set if `errors` field is empty
"""Ensure that required fields are set if ``errors`` field is empty
:param values: Values in model
:param required_fields: List of field names that are required if there are no errors
Expand All @@ -36,13 +36,15 @@ def _check_errors(
:return: Values in model
"""
if not values.get("errors"):
if not all(values.get(required_field) for required_field in required_fields):
if not all(
values.get(required_field) is not None for required_field in required_fields
):
err_msg = f"{required_fields} must all be provided"
raise ValueError(err_msg)

if either_or_fields:
for field1, field2 in either_or_fields:
if not (values.get(field1) or values.get(field2)):
if not (values.get(field1) is not None or values.get(field2)):
err_msg = f"At least one of {field1} or {field2} must be provided"
raise ValueError(err_msg)

Expand Down Expand Up @@ -989,7 +991,7 @@ async def _get_grch38_ac_pos(
:param genomic_ac: RefSeq genomic accession
:param genomic_pos: Genomic position on ``genomic_ac``
:param grch38_ac: GRCh38 genomic accession for ``genomic_ac``. If not provided,
will get associated GRCh38 accession.
will attempt to retrieve associated GRCh38 accession from UTA.
:return: GRCh38 accession, GRCh38 position, and errors if unable to get GRCh38
representation
"""
Expand All @@ -999,7 +1001,7 @@ async def _get_grch38_ac_pos(
return _Grch38Data(
accession=None,
position=None,
errors=[f"Invalid genomic accession: {genomic_ac}"],
errors=[f"Unrecognized genomic accession: {genomic_ac}."],
)

grch38_ac = grch38_ac[0]
Expand All @@ -1010,10 +1012,17 @@ async def _get_grch38_ac_pos(
genomic_ac, Assembly.GRCH37.value
)
if not chromosome:
_logger.warning(
"SeqRepo could not find associated %s assembly for genomic accession %s.",
Assembly.GRCH37.value,
genomic_ac,
)
return _Grch38Data(
accession=None,
position=None,
errors=["`genomic_ac` must use GRCh37 or GRCh38"],
errors=[
f"`genomic_ac` must use {Assembly.GRCH37.value} or {Assembly.GRCH38.value} assembly."
],
)

chromosome = chromosome[-1].split(":")[-1]
Expand All @@ -1025,7 +1034,7 @@ async def _get_grch38_ac_pos(
accession=None,
position=None,
errors=[
f"Position {genomic_pos} does not exist on chromosome {chromosome}"
f"Lifting over {genomic_pos} on {genomic_ac} from {Assembly.GRCH37.value} to {Assembly.GRCH38.value} was unsuccessful."
],
)

Expand Down Expand Up @@ -1079,7 +1088,9 @@ async def _get_tx_seg_genomic_metadata(
grch38_ac = mane_data["GRCh38_chr"]

# Always liftover to GRCh38
grch38_data = await self._get_grch38_ac_pos(genomic_ac, genomic_pos)
grch38_data = await self._get_grch38_ac_pos(
genomic_ac, genomic_pos, grch38_ac=grch38_ac
)
if grch38_data.errors:
return _GenomicTxSeg(errors=grch38_data.errors)
genomic_ac, genomic_pos = grch38_data.accession, grch38_data.position
Expand Down

0 comments on commit 18b9118

Please sign in to comment.