-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.10_Peptide_Encoding_Problem.py
More file actions
36 lines (31 loc) · 1.28 KB
/
2.10_Peptide_Encoding_Problem.py
File metadata and controls
36 lines (31 loc) · 1.28 KB
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
dna = ''
peptide = ''
def dna_codon_map():
codon_map = {}
with open('RNA_codon_table_1.txt') as f:
for line in f:
pair = line.strip().split()
pair[0] = pair[0].replace('U', 'T')
if len(pair) == 2:
codon_map[pair[0]] = pair[1]
else:
codon_map[pair[0]] = 'X'
return codon_map
def reverse_complement(text):
return "".join(reversed([{'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}[l]
for l in list(text)]))
results = []
for f in range(3):
translated = ''.join([dna_codon_map()[dna[i:i+3]]
for i in range(f, (int((len(dna)-f)/3)*3), 3)])
for i in range(len(translated) - len(peptide) + 1):
if translated[i:i+len(peptide)] == peptide:
results.append(dna[i*3+f:i*3+f+3*len(peptide)])
for f in range(3):
translated = ''.join([dna_codon_map()[reverse_complement(dna)[i:i+3]]
for i in range(f, (int((len(dna)-f)/3)*3), 3)])
for i in range(len(translated) - len(peptide) + 1):
if translated[i:i+len(peptide)] == peptide:
results.append(reverse_complement(
reverse_complement(dna)[i*3+f:i*3+f+3*len(peptide)]))
print (*(results), sep = '\n')