35 #ifndef OPENMS_TRANSFORMATIONS_RAW2PEAK_PEAKPICKERHIRES_H 36 #define OPENMS_TRANSFORMATIONS_RAW2PEAK_PEAKPICKERHIRES_H 48 #define DEBUG_PEAK_PICKING 49 #undef DEBUG_PEAK_PICKING 104 std::vector<PeakBoundary> boundaries;
105 pick(input, output, boundaries);
117 std::vector<PeakBoundary> boundaries;
118 pick(input, output, boundaries);
135 output.SpectrumSettings::operator=(input);
136 output.MetaInfoInterface::operator=(input);
148 if (input.size() < 5)
return;
151 if ((spacing_difference_ == std::numeric_limits<double>::infinity()) &&
152 (spacing_difference_gap_ == std::numeric_limits<double>::infinity()))
154 check_spacings =
false;
161 if (signal_to_noise_ > 0.0)
167 for (
Size i = 2; i < input.size() - 2; ++i)
169 double central_peak_mz = input[i].getMZ(), central_peak_int = input[i].getIntensity();
170 double left_neighbor_mz = input[i - 1].getMZ(), left_neighbor_int = input[i - 1].getIntensity();
171 double right_neighbor_mz = input[i + 1].getMZ(), right_neighbor_int = input[i + 1].getIntensity();
174 if (std::fabs(left_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
175 if (std::fabs(right_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
178 double left_to_central = 0.0, central_to_right = 0.0, min_spacing = 0.0;
181 left_to_central = central_peak_mz - left_neighbor_mz;
182 central_to_right = right_neighbor_mz - central_peak_mz;
183 min_spacing = (left_to_central < central_to_right) ? left_to_central : central_to_right;
186 double act_snt = 0.0, act_snt_l1 = 0.0, act_snt_r1 = 0.0;
187 if (signal_to_noise_ > 0.0)
195 if ((central_peak_int > left_neighbor_int) &&
196 (central_peak_int > right_neighbor_int) &&
197 (act_snt >= signal_to_noise_) &&
198 (act_snt_l1 >= signal_to_noise_) &&
199 (act_snt_r1 >= signal_to_noise_) &&
201 ((left_to_central < spacing_difference_ * min_spacing) &&
202 (central_to_right < spacing_difference_ * min_spacing))))
208 double act_snt_l2 = 0.0, act_snt_r2 = 0.0;
210 if (signal_to_noise_ > 0.0)
218 (i + 2 < input.size()) &&
219 (left_neighbor_int < input[i - 2].getIntensity()) &&
220 (right_neighbor_int < input[i + 2].getIntensity()) &&
221 (act_snt_l2 >= signal_to_noise_) &&
222 (act_snt_r2 >= signal_to_noise_) &&
224 ((left_neighbor_mz - input[i - 2].getMZ() < spacing_difference_ * min_spacing) &&
225 (input[i + 2].getMZ() - right_neighbor_mz < spacing_difference_ * min_spacing))))
231 std::map<double, double> peak_raw_data;
233 peak_raw_data[central_peak_mz] = central_peak_int;
234 peak_raw_data[left_neighbor_mz] = left_neighbor_int;
235 peak_raw_data[right_neighbor_mz] = right_neighbor_int;
241 bool previous_zero_left(
false);
242 Size missing_left(0);
243 Size left_boundary(i - 1);
247 !previous_zero_left &&
248 (missing_left <= missing_) &&
249 (input[i - k].getIntensity() <= peak_raw_data.begin()->second) &&
251 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_gap_ * min_spacing)))
253 double act_snt_lk = 0.0;
255 if (signal_to_noise_ > 0.0)
260 if ((act_snt_lk >= signal_to_noise_) &&
262 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_ * min_spacing)))
264 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
269 if (missing_left <= missing_)
271 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
275 previous_zero_left = (input[i -
k].getIntensity() == 0);
276 left_boundary = i -
k;
283 bool previous_zero_right(
false);
284 Size missing_right(0);
285 Size right_boundary(i+1);
287 while ((i + k < input.size()) &&
288 !previous_zero_right &&
289 (missing_right <= missing_) &&
290 (input[i +
k].getIntensity() <= peak_raw_data.rbegin()->second) &&
292 (input[i + k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_gap_ * min_spacing)))
294 double act_snt_rk = 0.0;
296 if (signal_to_noise_ > 0.0)
301 if ((act_snt_rk >= signal_to_noise_) &&
303 (input[i + k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_ * min_spacing)))
305 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
310 if (missing_right <= missing_)
312 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
316 previous_zero_right = (input[i +
k].getIntensity() == 0);
317 right_boundary = i +
k;
322 if (peak_raw_data.size() < 3)
continue;
328 double max_peak_mz = central_peak_mz;
329 double max_peak_int = central_peak_int;
330 double threshold = 0.000001;
331 double lefthand = left_neighbor_mz;
332 double righthand = right_neighbor_mz;
334 bool lefthand_sign = 1;
335 double eps = std::numeric_limits<double>::epsilon();
340 double mid = (lefthand + righthand) / 2.0;
341 double midpoint_deriv_val = peak_spline.
derivatives(mid, 1);
344 if (!(std::fabs(midpoint_deriv_val) > eps))
349 bool midpoint_sign = (midpoint_deriv_val < 0.0) ? 0 : 1;
351 if (lefthand_sign ^ midpoint_sign)
360 while (righthand - lefthand > threshold);
362 max_peak_mz = (lefthand + righthand) / 2;
363 max_peak_int = peak_spline.
eval(max_peak_mz);
370 double fwhm_int = max_peak_int / 2.0;
371 threshold = 0.01 * fwhm_int;
372 double mz_mid, int_mid;
374 double mz_left = peak_raw_data.begin()->first;
375 double mz_center = max_peak_mz;
376 if (peak_spline.
eval(mz_left) > fwhm_int)
383 mz_mid = mz_left / 2 + mz_center / 2;
384 int_mid = peak_spline.
eval(mz_mid);
385 if (int_mid < fwhm_int)
393 }
while(fabs(int_mid - fwhm_int) > threshold);
395 const double fwhm_left_mz = mz_mid;
398 double mz_right = peak_raw_data.rbegin()->first;
399 mz_center = max_peak_mz;
400 if (peak_spline.
eval(mz_right) > fwhm_int)
407 mz_mid = mz_right / 2 + mz_center / 2;
408 int_mid = peak_spline.
eval(mz_mid);
409 if (int_mid < fwhm_int)
418 }
while(fabs(int_mid - fwhm_int) > threshold);
420 const double fwhm_right_mz = mz_mid;
421 const double fwhm_absolute = fwhm_right_mz - fwhm_left_mz;
422 output.
getFloatDataArrays()[0].push_back( report_FWHM_as_ppm_ ? fwhm_absolute / max_peak_mz * 1e6 : fwhm_absolute);
428 peak.
setMZ(max_peak_mz);
430 peak_boundary.
mz_min = input[left_boundary].getMZ();
431 peak_boundary.
mz_max = input[right_boundary].getMZ();
432 output.push_back(peak);
434 boundaries.push_back(peak_boundary);
457 output.ChromatogramSettings::operator=(input);
458 output.MetaInfoInterface::operator=(input);
463 for (MSChromatogram::const_iterator it = input.begin(); it != input.end(); ++it)
466 p.
setMZ(it->getRT());
468 input_spectrum.push_back(p);
471 pick(input_spectrum, output_spectrum, boundaries,
false);
473 for (MSSpectrum::const_iterator it = output_spectrum.begin(); it != output_spectrum.end(); ++it)
476 p.
setRT(it->getMZ());
501 std::vector<std::vector<PeakBoundary> > boundaries_spec;
502 std::vector<std::vector<PeakBoundary> > boundaries_chrom;
503 pickExperiment(input, output, boundaries_spec, boundaries_chrom, check_spectrum_type);
517 void pickExperiment(
const PeakMap& input,
PeakMap& output, std::vector<std::vector<PeakBoundary> >& boundaries_spec, std::vector<std::vector<PeakBoundary> >& boundaries_chrom,
const bool check_spectrum_type =
true)
const 533 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
537 output[scan_idx] = input[scan_idx];
541 std::vector<PeakBoundary> boundaries_s;
551 pick(input[scan_idx], output[scan_idx], boundaries_s);
552 boundaries_spec.push_back(boundaries_s);
554 setProgress(++progress);
562 std::vector<PeakBoundary> boundaries_c;
565 boundaries_chrom.push_back(boundaries_c);
566 setProgress(++progress);
597 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
601 output[scan_idx] = input[scan_idx];
616 pick(s, output[scan_idx]);
618 setProgress(++progress);
627 setProgress(++progress);
657 void updateMembers_();
bool report_FWHM_
add floatDataArray 'FWHM'/'FWHM_ppm' to spectra with peak FWHM
Definition: PeakPickerHiRes.h:651
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:129
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:117
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:163
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:861
void pickExperiment(const PeakMap &input, PeakMap &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:499
void sortByPosition()
Lexicographically sorts the peaks by their position.
Peak data (also called centroided data or stick data)
Definition: SpectrumSettings.h:74
void pick(const MSChromatogram &input, MSChromatogram &output) const
Applies the peak-picking algorithm to a single chromatogram (MSChromatogram). The resulting picked pe...
Definition: PeakPickerHiRes.h:115
The representation of a chromatogram.
Definition: MSChromatogram.h:55
SpectrumType
Spectrum peak type.
Definition: SpectrumSettings.h:71
const String & getName() const
Returns the name.
void pickExperiment(const PeakMap &input, PeakMap &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:517
void pickExperiment(OnDiscPeakMap &input, PeakMap &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:580
void setName(const String &name)
Sets the name.
void resize(Size s)
Definition: MSExperiment.h:137
void addChromatogram(const MSChromatogram &chromatogram)
adds a chromatogram to the list
Definition: MSExperiment.h:855
Size size() const
Definition: MSExperiment.h:132
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:120
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:111
bool report_FWHM_as_ppm_
unit of 'FWHM' float data array (can be absolute or ppm).
Definition: PeakPickerHiRes.h:654
void setParameters(const Param ¶m)
Sets the parameters.
void setName(const String &name)
Sets the name.
double spacing_difference_gap_
Definition: PeakPickerHiRes.h:639
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
void pick(const MSSpectrum &input, MSSpectrum &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:131
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:145
unsigned missing_
Definition: PeakPickerHiRes.h:645
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:217
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:69
void pick(const MSChromatogram &input, MSChromatogram &output, std::vector< PeakBoundary > &boundaries) const
Applies the peak-picking algorithm to a single chromatogram (MSChromatogram). The resulting picked pe...
Definition: PeakPickerHiRes.h:453
The representation of a 1D spectrum.
Definition: MSSpectrum.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:649
std::vector< Int > ms_levels_
Definition: PeakPickerHiRes.h:648
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:169
double mz_min
Definition: PeakPickerHiRes.h:90
SpectrumType getType() const
returns the spectrum type
Size getNrSpectra() const
get the total number of spectra available
Definition: MSExperiment.h:887
const FloatDataArrays & getFloatDataArrays() const
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
void setMSLevel(UInt ms_level)
Sets the MS level.
double derivatives(double x, unsigned order) const
evaluates derivative of spline at position x
void pick(const MSSpectrum &input, MSSpectrum &output) const
Applies the peak-picking algorithm to a single spectrum (MSSpectrum). The resulting picked peaks are ...
Definition: PeakPickerHiRes.h:102
void clear(bool clear_meta_data)
Clears all data and meta data.
void setRT(double rt)
Sets the absolute retention time (in seconds)
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
double signal_to_noise_
Definition: PeakPickerHiRes.h:636
const String & getName() const
void setType(SpectrumType type)
sets the spectrum type
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:108
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSExperiment.h:929
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
UInt getMSLevel() const
Returns the MS level.
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:55
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
double mz_max
Definition: PeakPickerHiRes.h:91
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:157
double eval(double x) const
evaluates the spline at position x
void clear(bool clear_meta_data)
Clears all data and meta data.
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:59
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:76
structure for peak boundaries
Definition: PeakPickerHiRes.h:88
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
double spacing_difference_
Definition: PeakPickerHiRes.h:642