[Bio] / PyGUI / RecoElempanel.py Repository:
ViewVC logotype

Annotation of /PyGUI/RecoElempanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (view) (download) (as text)

1 : efrank 1.14 import copy
2 : efrank 1.40 from wxPython.wx import *
3 :     from KahApp.KahConfigMgr import KahConfigMgr
4 :     from FaST.BssFactory import BssFactory
5 :     from KahOM.RecoElem import RecoElem
6 : efrank 1.23 import os
7 : efrank 1.40 from tempfile import mktemp
8 :     from tempfile import TemporaryFile
9 : efrank 1.23
10 : hwang 1.1
11 : efrank 1.34 #------------------------------------------------------------------------
12 :     class TreeData:
13 :     #------------------------------------------------------------------------
14 :     """
15 :     TreeData instances are associated with wxTree nodes via
16 :     SetPyData(). TreeData is just a struct to keep us sane
17 :     when fetching things back. It holds a RecoElem and the
18 :     CatalogEntry that owns it.
19 :     """
20 :    
21 : efrank 1.35 def __init__(self, itemId, aRecoElem, aCatalogEntry):
22 :     self.re = aRecoElem
23 :     self.ce = aCatalogEntry
24 :     self.itemId = itemId
25 : efrank 1.34 return
26 :    
27 :    
28 :    
29 :    
30 :     #------------------------------------------------------------------------
31 : hwang 1.32 class RecoElempanel:
32 : efrank 1.34 #------------------------------------------------------------------------
33 : efrank 1.11 # def __init__(self, parent):
34 :     # def initEvents(self):
35 :     # def ID_NUM(self,event):
36 : efrank 1.34 # def AddRecoElemTree( self, treeItemId, aRecoElem, aCatalogEntry ):
37 : efrank 1.11 # def onSelectReaction(self,event):
38 :     # def onSelect(self, treeEvent):
39 :     # def redrawRecoElemRxList(self, re):
40 : efrank 1.37 # def onRightListClick( self, event):
41 : efrank 1.11 # def setupRecoElemRxListEditMenu(self):
42 :     # def rightTreeClick( self, event):
43 :     # def setupRecoElemEditMenu(self):
44 : hwang 1.18 # def updateTreeBranchText(self, sourceRXNum):
45 : efrank 1.11 # def recoElemPasteRx(self, event):
46 :     # def recoElemPasteFromSelectedRxGrid(self, event):
47 :     # def recoElemAddKid(self, event):
48 :     # def recoElemAddRoot(self, event):
49 :     # def recoElemRxListCut(self, event):
50 :     # def recoElemRxListCopy(self, event):
51 :     # def recoElemRxListPaste(self, event):
52 : hwang 1.1
53 : efrank 1.4 #------------------------------------------------------------------
54 : hwang 1.1 def __init__(self, parent):
55 : efrank 1.4 #------------------------------------------------------------------
56 : efrank 1.34 self.selectedItem = None # last thing selected. Instance of TreeItem
57 : efrank 1.10 self.cutOrCopiedRx = None
58 : efrank 1.14 self.cutOrCopiedRE = None
59 : efrank 1.35 self._pluginDict = {} # used to dispatch calls to plugins.
60 : hwang 1.1 self.parent = parent
61 : efrank 1.10
62 : efrank 1.4 self.parent.rootId = self.parent.tree_ctr.AddRoot("top item")
63 :    
64 : hwang 1.39
65 : efrank 1.4 #set up menu for editing recoelem
66 :     self.recoElemEditMenu = wxMenu()
67 : efrank 1.14 self.recoElemNewKidId = wxNewId()
68 :     self.recoElemCopyREBranchId = wxNewId()
69 :     self.recoElemCutREBranchId = wxNewId()
70 :     self.recoElemPasteREBranchId = wxNewId()
71 :    
72 : efrank 1.10 self.recoElemPasteRxId = wxNewId()
73 :     self.recoElemPasteFromSelectedRxGridId = wxNewId()
74 : efrank 1.23 self.recoElemVizWithCytoScapeId = wxNewId()
75 : efrank 1.31 self.recoElemWriteToBssId = wxNewId()
76 : efrank 1.4 self.setupRecoElemEditMenu()
77 :    
78 : hwang 1.7 #set up menu for list
79 : efrank 1.9 self.recoElemRxListEditMenu = wxMenu()
80 :     self.recoElemRxListCutId = wxNewId()
81 :     self.recoElemRxListCopyId = wxNewId()
82 : efrank 1.10 self.recoElemRxListPasteId = wxNewId()
83 : efrank 1.9 self.setupRecoElemRxListEditMenu()
84 : hwang 1.7
85 : efrank 1.4 self.initEvents()
86 :     return
87 :    
88 :     #------------------------------------------------------------------
89 :     def initEvents(self):
90 :     #------------------------------------------------------------------
91 :    
92 : hwang 1.32 #button1= self.parent.OK_button
93 : efrank 1.4 # select in list of reactions
94 : efrank 1.8 EVT_LISTBOX(self.parent, self.parent.list_box.GetId(),
95 :     self.onSelectReaction)
96 : efrank 1.4
97 :     # hit the button that loads a RecoElem id
98 : hwang 1.32 #EVT_BUTTON(self.parent, button1.GetId(), self.ID_NUM)
99 : efrank 1.4
100 :     # select in tree
101 :     EVT_TREE_SEL_CHANGED(self.parent.tree_ctr,
102 :     self.parent.tree_ctr.GetId(), self.onSelect)
103 :    
104 :     # Right click on tree (presumably after selection)
105 :     EVT_RIGHT_DOWN(self.parent.tree_ctr, self.rightTreeClick)
106 : hwang 1.7
107 : efrank 1.8 # Right click on List (presumably after selection)
108 : efrank 1.37 EVT_RIGHT_DOWN(self.parent.list_box, self.onRightListClick)
109 : efrank 1.8
110 :     # this does not work for some reason.
111 :     #EVT_LISTBOX(self.parent.list_box, self.parent.list_box.GetId(),
112 : efrank 1.37 # self.onRightListClick)
113 : hwang 1.7
114 : hwang 1.1
115 : efrank 1.4 return
116 : hwang 1.1
117 : efrank 1.4
118 :     #------------------------------------------------------------------
119 : efrank 1.37 def addRecoElemTree( self, treeItemId, aRecoElem, aCatalogEntry ):
120 : efrank 1.4 #------------------------------------------------------------------
121 : hwang 1.1
122 :     numrx= len(aRecoElem.Reactions)
123 :     if numrx > 0:
124 :     rxitem = "(" + str(numrx) + "rx"+ ") " + aRecoElem.Name
125 :     else:
126 :     rxitem = aRecoElem.Name
127 : efrank 1.35
128 : hwang 1.1 itemId=self.parent.tree_ctr.AppendItem(treeItemId, rxitem )
129 : efrank 1.34 self.parent.tree_ctr.SetPyData(itemId,
130 : efrank 1.35 TreeData( itemId, aRecoElem, aCatalogEntry))
131 : hwang 1.1
132 :     for kid in aRecoElem.SubElems:
133 : efrank 1.37 self.addRecoElemTree( itemId, kid, aCatalogEntry )
134 : hwang 1.1
135 :     return
136 :    
137 : efrank 1.4 #------------------------------------------------------------------
138 : efrank 1.9 def onSelectReaction(self,event):
139 : efrank 1.4 #------------------------------------------------------------------
140 :     return
141 : hwang 1.1
142 :     pt=self.parent.list_box.GetPosition()
143 :     item =self.parent.list_box.HitTest(pt)
144 :    
145 :     selectedlist=self.parent.list_box.GetSelections()
146 :    
147 :     for count in selectedlist:
148 : efrank 1.9 rx = self.parent.list_boxData[count]
149 :    
150 :     return
151 : hwang 1.1
152 : efrank 1.4 #------------------------------------------------------------------
153 : efrank 1.3 def onSelect(self, treeEvent):
154 : efrank 1.4 #------------------------------------------------------------------
155 : efrank 1.3 item = treeEvent.GetItem()
156 : efrank 1.34 re = self.parent.tree_ctr.GetPyData(item).re
157 : efrank 1.4 self.selectedItem=item
158 : efrank 1.3
159 : efrank 1.9 self.redrawRecoElemRxList( re )
160 :     return
161 :    
162 :     #------------------------------------------------------------------
163 :     def redrawRecoElemRxList(self, re):
164 :     #------------------------------------------------------------------
165 : efrank 1.37 """
166 : efrank 1.38 @type re: KahOM.RecoElem
167 : efrank 1.37 @rtype: none
168 :     """
169 : efrank 1.3 wxBeginBusyCursor()
170 : efrank 1.9 self.parent.list_box.Clear()
171 :     offset = 0
172 :     self.parent.list_boxData.clear()
173 : efrank 1.3 for rx in re.Reactions:
174 :     item = rx.asString()
175 :     listnum = self.parent.list_box.Append(item)
176 : efrank 1.9 itemNo = self.parent.list_box.GetCount()-1
177 :     # we store the recoElem ptr too in case we have to rm the rx
178 :     self.parent.list_boxData[itemNo] = (rx, offset, re)
179 :     offset += 1
180 : efrank 1.3
181 :     wxEndBusyCursor()
182 : hwang 1.1
183 : efrank 1.3 return
184 : hwang 1.7
185 :     #------------------------------------------------------------------
186 : efrank 1.37 def onRightListClick( self, event):
187 : hwang 1.7 #------------------------------------------------------------------
188 : hwang 1.22
189 : hwang 1.13 listBoxObject = event.GetEventObject()
190 :     listBoxObject.PopupMenu(self.recoElemRxListEditMenu, event.GetPosition())
191 :    
192 : hwang 1.7 return
193 :    
194 :     #------------------------------------------------------------------
195 : efrank 1.9 def setupRecoElemRxListEditMenu(self):
196 : hwang 1.7 #------------------------------------------------------------------
197 : efrank 1.9 self.recoElemRxListEditMenu.Append( self.recoElemRxListCutId,
198 :     "Cut", "Cut" )
199 :     EVT_MENU(self.parent, self.recoElemRxListCutId, self.recoElemRxListCut)
200 : hwang 1.7
201 :    
202 : efrank 1.9 self.recoElemRxListEditMenu.Append( self.recoElemRxListCopyId,
203 :     "Copy","Copy")
204 :     EVT_MENU(self.parent, self.recoElemRxListCopyId,self.recoElemRxListCopy)
205 : efrank 1.10 self.recoElemRxListEditMenu.Append( self.recoElemRxListPasteId,
206 :     "Paste", "Paste")
207 :     EVT_MENU(self.parent, self.recoElemRxListPasteId,
208 :     self.recoElemRxListPaste)
209 :    
210 :     self.recoElemRxListEditMenu.Append( self.recoElemPasteFromSelectedRxGridId,
211 :     "Paste From Selected Rx Table",
212 :     "Paste From Selected Rx Table")
213 :     EVT_MENU(self.parent, self.recoElemPasteFromSelectedRxGridId,
214 :     self.recoElemPasteFromSelectedRxGrid)
215 :    
216 :    
217 : hwang 1.7 return
218 :    
219 : efrank 1.4 #------------------------------------------------------------------
220 :     def rightTreeClick( self, event):
221 :     #------------------------------------------------------------------
222 : hwang 1.13 #pt=event.GetPosition()
223 : efrank 1.25 #if self.selectedItem != None:
224 :     if 1:
225 : hwang 1.18 treeObject = event.GetEventObject()
226 :     treeObject.PopupMenu(self.recoElemEditMenu, event.GetPosition() )
227 : efrank 1.4
228 :     return
229 :    
230 :     #------------------------------------------------------------------
231 :     def setupRecoElemEditMenu(self):
232 :     #------------------------------------------------------------------
233 : efrank 1.14 self.recoElemEditMenu.Append( self.recoElemNewKidId,
234 :     "New Sub Element", "New kid arg3" )
235 :     EVT_MENU(self.parent, self.recoElemNewKidId, self.recoElemNewKid)
236 :     #
237 :     self.recoElemEditMenu.Append( self.recoElemCopyREBranchId,
238 :     "Copy Tree Branch", "Copy Tree Branch" )
239 :     EVT_MENU(self.parent, self.recoElemCopyREBranchId, self.recoElemCopyREBranch)
240 :     #
241 :     self.recoElemEditMenu.Append( self.recoElemCutREBranchId,
242 :     "Cut Tree Branch", "Cut Tree Branch" )
243 :     EVT_MENU(self.parent, self.recoElemCutREBranchId, self.recoElemCutREBranch)
244 :     #
245 :     self.recoElemEditMenu.Append( self.recoElemPasteREBranchId,
246 :     "Paste Tree Branch", "Paste Tree Branch" )
247 :     EVT_MENU(self.parent, self.recoElemPasteREBranchId, self.recoElemPasteREBranch)
248 :     #
249 :     # Rx related
250 :     #
251 : efrank 1.35
252 :     #
253 :     self.recoElemEditMenu.AppendSeparator()
254 :     #
255 :    
256 : efrank 1.10 self.recoElemEditMenu.Append( self.recoElemPasteRxId,
257 :     "Paste Rx", "Add kid arg3" )
258 :     EVT_MENU(self.parent, self.recoElemPasteRxId, self.recoElemPasteRx)
259 : efrank 1.14 #
260 : efrank 1.10 self.recoElemEditMenu.Append( self.recoElemPasteFromSelectedRxGridId,
261 :     "Paste From Selected Rx Table",
262 :     "Paste From Selected Rx Table")
263 :     EVT_MENU(self.parent, self.recoElemPasteFromSelectedRxGridId,
264 :     self.recoElemPasteFromSelectedRxGrid)
265 : efrank 1.23 #
266 : efrank 1.35 self.recoElemEditMenu.AppendSeparator()
267 : efrank 1.31 #
268 :     self.recoElemEditMenu.Append( self.recoElemWriteToBssId,
269 :     "Write to BSS",
270 :     "Write to BSS")
271 :     EVT_MENU(self.parent, self.recoElemWriteToBssId,
272 :     self.recoElemWriteToBss)
273 : hwang 1.19
274 : efrank 1.23
275 : efrank 1.35 #
276 :     # plug-ins will be added beyond here via extendRecoElemEditMenu.
277 :     #
278 :    
279 :     self.recoElemEditMenu.AppendSeparator()
280 :    
281 :     self.recoElemEditMenu.Append( self.recoElemVizWithCytoScapeId,
282 :     "Visualize in CytoScape",
283 :     "Visualize in CytoScape")
284 :     EVT_MENU(self.parent, self.recoElemVizWithCytoScapeId,
285 :     self.recoElemVizWithCytoScape)
286 :    
287 :     return
288 :    
289 :     #------------------------------------------------------------------
290 :     def extendRecoElemEditMenu(self, menuText, helpText, handler):
291 :     #------------------------------------------------------------------
292 : efrank 1.37 """
293 :     Used for plugins. Adds them to the RecoElemEditMenu
294 :    
295 :     @type menuText: string The text to be shown in the menu.
296 :     @type helpText: string The help text for the item.
297 :     @type handler: function taking a RecoElem returning nothing.
298 :     """
299 : efrank 1.35
300 :     theNewId = wxNewId()
301 :     try:
302 :     self._pluginDict[theNewId] = handler
303 :     except LookupError:
304 :     self.parent.error( "Program error extendRecoelemEditMenu: plugin not registerd")
305 :     return
306 :    
307 :     self.recoElemEditMenu.Append( theNewId, menuText, helpText )
308 :     EVT_MENU(self.parent, theNewId, self.pluginHandler)
309 :    
310 :     return
311 :    
312 :     #------------------------------------------------------------------
313 :     def pluginHandler(self, event):
314 :     #------------------------------------------------------------------
315 :     """
316 :     Dispatches a wxCommandEvent that arose from an EVT_MENU
317 :     registration to the actual plugin.
318 :     """
319 :    
320 :     if (self.selectedItem == None):
321 :     self.parent.error( "Select a RecoElem first" )
322 :     return
323 :    
324 :     # form the arg list to the plugin
325 :    
326 :     treeData = self.parent.tree_ctr.GetPyData( self.selectedItem)
327 :     re = treeData.re
328 :    
329 : efrank 1.40 ##
330 : efrank 1.35 # find and call the plugin
331 : efrank 1.40 #
332 :     # this is a little wonky right now. we'r exposing the execution
333 :     # rules and have the config file hardwired. its a start. don't
334 :     # copy this code.
335 :     ##
336 :    
337 :     theModule = self._pluginDict[ event.GetId() ]
338 :     mgr = KahConfigMgr()
339 :    
340 :     mgr.newSection( theModule.name() )
341 :     cfg = mgr.getSection( theModule.name() )
342 :     theModule.config( cfg )
343 :     print "h"
344 :     cfg.dump()
345 :     print "h"
346 :     mgr.dump()
347 :     mgr.loadConfigFile( "ModelEditor.cfg" )
348 :     print "now"
349 :     mgr.dump()
350 :     theModule.process( re, cfg )
351 :     theModule.finish( cfg )
352 : efrank 1.35
353 :     # the plugin may have changed the recoelem, so we have to
354 :     # bring the display up to date. this is really inefficient,
355 :     # but we're going to destroy everything for the recoelem
356 :     # and rebuilt from scratch to make sure we get it right.
357 :    
358 :     id=treeData.itemId
359 :     self.parent.tree_ctr.DeleteChildren( id )
360 :     self.parent.tree_ctr.Delete( id )
361 :     parentId = self.parent.tree_ctr.GetItemParent( id )
362 :    
363 : efrank 1.37 self.addRecoElemTree( parentId, re, treeData.ce )
364 : efrank 1.35
365 : efrank 1.10 return
366 : hwang 1.18
367 :     #------------------------------------------------------------------
368 : hwang 1.19 def updateTreeBranchText(self, sourceRXNum, recoElemName):
369 : hwang 1.18 #------------------------------------------------------------------
370 :    
371 :     rxPrevName = self.parent.tree_ctr.GetItemText(self.selectedItem)
372 : hwang 1.19 newLabel = "(" + str(sourceRXNum) + "rx" ") " + recoElemName
373 : hwang 1.18
374 :     #sylistic purposes get rid of (0 rx) if it exist
375 :     if newLabel[1] == '0':
376 :     newLabel = newLabel[6:]
377 :    
378 :    
379 :     self.parent.tree_ctr.SetItemText(self.selectedItem, newLabel)
380 :     return
381 : efrank 1.10
382 :     #------------------------------------------------------------------
383 : efrank 1.14 def recoElemNewKid(self, event):
384 : efrank 1.4 #------------------------------------------------------------------
385 :     if (self.selectedItem == None): return
386 : efrank 1.34 treeData = self.parent.tree_ctr.GetPyData( self.selectedItem)
387 :     re = treeData.re
388 : efrank 1.4
389 :     prompt = "Name of new child for " + re.Name
390 :     dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)
391 :    
392 :     if ( dlg.ShowModal() == wxID_OK):
393 :     kidName = dlg.GetValue()
394 :     if ( kidName=="" ): return
395 :     dlg.Destroy()
396 :     else:
397 :     #didn't get a kid name
398 :     dlg.Destroy()
399 :     return
400 :    
401 : efrank 1.37 newKid = RecoElem( kidName )
402 : efrank 1.4 re.SubElems.append( newKid )
403 : efrank 1.37 self.addRecoElemTree( self.selectedItem, newKid, treeData.ce)
404 : efrank 1.4
405 :     return
406 :    
407 :     #------------------------------------------------------------------
408 : efrank 1.14 def recoElemCopyREBranch(self, event):
409 : efrank 1.20 #------------------------------------------------------------------
410 : efrank 1.25 if (self.selectedItem == None): return
411 : efrank 1.14 self.cutOrCopiedRE = self.selectedItem
412 :     return
413 :    
414 :     #------------------------------------------------------------------
415 :     def recoElemCutREBranch(self, event):
416 : efrank 1.20 #------------------------------------------------------------------
417 : efrank 1.25 if (self.selectedItem == None): return
418 : hwang 1.18
419 : efrank 1.20 # first, modify the actual recoElem tree.
420 :     parentItem = self.parent.tree_ctr.GetItemParent(self.selectedItem)
421 : efrank 1.34 parentRe = self.parent.tree_ctr.GetPyData( parentItem ).re
422 :     selectedRe = self.parent.tree_ctr.GetPyData(self.selectedItem ).re
423 : efrank 1.20
424 : efrank 1.26 # if we have a parent, i.e., if we are not the top of the tree,
425 :     # then remove ourself from our parents kid-list
426 :    
427 :     if (parentRe != None):
428 :     parentRe.SubElems.remove( selectedRe )
429 : efrank 1.20
430 :     # this no longer points anyplace valid
431 :     self.cutOrCopiedRE = None
432 : efrank 1.26 self.selectedItem == None
433 : hwang 1.18
434 : efrank 1.20 # now modify the display
435 : hwang 1.18 self.parent.tree_ctr.Delete(self.selectedItem)
436 : efrank 1.14 return
437 :    
438 :     #------------------------------------------------------------------
439 :     def recoElemPasteREBranch(self, event):
440 : efrank 1.25 #------------------------------------------------------------------
441 : efrank 1.14 if (self.selectedItem == None):
442 :     self.parent.error( "Select a tree branch first as target.")
443 :     return
444 :    
445 :     if (self.cutOrCopiedRE == None):
446 : efrank 1.26 self.parent.error( "Select and copy a tree branch first.")
447 : efrank 1.14 return
448 :    
449 : efrank 1.34 reSource = self.parent.tree_ctr.GetPyData( self.cutOrCopiedRE ).re
450 :     reTarget = self.parent.tree_ctr.GetPyData( self.selectedItem).re
451 :     ceTarget = self.parent.tree_ctr.GetPyData( self.selectedItem).ce
452 : efrank 1.14
453 :     reSourceCopy = copy.deepcopy( reSource )
454 : efrank 1.21 reTarget.SubElems.append( reSourceCopy )
455 : efrank 1.14
456 : efrank 1.37 self.addRecoElemTree( self.selectedItem, reSourceCopy, ceTarget )
457 : efrank 1.14
458 :     return
459 :    
460 :     #------------------------------------------------------------------
461 : efrank 1.25 def recoElemPasteRx(self, event):
462 :     #------------------------------------------------------------------
463 :    
464 : efrank 1.28 if ( None == self.selectedItem ): return
465 :     if ( None == self.cutOrCopiedRx ): return
466 : efrank 1.25
467 :    
468 : efrank 1.34 re = self.parent.tree_ctr.GetPyData( self.selectedItem).re
469 : efrank 1.28
470 : efrank 1.25 re.Reactions.append( self.cutOrCopiedRx )
471 :    
472 :     rxListNum = len(re.Reactions)
473 :    
474 :     self.updateTreeBranchText(rxListNum, re.Name)
475 :     self.redrawRecoElemRxList(re)
476 :    
477 :     return
478 :    
479 :    
480 :     #------------------------------------------------------------------
481 :     def recoElemPasteFromSelectedRxGrid(self, event):
482 :     #------------------------------------------------------------------
483 :     if (self.selectedItem == None): return
484 :    
485 : efrank 1.34 re = self.parent.tree_ctr.GetPyData( self.selectedItem).re
486 : efrank 1.25
487 :     rxList = self.parent.rx.getSelectedRx()
488 :     rxListNum = len(re.Reactions)
489 :    
490 :     for rx in rxList:
491 :     re.Reactions.append( rx )
492 :    
493 :     self.updateTreeBranchText(rxListNum, re.Name)
494 :     self.redrawRecoElemRxList(re)
495 :    
496 :     return
497 :    
498 :     #------------------------------------------------------------------
499 :     def recoElemVizWithCytoScape(self, event):
500 :     #------------------------------------------------------------------
501 :     if (self.selectedItem == None): return
502 : efrank 1.34 re = self.parent.tree_ctr.GetPyData( self.selectedItem).re
503 : efrank 1.25
504 :     # "not connectable" is for things like ATP that happen so much
505 :     # that you can't just draw one node or you get a mess. But cytoscape
506 :     # SIF files uses "same name, same node." So we're going to bump up
507 :     # a counter every time we hit a not-connectible and tack it on the
508 :     # end of the name.
509 :     #
510 :     nNotConnect = 0
511 :    
512 : efrank 1.41 #
513 :     # KEGG provides isConnected as an attribute of a reactant. We're
514 :     # going to try something here and ignore the isConnected int he
515 :     # Reactant object and make our decions based upon the number of
516 :     # edges coming into a reactant node in the full graph of the
517 :     # system
518 :    
519 :     rxGraph = re.getGraph()
520 :     thresh = 5
521 :    
522 :    
523 : efrank 1.25 allRxList = []
524 :     re.gatherReactions( allRxList )
525 :    
526 : efrank 1.29 output = mktemp(suffix=".sif")
527 :     nodeAttribs = mktemp(suffix=".node")
528 :     out_file = open(output, "w") # Create temporary
529 :     nodeAttrib_file = open(nodeAttribs, "w") # Create temporary
530 :     print output, nodeAttribs
531 : efrank 1.25
532 : efrank 1.30 nodeAttrib_file.write("NodeType\n")
533 :    
534 : efrank 1.25 nRx = 0
535 :     for r in allRxList:
536 :     nRx += 1
537 : efrank 1.29 rxKind="enzymatic"
538 :     if (len(r.enzymeNames) > 0):
539 :     enzName= r.enzymeNames[0]
540 :     if (enzName == "spontaneous"): rxKind = "spontaneous"
541 :     enzName.replace(' ', '_')
542 :     else:
543 :     enzName= ""
544 :     rxKind="spontaneous"
545 :     rxName = "Rx%d-%s" % ( nRx, enzName)
546 : efrank 1.30 nodeAttrib_file.write("%s = %s\n" % ( rxName, rxKind) )
547 : efrank 1.27 if (r.Direction == "forward"):
548 :     edgeName = "ci" # compound to irreversible rx
549 :     else:
550 :     edgeName = "cr" # compound to reversible rx
551 : efrank 1.25 for i in r.Inputs:
552 : efrank 1.41 if (not i.isConnected or (rxGraph.all_degree( i.Name) > thresh) ):
553 : efrank 1.25 theName=i.Name.replace(' ','_')+ ":%d" % (nNotConnect)
554 :     nNotConnect += 1
555 :     else:
556 :     theName=i.Name.replace(' ','_')
557 : efrank 1.29 out_file.write( "%s %s %s\n" % (theName, edgeName, rxName) )
558 :     nodeAttrib_file.write("%s = reactant\n" % (theName) )
559 :    
560 : efrank 1.25 for o in r.Outputs:
561 : efrank 1.41 if (not o.isConnected or (rxGraph.all_degree( o.Name)>thresh) ):
562 : efrank 1.25 theName=o.Name.replace(' ','_')+ ":%d" % (nNotConnect)
563 :     nNotConnect += 1
564 :     else:
565 :     theName=o.Name.replace(' ','_')
566 : efrank 1.29 out_file.write( "%s rc %s\n" % (rxName, theName))
567 :     nodeAttrib_file.write("%s = reactant\n" % (theName) )
568 : efrank 1.25
569 :     out_file.close()
570 :     cytoInstallDir = os.getenv( 'CYTOSCAPE_HOME' )
571 :     cytoCmd = os.getenv( 'CYTOSCAPE_COMMAND' )
572 :    
573 : efrank 1.29 #cmd = "(cd $CYTOSCAPE_HOME; java -jar cytoscape.jar -i %s -n %s&)" % (output, nodeAttribs)
574 :     cmd = "(cd %s; %s -i %s -n %s&)" % (cytoInstallDir, cytoCmd, output, nodeAttribs)
575 : efrank 1.25 print cytoInstallDir
576 :     print cytoCmd
577 :     print cmd
578 :    
579 :     os.system( cmd )
580 :    
581 :     #os.unlink( output )
582 :    
583 :     return
584 : efrank 1.31
585 :     #------------------------------------------------------------------
586 :     def recoElemWriteToBss(self, event):
587 :     #------------------------------------------------------------------
588 :     # there are so many problems here it's not funny. We _will_
589 :     # corrupt the DB with this but have to start somewhere. Example:
590 :     # How do we know we've not been passed a REcoElem that is
591 : efrank 1.35 # owned by a higher entity? The system needs to be extended to
592 : efrank 1.31 # understand the ownership model and catalog arch.
593 :    
594 : efrank 1.37 if (self.selectedItem == None): return
595 :     re = self.parent.tree_ctr.GetPyData( self.selectedItem).re
596 :     catalogEntry = self.parent.tree_ctr.GetPyData( self.selectedItem).ce
597 : efrank 1.35
598 :     foundryItemKey = catalogEntry.write( re )
599 :    
600 :     if (foundryItemKey == None ):
601 :     self.parent.error( "Write failed.")
602 :     else:
603 :     self.parent.error( "Write succeeded" )
604 : efrank 1.31 return
605 : efrank 1.25
606 : efrank 1.9 #------------------------------------------------------------------
607 :     def recoElemRxListCut(self, event):
608 :     #------------------------------------------------------------------
609 : efrank 1.37 # this has gotta be wrong...what were we thinking? It's ok for a
610 :     # single selection.
611 : efrank 1.26
612 :     re = None
613 : efrank 1.9 for count in self.parent.list_box.GetSelections():
614 :     (rx,offset, re) = self.parent.list_boxData[count]
615 :     del( re.Reactions[offset:offset+1] )
616 :     self.redrawRecoElemRxList(re)
617 : efrank 1.10 self.cutOrCopiedRx = rx
618 : hwang 1.19
619 : efrank 1.26 if (re == None):
620 :     return
621 :     else:
622 :     rxListNum = len(re.Reactions)
623 :     self.updateTreeBranchText(rxListNum, re.Name)
624 : hwang 1.18
625 : efrank 1.9 return
626 :    
627 :     #------------------------------------------------------------------
628 :     def recoElemRxListCopy(self, event):
629 :     #------------------------------------------------------------------
630 :     for count in self.parent.list_box.GetSelections():
631 :     (rx,offset,re) = self.parent.list_boxData[count]
632 : efrank 1.10 self.cutOrCopiedRx = rx
633 :    
634 :     return
635 :    
636 :     #------------------------------------------------------------------
637 :     def recoElemRxListPaste(self, event):
638 :     #------------------------------------------------------------------
639 :     # we're pasting into a list_box. This list box is being
640 :     # shown *because* a recoElem has been selected. that means
641 :     # _it_ is the recoElem to modify.
642 : hwang 1.18
643 :     #since the listbox is only allowing single select.
644 :     #we won't count how big the selection is
645 : efrank 1.37
646 : efrank 1.10 if (self.selectedItem == None): return
647 : efrank 1.34 re = self.parent.tree_ctr.GetPyData( self.selectedItem).re
648 : efrank 1.10 re.Reactions.append( self.cutOrCopiedRx )
649 : hwang 1.18
650 : hwang 1.19 rxListNum = len(re.Reactions)
651 :     self.updateTreeBranchText(rxListNum, re.Name)
652 : efrank 1.10 self.redrawRecoElemRxList(re)
653 : efrank 1.9
654 :     return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3