diff --git a/mavetools/convert/convert.py b/mavetools/convert/convert.py index 157e9db..035eb76 100644 --- a/mavetools/convert/convert.py +++ b/mavetools/convert/convert.py @@ -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. @@ -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 ------- @@ -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 diff --git a/tests/test_convert/test_convert.py b/tests/test_convert/test_convert.py index a0aea33..ddc5046 100644 --- a/tests/test_convert/test_convert.py +++ b/tests/test_convert/test_convert.py @@ -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"), ]