OpenMS  2.7.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-2021.
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 #include <svm.h>
46 
47 namespace OpenMS
48 {
49 
58  class OPENMS_DLLAPI FeatureHypothesis
59  {
60 public:
62  FeatureHypothesis() = default;
63 
65  ~FeatureHypothesis() = default;
66 
69 
72 
73  // getter & setter
74  Size getSize() const;
75 
76  String getLabel() const;
77 
78  std::vector<String> getLabels() const;
79 
80  double getScore() const;
81 
82  void setScore(const double& score);
83 
85 
86  void setCharge(const SignedSize& ch);
87 
88  std::vector<double> getAllIntensities(bool smoothed = false) const;
89 
90  std::vector<double> getAllCentroidMZ() const;
91 
92  std::vector<double> getAllCentroidRT() const;
93 
94  std::vector<double> getIsotopeDistances() const;
95 
96  double getCentroidMZ() const;
97 
98  double getCentroidRT() const;
99 
100  double getFWHM() const;
101 
103  void addMassTrace(const MassTrace&);
105  double getSummedFeatureIntensity(bool) const;
106 
108  double getMaxIntensity(bool smoothed = false) const;
109 
111  std::vector<ConvexHull2D> getConvexHulls() const;
112  std::vector< OpenMS::MSChromatogram > getChromatograms(UInt64 feature_id) const;
113 
114 private:
115 
116  // pointers of MassTraces contained in isotopic pattern
117  std::vector<const MassTrace*> iso_pattern_;
118 
119  double feat_score_{};
120 
121  SignedSize charge_{};
122  };
123 
124  class OPENMS_DLLAPI CmpMassTraceByMZ
125  {
126 public:
127 
128  bool operator()(const MassTrace& x, const MassTrace& y) const
129  {
130  return x.getCentroidMZ() < y.getCentroidMZ();
131  }
132 
133  };
134 
135  class OPENMS_DLLAPI CmpHypothesesByScore
136  {
137 public:
138 
139  bool operator()(const FeatureHypothesis& x, const FeatureHypothesis& y) const
140  {
141  return x.getScore() > y.getScore();
142  }
143 
144  };
145 
149  struct OPENMS_DLLAPI Range
150 {
153 };
154 
180  class OPENMS_DLLAPI FeatureFindingMetabo :
181  public DefaultParamHandler,
182  public ProgressLogger
183  {
184 public:
187 
190 
192  void run(std::vector<MassTrace>& input_mtraces, FeatureMap& output_featmap, std::vector<std::vector< OpenMS::MSChromatogram > >& output_chromatograms);
193 
194 protected:
195  void updateMembers_() override;
196 
197 private:
203  std::vector<const Element*> elementsFromString_(const std::string& elements_string) const;
211  Range getTheoreticIsotopicMassWindow_(const std::vector<Element const *> alphabet, int peakOffset) const;
212 
221  double computeCosineSim_(const std::vector<double>&, const std::vector<double>&) const;
222 
235  int isLegalIsotopePattern_(const FeatureHypothesis& feat_hypo) const;
236 
237  void loadIsotopeModel_(const String&);
238 
262  double scoreMZ_(const MassTrace &, const MassTrace &, Size isotopic_position, Size charge, Range isotope_window) const;
263 
272  double scoreMZByExpectedMean_(Size iso_pos, Size charge, const double diff_mz, double mt_variances) const;
273 
282  double scoreMZByExpectedRange_(Size charge, const double diff_mz, double mt_variances, Range isotope_window) const;
283 
295  double scoreRT_(const MassTrace&, const MassTrace&) const;
296 
303  double computeAveragineSimScore_(const std::vector<double>& intensities, const double& molecular_weight) const;
304 
313  void findLocalFeatures_(const std::vector<const MassTrace*>& candidates, double total_intensity, std::vector<FeatureHypothesis>& output_hypotheses) const;
314 
316  svm_model* isotope_filt_svm_ = nullptr;
317  std::vector<double> svm_feat_centers_;
318  std::vector<double> svm_feat_scales_;
319 
320  //unused
321  //double total_intensity_;
322 
328  double chrom_fwhm_;
329 
334 
339 
341  std::vector<const Element*> elements_;
342  };
343 
344 }
345 
Definition: FeatureFindingMetabo.h:136
bool operator()(const FeatureHypothesis &x, const FeatureHypothesis &y) const
Definition: FeatureFindingMetabo.h:139
Definition: FeatureFindingMetabo.h:125
bool operator()(const MassTrace &x, const MassTrace &y) const
Definition: FeatureFindingMetabo.h:128
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
Method for the assembly of mass traces belonging to the same isotope pattern, i.e....
Definition: FeatureFindingMetabo.h:183
void findLocalFeatures_(const std::vector< const MassTrace * > &candidates, double total_intensity, std::vector< FeatureHypothesis > &output_hypotheses) const
Identify groupings of mass traces based on a set of reasonable candidates.
FeatureFindingMetabo()
Default constructor.
String isotope_filtering_model_
Definition: FeatureFindingMetabo.h:332
std::vector< const Element * > elementsFromString_(const std::string &elements_string) const
parses a string of element symbols into a vector of Elements
Size charge_upper_bound_
Definition: FeatureFindingMetabo.h:327
~FeatureFindingMetabo() override
Default destructor.
bool use_mz_scoring_C13_
Definition: FeatureFindingMetabo.h:335
bool report_chromatograms_
Definition: FeatureFindingMetabo.h:338
std::vector< double > svm_feat_centers_
Definition: FeatureFindingMetabo.h:317
double scoreMZ_(const MassTrace &, const MassTrace &, Size isotopic_position, Size charge, Range isotope_window) const
Perform mass to charge scoring of two multiple mass traces.
bool report_summed_ints_
Definition: FeatureFindingMetabo.h:330
bool report_convex_hulls_
Definition: FeatureFindingMetabo.h:337
Size charge_lower_bound_
Definition: FeatureFindingMetabo.h:326
double computeCosineSim_(const std::vector< double > &, const std::vector< double > &) const
Computes the cosine similarity between two vectors.
std::vector< double > svm_feat_scales_
Definition: FeatureFindingMetabo.h:318
double scoreMZByExpectedRange_(Size charge, const double diff_mz, double mt_variances, Range isotope_window) const
score isotope m/z distance based on an expected isotope window which was calculated from a set of exp...
void run(std::vector< MassTrace > &input_mtraces, FeatureMap &output_featmap, std::vector< std::vector< OpenMS::MSChromatogram > > &output_chromatograms)
main method of FeatureFindingMetabo
double local_rt_range_
parameter stuff
Definition: FeatureFindingMetabo.h:324
bool use_mz_scoring_by_element_range_
Definition: FeatureFindingMetabo.h:336
double local_mz_range_
Definition: FeatureFindingMetabo.h:325
double scoreMZByExpectedMean_(Size iso_pos, Size charge, const double diff_mz, double mt_variances) const
score isotope m/z distance based on the expected m/z distances using C13-C12 or Kenar method
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
double scoreRT_(const MassTrace &, const MassTrace &) const
Perform retention time scoring of two multiple mass traces.
std::vector< const Element * > elements_
Definition: FeatureFindingMetabo.h:341
int isLegalIsotopePattern_(const FeatureHypothesis &feat_hypo) const
Compare intensities of feature hypothesis with model.
bool remove_single_traces_
Definition: FeatureFindingMetabo.h:340
double chrom_fwhm_
Definition: FeatureFindingMetabo.h:328
void loadIsotopeModel_(const String &)
bool enable_RT_filtering_
Definition: FeatureFindingMetabo.h:331
double computeAveragineSimScore_(const std::vector< double > &intensities, const double &molecular_weight) const
Perform intensity scoring using the averagine model (for peptides only)
bool use_smoothed_intensities_
Definition: FeatureFindingMetabo.h:333
Range getTheoreticIsotopicMassWindow_(const std::vector< Element const * > alphabet, int peakOffset) const
Internal structure used in FeatureFindingMetabo that keeps track of a feature hypothesis (isotope gro...
Definition: FeatureFindingMetabo.h:59
std::vector< String > getLabels() const
double getCentroidMZ() const
FeatureHypothesis()=default
default constructor
void addMassTrace(const MassTrace &)
addMassTrace
void setCharge(const SignedSize &ch)
FeatureHypothesis(const FeatureHypothesis &)=default
copy constructor
std::vector< double > getAllCentroidRT() const
FeatureHypothesis & operator=(const FeatureHypothesis &rhs)=default
assignment operator
std::vector< OpenMS::MSChromatogram > getChromatograms(UInt64 feature_id) const
std::vector< double > getAllIntensities(bool smoothed=false) const
void setScore(const double &score)
std::vector< double > getAllCentroidMZ() const
std::vector< ConvexHull2D > getConvexHulls() const
double getMonoisotopicFeatureIntensity(bool) const
std::vector< const MassTrace * > iso_pattern_
Definition: FeatureFindingMetabo.h:117
double getSummedFeatureIntensity(bool) const
std::vector< double > getIsotopeDistances() const
double getCentroidRT() const
~FeatureHypothesis()=default
default destructor
Size getNumFeatPoints() const
SignedSize getCharge() const
double getMaxIntensity(bool smoothed=false) const
return highest apex of all isotope traces
A container for features.
Definition: FeatureMap.h:105
A container type that gathers peaks similar in m/z and moving along retention time.
Definition: MassTrace.h:62
double getCentroidMZ() const
Returns the centroid m/z.
Definition: MassTrace.h:179
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A more convenient string class.
Definition: String.h:61
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
double left_boundary
Definition: FeatureFindingMetabo.h:151
double right_boundary
Definition: FeatureFindingMetabo.h:152
Internal structure to store a lower and upper bound of an m/z range.
Definition: FeatureFindingMetabo.h:150