From e7812345a5da1d7e836d8f20338b6b23d8fbed79 Mon Sep 17 00:00:00 2001 From: Veena Rajaraman Date: Thu, 28 Sep 2023 14:09:25 -0700 Subject: [PATCH 1/2] adding vertebrate mitochondrial translate table --- src/bioutils/sequences.py | 15 +++++++++++++++ tests/test_sequences.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/bioutils/sequences.py b/src/bioutils/sequences.py index 1a2ce75..c67f966 100644 --- a/src/bioutils/sequences.py +++ b/src/bioutils/sequences.py @@ -221,6 +221,18 @@ dna_to_aa1_sec = dna_to_aa1_lut.copy() dna_to_aa1_sec["TGA"] = "U" +# Vertebrate micochondrial translation table +# https://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi?chapter=tgencodes#SG2 + +dna_to_aa1_vmito = dna_to_aa1_lut.copy() +dna_to_aa1_vmito["AGA"] = "*" +dna_to_aa1_vmito["AGG"] = "*" +dna_to_aa1_vmito["ATA"] = "M" +dna_to_aa1_vmito["TGA"] = "W" + + + + complement_transtable = bytes.maketrans(b"ACGT", b"TGCA") @@ -506,6 +518,7 @@ class TranslationTable(StrEnum): standard = "standard" selenocysteine = "sec" + vertebrate_mitochondrial = 'vmito' def translate_cds(seq, full_codons=True, ter_symbol="*", translation_table=TranslationTable.standard): @@ -596,6 +609,8 @@ def translate_cds(seq, full_codons=True, ter_symbol="*", translation_table=Trans trans_table = dna_to_aa1_lut elif translation_table == TranslationTable.selenocysteine: trans_table = dna_to_aa1_sec + elif translation_table == TranslationTable.vertebrate_mitochondrial: + trans_table = dna_to_aa1_vmito else: raise ValueError("Unsupported translation table {}".format(translation_table)) seq = replace_u_to_t(seq) diff --git a/tests/test_sequences.py b/tests/test_sequences.py index 00745bc..fda132a 100644 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -42,3 +42,19 @@ def test_translate_selenoproteins(): with pytest.raises(ValueError): translate_cds("AUGTGATA", translation_table=TranslationTable.selenocysteine) + +def test_translate_vertebrate_mitochondrial(): + """unit test for vertebrate mitochondrial codons""" + assert translate_cds("AUGTGATAA") == "M**" + assert translate_cds("ATATGAAGGAGA", translation_table=TranslationTable.standard) == "MW**" + assert ( + translate_cds( + "ATAAG", + translation_table=TranslationTable.vertebrate_mitochondrial, + full_codons=False, + ) + == "M*" + ) + + with pytest.raises(ValueError): + translate_cds("ATAAG", translation_table=TranslationTable.vertebrate_mitochondrial) From 6144de7069d508cc159351c0677102e439425d74 Mon Sep 17 00:00:00 2001 From: Veena Rajaraman Date: Thu, 28 Sep 2023 14:24:49 -0700 Subject: [PATCH 2/2] fixed black formatting and failing test --- src/bioutils/sequences.py | 4 +--- tests/test_sequences.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bioutils/sequences.py b/src/bioutils/sequences.py index c67f966..e994cea 100644 --- a/src/bioutils/sequences.py +++ b/src/bioutils/sequences.py @@ -231,8 +231,6 @@ dna_to_aa1_vmito["TGA"] = "W" - - complement_transtable = bytes.maketrans(b"ACGT", b"TGCA") @@ -518,7 +516,7 @@ class TranslationTable(StrEnum): standard = "standard" selenocysteine = "sec" - vertebrate_mitochondrial = 'vmito' + vertebrate_mitochondrial = "vmito" def translate_cds(seq, full_codons=True, ter_symbol="*", translation_table=TranslationTable.standard): diff --git a/tests/test_sequences.py b/tests/test_sequences.py index fda132a..cd76e3c 100644 --- a/tests/test_sequences.py +++ b/tests/test_sequences.py @@ -43,10 +43,11 @@ def test_translate_selenoproteins(): with pytest.raises(ValueError): translate_cds("AUGTGATA", translation_table=TranslationTable.selenocysteine) + def test_translate_vertebrate_mitochondrial(): """unit test for vertebrate mitochondrial codons""" assert translate_cds("AUGTGATAA") == "M**" - assert translate_cds("ATATGAAGGAGA", translation_table=TranslationTable.standard) == "MW**" + assert translate_cds("ATATGAAGGAGA", translation_table=TranslationTable.vertebrate_mitochondrial) == "MW**" assert ( translate_cds( "ATAAG",