Beispiel #1
0
    def onPlot(self, evt=None):
        """Calculate and show mass defect plot."""

        # clear previous data
        self.plotCanvasContainer.empty()

        # get params
        if not self.getParams():
            self.plotCanvas.refresh()
            wx.Bell()
            return

        # show annotations for current document on top
        if self.currentDocument is not None and config.massDefectPlot[
                "showNotations"]:

            buff = []
            for item in self.currentDocument.annotations:
                buff.append((item.mz, item.charge))
            for sequence in self.currentDocument.sequences:
                for item in sequence.matches:
                    buff.append((item.mz, item.charge))

            points = self.makeDataPoints(
                mspy.peaklist(buff), self.currentDocument.spectrum.polarity)
            obj = mspy.plot.points(points,
                                   pointColour=(255, 0, 0),
                                   showPoints=True,
                                   showLines=False)
            self.plotCanvasContainer.append(obj)

        # show all documents
        if config.massDefectPlot["showAllDocuments"]:
            for docData in self.parent.documents:
                if docData.visible:
                    points = self.makeDataPoints(docData.spectrum.peaklist,
                                                 docData.spectrum.polarity)
                    obj = mspy.plot.points(
                        points,
                        pointColour=docData.colour,
                        showPoints=True,
                        showLines=False,
                    )
                    self.plotCanvasContainer.append(obj)

        # show current document only
        elif self.currentDocument is not None:
            points = self.makeDataPoints(
                self.currentDocument.spectrum.peaklist,
                self.currentDocument.spectrum.polarity,
            )
            obj = mspy.plot.points(points,
                                   pointColour=(0, 255, 0),
                                   showPoints=True,
                                   showLines=False)
            self.plotCanvasContainer.append(obj)

        # update plot
        self.updatePlotCanvasLabels()
        self.plotCanvas.draw(self.plotCanvasContainer)
Beispiel #2
0
    def makeCurrentPeaklist(self):
        """Convert peaklist for current error range."""

        # get error range
        minY = 0
        maxY = 1
        if self.currentErrors:
            errors = [x[1] for x in self.currentErrors]
            minY = min(errors)
            maxY = max(errors)
            if minY == maxY:
                minY -= abs(minY * 0.1)
                maxY += abs(maxY * 0.1)
            minY -= 0.05 * abs(maxY - minY)

        # convert peaklist
        peaklist = []
        basePeak = self.currentPeaklist.basepeak
        f = abs(maxY - minY) / basePeak.intensity
        for peak in self.currentPeaklist:
            intensity = (peak.intensity * f) + minY
            peaklist.append(mspy.peak(mz=peak.mz, ai=intensity, base=minY))

        # convert to mspy.peaklist
        return mspy.peaklist(peaklist)
Beispiel #3
0
 def makeCurrentPeaklist(self):
     """Convert peaklist for current error range."""
     
     # get error range
     minY = 0
     maxY = 1
     if self.currentErrors:
         errors = [x[1] for x in self.currentErrors]
         minY = min(errors)
         maxY = max(errors)
         if minY == maxY:
             minY -= abs(minY*0.1)
             maxY += abs(maxY*0.1)
         minY -= 0.05 * abs(maxY - minY)
     
     # convert peaklist
     peaklist = []
     basePeak = self.currentPeaklist.basepeak
     f = abs(maxY - minY) / basePeak.intensity
     for peak in self.currentPeaklist:
         intensity = (peak.intensity * f) + minY
         peaklist.append(mspy.peak(mz=peak.mz, ai=intensity, base=minY))
     
     # convert to mspy.peaklist
     return mspy.peaklist(peaklist)
Beispiel #4
0
    def makeCurrentPeaklist(self, minY, maxY):
        """Convert peaklist for current error range."""

        # shift peaklist
        if (minY, maxY) != (0, 1):
            minY -= 0.05 * abs(maxY - minY)

        # convert peaklist
        peaklist = []
        basePeak = self.currentDocument.spectrum.peaklist.basepeak
        f = abs(maxY - minY) / basePeak.intensity
        for peak in self.currentDocument.spectrum.peaklist:
            intensity = (peak.intensity * f) + minY
            peaklist.append(mspy.peak(mz=peak.mz, ai=intensity, base=minY))

        # convert to mspy.peaklist
        return mspy.peaklist(peaklist)
    def makeCurrentPeaklist(self, minY, maxY):
        """Convert peaklist for current error range."""

        # shift peaklist
        if (minY, maxY) != (0, 1):
            minY -= 0.05 * abs(maxY - minY)

        # convert peaklist
        peaklist = []
        basePeak = self.currentDocument.spectrum.peaklist.basepeak
        f = abs(maxY - minY) / basePeak.intensity
        for peak in self.currentDocument.spectrum.peaklist:
            intensity = (peak.intensity * f) + minY
            peaklist.append(mspy.peak(mz=peak.mz, ai=intensity, base=minY))

        # convert to mspy.peaklist
        return mspy.peaklist(peaklist)
Beispiel #6
0
    def makeProfile(self):
        """Generate pattern profile."""

        self.currentPatternProfile = None
        self.currentPatternPeaks = None
        self.currentPatternScan = None

        # check pattern
        if self.currentPattern == None:
            return

        # get selected charge
        charge = 0
        if self.currentIon != None:
            charge = self.currentIon[3]

        # make profile
        self.currentPatternProfile = mspy.profile(
            peaklist=self.currentPattern,
            fwhm=config.massCalculator['patternFwhm'],
            points=20,
            model=config.massCalculator['patternPeakShape'],
        )

        # get scale and shift for specified intensity and baseline
        basepeak = mspy.basepeak(self.currentPatternProfile)
        scale = (config.massCalculator['patternIntensity'] -
                 config.massCalculator['patternBaseline']
                 ) / self.currentPatternProfile[basepeak][1]
        shift = config.massCalculator['patternBaseline']

        # rescale profile
        self.currentPatternProfile = mspy.multiply(self.currentPatternProfile,
                                                   y=scale)
        self.currentPatternProfile = mspy.offset(self.currentPatternProfile,
                                                 y=shift)

        # make real peaklist from profile
        peaklist = []
        for isotope in mspy.maxima(self.currentPatternProfile):
            mz = isotope[0]
            centroid = mspy.centroid(self.currentPatternProfile, isotope[0],
                                     isotope[1] * 0.99)
            if abs(mz - centroid) < config.massCalculator['patternFwhm'] / 20:
                mz = centroid
            peak = mspy.peak(mz=mz, ai=isotope[1], base=shift, charge=charge)
            peaklist.append(peak)
        peaklist = mspy.peaklist(peaklist)

        # make individual peak shapes
        self.currentPatternPeaks = []
        if config.massCalculator['patternShowPeaks']:

            # gaussian shape
            if config.massCalculator['patternPeakShape'] == 'gaussian':
                for isotope in self.currentPattern:
                    peak = mspy.gaussian(
                        x=isotope[0],
                        minY=shift,
                        maxY=isotope[1] * scale + shift,
                        fwhm=config.massCalculator['patternFwhm'])
                    self.currentPatternPeaks.append(peak)

            # lorentzian shape
            elif config.massCalculator['patternPeakShape'] == 'lorentzian':
                for isotope in self.currentPattern:
                    peak = mspy.lorentzian(
                        x=isotope[0],
                        minY=shift,
                        maxY=isotope[1] * scale + shift,
                        fwhm=config.massCalculator['patternFwhm'])
                    self.currentPatternPeaks.append(peak)

            # gauss-lorentzian shape
            elif config.massCalculator[
                    'patternPeakShape'] == 'gausslorentzian':
                for isotope in self.currentPattern:
                    peak = mspy.gausslorentzian(
                        x=isotope[0],
                        minY=shift,
                        maxY=isotope[1] * scale + shift,
                        fwhm=config.massCalculator['patternFwhm'])
                    self.currentPatternPeaks.append(peak)

        # make scan object
        self.currentPatternScan = mspy.scan(profile=self.currentPatternProfile,
                                            peaklist=peaklist)
 def makeProfile(self):
     """Generate pattern profile."""
     
     self.currentPatternProfile = None
     self.currentPatternPeaks = None
     self.currentPatternScan = None
     
     # check pattern
     if self.currentPattern == None:
         return
     
     # get selected charge
     charge = 0
     if self.currentIon != None:
         charge = self.currentIon[3]
     
     # make profile
     self.currentPatternProfile = mspy.profile(
         peaklist = self.currentPattern,
         fwhm = config.massCalculator['patternFwhm'],
         points = 20,
         model = config.massCalculator['patternPeakShape'],
     )
     
     # get scale and shift for specified intensity and baseline
     basepeak = mspy.basepeak(self.currentPatternProfile)
     scale = (config.massCalculator['patternIntensity'] - config.massCalculator['patternBaseline']) / self.currentPatternProfile[basepeak][1]
     shift = config.massCalculator['patternBaseline']
     
     # rescale profile
     self.currentPatternProfile = mspy.multiply(self.currentPatternProfile, y=scale)
     self.currentPatternProfile = mspy.offset(self.currentPatternProfile, y=shift)
     
     # make real peaklist from profile
     peaklist = []
     for isotope in mspy.maxima(self.currentPatternProfile):
         mz = isotope[0]
         centroid = mspy.centroid(self.currentPatternProfile, isotope[0], isotope[1]*0.99)
         if abs(mz-centroid) < config.massCalculator['patternFwhm']/20:
             mz = centroid
         peak = mspy.peak(
             mz = mz,
             ai = isotope[1],
             base = shift,
             charge = charge
         )
         peaklist.append(peak)
     peaklist = mspy.peaklist(peaklist)
     
     # make individual peak shapes
     self.currentPatternPeaks = []
     if config.massCalculator['patternShowPeaks']:
         
         # gaussian shape
         if config.massCalculator['patternPeakShape'] == 'gaussian':
             for isotope in self.currentPattern:
                 peak = mspy.gaussian(
                     x = isotope[0],
                     minY = shift,
                     maxY = isotope[1]*scale+shift,
                     fwhm = config.massCalculator['patternFwhm']
                 )
                 self.currentPatternPeaks.append(peak)
         
         # lorentzian shape
         elif config.massCalculator['patternPeakShape'] == 'lorentzian':
             for isotope in self.currentPattern:
                 peak = mspy.lorentzian(
                     x = isotope[0],
                     minY = shift,
                     maxY = isotope[1]*scale+shift,
                     fwhm = config.massCalculator['patternFwhm']
                 )
                 self.currentPatternPeaks.append(peak)
         
         # gauss-lorentzian shape
         elif config.massCalculator['patternPeakShape'] == 'gausslorentzian':
             for isotope in self.currentPattern:
                 peak = mspy.gausslorentzian(
                     x = isotope[0],
                     minY = shift,
                     maxY = isotope[1]*scale+shift,
                     fwhm = config.massCalculator['patternFwhm']
                 )
                 self.currentPatternPeaks.append(peak)
     
     # make scan object
     self.currentPatternScan = mspy.scan(profile=self.currentPatternProfile, peaklist=peaklist)