Example #1
0
    def labelpeak(self, mz=None, minX=None, maxX=None, pickingHeight=0.75, baselineWindow=0.1, baselineOffset=0.0):
        """Return labeled peak in given m/z range.
            mz (float) - m/z value to label
            minX (float) - m/z range start
            maxX (float) - m/z range end
            pickingHeight (float) - centroiding height
            baselineWindow (float) - noise calculation window (in %/100)
            baselineOffset (float) - baseline offset, relative to noise width (in %/100)
        """

        # get baseline
        baseline = self.baseline(window=baselineWindow, offset=baselineOffset)

        # label peak
        peak = mod_peakpicking.labelpeak(
            signal=self.profile, mz=mz, minX=minX, maxX=maxX, pickingHeight=pickingHeight, baseline=baseline
        )

        # check peak
        if not peak:
            return False

        # append peak
        self.peaklist.append(peak)

        return True
Example #2
0
def checkpattern(signal, pattern, pickingHeight=0.75, baseline=None):
    """Compare signal with given isotopic pattern. Return rms, basepeak
        intensity
        signal (numpy array) - signal data points
        pattern (list of [mz,intens]) - theoretical pattern to compare
        pickingHeight (float) - centroiding height
        baseline (numpy array) - signal baseline
    """

    # check signal type
    if not isinstance(signal, numpy.ndarray):
        raise TypeError, "Signal must be NumPy array!"

   # check baseline type
    if baseline is not None and not isinstance(baseline, numpy.ndarray):
        raise TypeError, "Baseline must be NumPy array!"

    # check signal data
    if len(signal) == 0:
        return None

    # get signal intensites for isotopes
    peaklist = []
    num_theo = 0
    num_found = 0
    for isotope in pattern:
        peak = mod_peakpicking.labelpeak(
            signal = signal,
            mz = isotope[0],
            pickingHeight = pickingHeight,
            baseline = baseline
        )
        num_theo += 1
        if peak:
            peaklist.append(peak.intensity)
            num_found += 1
        else:
            peaklist.append(0.0)

    # normalize peaklist
    basepeak = max(peaklist)
    if basepeak:
        peaklist = [p/basepeak for p in peaklist]
    else:
        return None

    # get rms
    rms = 0
    for x, isotope in enumerate(pattern):
        rms += (isotope[1] - peaklist[x])**2
    if len(pattern) > 1:
        rms = math.sqrt(rms / (len(pattern)-1))

    return (CheckPatternResult(rms, basepeak, (num_found, num_theo)))