34 #ifndef OPENMS_TRANSFORMATIONS_RAW2PEAK_PEAKPICKERHIRES_H
35 #define OPENMS_TRANSFORMATIONS_RAW2PEAK_PEAKPICKERHIRES_H
47 #define DEBUG_PEAK_PICKING
48 #undef DEBUG_PEAK_PICKING
101 template <
typename PeakType>
104 std::vector<PeakBoundary> boundaries;
105 pick(input, output, boundaries);
118 template <
typename PeakType>
123 output.SpectrumSettings::operator=(input);
124 output.MetaInfoInterface::operator=(input);
131 if (input.size() < 5)
return;
134 if ((spacing_difference_ == std::numeric_limits<double>::infinity()) &&
135 (spacing_difference_gap_ == std::numeric_limits<double>::infinity()))
137 check_spacings =
false;
144 if (signal_to_noise_ > 0.0)
150 for (
Size i = 2; i < input.size() - 2; ++i)
152 double central_peak_mz = input[i].getMZ(), central_peak_int = input[i].getIntensity();
153 double left_neighbor_mz = input[i - 1].getMZ(), left_neighbor_int = input[i - 1].getIntensity();
154 double right_neighbor_mz = input[i + 1].getMZ(), right_neighbor_int = input[i + 1].getIntensity();
157 if (std::fabs(left_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
158 if (std::fabs(right_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
161 double left_to_central = 0.0, central_to_right = 0.0, min_spacing = 0.0;
164 left_to_central = central_peak_mz - left_neighbor_mz;
165 central_to_right = right_neighbor_mz - central_peak_mz;
166 min_spacing = (left_to_central < central_to_right) ? left_to_central : central_to_right;
169 double act_snt = 0.0, act_snt_l1 = 0.0, act_snt_r1 = 0.0;
170 if (signal_to_noise_ > 0.0)
178 if ((central_peak_int > left_neighbor_int) &&
179 (central_peak_int > right_neighbor_int) &&
180 (act_snt >= signal_to_noise_) &&
181 (act_snt_l1 >= signal_to_noise_) &&
182 (act_snt_r1 >= signal_to_noise_) &&
184 ((left_to_central < spacing_difference_ * min_spacing) &&
185 (central_to_right < spacing_difference_ * min_spacing))))
191 double act_snt_l2 = 0.0, act_snt_r2 = 0.0;
193 if (signal_to_noise_ > 0.0)
200 if ((i + 2 < input.size()) &&
201 (left_neighbor_int < input[i - 2].getIntensity()) &&
202 (right_neighbor_int < input[i + 2].getIntensity()) &&
203 (act_snt_l2 >= signal_to_noise_) &&
204 (act_snt_r2 >= signal_to_noise_) &&
206 ((left_neighbor_mz - input[i - 2].getMZ() < spacing_difference_ * min_spacing) &&
207 (input[i + 2].getMZ() - right_neighbor_mz < spacing_difference_ * min_spacing))))
213 std::map<double, double> peak_raw_data;
215 peak_raw_data[central_peak_mz] = central_peak_int;
216 peak_raw_data[left_neighbor_mz] = left_neighbor_int;
217 peak_raw_data[right_neighbor_mz] = right_neighbor_int;
223 bool previous_zero_left(
false);
224 Size missing_left(0);
225 Size left_boundary(i - 1);
229 !previous_zero_left &&
230 (missing_left <= missing_) &&
231 (input[i - k].getIntensity() <= peak_raw_data.begin()->second) &&
233 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_gap_ * min_spacing)))
235 double act_snt_lk = 0.0;
237 if (signal_to_noise_ > 0.0)
242 if ((act_snt_lk >= signal_to_noise_) &&
244 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_ * min_spacing)))
246 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
251 if (missing_left <= missing_)
253 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
257 previous_zero_left = (input[i -
k].getIntensity() == 0);
258 left_boundary = i -
k;
265 bool previous_zero_right(
false);
266 Size missing_right(0);
267 Size right_boundary(i+1);
269 while ((i + k < input.size()) &&
270 !previous_zero_right &&
271 (missing_right <= missing_) &&
272 (input[i +
k].getIntensity() <= peak_raw_data.rbegin()->second) &&
274 (input[i + k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_gap_ * min_spacing)))
276 double act_snt_rk = 0.0;
278 if (signal_to_noise_ > 0.0)
283 if ((act_snt_rk >= signal_to_noise_) &&
285 (input[i + k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_ * min_spacing)))
287 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
292 if (missing_right <= missing_)
294 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
298 previous_zero_right = (input[i +
k].getIntensity() == 0);
299 right_boundary = i +
k;
304 if (peak_raw_data.size() < 4)
continue;
310 double max_peak_mz = central_peak_mz;
311 double max_peak_int = central_peak_int;
312 double threshold = 0.000001;
313 double lefthand = left_neighbor_mz;
314 double righthand = right_neighbor_mz;
316 bool lefthand_sign = 1;
317 double eps = std::numeric_limits<double>::epsilon();
322 double mid = (lefthand + righthand) / 2.0;
323 double midpoint_deriv_val = peak_spline.
derivatives(mid, 1);
326 if (!(std::fabs(midpoint_deriv_val) > eps))
331 bool midpoint_sign = (midpoint_deriv_val < 0.0) ? 0 : 1;
333 if (lefthand_sign ^ midpoint_sign)
342 while (righthand - lefthand > threshold);
345 max_peak_mz = (lefthand + righthand) / 2;
346 max_peak_int = peak_spline.
eval(max_peak_mz);
351 peak.
setMZ(max_peak_mz);
353 peak_boundary.
mz_min = input[left_boundary].getMZ();
354 peak_boundary.
mz_max = input[right_boundary].getMZ();
355 output.push_back(peak);
356 boundaries.push_back(peak_boundary);
373 template <
typename PeakType>
376 std::vector<PeakBoundary> boundaries;
377 pick(input, output, boundaries);
388 template <
typename PeakType>
393 output.ChromatogramSettings::operator=(input);
394 output.MetaInfoInterface::operator=(input);
401 input_spectrum.push_back(*it);
403 pick(input_spectrum, output_spectrum, boundaries,
false);
406 output.push_back(*it);
419 template <
typename PeakType,
typename ChromatogramPeakT>
422 std::vector<std::vector<PeakBoundary> > boundaries_spec;
423 std::vector<std::vector<PeakBoundary> > boundaries_chrom;
424 pickExperiment(input, output, boundaries_spec, boundaries_chrom, check_spectrum_type);
438 template <
typename PeakType,
typename ChromatogramPeakT>
455 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
459 output[scan_idx] = input[scan_idx];
463 std::vector<PeakBoundary> boundaries_s;
473 pick(input[scan_idx], output[scan_idx], boundaries_s);
474 boundaries_spec.push_back(boundaries_s);
476 setProgress(++progress);
484 std::vector<PeakBoundary> boundaries_c;
487 boundaries_chrom.push_back(boundaries_c);
488 setProgress(++progress);
502 template <
typename PeakType,
typename ChromatogramPeakT>
520 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
524 output[scan_idx] = input[scan_idx];
539 pick(s, output[scan_idx]);
541 setProgress(++progress);
550 setProgress(++progress);
574 void updateMembers_();
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:129
MSChromatogram< ChromatogramPeakT > getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:214
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:160
Size getNrSpectra() const
get the total number of spectra available
Definition: MSExperiment.h:808
const String & getName() const
Definition: MSChromatogram.h:217
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:259
Size size() const
Definition: MSExperiment.h:117
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:197
void sortByPosition()
Lexicographically sorts the peaks by their position.
Definition: MSSpectrum.h:419
Peak data (also called centroided data or stick data)
Definition: SpectrumSettings.h:74
The representation of a chromatogram.
Definition: MSChromatogram.h:52
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:142
SpectrumType
Spectrum peak type.
Definition: SpectrumSettings.h:71
void pickExperiment(OnDiscMSExperiment< PeakType, ChromatogramPeakT > &input, MSExperiment< PeakType, ChromatogramPeakT > &output, const bool check_spectrum_type=true) const
Applies the peak-picking algorithm to a map (MSExperiment). This method picks peaks for each scan in ...
Definition: PeakPickerHiRes.h:503
const String & getName() const
Returns the name.
Definition: MSSpectrum.h:271
void setName(const String &name)
Sets the name.
Definition: MSSpectrum.h:277
void resize(Size s)
Definition: MSExperiment.h:122
double eval(double x) const
evaluates the spline at position x
void pickExperiment(const MSExperiment< PeakType, ChromatogramPeakT > &input, MSExperiment< PeakType, ChromatogramPeakT > &output, const bool check_spectrum_type=true) const
Applies the peak-picking algorithm to a map (MSExperiment). This method picks peaks for each scan in ...
Definition: PeakPickerHiRes.h:420
void setParameters(const Param ¶m)
Sets the parameters.
void setName(const String &name)
Sets the name.
Definition: MSChromatogram.h:223
void addChromatogram(const MSChromatogram< ChromatogramPeakType > &chromatogram)
adds a chromatogram to the list
Definition: MSExperiment.h:782
double spacing_difference_gap_
Definition: PeakPickerHiRes.h:562
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:167
SpectrumType getType() const
returns the spectrum type
unsigned missing_
Definition: PeakPickerHiRes.h:568
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:67
virtual void init(const PeakIterator &it_begin, const PeakIterator &it_end)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:110
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
std::vector< Int > ms_levels_
Definition: PeakPickerHiRes.h:571
double mz_min
Definition: PeakPickerHiRes.h:89
void pick(const MSSpectrum< PeakType > &input, MSSpectrum< PeakType > &output) const
Applies the peak-picking algorithm to a single spectrum (MSSpectrum). The resulting picked peaks are ...
Definition: PeakPickerHiRes.h:102
double getRT() const
Definition: MSSpectrum.h:243
void setMSLevel(UInt ms_level)
Sets the MS level.
Definition: MSSpectrum.h:265
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:166
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSSpectrum.h:635
void setRT(double rt)
Sets the absolute retention time (is seconds)
Definition: MSSpectrum.h:249
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:69
double signal_to_noise_
Definition: PeakPickerHiRes.h:559
void setType(SpectrumType type)
sets the spectrum type
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:154
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSExperiment.h:850
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
double derivatives(double x, unsigned order) const
evaluates derivative of spline at position x
void pickExperiment(const MSExperiment< PeakType, ChromatogramPeakT > &input, MSExperiment< PeakType, ChromatogramPeakT > &output, std::vector< std::vector< PeakBoundary > > &boundaries_spec, std::vector< std::vector< PeakBoundary > > &boundaries_chrom, const bool check_spectrum_type=true) const
Applies the peak-picking algorithm to a map (MSExperiment). This method picks peaks for each scan in ...
Definition: PeakPickerHiRes.h:439
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
double mz_max
Definition: PeakPickerHiRes.h:90
void pick(const MSSpectrum< PeakType > &input, MSSpectrum< PeakType > &output, std::vector< PeakBoundary > &boundaries, bool check_spacings=true) const
Applies the peak-picking algorithm to a single spectrum (MSSpectrum). The resulting picked peaks are ...
Definition: PeakPickerHiRes.h:119
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSChromatogram.h:587
cubic spline interpolation as described in R.L. Burden, J.D. Faires, Numerical Analysis, 4th ed. PWS-Kent, 1989, ISBN 0-53491-585-X, pp. 126-131.
Definition: CubicSpline2d.h:50
static bool contains(const std::vector< T > &container, const E &elem)
Checks whether the element elem is contained in the given container.
Definition: ListUtils.h:150
This class implements a fast peak-picking algorithm best suited for high resolution MS data (FT-ICR-M...
Definition: PeakPickerHiRes.h:75
structure for peak boundaries
Definition: PeakPickerHiRes.h:87
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
void pick(const MSChromatogram< PeakType > &input, MSChromatogram< PeakType > &output, std::vector< PeakBoundary > &boundaries) const
Applies the peak-picking algorithm to a single chromatogram (MSChromatogram). The resulting picked pe...
Definition: PeakPickerHiRes.h:389
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:788
double spacing_difference_
Definition: PeakPickerHiRes.h:565
void pick(const MSChromatogram< PeakType > &input, MSChromatogram< PeakType > &output) const
Applies the peak-picking algorithm to a single chromatogram (MSChromatogram). The resulting picked pe...
Definition: PeakPickerHiRes.h:374