-
Notifications
You must be signed in to change notification settings - Fork 9
/
Code2_15_PeptideEncoding.py
60 lines (53 loc) · 2.54 KB
/
Code2_15_PeptideEncoding.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
"""
Protein Encoding Problem
"""
#Chunyu Zhao 20150913
import sys
GeneticCode = {'ACC': 'T', 'GCA': 'A', 'AAG': 'K', 'AAA': 'K', 'GUU': 'V', 'AAC': 'N', 'AGG': 'R', 'UGG': 'W', 'GUC': 'V', 'AGC': 'S', 'ACA': 'T', 'AGA': 'R', 'AAU': 'N', 'ACU': 'T', 'GUG': 'V', 'CAC': 'H', 'ACG': 'T', 'AGU': 'S', 'CCA': 'P', 'CAA': 'Q', 'CCC': 'P', 'UGU': 'C', 'GGU': 'G', 'UCU': 'S', 'GCG': 'A', 'CGA': 'R', 'CAG': 'Q', 'CGC': 'R', 'UAU': 'Y', 'CGG': 'R', 'UCG': 'S', 'CCU': 'P', 'GGG': 'G', 'GGA': 'G', 'GGC': 'G', 'CCG': 'P', 'UCC': 'S', 'UAC': 'Y', 'CGU': 'R', 'GAA': 'E', 'AUA': 'I', 'AUC': 'I', 'CUU': 'L', 'UCA': 'S', 'AUG': 'M', 'UGA': '', 'CUG': 'L', 'GAG': 'E', 'AUU': 'I', 'CAU': 'H', 'CUA': 'L', 'UAA': '', 'GCC': 'A', 'UUU': 'F', 'GAC': 'D', 'GUA': 'V', 'UGC': 'C', 'GCU': 'A', 'UAG': '', 'CUC': 'L', 'UUG': 'L', 'UUA': 'L', 'GAU': 'D', 'UUC': 'F'}
def rna_translate_protein(rna):
i = 0
protein = []
while i < len(rna)-2:
if len(GeneticCode[rna[i:i+3]]) ==0:
return protein
else:
protein.append(GeneticCode[rna[i:i+3]])
i = i + 3
return ''.join(protein)
def piptide_encoding(text,peptide):
k = 3 * len(peptide)
ret = []
for i in range(len(text)-k+1):
rna = text[i:i+k].replace('T','U')
protein = rna_translate_protein(rna)
if protein == peptide:
ret.append(text[i:i+k])
reversetext = reverse_complement(text)
for i in range(len(reversetext)-k+1):
rna = reversetext[i:i+k].replace('T','U')
protein = rna_translate_protein(rna)
if protein == peptide:
ret.append(reverse_complement(reversetext[i:i+k]))
return ret
def count_seq(peptide):
ret = 1
for pep in peptide:
ret = ret * len([i for i, v in GeneticCode.items() if v == pep])
print ret
def reverse_complement(dna):
dnadict = {'A':'T','C':'G','G':'C','T':'A'}
reverseDna = [ dnadict[c] for c in dna ]
reverseDna = reverseDna[::-1]
return ''.join(reverseDna)
if __name__ == '__main__':
if len(sys.argv) == 2:
filename = sys.argv[1]
with open(filename) as f:
lines = f.read().splitlines()
text = lines[0]
peptide = lines[1]
else:
text = "ATGGCCATGGCCCCCAGAACTGAGATCAATAGTACCCGTATTAACGGGTGA"
peptide = "MA"
protein = piptide_encoding(text,peptide)
print '\n'.join(protein)