Repository navigation
Expand file tree
/
Copy pathsequence.py
More file actions
166 lines (135 loc) · 3.13 KB
/
Copy pathsequence.py
File metadata and controls
166 lines (135 loc) · 3.13 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from sys import *
def codons_to_letter(c):
"""Converts codon to amino acid.
Args:
c (str) -- 3-letter codon
Returns:
str -- the 1-letter abbreviation of the corresponding amino acid
"""
return MAPPING2[MAPPING[c]]
# maps codons to amino acids
MAPPING = {
'UUU': 'phenylalanine',
'UUC': 'phenylalanine',
'UUA': 'leucine',
'UUG': 'leucine',
'CUU': 'leucine',
'CUC': 'leucine',
'CUA': 'leucine',
'CUG': 'leucine',
'AUU': 'isoleucine',
'AUC': 'isoleucine',
'AUA': 'isoleucine',
'AUG': 'START',
'GUU': 'valine',
'GUC': 'valine',
'GUA': 'valine',
'GUG': 'valine',
'UCU': 'serine',
'UCC': 'serine',
'UCA': 'serine',
'UCG': 'serine',
'CCU': 'proline',
'CCC': 'proline',
'CCA': 'proline',
'CCG': 'proline',
'ACU': 'threonine',
'ACC': 'threonine',
'ACA': 'threonine',
'ACG': 'threonine',
'GCU': 'alanine',
'GCC': 'alanine',
'GCA': 'alanine',
'GCG': 'alanine',
'UAU': 'tyrosine',
'UAC': 'tyrosine',
'UAA': 'STOP',
'UAG': 'STOP',
'CAU': 'histidine',
'CAC': 'histidine',
'CAA': 'glutamine',
'CAG': 'glutamine',
'AAU': 'asparagine',
'AAC': 'asparagine',
'AAA': 'lysine',
'AAG': 'lysine',
'GAU': 'aspartic acid',
'GAC': 'aspartic acid',
'GAA': 'glutamic acid',
'GAG': 'glutamic acid',
'UGU': 'cysteine',
'UGC': 'cysteine',
'UGA': 'STOP',
'UGG': 'tryptophan',
'CGU': 'arginine',
'CGC': 'arginine',
'CGA': 'arginine',
'CGG': 'arginine',
'AGU': 'serine',
'AGC': 'serine',
'AGA': 'arginine',
'AGG': 'arginine',
'GGU': 'glycine',
'GGC': 'glycine',
'GGA': 'glycine',
'GGG': 'glycine'
}
# maps amino acids to their abbreviations
MAPPING2 = {
'phenylalanine': 'F',
'leucine': 'L',
'isoleucine': 'I',
'START': 'M',
'valine': 'V',
'serine': 'S',
'proline': 'P',
'threonine': 'T',
'alanine': 'A',
'tyrosine': 'Y',
'STOP': '?',
'histidine': 'H',
'glutamine': 'Q',
'asparagine': 'N',
'lysine': 'K',
'aspartic acid': 'D',
'glutamic acid': 'E',
'cysteine': 'C',
'tryptophan': 'W',
'arginine': 'R',
'glycine': 'G'
}
dna = argv[1]
rna = ''
rna = dna.replace('T', 'U')
output = []
temp = ''
if 'AUG' in rna:
start = rna.index('AUG')
else:
start = len(rna)
i = start
while True:
codon = rna[i:i+3]
if len(codon) < 3:
if 'AUG' in rna[start+1:]: # reached end of sequence
temp = ''
start = rna.index('AUG', start+1) # looks for next
i = start # start codon
else:
break # no more start codons
else:
temp += codons_to_letter(codon)
i += 3
if codons_to_letter(codon) == '?':
output.append(temp) # valid sequence
if 'AUG' in rna[start+1:]:
temp = ''
start = rna.index('AUG', start+1)
i = start
else:
break
if not output:
output = 'No sequence found!'
print(rna.strip())
print(len(dna))
print(output)