From: <nat...@us...> - 2012-03-01 20:30:55
|
Revision: 14985 http://cctbx.svn.sourceforge.net/cctbx/?rev=14985&view=rev Author: natechols Date: 2012-03-01 20:30:48 +0000 (Thu, 01 Mar 2012) Log Message: ----------- new reports module for various list displays, including PDB BLAST and symmetry search results, with mixin for linking to PDB Modified Paths: -------------- trunk/wxtbx/browser.py Added Paths: ----------- trunk/wxtbx/reports/ trunk/wxtbx/reports/__init__.py trunk/wxtbx/reports/blast.py trunk/wxtbx/reports/pdb_symmetry.py Removed Paths: ------------- trunk/wxtbx/blast_report.py Deleted: trunk/wxtbx/blast_report.py =================================================================== --- trunk/wxtbx/blast_report.py 2012-03-01 20:29:38 UTC (rev 14984) +++ trunk/wxtbx/blast_report.py 2012-03-01 20:30:48 UTC (rev 14985) @@ -1,122 +0,0 @@ - -import wx -import sys - -class BlastFrame (wx.Frame) : - def __init__ (self, *args, **kwds) : - super(BlastFrame, self).__init__(*args, **kwds) - self.statusbar = self.CreateStatusBar() - szr = wx.BoxSizer(wx.VERTICAL) - self.SetSizer(szr) - panel = wx.Panel(self) - szr.Add(panel, 1, wx.EXPAND) - pszr = wx.BoxSizer(wx.VERTICAL) - panel.SetSizer(pszr) - box = wx.StaticBox(panel, label="BLAST results") - boxszr = wx.StaticBoxSizer(box, wx.VERTICAL) - pszr.Add(boxszr, 1, wx.ALL|wx.EXPAND, 5) - boxszr.Add(wx.StaticText(panel, -1, "Query sequence:")) - self.seq_ctrl = wx.TextCtrl(panel, style=wx.TE_READONLY|wx.TE_MULTILINE, - size=(600,100)) - boxszr.Add(self.seq_ctrl, 0, wx.ALL, 5) - boxszr.Add(wx.StaticText(panel, -1, "BLAST hits in PDB:")) - self.hit_list = BlastList(panel, style=wx.LC_REPORT|wx.LC_SINGLE_SEL, - size=(600,240)) - #self.hit_list.SetMinSize((600,240)) - boxszr.Add(self.hit_list, 1, wx.ALL|wx.EXPAND, 5) - szr2 = wx.BoxSizer(wx.HORIZONTAL) - boxszr.Add(szr2) - btn1 = wx.Button(panel, -1, "Download selected structure") - szr2.Add(btn1, 0, wx.ALL, 5) - self.Bind(wx.EVT_BUTTON, self.OnDownload, btn1) - btn2 = wx.Button(panel, -1, "View PDB web page") - szr2.Add(btn2, 0, wx.ALL, 5) - self.Bind(wx.EVT_BUTTON, self.OnViewPDB, btn2) - szr.Fit(panel) - self.Layout() - self.Fit() - self.SetMinSize(self.GetSize()) - self.web_frame = None - - def SetResults (self, query, results) : - assert (len(results) > 0) - self.statusbar.SetStatusText("%d results shown (top match: %s_%s)" % - (len(results), results[0].pdb_id, results[0].chain_id)) - self.seq_ctrl.SetValue(query) - self.hit_list.SetResults(results) - - def OnDownload (self, event) : - pdb_id = self.hit_list.GetSelectedID() - if (pdb_id is not None) : - def download (args) : - import mmtbx.command_line.fetch_pdb - return mmtbx.command_line.fetch_pdb.run2(args=args) - from wxtbx.process_control import download_file_basic - download_file_basic( - window=self, - dl_func=download, - args=[pdb_id]) - - def OnViewPDB (self, event) : - pdb_id = self.hit_list.GetSelectedID() - if (pdb_id is not None) : - url = "http://www.rcsb.org/pdb/explore/explore.do?structureId=%s" %pdb_id - if (sys.platform == "darwin") : - from wxtbx import browser - if (self.web_frame is None) : - self.web_frame = browser.webkit_frame(self, -1, "RCSB PDB") - self.web_frame.SetHomepage("http://www.rcsb.org") - self.Bind(wx.EVT_WINDOW_DESTROY, self.OnCloseWWW, self.web_frame) - self.web_frame.Show() - self.web_frame.Raise() - self.web_frame.Open(url) - self.web_frame.Refresh() - else : - from libtbx import easy_run - easy_run.call("env LD_LIBRARY_PATH='' firefox %s" % url) - - def OnCloseWWW (self, event) : - self.web_frame = None - -class BlastList (wx.ListCtrl) : - def __init__ (self, *args, **kwds) : - super(BlastList, self).__init__(*args, **kwds) - cols = ["PDB ID", "Chain ID", "E-value", "Length", "% Identity", - "% Positives"] - widths = [100, 80, 100, 100, 100, 100] - r, l = wx.LIST_FORMAT_RIGHT, wx.LIST_FORMAT_LEFT - alignments = [l, l, r, r, r, r] - for i, col in enumerate(cols) : - self.InsertColumn(i, col, alignments[i]) - self.SetColumnWidth(i, widths[i]) - - def SetResults (self, results) : - self.DeleteAllItems() - for result in results : - i = self.InsertStringItem(sys.maxsize, result.pdb_id) - self.SetStringItem(i, 1, result.chain_id) - self.SetStringItem(i, 2, "%g" % result.evalue) - self.SetStringItem(i, 3, "%d" % result.length) - self.SetStringItem(i, 4, "%.2f" % result.identity) - self.SetStringItem(i, 5, "%.2f" % result.positives) - - def GetSelectedID (self) : - item = self.GetFirstSelected() - if (item >= 0) : - return self.GetItem(item, 0).GetText() - return None - -if (__name__ == "__main__") : - from iotbx.command_line import blast_pdb - from iotbx.file_reader import any_file - seq_file = any_file(sys.argv[1], force_type="seq") - seq_file.check_file_type("seq") - seq_objects = seq_file.file_object - assert (len(seq_objects) == 1) - sequence = seq_objects[0].sequence - results = blast_pdb.summarize_blast_output(blast_file=sys.argv[2]) - app = wx.App(0) - frame = BlastFrame(None, -1, "BLAST results") - frame.SetResults(sequence, results) - frame.Show() - app.MainLoop() Modified: trunk/wxtbx/browser.py =================================================================== --- trunk/wxtbx/browser.py 2012-03-01 20:29:38 UTC (rev 14984) +++ trunk/wxtbx/browser.py 2012-03-01 20:30:48 UTC (rev 14985) @@ -37,7 +37,6 @@ #self.Bind(wx.EVT_WINDOW_CREATE, self.OnShow) def SetHomepage (self, url) : - print "URL: ", url self.home_url = url def SetupToolbar (self) : @@ -64,7 +63,6 @@ self.toolbar.Realize() def LoadURL (self, url) : - print "url: ", url if (wx.Platform == '__WXMAC__') : self.viewer.LoadURL(url) elif (wx.Platform == '__WXMSW__') : Added: trunk/wxtbx/reports/__init__.py =================================================================== --- trunk/wxtbx/reports/__init__.py (rev 0) +++ trunk/wxtbx/reports/__init__.py 2012-03-01 20:30:48 UTC (rev 14985) @@ -0,0 +1,54 @@ + +import wx +import sys + +class PDBLinkMixin (object) : + """ + Subclass this along with wx.Frame, etc. to link to the PDB from a list of + results. get_pdb_id_for_viewing() must be re-implemented in subclasses. + """ + def create_pdb_buttons (self, panel, sizer) : + szr2 = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(szr2) + btn1 = wx.Button(panel, -1, "Download selected structure") + szr2.Add(btn1, 0, wx.ALL, 5) + self.Bind(wx.EVT_BUTTON, self.OnDownload, btn1) + btn2 = wx.Button(panel, -1, "View PDB web page") + szr2.Add(btn2, 0, wx.ALL, 5) + self.Bind(wx.EVT_BUTTON, self.OnViewPDB, btn2) + + def get_pdb_id_for_viewing (self) : + raise NotImplementedError() + + def OnViewPDB (self, event) : + pdb_id = self.get_pdb_id_for_viewing() + if (pdb_id is not None) : + url = "http://www.rcsb.org/pdb/explore/explore.do?structureId=%s" %pdb_id + if (sys.platform == "darwin") : + from wxtbx import browser + if (getattr(self, "web_frame", None) is None) : + self.web_frame = browser.browser_frame(self, -1, "RCSB PDB") + self.web_frame.SetHomepage("http://www.rcsb.org") + self.Bind(wx.EVT_WINDOW_DESTROY, self.OnCloseWWW, self.web_frame) + self.web_frame.Show() + self.web_frame.Raise() + self.web_frame.Open(url) + self.web_frame.Refresh() + else : + from libtbx import easy_run + easy_run.call("env LD_LIBRARY_PATH='' firefox %s" % url) + + def OnDownload (self, event) : + pdb_id = self.get_pdb_id_for_viewing() + if (pdb_id is not None) : + def download (args) : + import mmtbx.command_line.fetch_pdb + return mmtbx.command_line.fetch_pdb.run2(args=args) + from wxtbx.process_control import download_file_basic + download_file_basic( + window=self, + dl_func=download, + args=[pdb_id]) + + def OnCloseWWW (self, event) : + self.web_frame = None Copied: trunk/wxtbx/reports/blast.py (from rev 14978, trunk/wxtbx/blast_report.py) =================================================================== --- trunk/wxtbx/reports/blast.py (rev 0) +++ trunk/wxtbx/reports/blast.py 2012-03-01 20:30:48 UTC (rev 14985) @@ -0,0 +1,86 @@ + +from wxtbx import reports +import wx +import sys + +class BlastFrame (wx.Frame, reports.PDBLinkMixin) : + def __init__ (self, *args, **kwds) : + super(BlastFrame, self).__init__(*args, **kwds) + self.statusbar = self.CreateStatusBar() + szr = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(szr) + panel = wx.Panel(self) + szr.Add(panel, 1, wx.EXPAND) + pszr = wx.BoxSizer(wx.VERTICAL) + panel.SetSizer(pszr) + box = wx.StaticBox(panel, label="BLAST results") + boxszr = wx.StaticBoxSizer(box, wx.VERTICAL) + pszr.Add(boxszr, 1, wx.ALL|wx.EXPAND, 5) + boxszr.Add(wx.StaticText(panel, -1, "Query sequence:")) + self.seq_ctrl = wx.TextCtrl(panel, style=wx.TE_READONLY|wx.TE_MULTILINE, + size=(600,100)) + boxszr.Add(self.seq_ctrl, 0, wx.ALL, 5) + boxszr.Add(wx.StaticText(panel, -1, "BLAST hits in PDB:")) + self.hit_list = BlastList(panel, style=wx.LC_REPORT|wx.LC_SINGLE_SEL, + size=(600,240)) + #self.hit_list.SetMinSize((600,240)) + boxszr.Add(self.hit_list, 1, wx.ALL|wx.EXPAND, 5) + self.create_pdb_buttons(panel, boxszr) + szr.Fit(panel) + self.Layout() + self.Fit() + self.SetMinSize(self.GetSize()) + self.web_frame = None + + def SetResults (self, query, results) : + assert (len(results) > 0) + self.statusbar.SetStatusText("%d results shown (top match: %s_%s)" % + (len(results), results[0].pdb_id, results[0].chain_id)) + self.seq_ctrl.SetValue(query) + self.hit_list.SetResults(results) + + def get_pdb_id_for_viewing (self) : + return self.hit_list.GetSelectedID() + +class BlastList (wx.ListCtrl) : + def __init__ (self, *args, **kwds) : + super(BlastList, self).__init__(*args, **kwds) + cols = ["PDB ID", "Chain ID", "E-value", "Length", "% Identity", + "% Positives"] + widths = [100, 80, 100, 100, 100, 100] + r, l = wx.LIST_FORMAT_RIGHT, wx.LIST_FORMAT_LEFT + alignments = [l, l, r, r, r, r] + for i, col in enumerate(cols) : + self.InsertColumn(i, col, alignments[i]) + self.SetColumnWidth(i, widths[i]) + + def SetResults (self, results) : + self.DeleteAllItems() + for result in results : + i = self.InsertStringItem(sys.maxsize, result.pdb_id) + self.SetStringItem(i, 1, result.chain_id) + self.SetStringItem(i, 2, "%g" % result.evalue) + self.SetStringItem(i, 3, "%d" % result.length) + self.SetStringItem(i, 4, "%.2f" % result.identity) + self.SetStringItem(i, 5, "%.2f" % result.positives) + + def GetSelectedID (self) : + item = self.GetFirstSelected() + if (item >= 0) : + return self.GetItem(item, 0).GetText() + return None + +if (__name__ == "__main__") : + from iotbx.command_line import blast_pdb + from iotbx.file_reader import any_file + seq_file = any_file(sys.argv[1], force_type="seq") + seq_file.check_file_type("seq") + seq_objects = seq_file.file_object + assert (len(seq_objects) == 1) + sequence = seq_objects[0].sequence + results = blast_pdb.summarize_blast_output(blast_file=sys.argv[2]) + app = wx.App(0) + frame = BlastFrame(None, -1, "BLAST results") + frame.SetResults(sequence, results) + frame.Show() + app.MainLoop() Added: trunk/wxtbx/reports/pdb_symmetry.py =================================================================== --- trunk/wxtbx/reports/pdb_symmetry.py (rev 0) +++ trunk/wxtbx/reports/pdb_symmetry.py 2012-03-01 20:30:48 UTC (rev 14985) @@ -0,0 +1,85 @@ + +from wxtbx import reports +import wx +import sys + +class SymmetryListFrame (wx.Frame, reports.PDBLinkMixin) : + def __init__ (self, *args, **kwds) : + super(SymmetryListFrame, self).__init__(*args, **kwds) + self.statusbar = self.CreateStatusBar() + szr = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(szr) + panel = wx.Panel(self) + szr.Add(panel, 1, wx.EXPAND) + pszr = wx.BoxSizer(wx.VERTICAL) + panel.SetSizer(pszr) + box = wx.StaticBox(panel, label="Symmetry search results") + boxszr = wx.StaticBoxSizer(box, wx.VERTICAL) + pszr.Add(boxszr, 1, wx.ALL|wx.EXPAND, 5) + box2 = wx.BoxSizer(wx.HORIZONTAL) + boxszr.Add(box2) + box2.Add(wx.StaticText(panel, -1, "Input symmetry:"), 0, wx.ALL, 5) + self.symm_txt = wx.StaticText(panel, -1, "", size=(540,-1)) + box2.Add(self.symm_txt, 0, wx.ALL, 5) + boxszr.Add(wx.StaticText(panel, -1, "Closest matching PDB entries:"), 0, + wx.ALL, 5) + self.symm_list = PDBSymmList( + parent=self, + style=wx.LC_REPORT|wx.LC_SINGLE_SEL, + size=(740,200)) + boxszr.Add(self.symm_list, 1, wx.ALL|wx.EXPAND, 5) + self.create_pdb_buttons(panel, boxszr) + szr.Fit(panel) + self.Layout() + self.Fit() + self.SetMinSize(self.GetSize()) + self.web_frame = None + + def SetResults (self, symmetry, hits) : + sg_txt = str(symmetry.space_group_info()) + uc_txt = "%g %g %g %g %g %g" % symmetry.unit_cell().parameters() + self.symm_txt.SetLabel("%s (%s)" % (sg_txt, uc_txt)) + self.statusbar.SetStatusText("%d results shown" % len(hits)) + self.symm_list.SetResults(hits) + + def get_pdb_id_for_viewing (self) : + return self.symm_list.GetSelectedID() + +class PDBSymmList (wx.ListCtrl) : + def __init__ (self, *args, **kwds) : + super(PDBSymmList, self).__init__(*args, **kwds) + cols = ["PDB ID", "RMSD", "Volume ratio", "Space group", "Unit cell"] + widths = [100, 80, 120, 120, 300] + r, l = wx.LIST_FORMAT_RIGHT, wx.LIST_FORMAT_LEFT + alignments = [l, r, r, r, r] + for i, col in enumerate(cols) : + self.InsertColumn(i, col, alignments[i]) + self.SetColumnWidth(i, widths[i]) + + def SetResults (self, results) : + self.DeleteAllItems() + for result in results : + i = self.InsertStringItem(sys.maxsize, result.pdb_id) + self.SetStringItem(i, 1, "%6.3f" % result.rmsd) + self.SetStringItem(i, 2, "%g" % result.volume_ratio) + self.SetStringItem(i, 3, str(result.pdb_symmetry.space_group_info())) + self.SetStringItem(i, 4, "%g %g %g %g %g %g" % + result.pdb_symmetry.unit_cell().parameters()) + + def GetSelectedID (self) : + item = self.GetFirstSelected() + if (item >= 0) : + return self.GetItem(item, 0).GetText() + return None + +def run (args) : + from mmtbx.command_line import search_pdb_symmetry + results = search_pdb_symmetry.run(args=args) + app = wx.App(0) + frame = SymmetryListFrame(None, -1, "PDB symmetry search") + frame.SetResults(results.crystal_symmetry, results.hits) + frame.Show() + app.MainLoop() + +if (__name__ == "__main__") : + run(sys.argv[1:]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |