OpenMS
BaseModel.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: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 #include <OpenMS/KERNEL/DPeak.h>
13 
14 namespace OpenMS
15 {
16 
22  {
23  public:
24  typedef double IntensityType;
25  typedef double CoordinateType;
27  typedef typename DPeak<1>::Type PeakType;
28  typedef std::vector<PeakType> SamplesType;
29 
30 
32  BaseModel() : DefaultParamHandler("BaseModel")
33  {
34  defaults_.setValue("cutoff", 0.0, "Low intensity cutoff of the model. Peaks below this intensity are not considered part of the model.");
35  }
36 
38  BaseModel(const BaseModel& source) = default;
39 
41  ~BaseModel() override
42  {
43  }
44 
46  BaseModel& operator=(const BaseModel& source) = default;
47 
49  virtual IntensityType getIntensity(const PositionType& pos) const = 0;
50 
52  virtual bool isContained(const PositionType& pos) const
53  {
54  return getIntensity(pos) >= cut_off_;
55  }
56 
61  template<typename PeakType>
62  void fillIntensity(PeakType& peak) const
63  {
64  peak.setIntensity(getIntensity(peak.getPosition()));
65  }
66 
70  template<class PeakIterator>
71  void fillIntensities(PeakIterator begin, PeakIterator end) const
72  {
73  for (PeakIterator it = begin; it != end; ++it)
74  {
75  fillIntensity(*it);
76  }
77  }
78 
80  virtual IntensityType getCutOff() const
81  {
82  return cut_off_;
83  }
84 
86  virtual void setCutOff(IntensityType cut_off)
87  {
88  cut_off_ = cut_off;
89  param_.setValue("cutoff", cut_off_);
90  }
91 
93  virtual void getSamples(SamplesType& cont) const = 0;
94 
96  virtual void getSamples(std::ostream& os)
97  {
98  SamplesType samples;
99  getSamples(samples);
100  for (const auto& sample : samples)
101  {
102  os << sample << std::endl;
103  }
104  }
105 
106  protected:
108 
109  void updateMembers_() override
110  {
111  cut_off_ = (double)param_.getValue("cutoff");
112  }
113  };
114 } // namespace OpenMS
Abstract base class for 1-dimensional models.
Definition: BaseModel.h:22
virtual IntensityType getIntensity(const PositionType &pos) const =0
access model predicted intensity at position pos
DPosition< 1 > PositionType
Definition: BaseModel.h:26
double CoordinateType
Definition: BaseModel.h:25
BaseModel()
Default constructor.
Definition: BaseModel.h:32
virtual void setCutOff(IntensityType cut_off)
set cutoff value
Definition: BaseModel.h:86
BaseModel & operator=(const BaseModel &source)=default
assignment operator
void fillIntensities(PeakIterator begin, PeakIterator end) const
Convenience function that applies fillIntensity() to an iterator range.
Definition: BaseModel.h:71
BaseModel(const BaseModel &source)=default
copy constructor
~BaseModel() override
Destructor.
Definition: BaseModel.h:41
virtual bool isContained(const PositionType &pos) const
check if position pos is part of the model regarding the models cut-off.
Definition: BaseModel.h:52
virtual IntensityType getCutOff() const
get cutoff value
Definition: BaseModel.h:80
std::vector< PeakType > SamplesType
Definition: BaseModel.h:28
void fillIntensity(PeakType &peak) const
Convenience function to set the intensity of a peak to the predicted intensity at its current positio...
Definition: BaseModel.h:62
virtual void getSamples(SamplesType &cont) const =0
get reasonable set of samples from the model (i.e. for printing)
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: BaseModel.h:109
double IntensityType
Definition: BaseModel.h:24
IntensityType cut_off_
Definition: BaseModel.h:107
virtual void getSamples(std::ostream &os)
fill stream with reasonable set of samples from the model (i.e. for printing)
Definition: BaseModel.h:96
DPeak< 1 >::Type PeakType
Definition: BaseModel.h:27
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
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
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
void setValue(const std::string &key, const ParamValue &value, const std::string &description="", const std::vector< std::string > &tags=std::vector< std::string >())
Sets a value.
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Metafunction to choose among Peak1D respectively Peak2D through a template argument.
Definition: DPeak.h:26