Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FeatureFinderAlgorithmSimplest.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-2013.
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: Clemens Groepl $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H
36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H
37 
39 
43 
44 namespace OpenMS
45 {
57  template <class PeakType, class FeatureType>
59  public FeatureFinderAlgorithm<PeakType, FeatureType>,
60  public FeatureFinderDefs
61  {
62 
63 public:
66  FeatureFinderAlgorithm<PeakType, FeatureType>()
67  {
69  this->check_defaults_ = false;
70  }
71 
72  virtual Param getDefaultParameters() const
73  {
74  Param tmp;
75 
76  SimpleSeeder<PeakType, FeatureType> seeder(this->map_, this->features_, this->ff_);
77  tmp.insert("seeder:", seeder.getParameters());
78  tmp.setSectionDescription("seeder", "Settings for the seeder (Determines potential feature regions)");
79 
80  SimpleExtender<PeakType, FeatureType> extender(this->map_, this->features_, this->ff_);
81  tmp.insert("extender:", extender.getParameters());
82  tmp.setSectionDescription("extender", "Settings for the extender (Collects all peaks belonging to a feature)");
83 
84  ModelFitter<PeakType, FeatureType> fitter(this->map_, this->features_, this->ff_);
85  tmp.insert("fitter:", fitter.getParameters());
86  tmp.setSectionDescription("fitter", "Settings for the modefitter (Fits a model to the data determinging the probapility that they represent a feature.)");
87 
88  return tmp;
89  }
90 
91  virtual void run()
92  {
93 #ifdef DEBUG_FEATUREFINDER
94  UInt seed_nr = 0;
95 #endif
96  SimpleSeeder<PeakType, FeatureType> seeder(this->map_, this->features_, this->ff_);
97  seeder.setParameters(this->getParameters().copy("seeder:", true));
98 
99  SimpleExtender<PeakType, FeatureType> extender(this->map_, this->features_, this->ff_);
100  extender.setParameters(this->getParameters().copy("extender:", true));
101 
102  ModelFitter<PeakType, FeatureType> fitter(this->map_, this->features_, this->ff_);
103  Param params;
104  params.setDefaults(this->getParameters().copy("fitter:", true));
105  params.setValue("fit_algorithm", "simplest");
106  fitter.setParameters(params);
107 
109  Summary summary;
110 
111  try
112  {
113  for (;; )
114  {
115 #ifdef DEBUG_FEATUREFINDER
116  std::cout << "===============================" << std::endl;
117  std::cout << "### Seeder (seed # " << ++seed_nr << ")..." << std::endl;
118 #endif
119  IndexPair seed = seeder.nextSeed();
120 
121 #ifdef DEBUG_FEATUREFINDER
122  std::cout << "seed ... " << seed.first << " - " << seed.second << std::endl;
123  std::cout << "### Extender..." << std::endl;
124 #endif
125  ChargedIndexSet index_set;
126  index_set.insert(seed);
127  ChargedIndexSet region;
128  extender.extend(index_set, region);
129 
130 #ifdef DEBUG_FEATUREFINDER
131  std::cout << "### ModelFitter..." << std::endl;
132 #endif
133  try
134  {
135  this->features_->push_back(fitter.fit(region));
136 
137  // gather information for fitting summary
138  {
139  const Feature & f = this->features_->back();
140 
141  // quality, correlation
142  DoubleReal corr = f.getOverallQuality();
143  summary.corr_mean += corr;
144  if (corr < summary.corr_min) summary.corr_min = corr;
145  if (corr > summary.corr_max) summary.corr_max = corr;
146 
147  // charge
148  UInt ch = f.getCharge();
149  if (ch >= summary.charge.size())
150  {
151  summary.charge.resize(ch + 1);
152  }
153  summary.charge[ch]++;
154 
155  // MZ model type
156  const Param & p = f.getModelDescription().getParam();
157  ++summary.mz_model[p.getValue("MZ")];
158 
159  // standard deviation of isotopic peaks
160  if (p.exists("MZ:isotope:stdev") && p.getValue("MZ:isotope:stdev") != DataValue::EMPTY)
161  {
162  ++summary.mz_stdev[p.getValue("MZ:isotope:stdev")];
163  }
164  }
165  }
166  catch (Exception::UnableToFit ex)
167  {
168  std::cout << "UnableToFit: " << ex.what() << std::endl;
169 
170  // set unused flag for all data points
171  for (IndexSet::const_iterator it = region.begin(); it != region.end(); ++it)
172  {
173  this->ff_->getPeakFlag(*it) = UNUSED;
174  }
175 
176  // gather information for fitting summary
177  {
178  ++summary.no_exceptions;
179  ++summary.exception[ex.getName()];
180  }
181  }
182  } // for
183  } // try
184  catch (NoSuccessor ex)
185  {
186  }
187 
188  this->ff_->endProgress();
189 
190  // print fitting summary
191  {
192  Size size = this->features_->size();
193  std::cout << size << " features were found. " << std::endl;
194 
195  // compute corr_mean
196  summary.corr_mean /= size;
197 
198  std::cout << "FeatureFinder summary:\n"
199  << "Correlation:\n\tminimum: " << summary.corr_min << "\n\tmean: " << summary.corr_mean
200  << "\n\tmaximum: " << summary.corr_max << std::endl;
201 
202  std::cout << "Exceptions:\n";
203  for (std::map<String, UInt>::const_iterator it = summary.exception.begin(); it != summary.exception.end(); ++it)
204  {
205  std::cout << "\t" << it->first << ": " << it->second * 100 / summary.no_exceptions << "% (" << it->second << ")\n";
206  }
207 
208  std::cout << "Chosen mz models:\n";
209  for (std::map<String, UInt>::const_iterator it = summary.mz_model.begin(); it != summary.mz_model.end(); ++it)
210  {
211  std::cout << "\t" << it->first << ": " << it->second * 100 / size << "% (" << it->second << ")\n";
212  }
213 
214  std::cout << "Chosen mz stdevs:\n";
215  for (std::map<float, UInt>::const_iterator it = summary.mz_stdev.begin(); it != summary.mz_stdev.end(); ++it)
216  {
217  std::cout << "\t" << it->first << ": " << it->second * 100 / (size - summary.charge[0]) << "% (" << it->second << ")\n";
218  }
219 
220  std::cout << "Charges:\n";
221  for (Size i = 1; i < summary.charge.size(); ++i)
222  {
223  if (summary.charge[i] != 0)
224  {
225  std::cout << "\t+" << i << ": " << summary.charge[i] * 100 / (size - summary.charge[0]) << "% (" << summary.charge[i] << ")\n";
226  }
227  }
228  }
229  } // run
230 
232  {
233  return new FeatureFinderAlgorithmSimplest();
234  }
235 
236  static const String getProductName()
237  {
238  return "simplest";
239  }
240 
241 private:
246 
247  }; // FeatureFinderAlgorithmSimplest
248 
249 } // namespace OpenMS
250 
251 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H
virtual Param getDefaultParameters() const
Returns the default parameters. Reimplment.
Definition: FeatureFinderAlgorithmSimplest.h:72
UInt no_exceptions
Definition: FeatureFinderAlgorithm.h:53
const ChargeType & getCharge() const
Non-mutable access to charge state.
void extend(const ChargedIndexSet &seed_region, ChargedIndexSet &result_region)
return next seed
Definition: SimpleExtender.h:127
IsotopeCluster::IndexPair IndexPair
Index to peak consisting of two UInts (scan index / peak index)
Definition: FeatureFinderDefs.h:54
FeatureMapType * features_
Output data pointer.
Definition: FeatureFinderAlgorithm.h:144
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!...
Definition: DefaultParamHandler.h:155
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
A more convenient string class.
Definition: String.h:56
const ModelDescription< 2 > & getModelDescription() const
Non-mutable access to the model description.
void insert(const String &prefix, const Param &param)
FeatureFinder * ff_
Pointer to the calling FeatureFinder that is used to access the feature flags.
Definition: FeatureFinderAlgorithm.h:147
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
QualityType getOverallQuality() const
Non-mutable access to the overall quality.
Definition: FeatureFinderDefs.h:63
DoubleReal corr_mean
Definition: FeatureFinderAlgorithm.h:57
const MapType * map_
Input data pointer.
Definition: FeatureFinderAlgorithm.h:141
std::map< String, UInt > mz_model
Definition: FeatureFinderAlgorithm.h:54
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:63
Abstract base class for FeatureFinder algorithms.
Definition: FeatureFinderAlgorithm.h:74
void setSectionDescription(const String &key, const String &description)
Sets a description for an existing section.
static const String getProductName()
Definition: FeatureFinderAlgorithmSimplest.h:236
std::map< float, UInt > mz_stdev
Definition: FeatureFinderAlgorithm.h:55
IndexPair nextSeed()
return the next seed
Definition: SimpleSeeder.h:94
void setParameters(const Param &param)
Sets the parameters.
The purpose of this struct is to provide definitions of classes and typedefs which are used throughou...
Definition: FeatureFinderDefs.h:51
DoubleReal corr_max
Definition: FeatureFinderAlgorithm.h:57
virtual void run()
Main method that implements the actual algorithm.
Definition: FeatureFinderAlgorithmSimplest.h:91
void endProgress() const
Ends the progress display.
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
FeatureFinderAlgorithmSimplest & operator=(const FeatureFinderAlgorithmSimplest &)
Not implemented.
std::map< String, UInt > exception
Definition: FeatureFinderAlgorithm.h:52
virtual const char * what() const
Returns the error message of the exception.
const char * getName() const
Returns the name of the exception.
FeatureFinderAlgorithm implementation using the Simple* modules.
Definition: FeatureFinderAlgorithmSimplest.h:58
void setDefaults(const Param &defaults, const String &prefix="", bool showMessage=false)
Insert all values of defaults and adds the prefix prefix, if the values are not already set...
std::vector< UInt > charge
Definition: FeatureFinderAlgorithm.h:56
Summary of fitting results.
Definition: FeatureFinderAlgorithm.h:50
Simple feature extension algorithm.
Definition: SimpleExtender.h:79
Tests a group of data points in an LC-MS map for goodness-of-fit with a 2D averagine model...
Definition: ModelFitter.h:77
bool exists(const String &key) const
Tests if a parameter is set (expecting its fully qualified name, e.g., TextExporter:1:proteins_only) ...
Exception that is thrown if a method an invalid IndexPair is given.
Definition: FeatureFinderDefs.h:66
An LC-MS feature.
Definition: Feature.h:66
Management and storage of parameters / INI files.
Definition: Param.h:69
static FeatureFinderAlgorithm< PeakType, FeatureType > * create()
Definition: FeatureFinderAlgorithmSimplest.h:231
DoubleReal corr_min
Definition: FeatureFinderAlgorithm.h:57
Exception used if an error occurred while fitting a model to a given dataset.
Definition: Exception.h:662
index set with associated charge estimate
Definition: IsotopeCluster.h:53
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
const Param & getParam() const
Non-mutable access to model parameters.
Definition: ModelDescription.h:127
bool check_defaults_
If this member is set to false no checking if parameters in done;.
Definition: DefaultParamHandler.h:174
FeatureFinderAlgorithmSimplest()
default constructor
Definition: FeatureFinderAlgorithmSimplest.h:65
const Flag & getPeakFlag(const IndexPair &index) const
Returns a non-mutable reference to a peak flag.
Definition: FeatureFinder.h:91
Simple seeding class that uses the strongest peak as next seed.
Definition: SimpleSeeder.h:61
Feature fit(const ChargedIndexSet &index_set)
Return next feature.
Definition: ModelFitter.h:226
const Param & getParameters() const
Non-mutable access to the parameters.

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:13 using doxygen 1.8.5