47 #define DEBUG_PEAK_PICKING 48 #undef DEBUG_PEAK_PICKING 103 std::vector<PeakBoundary> boundaries;
104 pick(input, output, boundaries);
116 std::vector<PeakBoundary> boundaries;
117 pick(input, output, boundaries);
134 output.SpectrumSettings::operator=(input);
135 output.MetaInfoInterface::operator=(input);
147 if (input.size() < 5)
return;
150 if ((spacing_difference_ == std::numeric_limits<double>::infinity()) &&
151 (spacing_difference_gap_ == std::numeric_limits<double>::infinity()))
153 check_spacings =
false;
160 if (signal_to_noise_ > 0.0)
166 for (
Size i = 2; i < input.size() - 2; ++i)
168 double central_peak_mz = input[i].getMZ(), central_peak_int = input[i].getIntensity();
169 double left_neighbor_mz = input[i - 1].getMZ(), left_neighbor_int = input[i - 1].getIntensity();
170 double right_neighbor_mz = input[i + 1].getMZ(), right_neighbor_int = input[i + 1].getIntensity();
173 if (std::fabs(left_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
174 if (std::fabs(right_neighbor_int) < std::numeric_limits<double>::epsilon())
continue;
177 double left_to_central = 0.0, central_to_right = 0.0, min_spacing = 0.0;
180 left_to_central = central_peak_mz - left_neighbor_mz;
181 central_to_right = right_neighbor_mz - central_peak_mz;
182 min_spacing = (left_to_central < central_to_right) ? left_to_central : central_to_right;
185 double act_snt = 0.0, act_snt_l1 = 0.0, act_snt_r1 = 0.0;
186 if (signal_to_noise_ > 0.0)
194 if ((central_peak_int > left_neighbor_int) &&
195 (central_peak_int > right_neighbor_int) &&
196 (act_snt >= signal_to_noise_) &&
197 (act_snt_l1 >= signal_to_noise_) &&
198 (act_snt_r1 >= signal_to_noise_) &&
200 ((left_to_central < spacing_difference_ * min_spacing) &&
201 (central_to_right < spacing_difference_ * min_spacing))))
207 double act_snt_l2 = 0.0, act_snt_r2 = 0.0;
209 if (signal_to_noise_ > 0.0)
217 (i + 2 < input.size()) &&
218 (left_neighbor_int < input[i - 2].getIntensity()) &&
219 (right_neighbor_int < input[i + 2].getIntensity()) &&
220 (act_snt_l2 >= signal_to_noise_) &&
221 (act_snt_r2 >= signal_to_noise_) &&
223 ((left_neighbor_mz - input[i - 2].getMZ() < spacing_difference_ * min_spacing) &&
224 (input[i + 2].getMZ() - right_neighbor_mz < spacing_difference_ * min_spacing))))
230 std::map<double, double> peak_raw_data;
232 peak_raw_data[central_peak_mz] = central_peak_int;
233 peak_raw_data[left_neighbor_mz] = left_neighbor_int;
234 peak_raw_data[right_neighbor_mz] = right_neighbor_int;
240 bool previous_zero_left(
false);
241 Size missing_left(0);
242 Size left_boundary(i - 1);
246 !previous_zero_left &&
247 (missing_left <= missing_) &&
248 (input[i -
k].getIntensity() <= peak_raw_data.begin()->second) &&
250 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_gap_ * min_spacing)))
252 double act_snt_lk = 0.0;
254 if (signal_to_noise_ > 0.0)
259 if ((act_snt_lk >= signal_to_noise_) &&
261 (peak_raw_data.begin()->first - input[i -
k].getMZ() < spacing_difference_ * min_spacing)))
263 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
268 if (missing_left <= missing_)
270 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
274 previous_zero_left = (input[i -
k].getIntensity() == 0);
275 left_boundary = i -
k;
282 bool previous_zero_right(
false);
283 Size missing_right(0);
284 Size right_boundary(i+1);
286 while ((i +
k < input.size()) &&
287 !previous_zero_right &&
288 (missing_right <= missing_) &&
289 (input[i +
k].getIntensity() <= peak_raw_data.rbegin()->second) &&
291 (input[i +
k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_gap_ * min_spacing)))
293 double act_snt_rk = 0.0;
295 if (signal_to_noise_ > 0.0)
300 if ((act_snt_rk >= signal_to_noise_) &&
302 (input[i +
k].getMZ() - peak_raw_data.rbegin()->first < spacing_difference_ * min_spacing)))
304 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
309 if (missing_right <= missing_)
311 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
315 previous_zero_right = (input[i +
k].getIntensity() == 0);
316 right_boundary = i +
k;
321 if (peak_raw_data.size() < 3)
continue;
327 double max_peak_mz = central_peak_mz;
328 double max_peak_int = central_peak_int;
329 double threshold = 0.000001;
330 double lefthand = left_neighbor_mz;
331 double righthand = right_neighbor_mz;
333 bool lefthand_sign = 1;
334 double eps = std::numeric_limits<double>::epsilon();
339 double mid = (lefthand + righthand) / 2.0;
340 double midpoint_deriv_val = peak_spline.
derivatives(mid, 1);
343 if (!(std::fabs(midpoint_deriv_val) > eps))
348 bool midpoint_sign = (midpoint_deriv_val < 0.0) ? 0 : 1;
350 if (lefthand_sign ^ midpoint_sign)
359 while (righthand - lefthand > threshold);
361 max_peak_mz = (lefthand + righthand) / 2;
362 max_peak_int = peak_spline.
eval(max_peak_mz);
369 double fwhm_int = max_peak_int / 2.0;
370 threshold = 0.01 * fwhm_int;
371 double mz_mid, int_mid;
373 double mz_left = peak_raw_data.begin()->first;
374 double mz_center = max_peak_mz;
375 if (peak_spline.
eval(mz_left) > fwhm_int)
382 mz_mid = mz_left / 2 + mz_center / 2;
383 int_mid = peak_spline.
eval(mz_mid);
384 if (int_mid < fwhm_int)
392 }
while(fabs(int_mid - fwhm_int) > threshold);
394 const double fwhm_left_mz = mz_mid;
397 double mz_right = peak_raw_data.rbegin()->first;
398 mz_center = max_peak_mz;
399 if (peak_spline.
eval(mz_right) > fwhm_int)
406 mz_mid = mz_right / 2 + mz_center / 2;
407 int_mid = peak_spline.
eval(mz_mid);
408 if (int_mid < fwhm_int)
417 }
while(fabs(int_mid - fwhm_int) > threshold);
419 const double fwhm_right_mz = mz_mid;
420 const double fwhm_absolute = fwhm_right_mz - fwhm_left_mz;
421 output.
getFloatDataArrays()[0].push_back( report_FWHM_as_ppm_ ? fwhm_absolute / max_peak_mz * 1e6 : fwhm_absolute);
427 peak.
setMZ(max_peak_mz);
429 peak_boundary.
mz_min = input[left_boundary].getMZ();
430 peak_boundary.
mz_max = input[right_boundary].getMZ();
431 output.push_back(peak);
433 boundaries.push_back(peak_boundary);
456 output.ChromatogramSettings::operator=(input);
457 output.MetaInfoInterface::operator=(input);
462 for (MSChromatogram::const_iterator it = input.begin(); it != input.end(); ++it)
465 p.
setMZ(it->getRT());
467 input_spectrum.push_back(p);
470 pick(input_spectrum, output_spectrum, boundaries,
false);
472 for (MSSpectrum::const_iterator it = output_spectrum.begin(); it != output_spectrum.end(); ++it)
475 p.
setRT(it->getMZ());
500 std::vector<std::vector<PeakBoundary> > boundaries_spec;
501 std::vector<std::vector<PeakBoundary> > boundaries_chrom;
502 pickExperiment(input, output, boundaries_spec, boundaries_chrom, check_spectrum_type);
516 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 532 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
536 output[scan_idx] = input[scan_idx];
540 std::vector<PeakBoundary> boundaries_s;
550 pick(input[scan_idx], output[scan_idx], boundaries_s);
551 boundaries_spec.push_back(boundaries_s);
553 setProgress(++progress);
561 std::vector<PeakBoundary> boundaries_c;
564 boundaries_chrom.push_back(boundaries_c);
565 setProgress(++progress);
596 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
600 output[scan_idx] = input[scan_idx];
615 pick(s, output[scan_idx]);
617 setProgress(++progress);
626 setProgress(++progress);
656 void updateMembers_()
override;
bool report_FWHM_
add floatDataArray 'FWHM'/'FWHM_ppm' to spectra with peak FWHM
Definition: PeakPickerHiRes.h:650
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:128
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:122
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:162
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
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:498
void sortByPosition()
Lexicographically sorts the peaks by their position.
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:114
The representation of a chromatogram.
Definition: MSChromatogram.h:54
SpectrumType
Spectrum peak type.
Definition: SpectrumSettings.h:70
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:516
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:579
void setName(const String &name)
Sets the name.
void resize(Size s)
Definition: MSExperiment.h:132
void addChromatogram(const MSChromatogram &chromatogram)
adds a chromatogram to the list
Size size() const
Definition: MSExperiment.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:119
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
bool report_FWHM_as_ppm_
unit of 'FWHM' float data array (can be absolute or ppm).
Definition: PeakPickerHiRes.h:653
void setParameters(const Param ¶m)
Sets the parameters.
void setName(const String &name)
Sets the name.
double spacing_difference_gap_
Definition: PeakPickerHiRes.h:638
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:130
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:144
unsigned missing_
Definition: PeakPickerHiRes.h:644
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:204
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:68
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:452
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
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:109
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
std::vector< Int > ms_levels_
Definition: PeakPickerHiRes.h:647
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:168
double mz_min
Definition: PeakPickerHiRes.h:89
SpectrumType getType() const
returns the spectrum type (centroided (PEAKS) or profile data (RAW))
Size getNrSpectra() const
get the total number of spectra available
const FloatDataArrays & getFloatDataArrays() const
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
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:101
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:77
double signal_to_noise_
Definition: PeakPickerHiRes.h:635
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:113
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
void clear(bool clear_meta_data)
Clears all data and meta data.
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
UInt getMSLevel() const
Returns the MS level.
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:54
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
double mz_max
Definition: PeakPickerHiRes.h:90
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:156
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:53
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:149
This class implements a fast peak-picking algorithm best suited for high resolution MS data (FT-ICR-M...
Definition: PeakPickerHiRes.h:75
centroid data or stick data
Definition: SpectrumSettings.h:73
structure for peak boundaries
Definition: PeakPickerHiRes.h:87
Description of the experimental settings.
Definition: ExperimentalSettings.h:58
double spacing_difference_
Definition: PeakPickerHiRes.h:641