forked from biopython/biopython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeqGui.py
234 lines (200 loc) · 8.07 KB
/
SeqGui.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
from Bio.Seq import translate, transcribe, back_transcribe
import wx
ID_APPLY = 101
ID_CLEAR = 102
ID_EXIT = 103
ID_CLOSE = 104
ID_ABOUT = 105
ID_CODON = 106
ID_TRANSFORM = 107
class ParamsPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
codon_table_static = wx.StaticText(self, -1, 'Codon Tables',
style=wx.ALIGN_CENTER)
lc = wx.LayoutConstraints()
lc.top.SameAs(self, wx.Top, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.AsIs()
lc.right.SameAs(self, wx.Right, 5)
codon_table_static.SetConstraints(lc)
codon_table_lb = wx.ListBox(self, ID_CODON)
lc = wx.LayoutConstraints()
lc.top.Below(codon_table_static, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.PercentOf(self, wx.Height, 30)
lc.right.SameAs(self, wx.Right, 5)
codon_table_lb.SetConstraints(lc)
self.codon_table_lb = codon_table_lb
codon_table_lb.Append('Standard')
codon_table_lb.Append('Vertebrate Mitochondrial')
codon_table_lb.Append('Yeast Mitochondrial')
codon_table_lb.Append('Mold Mitochondrial')
codon_table_lb.Append('Invertebrate Mitochondrial')
codon_table_lb.Append('Echinoderm Mitochondrial')
codon_table_lb.Append('Euplotid Nuclear')
codon_table_lb.Append('Bacterial')
codon_table_lb.Append('Alternative Yeast Nuclear')
codon_table_lb.Append('Ascidian Mitochondrial')
codon_table_lb.Append('Flatworm Mitochondrial')
codon_table_lb.Append('Blepharisma Macronuclear')
codon_table_lb.SetSelection(0)
transform_static = wx.StaticText(self, -1, 'Transformation',
style=wx.ALIGN_CENTER)
lc = wx.LayoutConstraints()
lc.top.Below(codon_table_lb, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.AsIs()
lc.right.SameAs(self, wx.Right, 5)
transform_static.SetConstraints(lc)
transform_lb = wx.ListBox(self, ID_TRANSFORM)
lc = wx.LayoutConstraints()
lc.top.Below(transform_static, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.PercentOf(self, wx.Height, 30)
lc.right.SameAs(self, wx.Right, 5)
transform_lb.SetConstraints(lc)
transform_lb.Append('Transcribe')
transform_lb.Append('Translate')
transform_lb.Append('Back transcribe')
transform_lb.SetSelection(1)
self.transform_lb = transform_lb
class SeqPanel(wx.Panel):
def __init__(self, parent, log):
self.parent = parent
wx.Panel.__init__(self, parent, -1)
apply_button = wx.Button(self, ID_APPLY, "Apply")
clear_button = wx.Button(self, ID_CLEAR, "Clear")
close_button = wx.Button(self, ID_CLOSE, "Close")
wx.EVT_BUTTON(self, ID_CLOSE, self.OnClose)
wx.EVT_BUTTON(self, ID_APPLY, self.OnApply)
wx.EVT_BUTTON(self, ID_CLEAR, self.OnClear)
lc = wx.LayoutConstraints()
lc.bottom.SameAs(self, wx.Bottom, 10)
lc.left.SameAs(self, wx.Left, 10)
lc.height.AsIs()
lc.width.PercentOf(self, wx.Width, 25)
apply_button.SetConstraints(lc)
lc = wx.LayoutConstraints()
lc.bottom.SameAs(self, wx.Bottom, 10)
lc.left.RightOf(apply_button, 5)
lc.height.AsIs()
lc.width.PercentOf(self, wx.Width, 25)
clear_button.SetConstraints(lc)
lc = wx.LayoutConstraints()
lc.bottom.SameAs(self, wx.Bottom, 10)
lc.left.RightOf(clear_button, 5)
lc.height.AsIs()
lc.width.PercentOf(self, wx.Width, 25)
close_button.SetConstraints(lc)
src_static = wx.StaticText(self, -1, 'Original Sequence',
style=wx.ALIGN_CENTER)
lc = wx.LayoutConstraints()
lc.top.SameAs(self, wx.Top, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.AsIs()
lc.right.SameAs(self, wx.Right, 5)
src_static.SetConstraints(lc)
src_text = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE)
lc = wx.LayoutConstraints()
lc.top.Below(src_static, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.PercentOf(self, wx.Height, 30)
lc.right.SameAs(self, wx.Right, 5)
src_text.SetConstraints(lc)
self.src_text = src_text
dest_static = wx.StaticText(self, -1, 'Transformed Sequence',
style=wx.ALIGN_CENTER)
lc = wx.LayoutConstraints()
lc.top.Below(src_text, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.AsIs()
lc.right.SameAs(self, wx.Right, 5)
dest_static.SetConstraints(lc)
dest_text = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE)
lc = wx.LayoutConstraints()
lc.top.Below(dest_static, 5)
lc.left.SameAs(self, wx.Left, 5)
lc.height.PercentOf(self, wx.Height, 30)
lc.right.SameAs(self, wx.Right, 5)
dest_text.SetConstraints(lc)
self.dest_text = dest_text
def OnClose(self, event):
parent = self.GetParent()
parent.Destroy()
def OnApply(self, event):
codon_table_lb = self.parent.params_panel.codon_table_lb
selection = codon_table_lb.GetStringSelection()
print selection
codon_table = selection[:]
transform_lb = self.parent.params_panel.transform_lb
selection = transform_lb.GetStringSelection()
transform = selection[:]
print transform
if(transform == 'Translate'):
self.translate(codon_table)
elif(transform == 'Transcribe'):
self.transcribe()
elif(transform == 'Back transcribe'):
self.back_transcribe()
def OnClear(self, event):
self.src_text.Clear()
self.dest_text.Clear()
def translate(self, codon_table):
seq = "".join(self.src_text.GetValue().split()) #remove whitespace
print seq
self.dest_text.Clear()
self.dest_text.SetValue(translate(seq, table=codon_table,
to_stop=True))
def transcribe(self):
seq = "".join(self.src_text.GetValue().split()) #remove whitespace
print seq
self.dest_text.Clear()
self.dest_text.SetValue(transcribe(seq))
def back_transcribe(self):
seq = "".join(self.src_text.GetValue().split()) #remove whitespace
print seq
self.dest_text.Clear()
self.dest_text.SetValue(back_transcribe(seq))
class SeqFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title,
wx.DefaultPosition, wx.Size(500, 400))
self.SetAutoLayout(True)
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
menu = wx.Menu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
menuBar = wx.MenuBar()
menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)
params_panel = ParamsPanel(self, -1)
lc = wx.LayoutConstraints()
lc.top.SameAs(self, wx.Top, 10)
lc.left.SameAs(self, wx.Left, 5)
lc.bottom.SameAs(self, wx.Bottom, 5)
lc.width.PercentOf(self, wx.Width, 40)
params_panel.SetConstraints(lc)
seq_panel = SeqPanel(self, -1)
lc = wx.LayoutConstraints()
lc.top.SameAs(self, wx.Top, 10)
lc.left.RightOf(params_panel, 5)
lc.bottom.SameAs(self, wx.Bottom, 5)
lc.right.SameAs(self, wx.Right)
seq_panel.SetConstraints(lc)
self.seq_panel = seq_panel
self.params_panel = params_panel
wx.EVT_MENU(self, ID_EXIT, self.exit)
def exit(self, event):
self.Close(True)
class MyApp(wx.App):
def OnInit(self):
frame = SeqFrame(None, -1, "Greetings from Biopython")
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()