-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpycodon.py
112 lines (106 loc) · 3.22 KB
/
pycodon.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from tabulate import tabulate
from colorama import Fore, Style
from colorama import init
init(autoreset=True)
codon_table = {
'TCA': 'Serine',
'TCC': 'Serine',
'TCG': 'Serine',
'TCT': 'Serine',
'TTC': 'Phenylalanine',
'TTT': 'Phenylalanine',
'TTA': 'Leucine',
'TTG': 'Leucine',
'TAC': 'Tyrosine',
'TAT': 'Tyrosine',
'TAA': 'Stop',
'TAG': 'Stop',
'TGC': 'Cysteine',
'TGT': 'Cysteine',
'TGA': 'Stop',
'TGG': 'Tryptophan',
'CTA': 'Leucine',
'CTC': 'Leucine',
'CTG': 'Leucine',
'CTT': 'Leucine',
'CCA': 'Proline',
'CCC': 'Proline',
'CCG': 'Proline',
'CCT': 'Proline',
'CAC': 'Histidine',
'CAT': 'Histidine',
'CAA': 'Glutamine',
'CAG': 'Glutamine',
'CGA': 'Arginine',
'CGC': 'Arginine',
'CGG': 'Arginine',
'CGT': 'Arginine',
'ATA': 'Isoleucine',
'ATC': 'Isoleucine',
'ATT': 'Isoleucine',
'ATG': 'Methionine/Start',
'ACA': 'Threonine',
'ACC': 'Threonine',
'ACG': 'Threonine',
'ACT': 'Threonine',
'AAC': 'Asparagine',
'AAT': 'Asparagine',
'AAA': 'Lysine',
'AAG': 'Lysine',
'AGC': 'Serine',
'AGT': 'Serine',
'AGA': 'Arginine',
'AGG': 'Arginine',
'GTA': 'Valine',
'GTC': 'Valine',
'GTG': 'Valine',
'GTT': 'Valine',
'GCA': 'Alanine',
'GCC': 'Alanine',
'GCG': 'Alanine',
'GCT': 'Alanine',
'GAC': 'Aspartic Acid',
'GAT': 'Aspartic Acid',
'GAA': 'Glutamic Acid',
'GAG': 'Glutamic Acid',
'GGA': 'Glycine',
'GGC': 'Glycine',
'GGG': 'Glycine',
'GGT': 'Glycine'
}
def identify_type(codon):
if 'U' in codon:
return f"{Fore.LIGHTBLUE_EX}mRNA{Style.RESET_ALL}"
elif 'T' in codon:
return f"{Fore.LIGHTWHITE_EX}DNA{Style.RESET_ALL}"
else:
return f"{Fore.LIGHTBLUE_EX}mRNA{Style.RESET_ALL}{Fore.LIGHTBLACK_EX}/{Fore.LIGHTWHITE_EX}DNA{Style.RESET_ALL}"
def print_codon(codon):
codon_type = identify_type(codon)
codon_in_table = codon.replace('U', 'T')
if codon_in_table in codon_table:
if codon_table[codon_in_table] == "Stop":
amino_acid = f"{Fore.RED}Stop{Style.RESET_ALL}"
elif codon_table[codon_in_table] == "Methionine/Start":
amino_acid = f"{Fore.GREEN}Methionine{Style.RESET_ALL}{Fore.LIGHTBLACK_EX}/{Fore.LIGHTWHITE_EX}Start{Style.RESET_ALL}"
else:
amino_acid = f"{Fore.GREEN}{codon_table[codon_in_table]}{Style.RESET_ALL}"
table_string = tabulate([[f"{Fore.LIGHTMAGENTA_EX}{codon}{Style.RESET_ALL}", amino_acid, codon_type]],
[f"{Fore.LIGHTBLACK_EX}Codon{Style.RESET_ALL}",
f"{Fore.LIGHTBLACK_EX}Amino Acid{Style.RESET_ALL}",
f"{Fore.LIGHTBLACK_EX}Type{Style.RESET_ALL}"],
tablefmt="fancy_grid")
print(table_string)
else:
print('')
print(Fore.RED + "Error: Invalid codon entered" + Style.RESET_ALL)
print(f"Codon {codon} not found in the table.")
def main():
while True:
print('')
codon = input("Enter a codon or (q)uit: ").upper()
if codon == 'Q':
break
print_codon(codon)
if __name__ == "__main__":
main()