Skip to content

Commit

Permalink
Merge pull request #55 from biocommons/translation-table-vertebrate-mito
Browse files Browse the repository at this point in the history
adding vertebrate mitochondrial translate table
  • Loading branch information
reece authored Jan 8, 2024
2 parents ed72a8a + 12d3dfd commit ab6a9e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/bioutils/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@
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")


Expand Down Expand Up @@ -506,6 +516,7 @@ class TranslationTable(StrEnum):

standard = "standard"
selenocysteine = "sec"
vertebrate_mitochondrial = "vmito"


def translate_cds(seq, full_codons=True, ter_symbol="*", translation_table=TranslationTable.standard):
Expand Down Expand Up @@ -596,6 +607,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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,20 @@ 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.vertebrate_mitochondrial) == "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)

0 comments on commit ab6a9e4

Please sign in to comment.