def openSingleAmphitriteDataFile(self, event, textCtrl): """Open amphitrite data file ('.a'), using path form textCtrl. :parameter textCtrl: Data file textCtrl, usually self.textCtrlFile1 """ dlg = wx.FileDialog(self, message='Select Amphitrite Data File', defaultFile=self.settings.defaultDirectory, wildcard='Amphitrite data file (*.a)|*.a', style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.settings.defaultDirectory = os.path.dirname(path) textCtrl.SetValue(path) # deal with data dataList = utils.unPickleAmphitriteProject(path) if dataList: imOb = Im() imOb.setDataFromAmphiExtract(dataList) imOb.normalisationBpi() imOb.generateMassSpectrum() imOb.massSpectrum.normalisationBpi() return imOb else: message = 'Error in amphitrite file: %s' % path gf.warningDialog(message) dlg.Destroy()
def openSingleAmphitriteDataFile(self,event,textCtrl): """Open amphitrite data file ('.a'), using path form textCtrl. :parameter textCtrl: Data file textCtrl, usually self.textCtrlFile1 """ dlg = wx.FileDialog( self,message = 'Select Amphitrite Data File', defaultFile = self.settings.defaultDirectory, wildcard = 'Amphitrite data file (*.a)|*.a', style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.settings.defaultDirectory = os.path.dirname(path) textCtrl.SetValue(path) # deal with data dataList = utils.unPickleAmphitriteProject(path) if dataList: imOb = Im() imOb.setDataFromAmphiExtract(dataList) imOb.normalisationBpi() imOb.generateMassSpectrum() imOb.massSpectrum.normalisationBpi() return imOb else: message = 'Error in amphitrite file: %s' %path gf.warningDialog(message) dlg.Destroy()
def eventButtonLoad(self, event): # wxGlade: AtroposGui.<event_handler> """Open mass spectrum and display it. Takes information from grain and openFilePath().""" path = self.textCtrlOpen.GetValue() self.settings.openFilePath = path if path[-4:] == '.txt': # textfile only grain = self.textCtrlGrain.GetValue() success = 0 if grain != '': try: grain = float(self.textCtrlGrain.GetValue()) success = 1 except: print 'Grain value not a float' if success: self.msPanel.loadTextFile(path, grain) else: self.msPanel.loadTextFile(path) elif path[-2:] == '.a': self.msPanel.loadAmphiFile(path) else: message = \ ''' Problem with file extension: %s Aborting... ''' %path gf.warningDialog(message)
def eventButtonLoad(self, event): # wxGlade: AtroposGui.<event_handler> """Open mass spectrum and display it. Takes information from grain and openFilePath().""" path = self.textCtrlOpen.GetValue() self.settings.openFilePath = path if path[-4:] == '.txt': # textfile only grain = self.textCtrlGrain.GetValue() success = 0 if grain != '': try: grain = float(self.textCtrlGrain.GetValue()) ; success = 1 except: print 'Grain value not a float' if success: self.msPanel.loadTextFile(path,grain) else: self.msPanel.loadTextFile(path) elif path[-2:] == '.a': self.msPanel.loadAmphiFile(path) else: message = \ ''' Problem with file extension: %s Aborting... ''' %path gf.warningDialog(message)
def loadTxtData(self,filenames): """Load data from spectrum list data files and store the valid filenames in self.txtFilenames. :parameter filenames: List of absolute paths """ toRemove = [] for fn in filenames: if not fn in self.loadedTxtFiles.keys(): try: msOb = MassSpectrum.MassSpectrum() msOb.readFile(fn) self.loadedTxtFiles[fn] = msOb self.massSpectra[fn] = msOb print 'Sucessfully Added: %s' %fn # save the filename self.txtFilenames.append(fn) self.msFitApplied[fn] = False except: toRemove.append(fn) if len(toRemove): if len(toRemove) == 1: message = 'Incorrect file format for: %s' %fn else: s = ['\n%s' %fn for fn in toRemove] s = ''.join(s) message = 'Incorrect file format for:'+s gf.warningDialog(message) return toRemove
def loadTxtData(self, filenames): """Load data from spectrum list data files and store the valid filenames in self.txtFilenames. :parameter filenames: List of absolute paths """ toRemove = [] for fn in filenames: if not fn in self.loadedTxtFiles.keys(): try: msOb = MassSpectrum.MassSpectrum() msOb.readFile(fn) self.loadedTxtFiles[fn] = msOb self.massSpectra[fn] = msOb print 'Sucessfully Added: %s' % fn # save the filename self.txtFilenames.append(fn) self.msFitApplied[fn] = False except: toRemove.append(fn) if len(toRemove): if len(toRemove) == 1: message = 'Incorrect file format for: %s' % fn else: s = ['\n%s' % fn for fn in toRemove] s = ''.join(s) message = 'Incorrect file format for:' + s gf.warningDialog(message) return toRemove
def setCalibration(self,filename): """Open the amphitrite IM calibration object. :parameter filename: Absolute path to pickled imClasses.Calibration() object """ import imClasses.Calibration try: self.calibrationOb = pickle.load(open(filename,'rb')) except: message = 'Something wrong with calibration file!' gf.warningDialog(message)
def setCalibration(self, path): """Load pickled calibration object. :parameter path: Absolute path to imClasses.Calibration() object """ import imClasses.Calibration try: self.calibrationOb = pickle.load(open(path, 'rb')) except: message = 'Something wrong with calibration file!' gf.warningDialog(message)
def eventTextCtrlWidthR(self, event): # wxGlade: SpectralAveragingGui.<event_handler> """Set the right peak FWHM multiplier for extracting arrival times. """ val = gf.checkIfNumberTextCtrl(self.textCtrlWidthR) if type(val).__name__ != 'str': self.settings.setWidthR(val) else: message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlWidthR.SetValue(str(self.settings.widthR))
def setCalibration(self, filename): """Open the amphitrite IM calibration object. :parameter filename: Absolute path to pickled imClasses.Calibration() object """ import imClasses.Calibration try: self.calibrationOb = pickle.load(open(filename, 'rb')) except: message = 'Something wrong with calibration file!' gf.warningDialog(message)
def setCalibration(self,path): """Load pickled calibration object. :parameter path: Absolute path to imClasses.Calibration() object """ import imClasses.Calibration try: self.calibrationOb = pickle.load(open(path,'rb')) except: message = 'Something wrong with calibration file!' gf.warningDialog(message)
def setManualMass(self,massText): """For use with plotting theoretical charge state m/z values. :parameter massText: Mass of species as text or number """ try: self.gui.msPanel.temporaryTheoMzs(massText) except: event.Veto() gf.warningDialog('Only enter numbers here!')
def eventTextCtrlLimit(self, event): # wxGlade: ContourGui.<event_handler> """Enter the limit for ignoring peaks when peak picking for "Show peak tops" check box. Value is given as percentage of base peak intensity. """ val = gf.checkIfNumberTextCtrl(self.textCtrlLimit) if type(val).__name__ == 'str': message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlLimit.SetValue(self.settings.limit) # (its left as a string) else: self.settings.limit = self.textCtrlLimit.GetValue()
def eventTextCtrlWidthR( self, event): # wxGlade: SpectralAveragingGui.<event_handler> """Set the right peak FWHM multiplier for extracting arrival times. """ val = gf.checkIfNumberTextCtrl(self.textCtrlWidthR) if type(val).__name__ != 'str': self.settings.setWidthR(val) else: message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlWidthR.SetValue(str(self.settings.widthR))
def eventTextCtrlVmax(self, event): # wxGlade: ContourGui.<event_handler> """The value used for the maximum color saturation value. """ val = gf.checkIfNumberTextCtrl(self.textCtrlVmax) if type(val).__name__ != 'str': self.plotPanel.setVmax(val) self.plotPanel.refresh_plot() else: message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlVmax.SetValue(str(self.plotPanel.vmax))
def eventTextCtrlLimit(self, event): # wxGlade: ContourGui.<event_handler> """Enter the limit for ignoring peaks when peak picking for "Show peak tops" check box. Value is given as percentage of base peak intensity. """ val = gf.checkIfNumberTextCtrl(self.textCtrlLimit) if type(val).__name__ == 'str': message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlLimit.SetValue( self.settings.limit) # (its left as a string) else: self.settings.limit = self.textCtrlLimit.GetValue()
def eventProcess(self, event): # wxGlade: ImProcessorGui.<event_handler> """Convert the selected Synapt data files into Amphitrite files. (Process button event.) """ # TODO(gns) - important sounding comment below here, check what its about ## NEED TO CHECK GRAIN AND OTHER TEXT BOXES selected = self._getSelectedItemsListCtrl() if not len(selected): message = 'Please select one or more files and try again' gf.warningDialog(message) else: grain = self._processGrain() self.settings.extract_rawfiles(selected, grain, self)
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()
def _displayPeaks(self): """Show peaks found using first derivative and those added manually.""" limit = self.settings.getLimit() numberOfPeaksFound = self.msPanel.plotMsWithGpeaks(limit) if numberOfPeaksFound != None: message = \ '''Over 2000 peaks found (%d) Please reduce by doing one of the following: + Increase smoothing + Increase peak identification limit + Increase the grain of spectrum (text input only) ''' %numberOfPeaksFound gf.warningDialog(message) self.radioBoxDisplay.SetSelection(0)
def eventTextCtrlGrain(self, event): # wxGlade: ImProcessorGui.<event_handler> """Set the grain of the m/z binning when converting the data files. """ val = event.GetString() if val != '': try: val = float(val) if val % 1 == 0: val = int(val) self.grainValue = val except: message = 'Please only enter numbers!' gf.warningDialog(message) self.textCtrlGrain.SetValue(str(self.grainValue))
def eventTextCtrlWidthR(self, event): # wxGlade: ContourGui.<event_handler> """Set the peak width (FWHM) multiplier to use for above the peak centre. (Is used to change the m/z window which is used for a charge state peak.) """ val = gf.checkIfNumberTextCtrl(self.textCtrlWidthR) species = self.choiceSpecies.GetStringSelection() if type(val).__name__ != 'str': if species != 'Apply to all': self.settings.setWidthR(val,species) else: for sp in self.settings.widthR.keys(): self.settings.setWidthR(val,sp) self.plotPanel.refresh_plot() else: message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlWidthR.SetValue(str(self.settings.widthR[species]))
def eventTextCtrlWidthR(self, event): # wxGlade: ContourGui.<event_handler> """Set the peak width (FWHM) multiplier to use for above the peak centre. (Is used to change the m/z window which is used for a charge state peak.) """ val = gf.checkIfNumberTextCtrl(self.textCtrlWidthR) species = self.choiceSpecies.GetStringSelection() if type(val).__name__ != 'str': if species != 'Apply to all': self.settings.setWidthR(val, species) else: for sp in self.settings.widthR.keys(): self.settings.setWidthR(val, sp) self.plotPanel.refresh_plot() else: message = 'Please only enter numbers in this box!' gf.warningDialog(message) self.textCtrlWidthR.SetValue(str(self.settings.widthR[species]))
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()
def eventButtonExportTextFile(self, event): # wxGlade: SpectralAveragingGui.<event_handler> """Export a text file spectrum list of the averaged mass spectrum. """ if len(self.settings.massSpectra): dlg = wx.FileDialog( self, message="Save file as ...", defaultDir=self.settings.defaultDirectory, defaultFile="", wildcard='Text file (*.txt)|*.txt| All files (*.*)|*.*', style=wx.SAVE ) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.settings.exportMsTxtFile(path) self.settings.defaultDirectory = os.path.dirname(path) dlg.Destroy() else: message = 'Load files before exporting!' gf.warningDialog(message)
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()
def eventButtonExportTextFile( self, event): # wxGlade: SpectralAveragingGui.<event_handler> """Export a text file spectrum list of the averaged mass spectrum. """ if len(self.settings.massSpectra): dlg = wx.FileDialog( self, message="Save file as ...", defaultDir=self.settings.defaultDirectory, defaultFile="", wildcard='Text file (*.txt)|*.txt| All files (*.*)|*.*', style=wx.SAVE) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.settings.exportMsTxtFile(path) self.settings.defaultDirectory = os.path.dirname(path) dlg.Destroy() else: message = 'Load files before exporting!' gf.warningDialog(message)
def getOutDirPath(self): """Get output directory path. If alternate directory checkbox is selected get the value from the output directory textCtrl, otherwise return the input directory. :returns: Absolute output path """ if self.gui.checkboxAlternateDirectory.IsChecked(): dirPath = self.gui.textCtrlAlternateDirectory.GetValue() if os.path.isdir(dirPath): return dirPath else: message = \ ''' Output directory not found: %s Using default directory: %s ''' %(dirPath,self.inDirPath) gf.warningDialog(message) return self.inDirPath else: return self.inDirPath
def _processGrain(self): """Check that the value for m/z binning widths (grain) is valid. :returns: grain (float) """ grain = self.textCtrlGrain.GetValue() try: grain = float(grain) if grain < 0.5: # warning message message = 'Grain spacing too low: %s\n \ Using minimum value (0.5 m/z units)' % grain dial = wx.MessageDialog(None, message, 'Warning', wx.OK | wx.ICON_EXCLAMATION) dial.ShowModal() # set grain value grain = 0.5 except: # warning message message = 'Non-number used for grain: %s\n \ Using default value (2.0 m/z units)' % grain gf.warningDialog(message) # set grain value grain = 2.0 return grain