OpenMS  3.0.0
FeatureFindingMetabo.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2022.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Erhan Kenar, Holger Franken $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
43 
44 #include <vector>
45 
46 struct svm_model;
47 
48 namespace OpenMS
49 {
50 
59  class OPENMS_DLLAPI FeatureHypothesis
60  {
61 public:
63  FeatureHypothesis() = default;
64 
66  ~FeatureHypothesis() = default;
67 
69  FeatureHypothesis(const FeatureHypothesis&) = default;
70 
72  FeatureHypothesis& operator=(const FeatureHypothesis& rhs) = default;
73 
74  // getter & setter
75  Size getSize() const;
76 
77  String getLabel() const;
78 
79  std::vector<String> getLabels() const;
80 
81  double getScore() const;
82 
83  void setScore(const double& score);
84 
85  SignedSize getCharge() const;
86 
87  void setCharge(const SignedSize& ch);
88 
89  std::vector<double> getAllIntensities(bool smoothed = false) const;
90 
91  std::vector<double> getAllCentroidMZ() const;
92 
93  std::vector<double> getAllCentroidRT() const;
94 
95  std::vector<double> getIsotopeDistances() const;
96 
97  double getCentroidMZ() const;
98 
99  double getCentroidRT() const;
100 
101  double getFWHM() const;
102 
104  void addMassTrace(const MassTrace&);
105  double getMonoisotopicFeatureIntensity(bool) const;
106  double getSummedFeatureIntensity(bool) const;
107 
109  double getMaxIntensity(bool smoothed = false) const;
110 
111  Size getNumFeatPoints() const;
112  std::vector<ConvexHull2D> getConvexHulls() const;
113  std::vector< OpenMS::MSChromatogram > getChromatograms(UInt64 feature_id) const;
114 
115 private:
116 
117  // pointers of MassTraces contained in isotopic pattern
118  std::vector<const MassTrace*> iso_pattern_;
119 
120  double feat_score_{};
121 
122  SignedSize charge_{};
123  };
124 
125  class OPENMS_DLLAPI CmpMassTraceByMZ
126  {
127 public:
128 
129  bool operator()(const MassTrace& x, const MassTrace& y) const
130  {
131  return x.getCentroidMZ() < y.getCentroidMZ();
132  }
133 
134  };
135 
136  class OPENMS_DLLAPI CmpHypothesesByScore
137  {
138 public:
139 
140  bool operator()(const FeatureHypothesis& x, const FeatureHypothesis& y) const
141  {
142  return x.getScore() > y.getScore();
143  }
144 
145  };
146 
150  struct OPENMS_DLLAPI Range
151 {
154 };
155 
181  class OPENMS_DLLAPI FeatureFindingMetabo :
182  public DefaultParamHandler,
183  public ProgressLogger
184  {
185 public:
188 
190  ~FeatureFindingMetabo() override;
191 
193  void run(std::vector<MassTrace>& input_mtraces, FeatureMap& output_featmap, std::vector<std::vector< OpenMS::MSChromatogram > >& output_chromatograms);
194 
195 protected:
196  void updateMembers_() override;
197 
198 private:
204  std::vector<const Element*> elementsFromString_(const std::string& elements_string) const;
212  Range getTheoreticIsotopicMassWindow_(const std::vector<Element const *> alphabet, int peakOffset) const;
213 
222  double computeCosineSim_(const std::vector<double>&, const std::vector<double>&) const;
223 
236  int isLegalIsotopePattern_(const FeatureHypothesis& feat_hypo) const;
237 
238  void loadIsotopeModel_(const String&);
239 
263  double scoreMZ_(const MassTrace &, const MassTrace &, Size isotopic_position, Size charge, Range isotope_window) const;
264 
273  double scoreMZByExpectedMean_(Size iso_pos, Size charge, const double diff_mz, double mt_variances) const;
274 
283  double scoreMZByExpectedRange_(Size charge, const double diff_mz, double mt_variances, Range isotope_window) const;
284 
296  double scoreRT_(const MassTrace&, const MassTrace&) const;
297 
304  double computeAveragineSimScore_(const std::vector<double>& intensities, const double& molecular_weight) const;
305 
314  void findLocalFeatures_(const std::vector<const MassTrace*>& candidates, double total_intensity, std::vector<FeatureHypothesis>& output_hypotheses) const;
315 
317  svm_model* isotope_filt_svm_ = nullptr;
318  std::vector<double> svm_feat_centers_;
319  std::vector<double> svm_feat_scales_;
320 
321  //unused
322  //double total_intensity_;
323 
329  double chrom_fwhm_;
330 
335 
340 
342  std::vector<const Element*> elements_;
343  };
344 
345 }
346 
DefaultParamHandler.h
OpenMS::UInt64
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
OpenMS::FeatureFindingMetabo::charge_lower_bound_
Size charge_lower_bound_
Definition: FeatureFindingMetabo.h:327
OpenMS::FeatureFindingMetabo::enable_RT_filtering_
bool enable_RT_filtering_
Definition: FeatureFindingMetabo.h:332
OpenMS::FeatureFindingMetabo::report_chromatograms_
bool report_chromatograms_
Definition: FeatureFindingMetabo.h:339
OpenMS::FeatureFindingMetabo::chrom_fwhm_
double chrom_fwhm_
Definition: FeatureFindingMetabo.h:329
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::FeatureFindingMetabo::local_rt_range_
double local_rt_range_
parameter stuff
Definition: FeatureFindingMetabo.h:325
OpenMS::MassTrace
A container type that gathers peaks similar in m/z and moving along retention time.
Definition: MassTrace.h:61
OpenMS::FeatureFindingMetabo
Method for the assembly of mass traces belonging to the same isotope pattern, i.e....
Definition: FeatureFindingMetabo.h:181
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::FeatureFindingMetabo::use_mz_scoring_C13_
bool use_mz_scoring_C13_
Definition: FeatureFindingMetabo.h:336
OpenMS::CmpHypothesesByScore::operator()
bool operator()(const FeatureHypothesis &x, const FeatureHypothesis &y) const
Definition: FeatureFindingMetabo.h:140
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::FeatureFindingMetabo::isotope_filtering_model_
String isotope_filtering_model_
Definition: FeatureFindingMetabo.h:333
Element.h
MassTrace.h
OpenMS::FeatureFindingMetabo::svm_feat_centers_
std::vector< double > svm_feat_centers_
Definition: FeatureFindingMetabo.h:318
OpenMS::Range
Internal structure to store a lower and upper bound of an m/z range.
Definition: FeatureFindingMetabo.h:150
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::Range::right_boundary
double right_boundary
Definition: FeatureFindingMetabo.h:153
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:52
ProgressLogger.h
OpenMS::FeatureFindingMetabo::use_mz_scoring_by_element_range_
bool use_mz_scoring_by_element_range_
Definition: FeatureFindingMetabo.h:337
OpenMS::Range::left_boundary
double left_boundary
Definition: FeatureFindingMetabo.h:152
FeatureMap.h
OpenMS::FeatureFindingMetabo::local_mz_range_
double local_mz_range_
Definition: FeatureFindingMetabo.h:326
OpenMS::CmpMassTraceByMZ
Definition: FeatureFindingMetabo.h:125
OpenMS::CmpMassTraceByMZ::operator()
bool operator()(const MassTrace &x, const MassTrace &y) const
Definition: FeatureFindingMetabo.h:129
OpenMS::FeatureHypothesis::iso_pattern_
std::vector< const MassTrace * > iso_pattern_
Definition: FeatureFindingMetabo.h:118
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::FeatureHypothesis
Internal structure used in FeatureFindingMetabo that keeps track of a feature hypothesis (isotope gro...
Definition: FeatureFindingMetabo.h:59
MSChromatogram.h
OpenMS::FeatureFindingMetabo::remove_single_traces_
bool remove_single_traces_
Definition: FeatureFindingMetabo.h:341
OpenMS::FeatureFindingMetabo::charge_upper_bound_
Size charge_upper_bound_
Definition: FeatureFindingMetabo.h:328
OpenMS::FeatureFindingMetabo::svm_feat_scales_
std::vector< double > svm_feat_scales_
Definition: FeatureFindingMetabo.h:319
OpenMS::CmpHypothesesByScore
Definition: FeatureFindingMetabo.h:136
OpenMS::FeatureFindingMetabo::use_smoothed_intensities_
bool use_smoothed_intensities_
Definition: FeatureFindingMetabo.h:334
OpenMS::MassTrace::getCentroidMZ
double getCentroidMZ() const
Returns the centroid m/z.
Definition: MassTrace.h:179
OpenMS::FeatureFindingMetabo::elements_
std::vector< const Element * > elements_
Definition: FeatureFindingMetabo.h:342
OpenMS::FeatureFindingMetabo::report_convex_hulls_
bool report_convex_hulls_
Definition: FeatureFindingMetabo.h:338
OpenMS::FeatureHypothesis::getScore
double getScore() const
OpenMS::FeatureFindingMetabo::report_summed_ints_
bool report_summed_ints_
Definition: FeatureFindingMetabo.h:331