-
Notifications
You must be signed in to change notification settings - Fork 0
/
PROT.py
41 lines (35 loc) · 1.1 KB
/
PROT.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
def RNA__seq_to_Protein(RNA_codon_dict):
"""
Translates RNA sequence to protein sequence
"""
file = open("data/rosalind_prot.txt", "r")
lines = file.readlines()
sequence = ""
for line in lines:
sequence += line.strip()
protein_sequence = ""
for i in range(0, len(sequence), 3):
current = RNA_codon_dict[sequence[i:i+3]]
if current == "Stop":
return protein_sequence
else:
protein_sequence += current
return protein_sequence
def getRNA_codon_dict():
"""
Reads file and returns RNA codon dictionary
"""
codon_dict = {}
with open("data/RNA_codon_table.txt", "r") as file:
for line in file:
line = line.rstrip().split()
for idx, item in enumerate(line):
if idx%2 == 0:
codon_dict[line[idx]] = line[idx+1]
return codon_dict
if __name__ == "__main__":
RNA_codon_dict = getRNA_codon_dict()
ps = RNA__seq_to_Protein(RNA_codon_dict)
#Write result to the file
result_file = open("results/PROT.txt", "w")
result_file.write(ps)