Skip to content

Commit

Permalink
feat!: rename residue mode to coordinate type (#591)
Browse files Browse the repository at this point in the history
close #590

* `/variation/alignment_mapper/p_to_c`,
`/variation/alignment_mapper/c_to_g`,
`"/variation/alignment_mapper/p_to_g",`: query string parameter
`residue_mode` changed to `coordinate_type`
  • Loading branch information
korikuzma authored Jan 6, 2025
1 parent 47db4d5 commit d93df25
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
24 changes: 12 additions & 12 deletions src/variation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,23 +678,23 @@ async def p_to_c(
p_ac: str = Query(..., description="Protein RefSeq accession"),
p_start_pos: int = Query(..., description="Protein start position"),
p_end_pos: int = Query(..., description="Protein end position"),
residue_mode: CoordinateType = Query(
coordinate_type: CoordinateType = Query(
CoordinateType.RESIDUE,
description="Residue mode for `p_start_pos` and `p_end_pos`",
description="Coordinate type for `p_start_pos` and `p_end_pos`",
),
) -> ToCdnaService:
"""Translate protein representation to cDNA representation
:param str p_ac: Protein RefSeq accession
:param int p_start_pos: Protein start position
:param int p_end_pos: Protein end position
:param CoordinateType residue_mode: Residue mode for `p_start_pos` and `p_end_pos`.
:param CoordinateType coordinate_type: Coordinate type for `p_start_pos` and `p_end_pos`.
:return: ToCdnaService containing cDNA representation, warnings, and
service meta
"""
try:
c_data, w = await query_handler.alignment_mapper.p_to_c(
p_ac, p_start_pos, p_end_pos, residue_mode
p_ac, p_start_pos, p_end_pos, coordinate_type
)
except Exception as e:
_logger.error("Unhandled exception: %s", str(e))
Expand Down Expand Up @@ -727,9 +727,9 @@ async def c_to_g(
cds_start: int | None = Query(
None, description="CDS start site. If not provided, this will be computed."
),
residue_mode: CoordinateType = Query(
coordinate_type: CoordinateType = Query(
CoordinateType.RESIDUE,
description="Residue mode for `c_start_pos` and `c_end_pos`",
description="Coordinate type for `c_start_pos` and `c_end_pos`",
),
target_genome_assembly: Assembly = Query(
Assembly.GRCH38, description="Genomic assembly to map to"
Expand All @@ -742,7 +742,7 @@ async def c_to_g(
:param int c_end_pos: cDNA end position for codon
:param Optional[int] cds_start: CDS start site. If not provided, this will be
computed.
:param CoordinateType residue_mode: Residue mode for `c_start_pos` and `c_end_pos`.
:param CoordinateType coordinate_type: Coordinate type for `c_start_pos` and `c_end_pos`.
:param Assembly target_genome_assembly: Genome assembly to get genomic data for
:return: ToGenomicService containing genomic representation, warnings, and
service meta
Expand All @@ -753,7 +753,7 @@ async def c_to_g(
c_start_pos,
c_end_pos,
cds_start=cds_start,
coordinate_type=residue_mode,
coordinate_type=coordinate_type,
target_genome_assembly=target_genome_assembly,
)
except Exception as e:
Expand Down Expand Up @@ -784,9 +784,9 @@ async def p_to_g(
p_ac: str = Query(..., description="Protein RefSeq accession"),
p_start_pos: int = Query(..., description="Protein start position"),
p_end_pos: int = Query(..., description="Protein end position"),
residue_mode: CoordinateType = Query(
coordinate_type: CoordinateType = Query(
CoordinateType.RESIDUE,
description="Residue mode for `p_start_pos` and `p_end_pos`",
description="Coordinate type for `p_start_pos` and `p_end_pos`",
),
target_genome_assembly: Assembly = Query(
Assembly.GRCH38, description="Genomic assembly to map to"
Expand All @@ -797,7 +797,7 @@ async def p_to_g(
:param str p_ac: Protein RefSeq accession
:param int p_start_pos: Protein start position
:param int p_end_pos: Protein end position
:param CoordinateType residue_mode: Residue mode for `p_start_pos` and `p_end_pos`.
:param CoordinateType coordinate_type: Coordinate type for `p_start_pos` and `p_end_pos`.
:param Assembly target_genome_assembly: Genome assembly to get genomic data for
:return: ToGenomicService containing genomic representation, warnings, and
service meta
Expand All @@ -807,7 +807,7 @@ async def p_to_g(
p_ac,
p_start_pos,
p_end_pos,
coordinate_type=residue_mode,
coordinate_type=coordinate_type,
target_genome_assembly=target_genome_assembly,
)
except Exception as e:
Expand Down
12 changes: 6 additions & 6 deletions src/variation/schemas/service_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CdnaRepresentation(BaseModel, extra="forbid"):
c_start_pos: StrictInt
c_end_pos: StrictInt
cds_start: StrictInt
residue_mode: Literal["inter-residue"] = CoordinateType.INTER_RESIDUE.value
coordinate_type: Literal["inter-residue"] = CoordinateType.INTER_RESIDUE.value

model_config = ConfigDict(
json_schema_extra={
Expand All @@ -37,7 +37,7 @@ class CdnaRepresentation(BaseModel, extra="forbid"):
"c_start_pos": 1797,
"c_end_pos": 1800,
"cds_start": 226,
"residue_mode": CoordinateType.INTER_RESIDUE.value,
"coordinate_type": CoordinateType.INTER_RESIDUE.value,
}
}
)
Expand All @@ -58,7 +58,7 @@ class ToCdnaService(BaseModel, extra="forbid"):
"c_start_pos": 1797,
"c_end_pos": 1800,
"cds_start": 226,
"residue_mode": "inter-residue",
"coordinate_type": "inter-residue",
},
"warnings": [],
"service_meta": {
Expand All @@ -78,15 +78,15 @@ class GenomicRepresentation(BaseModel, extra="forbid"):
g_ac: StrictStr
g_start_pos: StrictInt
g_end_pos: StrictInt
residue_mode: Literal["inter-residue"] = CoordinateType.INTER_RESIDUE.value
coordinate_type: Literal["inter-residue"] = CoordinateType.INTER_RESIDUE.value

model_config = ConfigDict(
json_schema_extra={
"example": {
"g_ac": "NC_000007.13",
"g_start_pos": 140453134,
"g_end_pos": 140453137,
"residue_mode": CoordinateType.INTER_RESIDUE.value,
"coordinate_type": CoordinateType.INTER_RESIDUE.value,
}
}
)
Expand All @@ -106,7 +106,7 @@ class ToGenomicService(BaseModel, extra="forbid"):
"g_ac": "NC_000007.13",
"g_start_pos": 140453134,
"g_end_pos": 140453137,
"residue_mode": "inter-residue",
"coordinate_type": "inter-residue",
},
"warnings": [],
"service_meta": {
Expand Down
14 changes: 7 additions & 7 deletions src/variation/translators/genomic_del_dup_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def translate(
grch38_data = None
vrs_variation = None
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA
residue_mode = CoordinateType.RESIDUE
coordinate_type = CoordinateType.RESIDUE
mane_genes = None

if do_liftover or endpoint_name == Endpoint.NORMALIZE:
Expand All @@ -141,7 +141,7 @@ async def translate(
pos1 = grch38_data.pos0
else:
pos1 = grch38_data.pos1
residue_mode = CoordinateType.INTER_RESIDUE
coordinate_type = CoordinateType.INTER_RESIDUE
ac = grch38_data.ac

if (
Expand All @@ -154,7 +154,7 @@ async def translate(
pos0,
pos0 + (len(ref) - 1),
ref,
coordinate_type=residue_mode,
coordinate_type=coordinate_type,
)
if invalid_ref_msg:
warnings.append(invalid_ref_msg)
Expand Down Expand Up @@ -198,7 +198,7 @@ async def translate(
pos0 = grch38_data.pos0 - 1
pos1 = grch38_data.pos0 if grch38_data.pos1 is None else grch38_data.pos1
mane_genes = grch38_data.mane_genes
residue_mode = CoordinateType.INTER_RESIDUE
coordinate_type = CoordinateType.INTER_RESIDUE
self.is_valid(classification.gene_token, ac, pos0, pos1, errors)

if errors:
Expand All @@ -211,7 +211,7 @@ async def translate(
pos1,
"g",
try_longest_compatible=True,
coordinate_type=residue_mode,
coordinate_type=coordinate_type,
gene=classification.gene_token.token
if classification.gene_token
else None,
Expand All @@ -223,7 +223,7 @@ async def translate(
vrs_seq_loc_ac_status = mane.status
pos0 = mane.pos[0] + mane.coding_start_site
pos1 = mane.pos[1] + mane.coding_start_site
residue_mode = CoordinateType.INTER_RESIDUE
coordinate_type = CoordinateType.INTER_RESIDUE
else:
return None

Expand All @@ -239,7 +239,7 @@ async def translate(
if alt_type == AltType.INSERTION:
alt = classification.inserted_sequence

start = pos0 if residue_mode == CoordinateType.INTER_RESIDUE else pos0 - 1
start = pos0 if coordinate_type == CoordinateType.INTER_RESIDUE else pos0 - 1
end = pos1 if pos1 else pos0

refget_accession = get_refget_accession(self.seqrepo_access, ac, warnings)
Expand Down
4 changes: 2 additions & 2 deletions src/variation/translators/genomic_delins.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def translate(
warnings,
alt=classification.inserted_sequence,
cds_start=mane.coding_start_site if gene else None,
residue_mode=CoordinateType.INTER_RESIDUE,
coordinate_type=CoordinateType.INTER_RESIDUE,
extensions=extensions,
)
else:
Expand All @@ -116,7 +116,7 @@ async def translate(
AltType.DELINS,
warnings,
alt=classification.inserted_sequence,
residue_mode=CoordinateType.RESIDUE,
coordinate_type=CoordinateType.RESIDUE,
)

if vrs_allele and vrs_seq_loc_ac:
Expand Down
4 changes: 2 additions & 2 deletions src/variation/translators/genomic_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def translate(
warnings,
alt=classification.inserted_sequence,
cds_start=mane.coding_start_site if gene else None,
residue_mode=CoordinateType.INTER_RESIDUE,
coordinate_type=CoordinateType.INTER_RESIDUE,
extensions=extensions,
)
else:
Expand All @@ -117,7 +117,7 @@ async def translate(
AltType.INSERTION,
warnings,
alt=classification.inserted_sequence,
residue_mode=CoordinateType.RESIDUE,
coordinate_type=CoordinateType.RESIDUE,
)

if vrs_allele and vrs_seq_loc_ac:
Expand Down
4 changes: 2 additions & 2 deletions src/variation/translators/genomic_reference_agree.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def translate(
AltType.REFERENCE_AGREE,
warnings,
cds_start=mane.coding_start_site if gene else None,
residue_mode=CoordinateType.INTER_RESIDUE,
coordinate_type=CoordinateType.INTER_RESIDUE,
extensions=extensions,
)
else:
Expand All @@ -113,7 +113,7 @@ async def translate(
AnnotationLayer.GENOMIC,
AltType.REFERENCE_AGREE,
warnings,
residue_mode=CoordinateType.RESIDUE,
coordinate_type=CoordinateType.RESIDUE,
)

if vrs_allele and vrs_seq_loc_ac:
Expand Down
4 changes: 2 additions & 2 deletions src/variation/translators/genomic_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def translate(
errors,
alt=classification.alt,
cds_start=mane.coding_start_site if gene else None,
residue_mode=CoordinateType.INTER_RESIDUE,
coordinate_type=CoordinateType.INTER_RESIDUE,
extensions=extensions,
)
else:
Expand All @@ -137,7 +137,7 @@ async def translate(
AltType.SUBSTITUTION,
errors,
alt=classification.alt,
residue_mode=CoordinateType.RESIDUE,
coordinate_type=CoordinateType.RESIDUE,
)

if vrs_allele and vrs_seq_loc_ac:
Expand Down
16 changes: 8 additions & 8 deletions src/variation/translators/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def is_valid(
errors: list[str],
pos2: int | None = None,
pos3: int | None = None,
residue_mode: CoordinateType = CoordinateType.RESIDUE,
coordinate_type: CoordinateType = CoordinateType.RESIDUE,
) -> None:
"""Check that positions are valid on a gene. Will mutate `errors` if invalid.
Expand All @@ -101,7 +101,7 @@ def is_valid(
:param errors: List of errors. Will get mutated if invalid.
:param pos2: Position 2 (GRCh38 assembly)
:param pos3: Position 3 (GRCh38 assembly)
:param residue_mode: Residue mode for positions
:param coordinate_type: Coordinate type for positions
"""
gene_start = None
gene_end = None
Expand All @@ -119,7 +119,7 @@ def is_valid(

for pos in [pos0, pos1, pos2, pos3]:
if pos not in {"?", None}:
if residue_mode == CoordinateType.RESIDUE:
if coordinate_type == CoordinateType.RESIDUE:
pos -= 1

if not (gene_start <= pos <= gene_end):
Expand All @@ -133,7 +133,7 @@ def validate_reference_sequence(
start_pos: int,
end_pos: int,
expected_ref: str,
residue_mode: CoordinateType = CoordinateType.RESIDUE,
coordinate_type: CoordinateType = CoordinateType.RESIDUE,
) -> str | None:
"""Validate that expected reference sequence matches actual reference sequence
This is also in validator, but there is a ticket to have this method be moved
Expand All @@ -143,11 +143,11 @@ def validate_reference_sequence(
:param start_pos: Start position
:param end_pos: End position
:param expected_ref: The expected reference sequence (from input string)
:param residue_mode: Residue mode for `start_pos` and `end_pos`
:param coordinate_type: Coordinate type for `start_pos` and `end_pos`
:return: Invalid message if invalid. If valid, `None`
"""
actual_ref, err_msg = self.seqrepo_access.get_reference_sequence(
ac, start=start_pos, end=end_pos, coordinate_type=residue_mode
ac, start=start_pos, end=end_pos, coordinate_type=coordinate_type
)

if not err_msg and (actual_ref != expected_ref):
Expand Down Expand Up @@ -227,7 +227,7 @@ async def get_p_or_cdna_translation_result(
errors,
cds_start=cds_start,
alt=alt,
residue_mode=CoordinateType.INTER_RESIDUE,
coordinate_type=CoordinateType.INTER_RESIDUE,
)

if not vrs_allele:
Expand All @@ -241,7 +241,7 @@ async def get_p_or_cdna_translation_result(
errors,
cds_start=cds_start,
alt=alt,
residue_mode=CoordinateType.RESIDUE,
coordinate_type=CoordinateType.RESIDUE,
)

if vrs_allele and vrs_seq_loc_ac:
Expand Down
Loading

0 comments on commit d93df25

Please sign in to comment.