Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding vertebrate mitochondrial translate table #55

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)