Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
BaseModel.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-2017.
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: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_BASEMODEL_H
36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_BASEMODEL_H
37 
39 #include <OpenMS/KERNEL/DPeak.h>
40 
41 namespace OpenMS
42 {
43 
50  template <UInt D>
51  class BaseModel :
52  public DefaultParamHandler
53  {
54 
55 public:
56 
57  typedef double IntensityType;
58  typedef double CoordinateType;
60  typedef typename DPeak<D>::Type PeakType;
61  typedef std::vector<PeakType> SamplesType;
62 
63 
66  DefaultParamHandler("BaseModel")
67  {
68  defaults_.setValue("cutoff", 0.0, "Low intensity cutoff of the model. Peaks below this intensity are not considered part of the model.");
69  }
70 
72  BaseModel(const BaseModel & source) :
73  DefaultParamHandler(source),
74  cut_off_(source.cut_off_)
75  {
76  }
77 
79  virtual ~BaseModel()
80  {
81  }
82 
84  virtual BaseModel & operator=(const BaseModel & source)
85  {
86  if (&source == this) return *this;
87 
89  cut_off_ = source.cut_off_;
90 
91  return *this;
92  }
93 
95  static void registerChildren();
96 
98  virtual IntensityType getIntensity(const PositionType & pos) const = 0;
99 
101  virtual bool isContained(const PositionType & pos) const
102  {
103  return getIntensity(pos) >= cut_off_;
104  }
105 
110  template <typename PeakType>
111  void fillIntensity(PeakType & peak) const
112  {
113  peak.setIntensity(getIntensity(peak.getPosition()));
114  }
115 
119  template <class PeakIterator>
121  {
122  for (PeakIterator it = begin; it != end; ++it)
123  {
124  fillIntensity(*it);
125  }
126  }
127 
129  virtual IntensityType getCutOff() const
130  {
131  return cut_off_;
132  }
133 
135  virtual void setCutOff(IntensityType cut_off)
136  {
137  cut_off_ = cut_off;
138  param_.setValue("cutoff", cut_off_);
139  }
140 
142  virtual void getSamples(SamplesType & cont) const = 0;
143 
145  virtual void getSamples(std::ostream & os)
146  {
147  SamplesType samples;
148  getSamples(samples);
149  for (typename SamplesType::const_iterator it = samples.begin(); it != samples.end(); ++it)
150  {
151  os << *it << std::endl;
152  }
153  }
154 
155 protected:
156  IntensityType cut_off_;
157 
158  virtual void updateMembers_()
159  {
160  cut_off_ = (double)param_.getValue("cutoff");
161  }
162 
163  };
164 }
165 
166 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_BASEMODEL_H
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!...
Definition: DefaultParamHandler.h:157
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
virtual bool isContained(const PositionType &pos) const
check if position pos is part of the model regarding the models cut-off.
Definition: BaseModel.h:101
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:150
virtual IntensityType getCutOff() const
get cutoff value
Definition: BaseModel.h:129
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
RawDataVector::iterator PeakIterator
Raw data iterator type.
Definition: OptimizePick.h:53
void fillIntensities(PeakIterator begin, PeakIterator end) const
Convenience function that applies fillIntensity() to an iterator range.
Definition: BaseModel.h:120
virtual void updateMembers_()
This method is used to update extra member variables at the end of the setParameters() method...
Definition: BaseModel.h:158
virtual void getSamples(std::ostream &os)
fill stream with reasonable set of samples from the model (i.e. for printing)
Definition: BaseModel.h:145
virtual void getSamples(SamplesType &cont) const =0
get reasonable set of samples from the model (i.e. for printing)
DPosition< D > PositionType
Definition: BaseModel.h:59
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
BaseModel()
Default constructor.
Definition: BaseModel.h:65
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:111
double CoordinateType
Definition: BaseModel.h:58
double IntensityType
Definition: BaseModel.h:57
virtual ~BaseModel()
Destructor.
Definition: BaseModel.h:79
virtual DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:51
static void registerChildren()
register all derived classes here (implemented in file BaseModel_impl.h)
IntensityType cut_off_
Definition: BaseModel.h:156
virtual IntensityType getIntensity(const PositionType &pos) const =0
access model predicted intensity at position pos
std::vector< PeakType > SamplesType
Definition: BaseModel.h:61
virtual BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:84
Metafunction to choose among Peak1D respectively Peak2D through a template argument.
Definition: DPeak.h:61
DPeak< D >::Type PeakType
Definition: BaseModel.h:60
virtual void setCutOff(IntensityType cut_off)
set cutoff value
Definition: BaseModel.h:135
BaseModel(const BaseModel &source)
copy constructor
Definition: BaseModel.h:72

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13