[Bio] / ModelEditor / RXpanel.py Repository:
ViewVC logotype

View of /ModelEditor/RXpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (download) (as text) (annotate)
Fri Mar 11 21:33:13 2005 UTC (14 years, 3 months ago) by efrank
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.8: +6 -9 lines
1. introduce Model as king of the hill rather than RecoElem.
2. migrations to follow
3. new modules for by-peg filtering
4. first stab at externalized app fwk
5. moved seed data factory

bunch of timing code still in this ...need to take out

#########################################################################
#
# BUGS:
#   o In addSelectedRx and addSearchedRx, we don't pay attention to the
#   o foundry and aux info.  to fix this, i plan to extend the rx to
#   o carry that info.
#
#########################################################################

from wxPython.wx import *
from wxPython.grid import *
from KahOM.RecoElem import RecoElem
from FaST.FactoryUtils import union
from ModelEditor.RecoElempanel import RecoElempanel
from ModelEditor.MainLayout import MainLayout
#from RXAddDialog import RXAddDialog
from ModelEditor.DoubleTextEntryDialog import DoubleTextEntryDialog
from ModelEditor.MetabolitePanel import MetabolitePanel
from ModelEditor.RXFromMetPageDialog import RXFromMetPageDialog
from ModelEditor.RXOnAddPageDialog import RXOnAddPageDialog
from FoundryInfo.FoundryItemKey import FoundryItemKey

class RXPanel:
#
#    def getSelectedRx(self):
#    def addSearchedRx(self, rx):
#    def addSelectedRx(self, rx):
#    def __init__(self, parent):
#    def initEvents(self ):
#    def addRxToGrid(self, rx, theGrid):
#    def onSearchRx(self, evt):
#    def onOptionsRxComboValue(self, evt):
#    def onAddRx(self, evt):
#    def onSelectRxBtn(self, evt):
#    def onClearSearchedRxBtn(self, evt):
#    def onClearSelectedRxBtn(self, evt):
# 
    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        #wxPanel.__init__(self, parent, -1)
        self.parent = parent
        self.cutRx  = None
        self.selectedRxDict = {}
        self.searchedRxDict = {}
        self.initEvents()
        # keeps us from clearing box unless last op was "From Metab Page"
        self.__needTextCtlClear = 0
       
        return

    
    #------------------------------------------------------------------------
    def initEvents(self ):
    #------------------------------------------------------------------------


        optionsRxComboValue = self.parent.optionsRxComboBox
        #
        # evt_combobox and evt_text:  the former is for a selection, the
        # latter for text changes.  so we really want the former.  this
        # works in 2.4.0.7.  but in 2.4.2.4 (on gentoo), it does not work.
        # so i hacked in evt_text and that was ok.  but, back in 2.4.0.7,
        # that gives an infinite recursion in onOptionsRxComboValue.
        # ...ignore until migration to 2.5.

        EVT_COMBOBOX(self.parent, optionsRxComboValue.GetId(),
                     self.onOptionsRxComboValue)
        #EVT_TEXT(self.parent, optionsRxComboValue.GetId(),
        #             self.onOptionsRxComboValue)
        
        addRxBtn = self.parent.addRxBtn
        EVT_BUTTON(self.parent, addRxBtn.GetId(), self.onAddRx)

        searchRxBtn = self.parent.searchRxBtn
        EVT_BUTTON(self.parent, searchRxBtn.GetId(), self.onSearchRx)

        selectRxBtn = self.parent.selectRxBtn
        EVT_BUTTON(self.parent, selectRxBtn.GetId(), self.onSelectRxBtn)
        
        clearSearchedRxBtn  = self.parent.clearSearchedRxBtn               
        EVT_BUTTON(self.parent, clearSearchedRxBtn.GetId(), 
                   self.onClearSearchedRxBtn)
                
        clearSelectedRxBtn  = self.parent.clearSelectedRxBtn
        EVT_BUTTON(self.parent, clearSelectedRxBtn.GetId(), 
                   self.onClearSelectedRxBtn)
                
        return
        

    #------------------------------------------------------------------------
    def getSelectedRx(self):
        # returns [Reaction] from the Selected Rx grid
    #------------------------------------------------------------------------
        return ( self.selectedRxDict.values() )

    #------------------------------------------------------------------------
    def getEnzymeText(self):
        # returns [Reaction] from the Selected Rx grid
    #------------------------------------------------------------------------
        return self.parent.hasEnzymesText.GetValue()


    #------------------------------------------------------------------------
    def addSearchedRx(self, rx, foundryName):
    #------------------------------------------------------------------------
            
        theGrid = self.parent.rxSearchResultsGrid
        self.searchedRxDict[ theGrid.GetNumberRows() ] = rx
        self.addRxToGrid(rx, foundryName, theGrid)
        theGrid.FitInside()
        return

    #------------------------------------------------------------------------
    def addSelectedRx(self, rx, foundryName):
    #------------------------------------------------------------------------
        theGrid = self.parent.rxSelectedResultsGrid
        self.selectedRxDict[ theGrid.GetNumberRows() ] = rx
        self.addRxToGrid(rx, foundryName, theGrid)
        return

    #------------------------------------------------------------------------
    def addRxToGrid(self, rx, foundryName, theGrid):
    #------------------------------------------------------------------------

        nRow    = theGrid.GetNumberRows()
        theGrid.AppendRows(numRows=1)
        
        theGrid.SetCellValue(nRow, 0, foundryName )
        #theGrid.SetCellValue(nRow, 1, rx.getFoundryItemKey().getIntValList(0) )
        theGrid.SetCellValue(nRow, 1, "")
        theGrid.SetCellValue(nRow, 2, rx.asString())
        theGrid.SetReadOnly(nRow, 0)
        theGrid.SetReadOnly(nRow, 1)
        theGrid.AutoSizeColumn(1)
        theGrid.SetReadOnly(nRow, 2)
        theGrid.AutoSizeColumn(2)

        return

   
    #------------------------------------------------------------------------
    def onSearchRx(self, evt):
    #------------------------------------------------------------------------
        factory     = self.parent.getCurrentDataFactory()
        if ( not factory.getFoundryType() == "KahChemDb"):
            self.parent.error( "Searching reactions only supported by KahChemDb" )
            return

        foundryName = factory.getFoundryName()

        rxns = []
        # Get rxns accordinng to specified metabolites
        #



        if (self.parent.optionsRxComboBox.GetValue() == "From Metabolite Page"):
            # get the search parameters via a dialog
            rxOnFromMetDialogWin = RXFromMetPageDialog(
                self.parent,  -1, "From Metabolite Page",
                pos=(300,300),size=(700,400),
                style=wxDEFAULT_FRAME_STYLE)

            result = rxOnFromMetDialogWin.ShowModal()

            if ( result != wxID_CANCEL):
                #self.parent.error( "remember -long- in onSearchRx" )
                rxns = apply( factory.searchRxByMetabolites, rxOnFromMetDialogWin.GetValue("compName") )
                rxOnFromMetDialogWin.Destroy()        

        elif (self.parent.optionsRxComboBox.GetValue() == "Input"):
            rxns = factory.findRxWithInput( self.parent.hasMetabsText.GetValue() )
        elif (self.parent.optionsRxComboBox.GetValue() == "Output"):
            rxns = factory.findRxWithOutput( self.parent.hasMetabsText.GetValue() )
        else:
            self.parent.error( "Program logic error RXPanel::onSearchRx")
            return
        
        # Get rxns according to EC number and union with rxns from above
        #
        enzText = self.getEnzymeText()
        if ( "" != enzText):
            enzRxns = factory.findRxViaEC( enzText )
            rxns = union(rxns, enzRxns)
            enzRxns = factory.findRxViaCatalystName( enzText )
            rxns = union(rxns, enzRxns)

        for r in rxns:
            self.addSearchedRx( r, foundryName )

        return
    

    #------------------------------------------------------------------------
    def onOptionsRxComboValue(self, evt):
    #------------------------------------------------------------------------

        # the needTextCtlClear business is so that if you switch input to
        # output you don't have to retype the query.  but if you
        # get 'Frm Metab Page', then you have to clear it


        choice = evt.GetString()
        self.parent.optionsRxComboBox.SetValue( choice )

        if (self.parent.optionsRxComboBox.GetValue()  == "From Metabolite Page"):
            self.parent.hasMetabsText.SetValue( " Now Hit Search ")
            self.__needTextCtlClear = 1
        else:
            if (self.__needTextCtlClear == 1):
                self.parent.hasMetabsText.SetValue( "")
            self.__needTextCtlClear = 0
       
        return

    #------------------------------------------------------------------------
    def onAddRx(self, evt):
    #------------------------------------------------------------------------

        factory     = self.parent.getCurrentDataFactory()
        if (not factory.getFoundryType() == "KahChemDb" ):
            self.parent.error( "Adding Reactions only supported for KahChemDb, not for " + factory.getFoundryType() )
            return

        rxOnAddRXPageDialog = RXOnAddPageDialog (self.parent, -1, "Add Reaction",
                                                  pos=(300,300), size=(700,400),
                                                  style=wxDEFAULT_FRAME_STYLE)

        result = rxOnAddRXPageDialog.ShowModal()

        if ( result == wxID_CANCEL):
            return
        elif ( result == wxID_OK ):
            rx = rxOnAddRXPageDialog.GetValue()
        else:
            self.parent.error( "Program error in RXpanel:onAddRx" )

        rx = rxOnAddRXPageDialog.GetValue()

        factory.writeReaction( rx, commit=1)
        
        return

   
    #------------------------------------------------------------------------
    def onSelectRxBtn(self, evt):
    #------------------------------------------------------------------------

        onSelectRows = self.parent.rxSearchResultsGrid.GetSelectedRows()

        rxBottomGrid       = self.parent.rxSelectedResultsGrid
        rxBottomGridNumber = self.parent.rxSelectedResultsGrid.GetNumberRows()
        
        for s in onSelectRows:
            foundryName = self.parent.rxSearchResultsGrid.GetCellValue(s,0)
            self.addSelectedRx( self.searchedRxDict[s], foundryName )
                        
        rxBottomGrid.FitInside()
        
        return

    #------------------------------------------------------------------------
    def onClearSearchedRxBtn(self, evt):
    #------------------------------------------------------------------------
        self.parent.rxSearchResultsGrid.DeleteRows(0, self.parent.rxSearchResultsGrid.GetNumberRows())
        self.parent.rxSearchResultsGrid.ClearGrid()
        self.searchedRxDict.clear()
        return

    #------------------------------------------------------------------------
    def onClearSelectedRxBtn(self, evt):
    #------------------------------------------------------------------------
        theGrid = self.parent.rxSelectedResultsGrid
        theGrid.DeleteRows(0, theGrid.GetNumberRows())
        theGrid.ClearGrid()
        self.selectedRxDict.clear()
        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3