Ejemplo n.º 1
0
 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()
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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))
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
    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!')
Ejemplo n.º 13
0
 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()
Ejemplo n.º 14
0
 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))
Ejemplo n.º 15
0
 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))         
Ejemplo n.º 16
0
 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))
Ejemplo n.º 17
0
 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()
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
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.º 20
0
    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)
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
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))
Ejemplo n.º 23
0
 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]))
Ejemplo n.º 24
0
 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]))
Ejemplo n.º 25
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.º 26
0
 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)
Ejemplo n.º 27
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.º 28
0
 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)
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
    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