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

View of /ModelEditor/EnzymeWindow.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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.2: +66 -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

import re
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.EnzAddEnzDialog import EnzAddEnzDialog

class EnzymeWindow:
#    def __init__(self, parent):
#    def initEvents(self ):


    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        self.parent = parent
        self.initEvents()

        self.__searchGrid   = self.parent.enzymesSearchResultsGrid
        self.__selectedGrid = self.parent.enzymesSelectedResultsGrid

        self.parent.addEnzymesBtn.Enable(true)
        self.parent.enzymesListFunctionBtn.Enable(false)
       
        return
    
    #------------------------------------------------------------------------
    def enzymeSearchText(self):
    #------------------------------------------------------------------------
        return self.parent.enzymesSearchText.GetValue()

    #------------------------------------------------------------------------
    def queryType(self):
    #
    #   What to search on.  Can be EC, Name, Substrate, Product
    #------------------------------------------------------------------------
        return self.parent.choicesEnzymesComboBox.GetValue()
    
    #------------------------------------------------------------------------
    def matchType(self):
    #
    #   Type of match: Can be Equals, Contains, Like, 
    #------------------------------------------------------------------------
        return self.parent.optionsEnzymesComboBox.GetValue()


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

        searchEnzymesBtn = self.parent.searchEnzymesBtn
        EVT_BUTTON(self.parent, searchEnzymesBtn.GetId(), self.onSearchEnzymes)

        addEnzymesBtn = self.parent.addEnzymesBtn
        EVT_BUTTON(self.parent, addEnzymesBtn.GetId(),
                   self.onAddEnzymes)

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

        enzymesListFunctionBtn = self.parent.enzymesListFunctionBtn
        EVT_BUTTON(self.parent, enzymesListFunctionBtn.GetId(),
                   self.onEnzymesListFunctions)

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

        clearSelectedEnzymesBtn =  self.parent.clearSelectedEnzymesBtn
        EVT_BUTTON(self.parent, clearSelectedEnzymesBtn.GetId(),
                   self.onClearSelectedEnzymes)

        
        return
        
   #------------------------------------------------------------------------
    def onSearchEnzymes(self, evt):
   #------------------------------------------------------------------------
        wxBeginBusyCursor()

        factory     = self.parent.getCurrentDataFactory()
        if (not factory.getFoundryType() == "KahChemDb"):
            self.parent.error( "Chose a KahChemDb format database." )
            return
        foundryName = factory.getFoundryName()

        target      = self.enzymeSearchText()
        likeOpt     = self.matchType()
        queryType   = self.queryType()

        results=[]
        if   (queryType == "EC"):
            results = factory.enzymeECSearch( target, likeOpt )
        elif (queryType == "Name"):
            results = factory.enzymeNameSearch( target, likeOpt )
        elif (queryType == "Substrate"):
            results = factory.enzymeBySubstrateSearch( target, likeOpt )
        elif (queryType == "Product"):
            results = factory.enzymeByProductSearch( target, likeOpt )
        else:
            self.parent.error( "searchSeedEnzymes: code logic error")
            wxEndBusyCursor()
            return
        self.updateSearchResultsGrid(foundryName, results)
        wxEndBusyCursor()
        return

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

        dlg = EnzAddEnzDialog(self.parent, -1, "Add Specie",
                              pos=(300,300), size=(700,400),
                              style=wxDEFAULT_FRAME_STYLE)
        result = dlg.ShowModal()
        if (not result == wxID_OK):
            return

        (enzName, ec) = dlg.GetValue()
        print "got back", (enzName, ec)

        # check enzyme name.
        
        if (enzName=="" or enzName==None):
            self.parent.error( "Invalid enzyme name: [%s]" % (enzName) )
            return
        
        ecs = re.findall(r"E[\.]*C[\.]*[\ ]*([\d]+\..*)", enzName.upper())
        if (not 0 ==len(ecs) ):
            self.parent.error( "Do not put EC number in name: [%s]" % (enzName) )
            return
            
        # check ec format
        
        if (not ec==""):
            ecs = re.findall(r"E[\.]*C[\.]*[\ ]*([\d]+\..*)", ec.upper())
            if (not 0==len(ecs)):
                self.parent.error( "Give only number, not 'EC or E.C. preface: [%s]" % ec)
                return
        else:
            ec=None

        # do the add

        try:
            enzId=factory.writeCatalyst( enzName, ec )
        except Exception, e:
            self.parent.error( "Database Error adding %s: %s" % ( enzName, e))
            return

        # update the display grid

        rowNum= self.parent.enzymesSearchResultsGrid.GetNumberRows()
        ecName=""
        if (not None==ec): ecName = ec
        self.parent.enzymesSearchResultsGrid.AppendRows(numRows=1)
        self.parent.enzymesSearchResultsGrid.SetCellValue(rowNum, 0, factory.getFoundryName())
        self.parent.enzymesSearchResultsGrid.SetCellValue(rowNum, 1, ecName)
        self.parent.enzymesSearchResultsGrid.SetCellValue(rowNum, 2, enzName)
        self.parent.enzymesSearchResultsGrid.SetCellValue(rowNum, 3, str(enzId))
        #$$??self.parent.enzymesSearchResultsGrid.AutoSizeColumn(1)

        return
        

    #------------------------------------------------------------------------
    def updateSearchResultsGrid(self, factoryName, results):
    #------------------------------------------------------------------------
        theGrid = self.__searchGrid
        n       = theGrid.GetNumberRows()
        for r in results:
            if (None == r[1]): r[1]=""
            theGrid.AppendRows(numRows=1)
            theGrid.SetCellValue(n, 0 , factoryName)
            theGrid.SetCellValue(n, 1, r[0] )
            theGrid.SetCellValue(n, 2, r[1] )
            theGrid.SetReadOnly(n, 0)
            theGrid.SetReadOnly(n, 1)
            theGrid.SetReadOnly(n, 2)
            n += 1
        theGrid.AutoSizeColumn(1)
        theGrid.AutoSizeColumn(2)
        theGrid.FitInside()
        
        return
    
    #------------------------------------------------------------------------
    def onClearSearchResults(self, event):
    #------------------------------------------------------------------------

        if (self.__searchGrid.GetNumberRows() == 0 ):
            return
        
        self.__searchGrid.DeleteRows(0, self.__searchGrid.GetNumberRows())
        self.__searchGrid.ClearGrid()
        return

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

        nRows = self.__selectedGrid.GetNumberRows()
        if (0 != nRows):
            self.__selectedGrid.DeleteRows(0, nRows)
            self.__selectedGrid.ClearGrid()

        return
        
    #------------------------------------------------------------------------
    def onEnzymesListFunctions(self, event):
    #
    #   Lists the enzymatic functions for the selected EC/enzyme
    #------------------------------------------------------------------------
        self.parent.error( "onEnzymesListFunctions")
        return
    
    #------------------------------------------------------------------------
    def onSelectSearchResults(self, event):
    #------------------------------------------------------------------------

        onSelectRows = self.__searchGrid.GetSelectedRows()

        bottomGrid       = self.__selectedGrid
        bottomGridNumber = self.__selectedGrid.GetNumberRows()
        
        for s in onSelectRows:
            bottomFoundryValue = self.__searchGrid.GetCellValue(s, 0)
            bottomECValue      = self.__searchGrid.GetCellValue(s, 1)
            bottomNameValue    = self.__searchGrid.GetCellValue(s, 2)

            bottomGrid.AppendRows(numRows=1)
            bottomGrid.SetCellValue(bottomGridNumber, 0, bottomFoundryValue)
            bottomGrid.SetCellValue(bottomGridNumber, 1, bottomECValue)
            bottomGrid.AutoSizeColumn(1)
            bottomGrid.SetCellValue(bottomGridNumber, 2, bottomNameValue)
            bottomGrid.AutoSizeColumn(2)
            bottomGridNumber += 1
        
        bottomGrid.FitInside()
        
        return
        
    #------------------------------------------------------------------------
    def onFoundryComboBox(self, evt):
    #------------------------------------------------------------------------
        
        cb = evt.GetEventObject()
        choice = evt.GetString()
        
        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3