Back to index

python-biopython  1.60
SeqGui.py
Go to the documentation of this file.
00001 from Bio.Seq import translate, transcribe, back_transcribe
00002 import wx
00003 
00004 ID_APPLY = 101
00005 ID_CLEAR  = 102
00006 ID_EXIT = 103
00007 ID_CLOSE = 104
00008 ID_ABOUT = 105
00009 ID_CODON = 106
00010 ID_TRANSFORM = 107
00011 
00012 
00013 class ParamsPanel(wx.Panel):
00014     def __init__(self, parent, log):
00015         wx.Panel.__init__(self, parent, -1)
00016         codon_table_static = wx.StaticText(self, -1, 'Codon Tables',
00017                                            style=wx.ALIGN_CENTER)
00018         lc = wx.LayoutConstraints()
00019         lc.top.SameAs(self, wx.Top, 5)
00020         lc.left.SameAs(self, wx.Left, 5)
00021         lc.height.AsIs()
00022         lc.right.SameAs(self, wx.Right, 5)
00023         codon_table_static.SetConstraints(lc)
00024 
00025         codon_table_lb = wx.ListBox(self, ID_CODON)
00026         lc = wx.LayoutConstraints()
00027         lc.top.Below(codon_table_static, 5)
00028         lc.left.SameAs(self, wx.Left, 5)
00029         lc.height.PercentOf(self, wx.Height, 30)
00030         lc.right.SameAs(self, wx.Right, 5)
00031         codon_table_lb.SetConstraints(lc)
00032         self.codon_table_lb = codon_table_lb
00033 
00034         codon_table_lb.Append('Standard')
00035         codon_table_lb.Append('Vertebrate Mitochondrial')
00036         codon_table_lb.Append('Yeast Mitochondrial')
00037         codon_table_lb.Append('Mold Mitochondrial')
00038         codon_table_lb.Append('Invertebrate Mitochondrial')
00039         codon_table_lb.Append('Echinoderm Mitochondrial')
00040         codon_table_lb.Append('Euplotid Nuclear')
00041         codon_table_lb.Append('Bacterial')
00042         codon_table_lb.Append('Alternative Yeast Nuclear')
00043         codon_table_lb.Append('Ascidian Mitochondrial')
00044         codon_table_lb.Append('Flatworm Mitochondrial')
00045         codon_table_lb.Append('Blepharisma Macronuclear')
00046         codon_table_lb.SetSelection(0)
00047 
00048         transform_static = wx.StaticText(self, -1, 'Transformation',
00049                                          style=wx.ALIGN_CENTER)
00050         lc = wx.LayoutConstraints()
00051         lc.top.Below(codon_table_lb, 5)
00052         lc.left.SameAs(self, wx.Left, 5)
00053         lc.height.AsIs()
00054         lc.right.SameAs(self, wx.Right, 5)
00055         transform_static.SetConstraints(lc)
00056 
00057         transform_lb = wx.ListBox(self, ID_TRANSFORM)
00058         lc = wx.LayoutConstraints()
00059         lc.top.Below(transform_static, 5)
00060         lc.left.SameAs(self, wx.Left, 5)
00061         lc.height.PercentOf(self, wx.Height, 30)
00062         lc.right.SameAs(self, wx.Right, 5)
00063         transform_lb.SetConstraints(lc)
00064 
00065         transform_lb.Append('Transcribe')
00066         transform_lb.Append('Translate')
00067         transform_lb.Append('Back transcribe')
00068         transform_lb.SetSelection(1)
00069         self.transform_lb = transform_lb
00070 
00071 
00072 class SeqPanel(wx.Panel):
00073     def __init__(self, parent, log):
00074         self.parent = parent
00075         wx.Panel.__init__(self, parent, -1)
00076         apply_button = wx.Button(self, ID_APPLY, "Apply")
00077         clear_button = wx.Button(self, ID_CLEAR, "Clear")
00078         close_button = wx.Button(self, ID_CLOSE, "Close")
00079         wx.EVT_BUTTON(self, ID_CLOSE, self.OnClose)
00080         wx.EVT_BUTTON(self, ID_APPLY, self.OnApply)
00081         wx.EVT_BUTTON(self, ID_CLEAR, self.OnClear)
00082 
00083         lc = wx.LayoutConstraints()
00084         lc.bottom.SameAs(self, wx.Bottom, 10)
00085         lc.left.SameAs(self, wx.Left, 10)
00086         lc.height.AsIs()
00087         lc.width.PercentOf(self, wx.Width, 25)
00088         apply_button.SetConstraints(lc)
00089 
00090         lc = wx.LayoutConstraints()
00091         lc.bottom.SameAs(self, wx.Bottom, 10)
00092         lc.left.RightOf(apply_button, 5)
00093         lc.height.AsIs()
00094         lc.width.PercentOf(self, wx.Width, 25)
00095         clear_button.SetConstraints(lc)
00096 
00097         lc = wx.LayoutConstraints()
00098         lc.bottom.SameAs(self, wx.Bottom, 10)
00099         lc.left.RightOf(clear_button, 5)
00100         lc.height.AsIs()
00101         lc.width.PercentOf(self, wx.Width, 25)
00102         close_button.SetConstraints(lc)
00103 
00104         src_static = wx.StaticText(self, -1, 'Original Sequence',
00105                                    style=wx.ALIGN_CENTER)
00106         lc = wx.LayoutConstraints()
00107         lc.top.SameAs(self, wx.Top, 5)
00108         lc.left.SameAs(self, wx.Left, 5)
00109         lc.height.AsIs()
00110         lc.right.SameAs(self, wx.Right, 5)
00111         src_static.SetConstraints(lc)
00112 
00113         src_text = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE)
00114         lc = wx.LayoutConstraints()
00115         lc.top.Below(src_static, 5)
00116         lc.left.SameAs(self, wx.Left, 5)
00117         lc.height.PercentOf(self, wx.Height, 30)
00118         lc.right.SameAs(self, wx.Right, 5)
00119         src_text.SetConstraints(lc)
00120         self.src_text = src_text
00121 
00122         dest_static = wx.StaticText(self, -1, 'Transformed Sequence',
00123                                     style=wx.ALIGN_CENTER)
00124         lc = wx.LayoutConstraints()
00125         lc.top.Below(src_text, 5)
00126         lc.left.SameAs(self, wx.Left, 5)
00127         lc.height.AsIs()
00128         lc.right.SameAs(self, wx.Right, 5)
00129         dest_static.SetConstraints(lc)
00130 
00131         dest_text = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE)
00132         lc = wx.LayoutConstraints()
00133         lc.top.Below(dest_static, 5)
00134         lc.left.SameAs(self, wx.Left, 5)
00135         lc.height.PercentOf(self, wx.Height, 30)
00136         lc.right.SameAs(self, wx.Right, 5)
00137         dest_text.SetConstraints(lc)
00138         self.dest_text = dest_text
00139 
00140     def OnClose(self, event):
00141         parent = self.GetParent()
00142         parent.Destroy()
00143 
00144     def OnApply(self, event):
00145         codon_table_lb = self.parent.params_panel.codon_table_lb
00146         selection = codon_table_lb.GetStringSelection()
00147         print selection
00148         codon_table = selection[:]
00149         transform_lb = self.parent.params_panel.transform_lb
00150         selection = transform_lb.GetStringSelection()
00151         transform = selection[:]
00152         print transform
00153         if(transform == 'Translate'):
00154             self.translate(codon_table)
00155         elif(transform == 'Transcribe'):
00156             self.transcribe()
00157         elif(transform == 'Back transcribe'):
00158             self.back_transcribe()
00159 
00160     def OnClear(self, event):
00161         self.src_text.Clear()
00162         self.dest_text.Clear()
00163 
00164     def translate(self, codon_table):
00165         seq = "".join(self.src_text.GetValue().split()) #remove whitespace
00166         print seq
00167         self.dest_text.Clear()
00168         self.dest_text.SetValue(translate(seq, table=codon_table,
00169                                           to_stop=True))
00170         
00171     def transcribe(self):
00172         seq = "".join(self.src_text.GetValue().split()) #remove whitespace
00173         print seq
00174         self.dest_text.Clear()
00175         self.dest_text.SetValue(transcribe(seq))
00176                                 
00177     def back_transcribe(self):
00178         seq = "".join(self.src_text.GetValue().split()) #remove whitespace
00179         print seq
00180         self.dest_text.Clear()
00181         self.dest_text.SetValue(back_transcribe(seq))
00182 
00183 
00184 class SeqFrame(wx.Frame):
00185     def __init__(self, parent, ID, title):
00186         wx.Frame.__init__(self, parent, ID, title,
00187                           wx.DefaultPosition, wx.Size(500, 400))
00188         self.SetAutoLayout(True)
00189         self.CreateStatusBar()
00190         self.SetStatusText("This is the statusbar")
00191         menu = wx.Menu()
00192         menu.Append(ID_ABOUT, "&About",
00193                     "More information about this program")
00194         menu.AppendSeparator()
00195         menu.Append(ID_EXIT, "E&xit", "Terminate the program")
00196 
00197         menuBar = wx.MenuBar()
00198         menuBar.Append(menu, "&File");
00199         self.SetMenuBar(menuBar)
00200 
00201         params_panel = ParamsPanel(self, -1)
00202         lc = wx.LayoutConstraints()
00203         lc.top.SameAs(self, wx.Top, 10)
00204         lc.left.SameAs(self, wx.Left, 5)
00205         lc.bottom.SameAs(self, wx.Bottom, 5)
00206         lc.width.PercentOf(self, wx.Width, 40)
00207         params_panel.SetConstraints(lc)
00208 
00209         seq_panel = SeqPanel(self, -1)
00210         lc = wx.LayoutConstraints()
00211         lc.top.SameAs(self, wx.Top, 10)
00212         lc.left.RightOf(params_panel, 5)
00213         lc.bottom.SameAs(self, wx.Bottom, 5)
00214         lc.right.SameAs(self, wx.Right)
00215         seq_panel.SetConstraints(lc)
00216 
00217         self.seq_panel = seq_panel
00218         self.params_panel = params_panel
00219 
00220         wx.EVT_MENU(self, ID_EXIT, self.exit)
00221 
00222     def exit(self, event):
00223         self.Close(True)
00224 
00225 
00226 class MyApp(wx.App):
00227     def OnInit(self):
00228         frame = SeqFrame(None, -1, "Greetings from Biopython")
00229         frame.Show(True)
00230         self.SetTopWindow(frame)
00231         return True
00232 
00233 app = MyApp(0)
00234 app.MainLoop()