OpenMS
BaseModel.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: $
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) : DefaultParamHandler(source), cut_off_(source.cut_off_)
39  {
40  }
41 
43  ~BaseModel() override
44  {
45  }
46 
48  BaseModel& operator=(const BaseModel& source)
49  {
50  if (&source == this)
51  return *this;
52 
54  cut_off_ = source.cut_off_;
55 
56  return *this;
57  }
58 
60  virtual IntensityType getIntensity(const PositionType& pos) const = 0;
61 
63  virtual bool isContained(const PositionType& pos) const
64  {
65  return getIntensity(pos) >= cut_off_;
66  }
67 
72  template<typename PeakType>
73  void fillIntensity(PeakType& peak) const
74  {
75  peak.setIntensity(getIntensity(peak.getPosition()));
76  }
77 
81  template<class PeakIterator>
82  void fillIntensities(PeakIterator begin, PeakIterator end) const
83  {
84  for (PeakIterator it = begin; it != end; ++it)
85  {
86  fillIntensity(*it);
87  }
88  }
89 
91  virtual IntensityType getCutOff() const
92  {
93  return cut_off_;
94  }
95 
97  virtual void setCutOff(IntensityType cut_off)
98  {
99  cut_off_ = cut_off;
100  param_.setValue("cutoff", cut_off_);
101  }
102 
104  virtual void getSamples(SamplesType& cont) const = 0;
105 
107  virtual void getSamples(std::ostream& os)
108  {
109  SamplesType samples;
110  getSamples(samples);
111  for (typename SamplesType::const_iterator it = samples.begin(); it != samples.end(); ++it)
112  {
113  os << *it << std::endl;
114  }
115  }
116 
117  protected:
119 
120  void updateMembers_() override
121  {
122  cut_off_ = (double)param_.getValue("cutoff");
123  }
124  };
125 } // 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
BaseModel(const BaseModel &source)
copy constructor
Definition: BaseModel.h:38
BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:48
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:97
void fillIntensities(PeakIterator begin, PeakIterator end) const
Convenience function that applies fillIntensity() to an iterator range.
Definition: BaseModel.h:82
~BaseModel() override
Destructor.
Definition: BaseModel.h:43
virtual bool isContained(const PositionType &pos) const
check if position pos is part of the model regarding the models cut-off.
Definition: BaseModel.h:63
virtual IntensityType getCutOff() const
get cutoff value
Definition: BaseModel.h:91
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:73
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:120
double IntensityType
Definition: BaseModel.h:24
IntensityType cut_off_
Definition: BaseModel.h:118
virtual void getSamples(std::ostream &os)
fill stream with reasonable set of samples from the model (i.e. for printing)
Definition: BaseModel.h:107
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
DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
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