OpenMS
FeatureFinderAlgorithmPicked.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
14 
15 #include <fstream>
16 
17 namespace OpenMS
18 {
32  class OPENMS_DLLAPI FeatureFinderAlgorithmPicked :
34  public FeatureFinderDefs
35  {
36 public:
38 
43 
47 
48 protected:
49  typedef Peak1D PeakType;
55 
56 public:
59 
60  // docu in base class
61  void setSeeds(const FeatureMap& seeds) override;
62 
64  void run() override;
65 
66  void run(PeakMap& input_map, FeatureMap& features, const Param& param, const FeatureMap& seeds);
67 
68 protected:
72  mutable std::ofstream log_;
74  bool debug_;
76  std::map<String, UInt> aborts_;
78  std::map<Seed, String> abort_reasons_;
81 
83 
88  double slope_bound_;
96  double min_rt_span_;
97  double max_rt_span_;
101 
103 
104  double intensity_rt_step_;
109  std::vector<std::vector<std::vector<double> > > intensity_thresholds_;
111 
113  std::vector<TheoreticalIsotopePattern> isotope_distributions_;
114 
115  // Docu in base class
116  void updateMembers_() override;
117 
119  void abort_(const Seed& seed, const String& reason);
120 
125  double intersection_(const Feature& f1, const Feature& f2) const;
126 
129 
137  double findBestIsotopeFit_(const Seed& center, UInt charge, IsotopePattern& best_pattern) const;
138 
146  void extendMassTraces_(const IsotopePattern& pattern, MassTraces& traces, Size meta_index_overall) const;
147 
166  void extendMassTrace_(MassTrace& trace, SignedSize spectrum_index, double mz, bool increase_rt, Size meta_index_overall, double min_rt = 0.0, double max_rt = 0.0) const;
167 
169  Size nearest_(double pos, const MSSpectrum& spec, Size start) const;
170 
180  void findIsotope_(double pos, Size spectrum_index, IsotopePattern& pattern, Size pattern_index, Size& peak_index) const;
181 
183  double positionScore_(double pos1, double pos2, double allowed_deviation) const;
184 
186  double isotopeScore_(const TheoreticalIsotopePattern& isotopes, IsotopePattern& pattern, bool consider_mz_distances) const;
187 
198  double intensityScore_(Size spectrum, Size peak) const;
199 
206  std::unique_ptr<TraceFitter> chooseTraceFitter_(double& tau);
207 
208  double intensityScore_(Size rt_bin, Size mz_bin, double intensity) const;
209 
216 
225  void cropFeature_(const std::shared_ptr<TraceFitter>& fitter,
226  const MassTraces& traces,
227  MassTraces& new_traces);
228 
252  bool checkFeatureQuality_(const std::shared_ptr<TraceFitter>& fitter,
253  MassTraces& feature_traces,
254  const double& seed_mz, const double& min_feature_score,
255  String& error_msg, double& fit_score, double& correlation, double& final_score);
256 
270  void writeFeatureDebugInfo_(const std::shared_ptr<TraceFitter>& fitter,
271  const MassTraces& traces,
272  const MassTraces& new_traces,
273  bool feature_ok, const String& error_msg, const double final_score, const Int plot_nr, const PeakType& peak,
274  const String& path = "debug/features/");
275 
277 private:
278 
283  };
284 
285 } // namespace OpenMS
286 
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:139
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:146
FeatureFinderAlgorithm for picked peaks.
Definition: FeatureFinderAlgorithmPicked.h:35
void setSeeds(const FeatureMap &seeds) override
Sets a reference to the calling FeatureFinder.
double positionScore_(double pos1, double pos2, double allowed_deviation) const
Calculates a score between 0 and 1 for the m/z deviation of two peaks.
double slope_bound_
Max slope of mass trace intensities.
Definition: FeatureFinderAlgorithmPicked.h:88
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition: FeatureFinderAlgorithmPicked.h:52
MapType map_
editable copy of the map
Definition: FeatureFinderAlgorithmPicked.h:70
void findIsotope_(double pos, Size spectrum_index, IsotopePattern &pattern, Size pattern_index, Size &peak_index) const
Searches for an isotopic peak in the current spectrum and the adjacent spectra.
double min_isotope_fit_
Minimum isotope pattern fit for a feature.
Definition: FeatureFinderAlgorithmPicked.h:94
double intensityScore_(Size rt_bin, Size mz_bin, double intensity) const
double findBestIsotopeFit_(const Seed &center, UInt charge, IsotopePattern &best_pattern) const
Finds the best fitting position of the isotopic pattern estimate defined by center.
UInt intensity_bins_
Number of bins (in RT and MZ) for intensity significance estimation.
Definition: FeatureFinderAlgorithmPicked.h:93
double max_feature_intersection_
Maximum allowed feature intersection (if larger, that one of the feature is removed)
Definition: FeatureFinderAlgorithmPicked.h:98
std::ofstream log_
Output stream for log/debug info.
Definition: FeatureFinderAlgorithmPicked.h:72
void extendMassTrace_(MassTrace &trace, SignedSize spectrum_index, double mz, bool increase_rt, Size meta_index_overall, double min_rt=0.0, double max_rt=0.0) const
Extends a single mass trace in one RT direction.
std::map< Seed, String > abort_reasons_
Array of abort reasons.
Definition: FeatureFinderAlgorithmPicked.h:78
std::unique_ptr< TraceFitter > chooseTraceFitter_(double &tau)
Choose a the best trace fitter for the current mass traces based on the user parameter (symmetric,...
FeatureMap seeds_
User-specified seed list.
Definition: FeatureFinderAlgorithmPicked.h:80
void extendMassTraces_(const IsotopePattern &pattern, MassTraces &traces, Size meta_index_overall) const
double mass_window_width_
Width of the isotope pattern mass bins.
Definition: FeatureFinderAlgorithmPicked.h:92
const TheoreticalIsotopePattern & getIsotopeDistribution_(double mass) const
Returns the isotope distribution for a certain mass window.
void run(PeakMap &input_map, FeatureMap &features, const Param &param, const FeatureMap &seeds)
double intensity_mz_step_
m/z bin width
Definition: FeatureFinderAlgorithmPicked.h:107
FeatureFinderAlgorithmPickedHelperStructs::IsotopePattern IsotopePattern
Definition: FeatureFinderAlgorithmPicked.h:54
SpectrumType::FloatDataArrays FloatDataArrays
Definition: FeatureFinderAlgorithmPicked.h:41
std::vector< std::vector< std::vector< double > > > intensity_thresholds_
Precalculated intensity 20-quantiles (binned)
Definition: FeatureFinderAlgorithmPicked.h:109
UInt max_missing_trace_peaks_
Stores mass_trace:max_missing.
Definition: FeatureFinderAlgorithmPicked.h:87
FeatureFinderAlgorithm::MapType MapType
Definition: FeatureFinderAlgorithmPicked.h:39
double min_rt_span_
Minimum RT range that has to be left after the fit.
Definition: FeatureFinderAlgorithmPicked.h:96
void abort_(const Seed &seed, const String &reason)
Writes the abort reason to the log file and counts occurrences for each reason.
UInt min_spectra_
Number of spectra that have to show the same mass (for finding a mass trace)
Definition: FeatureFinderAlgorithmPicked.h:86
double intensity_percentage_
Isotope pattern intensity contribution of required peaks.
Definition: FeatureFinderAlgorithmPicked.h:89
double trace_tolerance_
Stores isotopic_pattern:mz_tolerance.
Definition: FeatureFinderAlgorithmPicked.h:85
double intensityScore_(Size spectrum, Size peak) const
Compute the intensity score for the peak peak in spectrum spectrum.
double intersection_(const Feature &f1, const Feature &f2) const
bool checkFeatureQuality_(const std::shared_ptr< TraceFitter > &fitter, MassTraces &feature_traces, const double &seed_mz, const double &min_feature_score, String &error_msg, double &fit_score, double &correlation, double &final_score)
Checks the feature based on different score thresholds and model constraints.
double isotopeScore_(const TheoreticalIsotopePattern &isotopes, IsotopePattern &pattern, bool consider_mz_distances) const
Calculates a score between 0 and 1 for the correlation between theoretical and found isotope pattern.
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition: FeatureFinderAlgorithmPicked.h:51
double min_trace_score_
Minimum quality of a traces.
Definition: FeatureFinderAlgorithmPicked.h:95
double optional_fit_improvement_
Minimal improvement for leaving out optional isotope.
Definition: FeatureFinderAlgorithmPicked.h:91
FeatureFinderAlgorithmPicked & operator=(const FeatureFinderAlgorithmPicked &)
Not implemented.
double intensity_percentage_optional_
Isotope pattern intensity contribution of optional peaks.
Definition: FeatureFinderAlgorithmPicked.h:90
void cropFeature_(const std::shared_ptr< TraceFitter > &fitter, const MassTraces &traces, MassTraces &new_traces)
Creates new mass traces new_traces based on the fitting result and the original traces traces.
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
FeatureFinderAlgorithmPickedHelperStructs::Seed Seed
Definition: FeatureFinderAlgorithmPicked.h:50
double max_rt_span_
Maximum RT range the model is allowed to span.
Definition: FeatureFinderAlgorithmPicked.h:97
double pattern_tolerance_
Stores mass_trace:mz_tolerance.
Definition: FeatureFinderAlgorithmPicked.h:84
void writeFeatureDebugInfo_(const std::shared_ptr< TraceFitter > &fitter, const MassTraces &traces, const MassTraces &new_traces, bool feature_ok, const String &error_msg, const double final_score, const Int plot_nr, const PeakType &peak, const String &path="debug/features/")
Creates several files containing plots and viewable data of the fitted mass trace.
Peak1D PeakType
Definition: FeatureFinderAlgorithmPicked.h:49
void run() override
Main method for actual FeatureFinder.
FeatureFinderAlgorithmPickedHelperStructs::TheoreticalIsotopePattern TheoreticalIsotopePattern
Definition: FeatureFinderAlgorithmPicked.h:53
FeatureFinderAlgorithmPicked(const FeatureFinderAlgorithmPicked &)
Not implemented.
String reported_mz_
The mass type that is reported for features. 'maximum' returns the m/z value of the highest mass trac...
Definition: FeatureFinderAlgorithmPicked.h:99
MapType::SpectrumType SpectrumType
Definition: FeatureFinderAlgorithmPicked.h:40
FeatureFinderAlgorithmPicked()
default constructor
Size nearest_(double pos, const MSSpectrum &spec, Size start) const
Returns the index of the peak nearest to m/z pos in spectrum spec (linear search starting from index ...
bool debug_
debug flag
Definition: FeatureFinderAlgorithmPicked.h:74
std::vector< TheoreticalIsotopePattern > isotope_distributions_
Vector of precalculated isotope distributions for several mass windows.
Definition: FeatureFinderAlgorithmPicked.h:113
std::map< String, UInt > aborts_
Array of abort reasons.
Definition: FeatureFinderAlgorithmPicked.h:76
Abstract base class for FeatureFinder algorithms.
Definition: FeatureFinderAlgorithm.h:52
FeatureMap * features_
Output data pointer.
Definition: FeatureFinderAlgorithm.h:116
A container for features.
Definition: FeatureMap.h:80
An LC-MS feature.
Definition: Feature.h:46
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
std::vector< FloatDataArray > FloatDataArrays
Definition: MSSpectrum.h:96
Management and storage of parameters / INI files.
Definition: Param.h:44
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Helper structure for a found isotope pattern used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:168
Helper struct for mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:54
Helper struct for a collection of mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:85
Helper structure for seeds used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:37
Helper structure for a theoretical isotope pattern used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:148
The purpose of this struct is to provide definitions of classes and typedefs which are used throughou...
Definition: FeatureFinderDefs.h:25