OpenMS
Loading...
Searching...
No Matches
FeatureFinderAlgorithmPicked.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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
18
19#include <fstream>
20
21namespace OpenMS
22{
24 struct OPENMS_DLLAPI FeatureFinderDefs
25 {
28
31
34
36 enum Flag {UNUSED, USED};
37
39 class OPENMS_DLLAPI NoSuccessor :
41 {
42public:
43 NoSuccessor(const char * file, int line, const char * function, const IndexPair & index) :
44 BaseException(file, line, function, "NoSuccessor","there is no successor/predecessor for the given Index: " + StringUtils::toStr(index.first) + "/" + StringUtils::toStr(index.second)),
45 index_(index)
46 {
47 Exception::GlobalExceptionHandler::setMessage(what());
48 }
49
50 ~NoSuccessor() noexcept override = default;
51
52protected:
53 IndexPair index_; // index without successor/predecessor
54 };
55 };
56
57
88 class OPENMS_DLLAPI FeatureFinderAlgorithmPicked :
90 {
91public:
93
98
99protected:
106
107public:
110
111 void setSeeds(const FeatureMap& seeds);
112
113private:
114 void setData_(MSExperiment&& map, FeatureMap& features);
115
116public:
127 void run(PeakMap&& input_map,
128 FeatureMap& features,
129 const Param& param,
130 const FeatureMap& seeds);
131
133 {
134 return defaults_;
135 }
136
137protected:
138 void run_();
139
142
144 FeatureMap* features_{nullptr};
145
147 mutable std::ofstream log_;
149 bool debug_;
151 std::map<std::string, UInt> aborts_;
153 std::map<Seed, std::string> abort_reasons_;
156
158
174 std::string reported_mz_;
176
178
179
184 std::vector<std::vector<std::vector<double> > > intensity_thresholds_;
186
188 std::vector<TheoreticalIsotopePattern> isotope_distributions_;
189
190 // Docu in base class
191 void updateMembers_() override;
192
194 void abort_(const Seed& seed, const std::string& reason);
195
200 double intersection_(const Feature& f1, const Feature& f2) const;
201
204
212 double findBestIsotopeFit_(const Seed& center, UInt charge, IsotopePattern& best_pattern) const;
213
221 void extendMassTraces_(const IsotopePattern& pattern, MassTraces& traces, Size meta_index_overall) const;
222
241 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;
242
244 Size nearest_(double pos, const MSSpectrum& spec, Size start) const;
245
255 void findIsotope_(double pos, Size spectrum_index, IsotopePattern& pattern, Size pattern_index, Size& peak_index) const;
256
258 double positionScore_(double pos1, double pos2, double allowed_deviation) const;
259
261 double isotopeScore_(const TheoreticalIsotopePattern& isotopes, IsotopePattern& pattern, bool consider_mz_distances) const;
262
273 double intensityScore_(Size spectrum, Size peak) const;
274
281 std::unique_ptr<TraceFitter> chooseTraceFitter_(double& tau);
282
283 double intensityScore_(Size rt_bin, Size mz_bin, double intensity) const;
284
291
300 void cropFeature_(const std::shared_ptr<TraceFitter>& fitter,
301 const MassTraces& traces,
302 MassTraces& new_traces);
303
327 bool checkFeatureQuality_(const std::shared_ptr<TraceFitter>& fitter,
328 MassTraces& feature_traces,
329 const double& seed_mz, const double& min_feature_score,
330 std::string& error_msg, double& fit_score, double& correlation, double& final_score);
331
345 void writeFeatureDebugInfo_(const std::shared_ptr<TraceFitter>& fitter,
346 const MassTraces& traces,
347 const MassTraces& new_traces,
348 bool feature_ok, const std::string& error_msg, const double final_score, const Int plot_nr, const PeakType& peak,
349 const std::string& path = "debug/features/");
350
352private:
353
358 };
359
360} // namespace OpenMS
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Exception base class.
Definition Exception.h:63
FeatureFinderAlgorithm for picked peaks.
Definition FeatureFinderAlgorithmPicked.h:90
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:163
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition FeatureFinderAlgorithmPicked.h:103
MapType map_
the editable map (moved from input)
Definition FeatureFinderAlgorithmPicked.h:141
std::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:174
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:169
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:168
double max_feature_intersection_
Maximum allowed feature intersection (if larger, that one of the feature is removed)
Definition FeatureFinderAlgorithmPicked.h:173
std::ofstream log_
Output stream for log/debug info.
Definition FeatureFinderAlgorithmPicked.h:147
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.
FeatureMap seeds_
User-specified seed list.
Definition FeatureFinderAlgorithmPicked.h:155
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:167
std::unique_ptr< TraceFitter > chooseTraceFitter_(double &tau)
Choose a the best trace fitter for the current mass traces based on the user parameter (symmetric,...
const TheoreticalIsotopePattern & getIsotopeDistribution_(double mass) const
Returns the isotope distribution for a certain mass window.
double intensity_mz_step_
m/z bin width
Definition FeatureFinderAlgorithmPicked.h:182
FeatureFinderAlgorithmPickedHelperStructs::IsotopePattern IsotopePattern
Definition FeatureFinderAlgorithmPicked.h:105
SpectrumType::FloatDataArrays FloatDataArrays
Definition FeatureFinderAlgorithmPicked.h:96
Param getDefaultParameters() const
Definition FeatureFinderAlgorithmPicked.h:132
std::vector< std::vector< std::vector< double > > > intensity_thresholds_
Precalculated intensity 20-quantiles (binned)
Definition FeatureFinderAlgorithmPicked.h:184
UInt max_missing_trace_peaks_
Stores mass_trace:max_missing.
Definition FeatureFinderAlgorithmPicked.h:162
double min_rt_span_
Minimum RT range that has to be left after the fit.
Definition FeatureFinderAlgorithmPicked.h:171
UInt min_spectra_
Number of spectra that have to show the same mass (for finding a mass trace)
Definition FeatureFinderAlgorithmPicked.h:161
double intensity_percentage_
Isotope pattern intensity contribution of required peaks.
Definition FeatureFinderAlgorithmPicked.h:164
double trace_tolerance_
Stores mass_trace:mz_tolerance.
Definition FeatureFinderAlgorithmPicked.h:160
double intensityScore_(Size spectrum, Size peak) const
Compute the intensity score for the peak peak in spectrum spectrum.
bool checkFeatureQuality_(const std::shared_ptr< TraceFitter > &fitter, MassTraces &feature_traces, const double &seed_mz, const double &min_feature_score, std::string &error_msg, double &fit_score, double &correlation, double &final_score)
Checks the feature based on different score thresholds and model constraints.
double intersection_(const Feature &f1, const Feature &f2) const
void abort_(const Seed &seed, const std::string &reason)
Writes the abort reason to the log file and counts occurrences for each reason.
std::map< Seed, std::string > abort_reasons_
Array of abort reasons.
Definition FeatureFinderAlgorithmPicked.h:153
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:102
double min_trace_score_
Minimum quality of a traces.
Definition FeatureFinderAlgorithmPicked.h:170
double optional_fit_improvement_
Minimal improvement for leaving out optional isotope.
Definition FeatureFinderAlgorithmPicked.h:166
double intensity_percentage_optional_
Isotope pattern intensity contribution of optional peaks.
Definition FeatureFinderAlgorithmPicked.h:165
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 run(PeakMap &&input_map, FeatureMap &features, const Param &param, const FeatureMap &seeds)
Main method of the FeatureFinderAlgorithmPicked (explicit move overload).
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:101
void setData_(MSExperiment &&map, FeatureMap &features)
double max_rt_span_
Maximum RT range the model is allowed to span.
Definition FeatureFinderAlgorithmPicked.h:172
double pattern_tolerance_
Stores isotopic_pattern:mz_tolerance.
Definition FeatureFinderAlgorithmPicked.h:159
std::map< std::string, UInt > aborts_
Array of abort reasons.
Definition FeatureFinderAlgorithmPicked.h:151
Peak1D PeakType
Definition FeatureFinderAlgorithmPicked.h:100
double intensity_rt_step_
RT bin width.
Definition FeatureFinderAlgorithmPicked.h:180
void writeFeatureDebugInfo_(const std::shared_ptr< TraceFitter > &fitter, const MassTraces &traces, const MassTraces &new_traces, bool feature_ok, const std::string &error_msg, const double final_score, const Int plot_nr, const PeakType &peak, const std::string &path="debug/features/")
Creates several files containing plots and viewable data of the fitted mass trace.
FeatureFinderAlgorithmPickedHelperStructs::TheoreticalIsotopePattern TheoreticalIsotopePattern
Definition FeatureFinderAlgorithmPicked.h:104
FeatureFinderAlgorithmPicked(const FeatureFinderAlgorithmPicked &)
Not implemented.
MapType::SpectrumType SpectrumType
Definition FeatureFinderAlgorithmPicked.h:95
FeatureFinderAlgorithmPicked()
default constructor
void setSeeds(const FeatureMap &seeds)
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 ...
MSExperiment MapType
Definition FeatureFinderAlgorithmPicked.h:94
FeatureFinderAlgorithmPicked & operator=(const FeatureFinderAlgorithmPicked &)
Not implemented.
bool debug_
debug flag
Definition FeatureFinderAlgorithmPicked.h:149
std::vector< TheoreticalIsotopePattern > isotope_distributions_
Vector of precalculated isotope distributions for several mass windows.
Definition FeatureFinderAlgorithmPicked.h:188
Exception that is thrown if a method an invalid IndexPair is given.
Definition FeatureFinderAlgorithmPicked.h:41
~NoSuccessor() noexcept override=default
NoSuccessor(const char *file, int line, const char *function, const IndexPair &index)
Definition FeatureFinderAlgorithmPicked.h:43
A container for features.
Definition FeatureMap.h:78
An LC-MS feature.
Definition Feature.h:46
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
std::vector< FloatDataArray > FloatDataArrays
Definition MSSpectrum.h:106
Management and storage of parameters / INI files.
Definition Param.h:46
A 1-dimensional raw data point or peak.
Definition Peak1D.h:30
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
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:173
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:153
The purpose of this struct is to provide definitions of classes and typedefs which are used throughou...
Definition FeatureFinderAlgorithmPicked.h:25
Flag
Flags that indicate if a peak is already used in a feature.
Definition FeatureFinderAlgorithmPicked.h:36
IsotopeCluster::IndexPair IndexPair
Index to peak consisting of two UInts (scan index / peak index)
Definition FeatureFinderAlgorithmPicked.h:27
IsotopeCluster::ChargedIndexSet ChargedIndexSet
Index to peak consisting of two UInts (scan index / peak index) with charge information.
Definition FeatureFinderAlgorithmPicked.h:30
IsotopeCluster::IndexSet IndexSet
A set of peak indices.
Definition FeatureFinderAlgorithmPicked.h:33
Index set with associated charge estimate.
Definition IsotopeCluster.h:56
std::pair< Size, Size > IndexPair
An index pair typically representing (scan_index, peak_index) in an MSExperiment.
Definition IsotopeCluster.h:37
std::set< IndexPair > IndexSet
A set of index pairs, usually referring to peaks in an MSExperiment.
Definition IsotopeCluster.h:45