-
Notifications
You must be signed in to change notification settings - Fork 0
/
2023-07-20--protein-coding.py
executable file
·55 lines (46 loc) · 1.54 KB
/
2023-07-20--protein-coding.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
#!/usr/bin/env python3
import argparse
translation_table = """
AAs = FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
Starts = ---M------**--*----M---------------M----------------------------
Base1 = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
Base2 = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
Base3 = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
"""
line_hash = {}
for line in translation_table.split("\n"):
line = line.strip()
if not line:
continue
name, details = line.split("=")
line_hash[name.strip()] = details.strip()
codon_to_amino_acid = {}
for amino_acid, base1, base2, base3 in zip(
line_hash["AAs"],
line_hash["Base1"],
line_hash["Base2"],
line_hash["Base3"]):
codon_to_amino_acid[base1 + base2 + base3] = amino_acid
def rc(s):
return "".join({'T':'A',
'G':'C',
'A':'T',
'C':'G',
'N':'N'}[x] for x in reversed(s))
parser = argparse.ArgumentParser()
parser.add_argument("genome")
args = parser.parse_args()
for genome in [
args.genome[0:],
args.genome[1:],
args.genome[2:],
rc(args.genome)[0:],
rc(args.genome)[1:],
rc(args.genome)[2:]
]:
protein = []
for codon_start in range(0, len(genome), 3):
codon = genome[codon_start : codon_start + 3]
if len(codon) == 3:
protein.append(codon_to_amino_acid[codon])
print("".join(protein))