def prepare_peaklist(peaks): '''Ensure ``peaks`` is a :class:`~.PeakSet` object, converting from other compatible types as needed. Additionally, make a deep copy of the peaks as signal subtraction methods will modify peaks in place. This function ensures that any of the following common input types are coerced to the appropriate type: 1. :class:`ms_peak_picker.PeakSet` will be copied and indexed 2. :class:`ms_peak_picker.PeakIndex` will have its peaks extracted and copied 3. Any other *sequence* of :class:`PeakLike` objects (objects having an mz and intensity attribute) will be converted into a :class:`ms_peak_picker.PeakSet` 4. Any *sequence* of :class:`tuple` or :class:`list` having at least two entries will be converted into a :class:`ms_peak_picker.PeakSet` with the m/z value of each peak being the the `p[0]` of each entry and the intensity `p[1]`. Any other entries will be ignored. Parameters ---------- peaks: Sequence Any sequence of :class:`~.FittedPeak` objects, objects with ``mz`` and ``intensity`` attributes, or :class:`list` / :class:`tuple` objects containing paired values for ``mz`` and ``intensity`` Returns ------- :class:`~.PeakSet` ''' if isinstance(peaks, PeakIndex): peaks = PeakSet(peaks.peaks).clone() else: peaks = tuple(peaks) if len(peaks) == 0: return PeakSet([]) if not isinstance(peaks[0], FittedPeak): if is_peak(peaks[0]): peaks = [simple_peak(p.mz, p.intensity, 0.01) for p in peaks] elif isinstance(peaks[0], (list, tuple)): peaks = [simple_peak(p[0], p[1], 0.01) for p in peaks] else: raise TypeError("Cannot convert peaks into a PeakSet") peaks = PeakSet(peaks).clone() peaks.reindex() return peaks
def _pick_peaks_vendor(self, scan, *args, **kwargs): scan_info = Business.Scan.FromFile(self._source, scan.scan_number + 1) if scan_info.HasCentroidStream: stream = self._source.GetCentroidStream(scan.scan_number + 1, 0) mzs = stream.Masses intens = stream.Intensities peaks = PeakSet([simple_peak(mzs[i], intens[i], 0.001) for i in range(len(mzs))]) peaks.reindex() arrays = self._scan_arrays(scan) return PeakIndex(arrays[0], arrays[1], peaks) else: raise NotImplementedError()
def envelopes_to_peak_set(self): """Convert a set of deconvoluted peaks with fitted isotopic envelopes into a set of centroids representing those envelope peaks. Returns ------- :class:`ms_peak_picker.PeakSet` """ peaks = [] for peak in self: for point in peak.envelope: peaks.append( simple_peak(point.mz, point.intensity, peak.full_width_at_half_max)) new_peak_set = FittedPeakSet(peaks) new_peak_set.reindex() return new_peak_set