OpenMS  3.0.0
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-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: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 #include <OpenMS/KERNEL/DPeak.h>
39 
40 namespace OpenMS
41 {
42 
49  template <UInt D>
50  class BaseModel :
51  public DefaultParamHandler
52  {
53 
54 public:
55 
56  typedef double IntensityType;
57  typedef double CoordinateType;
59  typedef typename DPeak<D>::Type PeakType;
60  typedef std::vector<PeakType> SamplesType;
61 
62 
65  DefaultParamHandler("BaseModel")
66  {
67  defaults_.setValue("cutoff", 0.0, "Low intensity cutoff of the model. Peaks below this intensity are not considered part of the model.");
68  }
69 
71  BaseModel(const BaseModel & source) :
72  DefaultParamHandler(source),
73  cut_off_(source.cut_off_)
74  {
75  }
76 
78  ~BaseModel() override
79  {
80  }
81 
83  virtual BaseModel & operator=(const BaseModel & source)
84  {
85  if (&source == this) return *this;
86 
88  cut_off_ = source.cut_off_;
89 
90  return *this;
91  }
92 
94  static void registerChildren();
95 
97  virtual IntensityType getIntensity(const PositionType & pos) const = 0;
98 
100  virtual bool isContained(const PositionType & pos) const
101  {
102  return getIntensity(pos) >= cut_off_;
103  }
104 
109  template <typename PeakType>
110  void fillIntensity(PeakType & peak) const
111  {
112  peak.setIntensity(getIntensity(peak.getPosition()));
113  }
114 
118  template <class PeakIterator>
120  {
121  for (PeakIterator it = begin; it != end; ++it)
122  {
123  fillIntensity(*it);
124  }
125  }
126 
128  virtual IntensityType getCutOff() const
129  {
130  return cut_off_;
131  }
132 
134  virtual void setCutOff(IntensityType cut_off)
135  {
136  cut_off_ = cut_off;
137  param_.setValue("cutoff", cut_off_);
138  }
139 
141  virtual void getSamples(SamplesType & cont) const = 0;
142 
144  virtual void getSamples(std::ostream & os)
145  {
146  SamplesType samples;
147  getSamples(samples);
148  for (typename SamplesType::const_iterator it = samples.begin(); it != samples.end(); ++it)
149  {
150  os << *it << std::endl;
151  }
152  }
153 
154 protected:
156 
157  void updateMembers_() override
158  {
159  cut_off_ = (double)param_.getValue("cutoff");
160  }
161 
162  };
163 }
164 
LogStream.h
DefaultParamHandler.h
OpenMS::SpectrumSettings::CENTROID
centroid data or stick data
Definition: SpectrumSettings.h:73
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
Size
OpenMS::BaseModel::~BaseModel
~BaseModel() override
Destructor.
Definition: BaseModel.h:78
double
OpenMS::Param::setValue
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.
OpenMS::DefaultParamHandler::operator=
virtual DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
DPeak.h
OpenMS::BaseModel::IntensityType
double IntensityType
Definition: BaseModel.h:56
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::BaseModel::isContained
virtual bool isContained(const PositionType &pos) const
check if position pos is part of the model regarding the models cut-off.
Definition: BaseModel.h:100
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::BaseModel::getSamples
virtual void getSamples(std::ostream &os)
fill stream with reasonable set of samples from the model (i.e. for printing)
Definition: BaseModel.h:144
OpenMS::BaseModel::SamplesType
std::vector< PeakType > SamplesType
Definition: BaseModel.h:60
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::DPeak
Metafunction to choose among Peak1D respectively Peak2D through a template argument.
Definition: DPeak.h:60
OpenMS::MSExperiment::size
Size size() const
Definition: MSExperiment.h:120
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::BaseModel::operator=
virtual BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:83
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::OptimizationFunctions::PeakIterator
RawDataVector::iterator PeakIterator
Profile data iterator type.
Definition: OptimizePick.h:58
OpenMS::BaseModel::cut_off_
IntensityType cut_off_
Definition: BaseModel.h:155
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::BaseModel::setCutOff
virtual void setCutOff(IntensityType cut_off)
set cutoff value
Definition: BaseModel.h:134
OpenMS::BaseModel::CoordinateType
double CoordinateType
Definition: BaseModel.h:57
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::BaseModel::BaseModel
BaseModel(const BaseModel &source)
copy constructor
Definition: BaseModel.h:71
OpenMS::MSExperiment::empty
bool empty() const
Definition: MSExperiment.h:130
OpenMS::DPosition< D >
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
MSExperiment.h
OpenMS::BaseModel::BaseModel
BaseModel()
Default constructor.
Definition: BaseModel.h:64
OpenMS::MorphologicalFilter::filterExperiment
void filterExperiment(PeakMap &exp)
Applies the morphological filtering operation to an MSExperiment.
Definition: MorphologicalFilter.h:327
OpenMS::BaseModel::fillIntensity
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:110
OpenMS::BaseModel::updateMembers_
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: BaseModel.h:157
OpenMS::BaseModel::registerChildren
static void registerChildren()
register all derived classes here (implemented in file BaseModel_impl.h)
MorphologicalFilter.h
OpenMS::DefaultParamHandler::defaults_
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:173
OpenMS::BaseModel::getIntensity
virtual IntensityType getIntensity(const PositionType &pos) const =0
access model predicted intensity at position pos
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:69
OpenMS::BaseModel::PeakType
DPeak< D >::Type PeakType
Definition: BaseModel.h:59
OpenMS::BaseModel::PositionType
DPosition< D > PositionType
Definition: BaseModel.h:58
OpenMS::BaseModel::getCutOff
virtual IntensityType getCutOff() const
get cutoff value
Definition: BaseModel.h:128
OpenMS::Param::getValue
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
OpenMS::MorphologicalFilter
This class implements baseline filtering operations using methods from mathematical morphology.
Definition: MorphologicalFilter.h:160
OpenMS::BaseModel
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:50
OpenMS::BaseModel::getSamples
virtual void getSamples(SamplesType &cont) const =0
get reasonable set of samples from the model (i.e. for printing)
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
TOPPBase.h
OpenMS::BaseModel::fillIntensities
void fillIntensities(PeakIterator begin, PeakIterator end) const
Convenience function that applies fillIntensity() to an iterator range.
Definition: BaseModel.h:119
OpenMS::DefaultParamHandler::param_
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:166
OpenMS::DataProcessing::BASELINE_REDUCTION
Baseline reduction.
Definition: DataProcessing.h:66