Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SimpleSeeder.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 
36 
37 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
38 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
39 
43 
44 #include <algorithm>
45 #include <vector>
46 #include <iostream>
47 
48 namespace OpenMS
49 {
60  template <class PeakType, class FeatureType>
61  class SimpleSeeder :
62  public FeaFiModule<PeakType, FeatureType>,
63  public FeatureFinderDefs
64  {
65 public:
68 
71  Base(map, features, ff),
72  initialized_(false)
73  {
74  this->setName("SimpleSeeder");
75 
76  this->defaults_.setValue("min_intensity", 0.0, "Absolute value for the minimum intensity required for a seed.");
77  this->defaults_.setMinFloat("min_intensity", 0.0);
78  this->defaults_.setValue("signal_to_noise", 10.0, "Minimal required SignalToNoise (S/N) ratio for a seed.");
79  this->defaults_.setMinFloat("signal_to_noise", 0.0);
80 
81  //this->subsections_.push_back("SignalToNoiseEstimationParameter");
82  SignalToNoiseEstimatorMedian<typename MapType::SpectrumType> sne; // make sure this is the same as in pick()!
83  this->defaults_.insert("SignalToNoiseEstimationParameter:", sne.getDefaults());
84 
85  this->defaultsToParam_();
86  }
87 
89  virtual ~SimpleSeeder()
90  {
91  }
92 
95  {
96  if (!initialized_)
97  {
98  initialize_();
99  }
100 
101  // while the current peak is either already used or in a feature jump to next peak...
102  while (current_peak_ != indices_.end() && this->ff_->getPeakFlag(*current_peak_) == USED)
103  {
104  ++current_peak_;
105  }
106 
107  if (current_peak_ == indices_.end())
108  {
109  // if no seed was found:
110  if (indices_.empty()) throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, IndexPair());
111  else throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, *(current_peak_ - 1));
112  }
113 
114  this->ff_->setProgress(current_peak_ - indices_.begin());
115 
116  // set flag
117  this->ff_->getPeakFlag(*current_peak_) = USED;
118 
119  return *(current_peak_++);
120  } // nextSeed
121 
122 protected:
123 
124  void initialize_()
125  {
126  // determine mininum intensity and signal-to-noise parameter for last seed
127  typename FeatureType::IntensityType noise_threshold = this->param_.getValue("min_intensity");
128  typename FeatureType::IntensityType sn = this->param_.getValue("signal_to_noise");
129 
130 #ifdef DEBUG_FEATUREFINDER
131  std::cout << "Intensity threshold: " << noise_threshold << std::endl;
132  std::cout << "S/N: " << sn << std::endl;
133 #endif
134 
135  // fill indices_ for peaks above noise threshold and S/N
136  IndexPair tmp = std::make_pair(0, 0);
137  if (sn == 0)
138  {
139  while (tmp.first < (*this->map_).size())
140  {
141  tmp.second = 0;
142  while (tmp.second < (*this->map_)[tmp.first].size())
143  {
144  if (this->getPeakIntensity(tmp) > noise_threshold)
145  {
146  indices_.push_back(tmp);
147  }
148  ++tmp.second;
149  }
150  ++tmp.first;
151  }
152  }
153  else
154  {
156  Param param(this->param_.copy("SignalToNoiseEstimationParameter:", true));
157  estimator.setParameters(param);
158 
159  for (typename MapType::ConstIterator it = (*this->map_).begin(); it != (*this->map_).end(); ++it)
160  {
161  estimator.init(it->begin(), it->end());
162  tmp.second = 0;
163  for (typename MapType::SpectrumType::ConstIterator spec = it->begin(); spec != it->end(); ++spec)
164  {
165  if (estimator.getSignalToNoise(spec) > sn && this->getPeakIntensity(tmp) > noise_threshold)
166  {
167  indices_.push_back(tmp);
168  }
169  ++tmp.second;
170  }
171  ++tmp.first;
172  }
173  }
174 
175 #ifdef DEBUG_FEATUREFINDER
176  std::cout << "Number of peaks above threshold (" << noise_threshold << ") and S/N (" << sn << "): " << indices_.size() << std::endl;
177 #endif
178 
179  // sort index vector by intensity of peaks (highest first)
180  sort(indices_.begin(), indices_.end(),
182  );
183 
184  // progress logger
185  this->ff_->startProgress(0, indices_.size(), "FeatureFinder");
186 
187  current_peak_ = indices_.begin();
188 
189  initialized_ = true;
190  }
191 
193  std::vector<IndexPair> indices_;
194 
196  std::vector<IndexPair>::const_iterator current_peak_;
197 
200 
201 private:
203  SimpleSeeder();
207  SimpleSeeder(const SimpleSeeder &);
208 
209  }; // class SimpleSeeder
210 
211 } // namespace OpenMS
212 
213 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:130
Implements a module of the FeatureFinder algorithm.
Definition: FeaFiModule.h:157
void initialize_()
Definition: SimpleSeeder.h:124
IsotopeCluster::IndexPair IndexPair
Index to peak consisting of two UInts (scan index / peak index)
Definition: FeatureFinderDefs.h:54
Definition: FeatureFinderDefs.h:63
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.
const Param & getDefaults() const
Non-mutable access to the default parameters.
FeaFiModule< PeakType, FeatureType > Base
Definition: SimpleSeeder.h:66
void insert(const String &prefix, const Param &param)
IntensityType getPeakIntensity(const FeatureFinderDefs::IndexPair &index) const
Returns the intensity of a peak.
Definition: FeaFiModule.h:190
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:148
A container for features.
Definition: FeatureMap.h:111
MSExperiment< PeakType > MapType
Definition: SimpleSeeder.h:67
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:261
IndexPair nextSeed()
return the next seed
Definition: SimpleSeeder.h:94
void setParameters(const Param &param)
Sets the parameters.
FeatureFinder * ff_
Pointer to the calling FeatureFinder that is used to access the feature flags and report progress...
Definition: FeaFiModule.h:415
The purpose of this struct is to provide definitions of classes and typedefs which are used throughou...
Definition: FeatureFinderDefs.h:51
const MapType * map_
Input data pointer.
Definition: FeaFiModule.h:411
SimpleSeeder & operator=(const SimpleSeeder &)
Not implemented.
std::vector< IndexPair >::const_iterator current_peak_
Points to the next peak in the peak vector.
Definition: SimpleSeeder.h:196
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
SimpleSeeder()
Not implemented.
virtual void init(const PeakIterator &it_begin, const PeakIterator &it_end)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:111
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
virtual ~SimpleSeeder()
destructor
Definition: SimpleSeeder.h:89
Comparator that allows to compare the indices of two peaks by their intensity.
Definition: FeaFiModule.h:56
Exception that is thrown if a method an invalid IndexPair is given.
Definition: FeatureFinderDefs.h:66
bool initialized_
Flag that indicates of the indices are initialized.
Definition: SimpleSeeder.h:199
Management and storage of parameters / INI files.
Definition: Param.h:69
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
Estimates the signal/noise (S/N) ratio of each data point in a scan by using the median (histogram ba...
Definition: SignalToNoiseEstimatorMedian.h:71
SimpleSeeder(const MSExperiment< PeakType > *map, FeatureMap< FeatureType > *features, FeatureFinder *ff)
Constructor.
Definition: SimpleSeeder.h:70
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:103
void startProgress(SignedSize begin, SignedSize end, const String &label) const
Initializes the progress display.
void setProgress(SignedSize value) const
Sets the current progress.
std::vector< IndexPair > indices_
contains the indizes
Definition: SimpleSeeder.h:193
The main feature finder class.
Definition: FeatureFinder.h:57
void setName(const String &name)
Mutable access to the name.
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
void setMinFloat(const String &key, DoubleReal min)
Sets the minimum value for the floating point or floating point list parameter key.
void defaultsToParam_()
Updates the parameters after the defaults have been set in the constructor.

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