Example #1
0
    def generateSpeciesSlicesFwhm(self,
                                  speciesName,
                                  leftMultiplier=1,
                                  rightMultiplier=1):
        """Create data slices using peak width from mass spectrum fit
        for a specific species.
        :parameter speciesName: Name of molecular species
        :parameter leftMultiplier: Value to multiply the peak fwhm below the mean
        :parameter rightMultiplier: Value to multiply the peak fwhm above the mean
        """
        self.dataSlices[speciesName] = collections.OrderedDict()
        self.generateMassSpectrum()
        left = float(leftMultiplier * self.species[speciesName].peakFwhm) / 2
        right = float(rightMultiplier * self.species[speciesName].peakFwhm) / 2

        for z in self.species[speciesName].charges:
            mz = self.species[speciesName].getMz(z)
            mzIndex = utils.closest(mz, self.xaxis)
            mzIndex = localMaxima(mzIndex,
                                  self.massSpectrum.xvals,
                                  self.massSpectrum.yvals,
                                  scan_range=10)
            leftI = utils.closest(mz - left, self.xaxis)
            rightI = utils.closest(mz + right, self.xaxis)
            self.dataSlices[speciesName][z] = self._generateSlice(
                [leftI, rightI])
            self.dataSlices[speciesName][z].generateAtd()
            self.dataSlices[speciesName][z].charge = z
Example #2
0
    def limitAxisX(self, lims):
        """Reduce the range of values in the dataset. Reducing the xlimits here
        automatically reduces the yaxis.

        :parameter lims: List of limits in the form [lower,upper]
        """
        lowerI = utils.closest(lims[0], self.xvals)
        higherI = utils.closest(lims[1], self.xvals)

        self.xvals = self.xvals[lowerI:higherI]
        self.yvals = self.yvals[lowerI:higherI]
        self.rawyvals = self.rawyvals[lowerI:higherI]
Example #3
0
    def eventButtonTogglePeakPicking(self, event):  # wxGlade: AtroposGui.<event_handler>
        """This function just activates the peak picking so that the on_pick() function
        is able to record mouse clicks.
        When the toggle is turned off then the value is registered.
        """
        if self.buttonTogglePeakPicking.GetValue() == True:
            self.msPanel.pickingActive = True
            self.msPanel.axMs.set_picker(True)
            self.msPanel.pickedPeakIdLimit -= 1

        elif self.buttonTogglePeakPicking.GetValue() == False:
            
            self.msPanel.pickingActive = False
            self.msPanel.pickedAlready = False

            if self.msPanel.pickedValue:

                peakId = self.msPanel.pickedPeakIdLimit
                yi = utils.closest(self.msPanel.pickedValue, self.msPanel.ms.xvals)
                y = self.msPanel.ms.yvals[yi]
                self.msPanel.ms.gPeaks[peakId] = [self.msPanel.pickedValue,y]
                self.settings.addPeakMz(self.msPanel.pickedValue)
            else:
                self.msPanel.pickedPeakIdLimit += 1
            self.msPanel.pickedValue = None
Example #4
0
 def getAtdsFromMzLims(self, mzLow, mzHigh):
     """Extract arrival times from mass spectrum limits.
     :parameter mzLow: Lower limit for extraction
     :parameter mzHigh: Upper limit for extraction
     :returns: Dictionary of imClasses.Atd() objects (d[filename] = Atd())
     """
     atds = OrderedDict()
     for fn, imOb in self.settings.loadedFiles.items():
         mzLowIndex = utils.closest(mzLow,
                                    self.settings.massSpectra[fn].xvals)
         mzHighIndex = utils.closest(mzHigh,
                                     self.settings.massSpectra[fn].xvals)
         ds = imOb._generateSlice([mzLowIndex, mzHighIndex])
         ds.generateAtd()
         atds[fn] = ds.atd
     return atds
Example #5
0
    def _getMatrixWithinLimits(self):
        """Applies the self.xlims and self.ylims limits and returns the reduced
        matrix with x and y axes.

        :returns: matrix, x axis, yaxis
        """
        lowIndexX = utils.closest(self.xlims[0], self.xaxis)
        highIndexX = utils.closest(self.xlims[1], self.xaxis)
        x = self.xaxis[lowIndexX:highIndexX]

        lowIndexY = utils.closest(self.ylims[0], self.yaxis)
        highIndexY = utils.closest(self.ylims[1], self.yaxis)
        y = self.yaxis[lowIndexY:highIndexY]

        matrix = self.matrix[lowIndexY:highIndexY,lowIndexX:highIndexX]
        return matrix, x, y
Example #6
0
    def _getMatrixWithinLimits(self):
        """Applies the self.xlims and self.ylims limits and returns the reduced
        matrix with x and y axes.

        :returns: matrix, x axis, yaxis
        """
        lowIndexX = utils.closest(self.xlims[0], self.xaxis)
        highIndexX = utils.closest(self.xlims[1], self.xaxis)
        x = self.xaxis[lowIndexX:highIndexX]

        lowIndexY = utils.closest(self.ylims[0], self.yaxis)
        highIndexY = utils.closest(self.ylims[1], self.yaxis)
        y = self.yaxis[lowIndexY:highIndexY]

        matrix = self.matrix[lowIndexY:highIndexY, lowIndexX:highIndexX]
        return matrix, x, y
Example #7
0
    def eventButtonTogglePeakPicking(
            self, event):  # wxGlade: AtroposGui.<event_handler>
        """This function just activates the peak picking so that the on_pick() function
        is able to record mouse clicks.
        When the toggle is turned off then the value is registered.
        """
        if self.buttonTogglePeakPicking.GetValue() == True:
            self.msPanel.pickingActive = True
            self.msPanel.axMs.set_picker(True)
            self.msPanel.pickedPeakIdLimit -= 1

        elif self.buttonTogglePeakPicking.GetValue() == False:

            self.msPanel.pickingActive = False
            self.msPanel.pickedAlready = False

            if self.msPanel.pickedValue:

                peakId = self.msPanel.pickedPeakIdLimit
                yi = utils.closest(self.msPanel.pickedValue,
                                   self.msPanel.ms.xvals)
                y = self.msPanel.ms.yvals[yi]
                self.msPanel.ms.gPeaks[peakId] = [self.msPanel.pickedValue, y]
                self.settings.addPeakMz(self.msPanel.pickedValue)
            else:
                self.msPanel.pickedPeakIdLimit += 1
            self.msPanel.pickedValue = None
Example #8
0
    def plotConformationHeights(self,ax):
        """Track the abundance of the different conformations across
        the data files and plot them.
        """
        # gather the data
        ccsAxes,ccsLines = self.settings.getCcsLines()
        ccsDic = OrderedDict()
        for ccs in self.settings.conformations:
            ccsDic[ccs] = []
            for xaxis,line in zip(ccsAxes,ccsLines):
                height = line[utils.closest(xaxis,ccs)]
                ccsDic[ccs].append(height)

        # plot it
        if not '' in self.settings.values and len(self.settings.values):
                valueList = self.settings.values
                ax.set_xlabel(self.settings.units)
        else:
            valueList = [ x for x in range(len(ccsDic.keys())) ]
            ax.set_xlabel('Arbitary progression')

        ax.set_xticks(valueList)

        for i,ccs in enumerate(ccsDic.keys()):
            ax.plot(valueList, ccsDic[ccs], label=str(ccs),color=utils.colourList[i])
Example #9
0
 def getTotalIntensity(self,xvals,yvals):
     """Using the supplied data, sum the intensity of the highest
     point of the data at the m/z value for each charge state in
     self.charges using self.mass as the mass.
     """
     '''Gets experimental intensity'''
     intensity = 0
     for charge in self.charges:
         mz = utils.get_mz(self.mass, charge)
         i = utils.closest(mz, xvals)
         intensity += yvals[i]
     return intensity
Example #10
0
    def generateSpeciesSlicesFwhm(self,speciesName,leftMultiplier=1,rightMultiplier=1):
        """Create data slices using peak width from mass spectrum fit
        for a specific species.
        :parameter speciesName: Name of molecular species
        :parameter leftMultiplier: Value to multiply the peak fwhm below the mean
        :parameter rightMultiplier: Value to multiply the peak fwhm above the mean
        """
        self.dataSlices[speciesName] = collections.OrderedDict()
        self.generateMassSpectrum()
        left = float(leftMultiplier*self.species[speciesName].peakFwhm)/2
        right = float(rightMultiplier*self.species[speciesName].peakFwhm)/2

        for z in self.species[speciesName].charges:
            mz = self.species[speciesName].getMz(z)
            mzIndex = utils.closest(mz,self.xaxis)
            mzIndex = localMaxima(mzIndex,self.massSpectrum.xvals,self.massSpectrum.yvals, scan_range=10)
            leftI = utils.closest(mz-left,self.xaxis)
            rightI = utils.closest(mz+right,self.xaxis)
            self.dataSlices[speciesName][z] = self._generateSlice([leftI,rightI])
            self.dataSlices[speciesName][z].generateAtd()
            self.dataSlices[speciesName][z].charge = z
Example #11
0
 def getTotalIntensity(self, xvals, yvals):
     """Using the supplied data, sum the intensity of the highest
     point of the data at the m/z value for each charge state in
     self.charges using self.mass as the mass.
     """
     '''Gets experimental intensity'''
     intensity = 0
     for charge in self.charges:
         mz = utils.get_mz(self.mass, charge)
         i = utils.closest(mz, xvals)
         intensity += yvals[i]
     return intensity
Example #12
0
    def generateSpeciesSlicesExplicit(self,limitDic):
        """Create data slices using explicit m/z limits for arrival
        time data extraction, for all supplied species and charge states.
        :parameter limitDic: d[species][z] = [lowerLimit,upperLimit]
        """
        '''
        limitDic generated by ChargeStatePeak.py
        Has actual absolute mz values for the limits
        Does all species at the same time unlike self.generateSpeciesSlicesFwhm()
        which does them all together
        limitDic structure is species>z>[lowerMz,upperMz]
        '''
        self.generateMassSpectrum()

        for speciesName,subD in limitDic.items():
            self.dataSlices[speciesName] = collections.OrderedDict()
            for z,limit in subD.items():
                leftI = utils.closest(limit[0],self.xaxis)
                rightI = utils.closest(limit[-1],self.xaxis)
                self.dataSlices[speciesName][z] = self._generateSlice([leftI,rightI])
                self.dataSlices[speciesName][z].generateAtd()
                self.dataSlices[speciesName][z].charge = z
Example #13
0
    def generateSpeciesSlicesExplicit(self, limitDic):
        """Create data slices using explicit m/z limits for arrival
        time data extraction, for all supplied species and charge states.
        :parameter limitDic: d[species][z] = [lowerLimit,upperLimit]
        """
        '''
        limitDic generated by ChargeStatePeak.py
        Has actual absolute mz values for the limits
        Does all species at the same time unlike self.generateSpeciesSlicesFwhm()
        which does them all together
        limitDic structure is species>z>[lowerMz,upperMz]
        '''
        self.generateMassSpectrum()

        for speciesName, subD in limitDic.items():
            self.dataSlices[speciesName] = collections.OrderedDict()
            for z, limit in subD.items():
                leftI = utils.closest(limit[0], self.xaxis)
                rightI = utils.closest(limit[-1], self.xaxis)
                self.dataSlices[speciesName][z] = self._generateSlice(
                    [leftI, rightI])
                self.dataSlices[speciesName][z].generateAtd()
                self.dataSlices[speciesName][z].charge = z
Example #14
0
 def addPeak(self, mz):
     """This function allows you to add additional peaks not found using the
     findPeaks method"""
     try:
         keys = sorted(self.gPeaks.keys())
         id = 1 + keys[-1]
         self.gPeaks[id] = {}
     except:
         id = 0
         self.gPeaks = {}
         self.gPeaks[id] = {}
     self.gPeaks[id] = [[], []]
     self.gPeaks[id][0] = mz
     index = utils.closest(mz, self.xvals)
     self.gPeaks[id][1] = self.yvals[index]
Example #15
0
    def setSpeciesGivenMass(self, mass, xvals, yvals, peakFwhm, zs):
        """Similar to Species.setSpecies(). Except that instead of using
        gPeaks, the Species() object is setup automatically when given
        values for mass and the charges to be analysed.
        """
        self.mass = mass
        self.charges = zs
        pseudogPeaks = {}

        for z in zs:
            xval = utils.get_mz(self.mass, z)
            i = utils.closest(xval, xvals)
            yval = yvals[i]
            pseudogPeaks[z] = [xval, yval]
        self.setSpecies(pseudogPeaks, peakFwhm)
Example #16
0
    def setSpeciesGivenMass(self,mass,xvals,yvals,peakFwhm,zs):
        """Similar to Species.setSpecies(). Except that instead of using
        gPeaks, the Species() object is setup automatically when given
        values for mass and the charges to be analysed.
        """
        self.mass = mass
        self.charges = zs
        pseudogPeaks = {}

        for z in zs:
            xval = utils.get_mz(self.mass, z)
            i = utils.closest(xval, xvals)
            yval = yvals[i]
            pseudogPeaks[z] = [xval,yval]
        self.setSpecies(pseudogPeaks, peakFwhm)
Example #17
0
    def on_pick(self, event):
        """Check if peak picking is active. If it is draw vertical line at the
        peak's m/z value and label with peak ID.
        """
        if self.pickingActive:
            if self.pickedAlready:
                line = self.axMs.lines.pop(len(self.axMs.lines) - 1)
                self.tempAnnotation.set_visible(False)
            self.pickedValue = event.mouseevent.xdata
            yval = self.ms.yvals[utils.closest(self.pickedValue,
                                               self.ms.xvals)]

            peakId = self.pickedPeakIdLimit  #value controlled by gui

            self.axMs.axvline(self.pickedValue, color='k')
            self.tempAnnotation = self.axMs.annotate(str(peakId),
                                                     [self.pickedValue, yval])
            self.draw()

            self.pickedAlready = True