Ejemplo n.º 1
0
    def getValues(self):
        """Get the smoothing parameters (not limit).
        Checks for valid input.
        """
        # TODO(gns) - make alert boxes instead of printing to terminal
        strings = self.listCtrl.getColumnStrings(1)

        smoothing = utils.getBinaryReponse(strings[0])
        if smoothing == 'Error':
            smoothing = True
            print 'Smoothing entry is not a binary value (using default - True)'

        if utils.isNumber(strings[1]):
            wlen = float(strings[1])
        else:
            wlen = 5
            print 'Wlen entry is not a number (using default - %d)' % wlen

        if utils.isNumber(strings[2]):
            smoothes = int(strings[2])
        else:
            smoothes = 2
            print 'Wlen entry is not a number (using default - %d)' % smoothes

        if utils.isNumber(strings[3]):
            poly = float(strings[3])
        else:
            poly = 1
            print 'Polynomial entry is not a number (using default - %d)' % poly

        return smoothing, wlen, smoothes, poly
Ejemplo n.º 2
0
    def getValues(self):
        """Get the smoothing parameters (not limit).
        Checks for valid input.
        """
        # TODO(gns) - make alert boxes instead of printing to terminal
        strings = self.listCtrl.getColumnStrings(1)
        
        smoothing = utils.getBinaryReponse(strings[0])
        if smoothing == 'Error':
            smoothing = True
            print 'Smoothing entry is not a binary value (using default - True)'
        
        if utils.isNumber(strings[1]):
            wlen = float(strings[1])
        else:
            wlen = 5
            print 'Wlen entry is not a number (using default - %d)' %wlen
            
        if utils.isNumber(strings[2]):
            smoothes = int(strings[2])
        else:
            smoothes = 2
            print 'Wlen entry is not a number (using default - %d)' %smoothes
    
        if utils.isNumber(strings[3]):
            poly = float(strings[3])
        else:
            poly = 1
            print 'Polynomial entry is not a number (using default - %d)' %poly        

        
        return smoothing,wlen,smoothes,poly
Ejemplo n.º 3
0
    def eventButtonSimulate(self,
                            event):  # wxGlade: AtroposGui.<event_handler>
        """Simulate mass spectrum, display it and fill in the optimise ListCtrl with the
        deconvolution results. 
        """
        # please wait dialog
        bi = wx.BusyInfo("Simulating Spectrum...", self)
        wx.Yield()

        oneFwhm = 0
        if self.checkboxSinglePeakFwhm.GetValue():
            oneFwhm = utils.isNumber(self.textCtrlSinglePeakFwhm.GetValue())
            if oneFwhm:
                oneFwhm = float(self.textCtrlSinglePeakFwhm.GetValue())
            else:
                print 'Unrecognised value for single FWHM\nUsing default(10)'
                oneFwhm = 10
        self.settings.leastSquaresOptimisation(oneFwhm)
        self.simulationCompleted = True
        self.radioBoxDisplay.SetSelection(3)
        self.listCtrlOptimise.calculatePercentageArea()
        self.listCtrlOptimise.calculatePercentageIntensity()

        # please wait dialog
        bi.Destroy()
Ejemplo n.º 4
0
 def setValues(self, values):
     # TODO(gns) - do the comment
     self.values = []
     for value in values:
         if utils.isNumber(value):
             self.values.append(float(value))
         else:
             self.values.append(None)
Ejemplo n.º 5
0
 def setValues(self,values):
     # TODO(gns) - do the comment
     self.values = []
     for value in values:
         if utils.isNumber(value):
             self.values.append(float(value))
         else:
             self.values.append(None)
Ejemplo n.º 6
0
 def getLimit(self):
     """Get the lower limit for peak finding. Value is given as a
     percentage of base peak intensity.
     """
     limit = self.listCtrlSmoothing.listCtrl.GetItem(4,1).GetText()
     if utils.isNumber(limit):
         return float(limit)
     else:
         print 'Limit value is not a number (using default - 0.0)'    
         return 0
Ejemplo n.º 7
0
 def getLimit(self):
     """Get the lower limit for peak finding. Value is given as a
     percentage of base peak intensity.
     """
     limit = self.listCtrlSmoothing.listCtrl.GetItem(4, 1).GetText()
     if utils.isNumber(limit):
         return float(limit)
     else:
         print 'Limit value is not a number (using default - 0.0)'
         return 0
Ejemplo n.º 8
0
 def OnEndLabelEdit(self,event):
     """Function for editing the value labels for each of the
     data files.
     """
     val = event.GetText()
     message = 'Only enter numerical values here'
     if len(val):
         if utils.isNumber(val):
             self.listCtrl.SetItemText(event.GetIndex(),val)
             self.updateUnitValues()
             self.plotPanel.refresh_plot()
         else:
             gf.warningDialog(message)
             event.Veto()
Ejemplo n.º 9
0
 def eventAddPeak(self, event):  # wxGlade: AtroposGui.<event_handler>
     """Add additional peaks to those automatically detected using first derivative."""
     mz = self.textCtrlAddPeak.GetValue()
     if utils.isNumber(mz):
         self.settings.addPeakMz(float(mz))
         
         limit = self.settings.getLimit()
         self.msPanel.plotMsWithGpeaks(limit)
     else:
         dlg = wx.MessageDialog(self,
                     "Enter numerical m/z value!",
                     "Add Peak Error", wx.OK|wx.ICON_EXCLAMATION)
         result = dlg.ShowModal()
         dlg.Destroy()           
Ejemplo n.º 10
0
    def eventAddPeak(self, event):  # wxGlade: AtroposGui.<event_handler>
        """Add additional peaks to those automatically detected using first derivative."""
        mz = self.textCtrlAddPeak.GetValue()
        if utils.isNumber(mz):
            self.settings.addPeakMz(float(mz))

            limit = self.settings.getLimit()
            self.msPanel.plotMsWithGpeaks(limit)
        else:
            dlg = wx.MessageDialog(self, "Enter numerical m/z value!",
                                   "Add Peak Error",
                                   wx.OK | wx.ICON_EXCLAMATION)
            result = dlg.ShowModal()
            dlg.Destroy()
Ejemplo n.º 11
0
    def setPeakMzsAndSpecies(self,peakIdsComplexString,name,column=-1):
        """Set the peak m/zs corresponding to the peak ids entered in the
        ListCtrl. Also creates the Species() object and sets that.

        :parameter peakIdsComplexString: String containing peak ids can include commas and hyphens e.g. '4-7,9'.
        :parameter name: Species name
        :parameter column: The column to write to. Use -1 to use currently selected column
        """
        # get column to use
        if column == -1:
            self.getCurrentColumn()

        # get and set mz values
        peakIds = utils.getHyphenCommaList(peakIdsComplexString)
        gPeaks = self.settings.msPanel.ms.getgPeaksFromIds(peakIds)
        mzs =  [ "%.2f" %gPeaks[k][0] for k in gPeaks.keys()]
        mzString = ''
        for i,v in enumerate(mzs):
            if not i:
                mzString = v
            else:
                mzString += ', '+v
        self.listCtrl.SetStringItem(2,column,mzString)

        # get Peak FWHM value
        peakFwhm = self.listCtrl.GetItem(7,column).GetText()
        if utils.isNumber(peakFwhm):
            peakFwhm = float(peakFwhm)
        else:
            peakFwhm = 10
            print 'Peak Fwhm not a number\nUsing 10 ...'

        # set species
        spOb = Species(name)
        spOb.setSpecies(gPeaks, peakFwhm)
        self.settings.msPanel.ms.addSpecies(spOb,allowReplace=1)
        mass,error,zs = spOb.calculateMassAndCharges([float(mz) for mz in mzs])

        self.listCtrl.SetStringItem(3,column,"{:,}".format(round(mass,2)))
        self.listCtrl.SetStringItem(4,column,"{:,}".format(round(error,2)))

        # display zs
        if self.zsEmpty(column):
            self.setZs(zs,column)

        # put default calculated zs into ListCtrl
        self.listCtrl.SetStringItem(8,column,str(spOb.charges)[1:-1])

        # record current column
        self.settings.setSpeciesColumn(column)
Ejemplo n.º 12
0
    def OnEndLabelEdit(self, event):
        """Editing CCS value of a selected conformation entry in the ListCtrl.
        """
        newVal = event.GetText()
        i = event.GetIndex()

        if utils.isNumber(newVal):
            newVal = float(newVal)
            self.conformations[i] = newVal
            self.updateListCtrl()
            self.plotPanel.refresh_plot()
        else:
            if not newVal == '':
                message = 'Only enter a numerical value here!'
                gf.warningDialog(message)
                event.Veto()
            else:
                del self.conformations[i]
                self.updateListCtrl()
Ejemplo n.º 13
0
    def OnEndLabelEdit(self,event):
        """Editing CCS value of a selected conformation entry in the ListCtrl.
        """
        newVal = event.GetText()
        i = event.GetIndex()

        if utils.isNumber(newVal):
            newVal = float(newVal)
            self.conformations[i] = newVal
            self.updateListCtrl()
            self.plotPanel.refresh_plot()
        else:
            if not newVal == '':
                message = 'Only enter a numerical value here!'
                gf.warningDialog(message)
                event.Veto()
            else:
                del self.conformations[i]
                self.updateListCtrl()
Ejemplo n.º 14
0
 def checkFieldsValid(self):
     """Check if each of the plotting options contains a valid input.
     :returns: valid,errors - Boolean, list of the names of values with errors
     """
     valid = True
     errors = []
     smoothing = self.getSettingValue('Smoothing')
     if not utils.isBinaryResponse(smoothing):
         valid = False
         errors.append('Smoothing')
     aaxis = self.getSettingValue('Auto Axis')
     if not utils.isBinaryResponse(aaxis):
         valid = False
         errors.append('Auto Axis')
     colour = self.getSettingValue('Colour')
     if not utils.isMplColour(colour):
         valid = False
         errors.append('Colour')
     lw = self.getSettingValue('Line Width')
     if not utils.isNumber(lw):
         valid = False
         errors.append('Line Width')
     return valid, errors
Ejemplo n.º 15
0
 def checkFieldsValid(self):
     """Check if each of the plotting options contains a valid input.
     :returns: valid,errors - Boolean, list of the names of values with errors
     """
     valid = True
     errors = []
     smoothing = self.getSettingValue('Smoothing')
     if not utils.isBinaryResponse(smoothing):
         valid = False
         errors.append('Smoothing')
     aaxis = self.getSettingValue('Auto Axis')
     if not utils.isBinaryResponse(aaxis):
         valid = False
         errors.append('Auto Axis') 
     colour = self.getSettingValue('Colour')
     if not utils.isMplColour(colour):
         valid = False
         errors.append('Colour')
     lw = self.getSettingValue('Line Width')
     if not utils.isNumber(lw):
         valid = False
         errors.append('Line Width')
     return valid,errors
Ejemplo n.º 16
0
    def eventButtonSimulate(self, event):  # wxGlade: AtroposGui.<event_handler>
        """Simulate mass spectrum, display it and fill in the optimise ListCtrl with the
        deconvolution results. 
        """
        # please wait dialog
        bi = wx.BusyInfo("Simulating Spectrum...",self)
        wx.Yield()
        
        oneFwhm = 0
        if self.checkboxSinglePeakFwhm.GetValue():
            oneFwhm = utils.isNumber(self.textCtrlSinglePeakFwhm.GetValue())
            if oneFwhm:
                oneFwhm = float(self.textCtrlSinglePeakFwhm.GetValue())
            else:
                print 'Unrecognised value for single FWHM\nUsing default(10)'
                oneFwhm = 10
        self.settings.leastSquaresOptimisation(oneFwhm)
        self.simulationCompleted = True
        self.radioBoxDisplay.SetSelection(3)
        self.listCtrlOptimise.calculatePercentageArea()
        self.listCtrlOptimise.calculatePercentageIntensity()

        # please wait dialog
        bi.Destroy()
Ejemplo n.º 17
0
 def setVmax(self, vmax):
     """The value used for the maximum color saturation value.
     """
     if utils.isNumber(vmax):
         self.vmax = float(vmax)
Ejemplo n.º 18
0
 def setVmax(self,vmax):
     """The value used for the maximum color saturation value.
     """
     if utils.isNumber(vmax):
         self.vmax = float(vmax)
Ejemplo n.º 19
0
    def OnEndLabelEdit(self,event):
        """Context specific function for deciding what to do when a cell
        is edited depending on which row it belongs to.
        """
        row = event.m_itemIndex
        column = event.GetColumn()
        #===========================================================================
        # Species Name
        #===========================================================================
        if row == 0:
            newName = event.GetText()
            if not column in self.columnSpeciesNames:
                # name not set before
                self.columnSpeciesNames[column] = newName
            else:
                # name already set and changing it
                spD = self.settings.msPanel.ms.species
                spDsimulated = self.settings.msPanel.ms.simulatedSpecies

                if not newName in spD:
                    oldName = self.columnSpeciesNames[column]
                    # TODO (gns) - this isn't doing enough
                    # The problem must be coming from elsewhere (trying to access
                    # species 'Default09' for example)
                    # The problem occured when I reloaded the figure, so look into what
                    # happens when that button is pushed
                    spD[newName] = spD.pop(oldName)
                    spD[newName].name = newName

                    try:
                        spDsimulated[newName] = spDsimulated.pop(oldName)
                        spDsimulated[newName].name = newName
                    except:
                        spDsimulated[newName] = Species(newName)


                    self.columnSpeciesNames[column] = newName
                else:
                    print 'Provided species name is already in use'
        #===========================================================================
        # Peak finding
        #===========================================================================
        elif row == 1:
            # get text and set m/zs
            text = event.GetText()
            # Add default name if none given
            item = self.listCtrl.GetItem(0,column)
            name = item.GetText()
            if str(name) == '':
                name = 'Default%02d' %column
                self.listCtrl.SetStringItem(0,column,name)
                self.columnSpeciesNames[column] = name

            self.setPeakMzsAndSpecies(text,name, column)
        #===========================================================================
        # Entering mass
        #===========================================================================
        elif row == 3:
            '''
            use the mass to display theoretical charge states
            only works on unassigned Species # TODO(gns) - why?
            '''
            charges = self.listCtrlAssigningSpecies.listCtrl.GetItem(5,column).GetText()
            if charges == '': # TODO(gns) - why do the charges need to be blank?
                # TODO(gns) - warning dialog to say "Enter charge states before simulating"
                self.setManualMass(event.GetText())
            else:
                # Clear all the peak information
                # open warning box saying "Enter charge states before simulating"
                # Make sure that adding the charges recalculates the peak m/zs
                # and sets them properly
                event.Veto()
        #===========================================================================
        # Changing charges
        #===========================================================================
        elif row == 5:
            event.Veto()
        #===========================================================================
        # Peak FWHM
        #===========================================================================
        elif row == 7:
            # get current species name
            item = self.listCtrl.GetItem(0,column)
            name = item.GetText()
            peakFwhm = event.GetText()
            print peakFwhm, 'peakfwhm'
            if utils.isNumber(peakFwhm):
                peakFwhm = float(peakFwhm)
                if name in self.settings.msPanel.ms.species.keys():
                    self.settings.msPanel.ms.species[name].peakFwhm = peakFwhm
            else:
                self.listCtrl.SetStringItem(row,column, "10")
                event.Veto()
                print 'Peak FWHM value not a number\nReverting to default (10)'

        #===========================================================================
        # Charges to simulate
        #===========================================================================
        elif row == 8:
            # get current species name
            item = self.listCtrl.GetItem(0,column)
            name = item.GetText()

            zstext = event.GetText()
            zs = utils.getHyphenCommaList(zstext)
            if zs:
                #self.zsToSimulate[column] = zs
                if name != '':
                    self.settings.msPanel.ms.species[name].charges = zs
            else:
                print 'Invalid list of charges: %s' %zstext
                event.Veto()