def conform_envelopes(experimental, base_theoretical, minimum_theoretical_abundance=0.05):
    total = 0
    n_missing = 0
    i = 0
    cleaned_eid = []
    for peak in experimental:
        if peak is None:
            peak = FittedPeak(base_theoretical[i].mz, 1, 1, -1, -1, 0, 1, 0, 0)
            if base_theoretical[i].intensity > minimum_theoretical_abundance:
                n_missing += 1
        total += peak.intensity
        cleaned_eid.append(peak)
        i += 1

    tid = []
    for peak in base_theoretical:
        peak = peak.clone()
        peak.intensity *= total
        tid.append(peak)
    return cleaned_eid, tid, n_missing
Exemple #2
0
def average_fitted_peak(peak_cluster, divisor=False):
    if divisor:
        scale = divisor
    else:
        scale = 1
    weighted_mz = peak_cluster.weighted_mz()
    total_intensity = peak_cluster.intensity
    signal_to_noise = sum(p.signal_to_noise * p.intensity for p in peak_cluster) / total_intensity
    fwhm = sum(p.full_width_at_half_max * p.intensity for p in peak_cluster) / total_intensity
    area = sum(p.area * p.intensity for p in peak_cluster) / total_intensity
    return FittedPeak(weighted_mz, total_intensity / scale, signal_to_noise, -1, -1, fwhm, area)
def conform_envelopes(experimental, base_theoretical, minimum_theoretical_abundance=0.05):
    total = 0
    n_missing = 0
    i = 0
    cleaned_eid = []
    for peak in experimental:
        if peak is None:
            peak = FittedPeak(base_theoretical[i].mz, 1, 1, -1, -1, 0, 1, 0, 0)
            if base_theoretical[i].intensity > minimum_theoretical_abundance:
                n_missing += 1
        total += peak.intensity
        cleaned_eid.append(peak)
        i += 1

    tid = []
    for peak in base_theoretical:
        peak = peak.clone()
        peak.intensity *= total
        tid.append(peak)
    return cleaned_eid, tid, n_missing
Exemple #4
0
def deserialize_peak_set(scan_dict):
    mz_array = scan_dict['m/z array']
    intensity_array = scan_dict['intensity array']
    n = len(scan_dict['m/z array'])
    peaks = []
    for i in range(n):
        peak = FittedPeak(mz_array[i], intensity_array[i], 1, i, i, 0,
                          intensity_array[i], 0, 0)
        peaks.append(peak)
    peak_set = PeakSet(peaks)
    peak_set.reindex()
    return PeakIndex(np.array([]), np.array([]), peak_set)
def make_profile(points, fwhm):
    peaks = []
    i = 0
    for point in points:
        tid = peptide.isotopic_cluster(point[0], point[1], truncate_after=0.99)
        for tp in tid:
            fp = FittedPeak(tp.mz, tp.intensity * point[2], 0, i, i, fwhm,
                            tp.intensity * point[2])
            peaks.append(fp)
    mz = np.array([0])
    intensity = np.array([0])

    for p in peaks:
        x, y = gaussian_shape(p)
        mz = np.concatenate([mz, [x[0] - 0.0001], x, [x[-1] + 0.0001]])
        intensity = np.concatenate([intensity, [0], y, [0]])
    return mz, intensity
Exemple #6
0
    def _find_next_putative_peak(self,
                                 mz,
                                 charge,
                                 step=1,
                                 tolerance=ERROR_TOLERANCE):
        """
        Recalibrates the current peak location given the position of the **next** putative peak
        in a theoretical isotopic cluster.

        Suppose that the peak at `mz` is roughly in the neighborhood of a real isotopic peak,
        but the alignment is bad, so it won't make a good starting point for the search for the
        rest of the peaks in its cluster under a stringent error tolerance.

        However, if we're willing to search for the **next** putative peak with a more permissive error
        tolerance, which we expect will be properly aligned with the rest of its isotopic cluster,
        we can recalibrate the proper starting peak's mz and use that for isotopic cluster fitting.

        Parameters
        ----------
        mz : float
            Starting m/z value to search from
        charge : int
            Charge state to use when calculating the step size in m/z
        step : int, optional
            The number of steps into the putative isotopic cluster to take. Defaults to 1
        tolerance : float, optional
            The error tolerance to accept for finding supporting peaks.

        Returns
        -------
        list
        """
        shift = isotopic_shift(charge)
        next_peak = mz + (shift * step)
        peaklist_slice = self.between(next_peak - (next_peak * tolerance),
                                      next_peak + (next_peak * tolerance))
        candidates = []
        for forward in peaklist_slice:
            prev_peak_mz = forward.mz - (shift * step)
            dummy_peak = FittedPeak(prev_peak_mz, 1.0, 1.0, -1, 0, 0, 0)
            candidates.append((dummy_peak, charge))
        return candidates
Exemple #7
0
    def has_peak(self, mz, error_tolerance):
        """Query :attr:`peaklist` for a peak at `mz` within `error_tolerance` ppm. If a peak
        is not found, this method returns a placeholder peak.

        Parameters
        ----------
        mz : float
            The m/z to search for a peak at
        error_tolerance : float
            The parts-per-million error tolerance to search with

        Returns
        -------
        FittedPeak
            A peak from :attr:`peaklist` if present, else a placeholder peak.
        """
        peak = self.peaklist.has_peak(mz, error_tolerance)
        if peak is None or peak.intensity < self.minimum_intensity:
            return FittedPeak(mz, 1.0, 1.0, -1, 0, 0, 0)
        return peak
Exemple #8
0
def envelope_to_peak_list(envelope):
    return [FittedPeak(e[0], e[1], 0, 0, 0, 0, 0, 0, 0) for e in envelope]
import unittest

import numpy as np

from ms_peak_picker import FittedPeak
from brainpy._c.isotopic_distribution import TheoreticalPeak as Peak

from ms_deisotope.scoring import (PenalizedMSDeconVFitter, MSDeconVFitter,
                                  DotProductFitter, ScaledGTestFitter,
                                  GTestFitter, LeastSquaresFitter)

experimental = [
    FittedPeak(mz=739.920,
               intensity=8356.829,
               signal_to_noise=100.000,
               peak_count=30,
               index=30588,
               full_width_at_half_max=0.050,
               area=425.445),
    FittedPeak(mz=740.255,
               intensity=8006.456,
               signal_to_noise=100.000,
               peak_count=31,
               index=30622,
               full_width_at_half_max=0.051,
               area=416.640),
    FittedPeak(mz=740.589,
               intensity=4970.605,
               signal_to_noise=100.000,
               peak_count=32,
               index=30655,