Skip to content

Commit

Permalink
add option for delins or two substitutions (#4)
Browse files Browse the repository at this point in the history
* prefer two substitions rather than delins in codons

* change default for prefer_delins
  • Loading branch information
afrubin committed Nov 26, 2021
1 parent 4aac65f commit 847a782
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
30 changes: 24 additions & 6 deletions mavetools/convert/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def codon_sub_to_mavehgvs(
variant_codon: str,
aa_position: int,
target_id: Optional[str] = None,
prefer_delins: bool = True,
) -> str:
"""Create a MAVE-HGVS coding variant string describing the change between two codons.
Expand All @@ -23,6 +24,11 @@ def codon_sub_to_mavehgvs(
This will be used to calculate the nucleotide positions.
target_id : Optional[str]
Optional target identifier for the resulting variant.
Default ``None``.
prefer_delins : bool
If True, consecutive two-base changes will be described as a deletion-insertion;
otherwise they will be described as two single-nucleotide substitutions.
Default ``True``.
Returns
-------
Expand Down Expand Up @@ -64,13 +70,25 @@ def codon_sub_to_mavehgvs(
f"{variant_pos + 2}{target_codon[2]}>{variant_codon[2]}]"
)
elif changes[0]: # delins of first two bases
variant_string = (
f"c.{variant_pos}_{variant_pos + 1}delins{variant_codon[:2]}"
)
if prefer_delins:
variant_string = (
f"c.{variant_pos}_{variant_pos + 1}delins{variant_codon[:2]}"
)
else:
variant_string = (
f"c.[{variant_pos}{target_codon[0]}>{variant_codon[0]};"
f"{variant_pos + 1}{target_codon[1]}>{variant_codon[1]}]"
)
else: # delins of last two bases
variant_string = (
f"c.{variant_pos + 1}_{variant_pos + 2}delins{variant_codon[1:]}"
)
if prefer_delins:
variant_string = (
f"c.{variant_pos + 1}_{variant_pos + 2}delins{variant_codon[1:]}"
)
else:
variant_string = (
f"c.[{variant_pos + 1}{target_codon[1]}>{variant_codon[1]};"
f"{variant_pos + 2}{target_codon[2]}>{variant_codon[2]}]"
)
elif sum(changes) == 3: # full codon delins
variant_string = f"c.{variant_pos}_{variant_pos + 2}delins{variant_codon}"
else: # pragma: nocover
Expand Down
12 changes: 8 additions & 4 deletions tests/test_convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def test_valid_substitution(self):
(("ATG", "AAG", 11), "c.32T>A"),
(("ATG", "ATT", 88), "c.264G>T"),
(("ATG", "TTT", 1), "c.[1A>T;3G>T]"),
(("ATG", "TAG", 1), "c.1_2delinsTA"),
(("ATG", "AGT", 1), "c.2_3delinsGT"),
(("ATG", "TAG", 1, None, False), "c.[1A>T;2T>A]"),
(("ATG", "AGT", 1, None, False), "c.[2T>G;3G>T]"),
(("ATG", "TAG", 1, None, True), "c.1_2delinsTA"),
(("ATG", "AGT", 1, None, True), "c.2_3delinsGT"),
(("ATG", "TTT", 2), "c.[4A>T;6G>T]"),
(("ATG", "TAG", 11), "c.31_32delinsTA"),
(("ATG", "AGT", 88), "c.263_264delinsGT"),
(("ATG", "TAG", 11, None, False), "c.[31A>T;32T>A]"),
(("ATG", "AGT", 88, None, False), "c.[263T>G;264G>T]"),
(("ATG", "TAG", 11, None, True), "c.31_32delinsTA"),
(("ATG", "AGT", 88, None, True), "c.263_264delinsGT"),
(("ATG", "CAT", 1), "c.1_3delinsCAT"),
(("ATG", "CAT", 101), "c.301_303delinsCAT"),
]
Expand Down

0 comments on commit 847a782

Please sign in to comment.