commit
401084bab3
265 files changed
+69224
No files matched your search
@@ -0,0 +1,34 @@
|
||||
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
||||
from std.collections import Set
|
||||
|
||||
# Translate a reading frame into amino acids, stopping at the first stop codon.
|
||||
def stops() -> Set[String]:
|
||||
return Set[String]("TAA", "TAG", "TGA")
|
||||
|
||||
|
||||
def translate(t: String) raises -> String:
|
||||
var table = Dict[String, String]()
|
||||
var protein: String
|
||||
var codon: String
|
||||
table["ATG"] = "M"
|
||||
table["GCC"] = "A"
|
||||
table["AAA"] = "K"
|
||||
table["TTT"] = "F"
|
||||
table["GGC"] = "G"
|
||||
protein = ""
|
||||
for i in range(0, t.count_codepoints() // 3 * 3, 3):
|
||||
var _piece2 = String("")
|
||||
for _at1 in range(i, i + 3):
|
||||
_piece2 += String(t[codepoint=_at1])
|
||||
codon = _piece2
|
||||
if codon in stops():
|
||||
break
|
||||
elif codon in table:
|
||||
protein = protein + table[codon]
|
||||
else:
|
||||
protein = protein + "X"
|
||||
return protein
|
||||
|
||||
|
||||
def main() raises:
|
||||
print(translate("ATGGCCAAATAGTTT"))
|
||||
Reference in new issue
Block a user