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

View of /ModelEditor/MetabolitePanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Fri Mar 11 21:33:13 2005 UTC (14 years, 6 months ago) by efrank
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.7: +10 -7 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

from wxPython.wx import *
from wxPython.grid import *
from KahOM.RecoElem import RecoElem
from ModelEditor.RecoElempanel import RecoElempanel
from ModelEditor.MainLayout import MainLayout
from ModelEditor.DoubleTextEntryDialog import DoubleTextEntryDialog
from ModelEditor.MetAddMetDialog import MetAddMetDialog

class MetabolitePanel:
    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        #wxPanel.__init__(self, parent, -1)
        self.parent = parent
        
        
        self.initEvents()
        
       
        return

    
    #------------------------------------------------------------------------
    def initEvents(self):
    #------------------------------------------------------------------------
        EVT_COMBOBOX(self.parent,
                     self.parent.foundryComboBox.GetId(),
                     self.onFoundryComboBox)

        searchMetabsBtn = self.parent.searchMetabsBtn
        EVT_BUTTON(self.parent, searchMetabsBtn.GetId(), self.onSearchMetabs)

        addMetabsBtn = self.parent.addMetabsBtn
        EVT_BUTTON(self.parent, addMetabsBtn.GetId(),
                   self.onAddMetabs)


        clearSearchResultsBtn = self.parent.clearSearchResultsBtn
        EVT_BUTTON(self.parent, clearSearchResultsBtn.GetId(),
                   self.onClearSearchResults)

        
        clearSelectedMetabsBtn =  self.parent.clearSelectedMetabsBtn
        
        EVT_BUTTON(self.parent, clearSelectedMetabsBtn.GetId(),
                   self.onClearSelectedMetabs)

        
        
        selectSearchResultsBtn = self.parent.selectSearchResultsBtn
        EVT_BUTTON(self.parent, selectSearchResultsBtn.GetId(),
                   self.onSelectSearchResults)

        return
        
    #------------------------------------------------------------------------
    def onSearchMetabs(self, evt):
    #------------------------------------------------------------------------
        # this replaces the old seed specific and bss specific searches.
        # that means that the short name search is now kaput.

        factory = self.parent.getCurrentDataFactory()
        foundryName = factory.getFoundryName()

        if ( not factory.getFoundryType() == "KahChemDb"):
            self.parent.error( "Metabolite search only supported by KahChemDb" )
            return

        wxBeginBusyCursor()


        longName    = self.parent.longText.GetValue() 
        longLikeOpt   = self.parent.optionsLongComboBox.GetValue()

        if longName  == "": longName = None

        metabsResults=[]
        
        if (longName != None):
            metabsResults = factory.longMetabSearch( longName, longLikeOpt )
        else:
            metabsResults = []

        
        theGrid = self.parent.bssGrid
        n       = theGrid.GetNumberRows()
        

        for r in metabsResults:
            (compId, name, ic) = r
            if (ic==1):
                isClass="Y"
            elif (ic==0):
                isClass="N"
            else:
                isClass="?"

            theGrid.AppendRows(numRows=1)
            theGrid.SetCellValue(n, 0 , foundryName)
            theGrid.SetCellValue(n, 1, name )
            theGrid.SetCellValue(n, 2, str(compId ) )
            theGrid.SetCellValue(n, 3, isClass )
            theGrid.SetReadOnly(n, 0)
            theGrid.SetReadOnly(n, 1)
            theGrid.SetReadOnly(n, 2)
            theGrid.SetReadOnly(n, 3)
            theGrid.AutoSizeColumn(1)
            theGrid.AutoSizeColumn(2)
            n += 1
        theGrid.FitInside()
        

        wxEndBusyCursor()

        return

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

        prompt = "New specie name:"
        dlg = MetAddMetDialog(self.parent, -1, "Add Specie",
                              pos=(300,300), size=(700,400),
                              style=wxDEFAULT_FRAME_STYLE)

        #dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxDEFAULT_DIALOG_STYLE)

        result = dlg.ShowModal()
        if (not result == wxID_OK):
            return

        (specieName, isClass) = dlg.GetValue()
        if (specieName=="" or specieName==None):
            self.parent.error( "Invalid Metabolite name: [%s]" % (specieName) )
            return
             
        if (isClass=="Unknown"):
            ic=-1
            icstr="?"
        elif (isClass=="Class"):
            ic=1
            icstr="Y"
        elif (isClass=="Specific"):
            icstr="N"
            ic=0
        else:
            raise ImplementationError, "MetabolitePanel.onAddMetabs, logic error"

        try:
            specieId=factory.writeMetabolite( specieName, ic)
        except Exception, e:
            self.parent.error( "Database Error adding %s: %s" % ( specieName, e))
            return

        bssRowNum= self.parent.bssGrid.GetNumberRows()
        self.parent.bssGrid.AppendRows(numRows=1)
        self.parent.bssGrid.SetCellValue(bssRowNum, 0, factory.getFoundryName())
        self.parent.bssGrid.SetCellValue(bssRowNum, 1, specieName)
        self.parent.bssGrid.SetCellValue(bssRowNum, 2, str(specieId))
        self.parent.bssGrid.SetCellValue(bssRowNum, 3, icstr)
        self.parent.bssGrid.AutoSizeColumn(1)
         
        return

    #------------------------------------------------------------------------
    def OLDonAddMetabs(self, evt):
    #------------------------------------------------------------------------
        
        factory = self.parent.getCurrentDataFactory()
        if ( not factory.getFoundryType() == "KahDb"):
            self.parent.error( "Add metabolite only supported by Bss" )
            return

        onAddMetDialogWin =  DoubleTextEntryDialog(self.parent, -1,
                             "New Metabolite", prompt=("Short Name", "Long Name"),
                             pos=(300,300),size=wxSize(350,200),
                             style=wxDEFAULT_DIALOG_STYLE)
        result = onAddMetDialogWin.ShowModal()

        if ( result == wxID_CANCEL):
            return
        elif ( result == wxID_OK ):
            (shortName,longName) = onAddMetDialogWin.GetValue()
        else:
            self.parent.error( "Program error in onAddMetabs" )

        if ( longName == "" or longName == None or
             shortName =="" or shortName == None ):
            self.parent.error( "Invalid Metabolite name: [%s] [%s]" %
                               (shortName, longName) )
            return
             

        try:
            factory.writeMetabolite( shortName, longName)
        except:
            self.parent.error( "Database Error adding " + shortName 
                               + " " + longName )
            return

        bssRowNum= self.parent.bssGrid.GetNumberRows()
        self.parent.bssGrid.AppendRows(numRows=1)
        self.parent.bssGrid.SetCellValue(bssRowNum, 0, factory.getFoundryName())
        self.parent.bssGrid.SetCellValue(bssRowNum, 1, longName)
        self.parent.bssGrid.AutoSizeColumn(1)
         
        return

    #------------------------------------------------------------------------
    def onClearSearchResults(self, event):
    #------------------------------------------------------------------------
        if (self.parent.bssGrid.GetNumberRows() == 0 ):
            return
        
        self.parent.bssGrid.DeleteRows(0, self.parent.bssGrid.GetNumberRows())
        self.parent.bssGrid.ClearGrid()
        return

    #------------------------------------------------------------------------
    def onClearSelectedMetabs(self, event):
    #------------------------------------------------------------------------

        if (self.parent.selectedMetabsGrid.GetNumberRows() == 0 ):
            return
        
        self.parent.selectedMetabsGrid.DeleteRows(0, self.parent.selectedMetabsGrid.GetNumberRows())
        self.parent.selectedMetabsGrid.ClearGrid()
        return
        
    #------------------------------------------------------------------------
    def onSelectSearchResults(self, event):
    #------------------------------------------------------------------------
        onSelectRows = self.parent.bssGrid.GetSelectedRows()

        bottomGrid       = self.parent.selectedMetabsGrid
        bottomGridNumber = self.parent.selectedMetabsGrid.GetNumberRows()
        
        for s in onSelectRows:
            bottomFoundryValue = self.parent.bssGrid.GetCellValue(s, 0)
            bottomCompNameValue = self.parent.bssGrid.GetCellValue(s, 1)
            bottomAuxValue = self.parent.bssGrid.GetCellValue(s, 2)

            bottomGrid.AppendRows(numRows=1)
            bottomGrid.SetCellValue(bottomGridNumber, 0, bottomFoundryValue)
            bottomGrid.SetCellValue(bottomGridNumber, 1, bottomCompNameValue)
            bottomGrid.AutoSizeColumn(1)
            bottomGrid.SetCellValue(bottomGridNumber, 2, bottomAuxValue)
            bottomGrid.AutoSizeColumn(2)
            bottomGridNumber += 1
            
        
        #doesn't work 
        #bottomGrid.SelectAll()
        #print "bottomGridSelectAll ", bottomGrid.GetSelectedRows()
        bottomGrid.FitInside()
        
        return
        
    #------------------------------------------------------------------------
    def onFoundryComboBox(self, evt):
    #------------------------------------------------------------------------

        print "i'm in the metabolitepanel onFoundryComboBox"
        self.parent.error( "CALLED onFoundryCombBox in MetabolitePanel")
        return
        
        cb = evt.GetEventObject()
        choice = evt.GetString()
        
        if (choice == "Bss"):
            self.parent.shortText.Enable(true)
            self.parent.optionsShortComboBox.Enable(true)
            self.parent.orAndMetabsComboBox.Enable(true)
        elif (choice == "Wit"):
            self.parent.shortText.Enable(false)
            self.parent.optionsShortComboBox.Enable(false)
            self.parent.orAndMetabsComboBox.Enable(false)
        else:
            # of of the N seed factory instances.
            self.parent.shortText.Enable(false)
            self.parent.optionsShortComboBox.Enable(false)
            self.parent.orAndMetabsComboBox.Enable(false)

            
        return
        
    #------------------------------------------------------------------------
    def DOOMwitShow(self):
    #------------------------------------------------------------------------

        self.parent.MetTop.ReplaceWindow(self.parent.theBssPanel, self.parent.theWitPanel)
        self.parent.theBssPanel.Hide()
                
        return

    
    #------------------------------------------------------------------------
    def DOOMbssShow(self):
    #------------------------------------------------------------------------
        
        self.parent.MetTop.ReplaceWindow(self.parent.theWitPanel, self.parent.theBssPanel)
        self.parent.theWitPanel.Hide()

        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3