-
Notifications
You must be signed in to change notification settings - Fork 1
/
converter.py
73 lines (63 loc) · 2.02 KB
/
converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#This program turns a strand of DNA into mRNA, which is then converted into amino acids using a codon chart
#MIT License as usual
#Ravi Shah 2020
from amino_acids import codons_to_acids
stop_index = "NaN"
def transcription(dna):
res = []
newlist = []
res[:] = dna
for i in res:
if i == "G":
newlist.append("C")
elif i == "C":
newlist.append("G")
elif i == "A":
newlist.append("U")
elif i == "T":
newlist.append("A")
mrna_strand = ''.join(newlist)
return mrna_strand
def find_start(mrna):
try:
start_index = mrna.index("AUG")
inter_rna = mrna[start_index:]
return inter_rna
except:
print("Please enter a valid DNA strand with a start codon.")
quit()
def find_stop(mrna):
for i in mrna:
if "UAA" in i:
print("UAA STOP codon found")
stop_index = mrna.index("UAA")
elif "UAG" in i:
print("UAG STOP codon found")
stop_index = mrna.index("UAG")
elif "UGA" in i:
print("UGA STOP codon found")
stop_index = mrna.index("UGA")
else:
continue
return stop_index
def break_into_codons(mrna):
n = 3
res = [mrna[i:i+n] for i in range(0, len(mrna), n)]
return res
def truncate(codons, stop_index):
codons = codons[0:stop_index+1]
return codons
def translation(final_codons):
print("The codons are:", final_codons)
list_of_amino_acids = codons_to_acids(final_codons)
print("There are", len(list_of_amino_acids), "amino acids translated from this mRNA strand.")
return list_of_amino_acids
strand = input("Enter the DNA strand to be transcribed and translated: ")
strand = strand.upper()
messenger_rna = transcription(strand)
with_start = find_start(messenger_rna)
into_codons = break_into_codons(with_start)
stop_index = find_stop(into_codons)
final_codons = truncate(into_codons, stop_index)
amino_acids_list = translation(final_codons)
print(amino_acids_list)