Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

SimpleSeeder.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl$
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 
00035 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinder.h>
00036 
00037 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00038 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00039 
00040 #include <OpenMS/CONCEPT/Exception.h>
00041 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeaFiModule.h>
00042 #include <OpenMS/FILTERING/NOISEESTIMATION/SignalToNoiseEstimatorMedian.h>
00043 
00044 #include <algorithm>
00045 #include <vector>
00046 #include <iostream>
00047 
00048 namespace OpenMS
00049 {
00060   template <class PeakType, class FeatureType>
00061   class SimpleSeeder :
00062     public FeaFiModule<PeakType, FeatureType>,
00063     public FeatureFinderDefs
00064   {
00065 public:
00066     typedef FeaFiModule<PeakType, FeatureType> Base;
00067     typedef MSExperiment<PeakType> MapType;
00068 
00070     SimpleSeeder(const MSExperiment<PeakType> * map, FeatureMap<FeatureType> * features, FeatureFinder * ff) :
00071       Base(map, features, ff),
00072       initialized_(false)
00073     {
00074       this->setName("SimpleSeeder");
00075 
00076       this->defaults_.setValue("min_intensity", 0.0, "Absolute value for the minimum intensity required for a seed.");
00077       this->defaults_.setMinFloat("min_intensity", 0.0);
00078       this->defaults_.setValue("signal_to_noise", 10.0, "Minimal required SignalToNoise (S/N) ratio for a seed.");
00079       this->defaults_.setMinFloat("signal_to_noise", 0.0);
00080 
00081       //this->subsections_.push_back("SignalToNoiseEstimationParameter");
00082       SignalToNoiseEstimatorMedian<typename MapType::SpectrumType> sne;              // make sure this is the same as in pick()!
00083       this->defaults_.insert("SignalToNoiseEstimationParameter:", sne.getDefaults());
00084 
00085       this->defaultsToParam_();
00086     }
00087 
00089     virtual ~SimpleSeeder()
00090     {
00091     }
00092 
00094     IndexPair nextSeed()
00095     {
00096       if (!initialized_)
00097       {
00098         initialize_();
00099       }
00100 
00101       // while the current peak is either already used or in a feature jump to next peak...
00102       while (current_peak_ != indices_.end() && this->ff_->getPeakFlag(*current_peak_) == USED)
00103       {
00104         ++current_peak_;
00105       }
00106 
00107       if (current_peak_ == indices_.end())
00108       {
00109         // if no seed was found:
00110         if (indices_.empty()) throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, IndexPair());
00111         else throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, *(current_peak_ - 1));
00112       }
00113 
00114       this->ff_->setProgress(current_peak_ - indices_.begin());
00115 
00116       // set flag
00117       this->ff_->getPeakFlag(*current_peak_) = USED;
00118 
00119       return *(current_peak_++);
00120     }         // nextSeed
00121 
00122 protected:
00123 
00124     void initialize_()
00125     {
00126       // determine mininum intensity and signal-to-noise parameter for last seed
00127       typename FeatureType::IntensityType noise_threshold  = this->param_.getValue("min_intensity");
00128       typename FeatureType::IntensityType sn  = this->param_.getValue("signal_to_noise");
00129 
00130 #ifdef DEBUG_FEATUREFINDER
00131       std::cout << "Intensity threshold: " << noise_threshold << std::endl;
00132       std::cout << "S/N: " << sn << std::endl;
00133 #endif
00134 
00135       // fill indices_ for peaks above noise threshold and S/N
00136       IndexPair tmp = std::make_pair(0, 0);
00137       if (sn == 0)
00138       {
00139         while (tmp.first < (*this->map_).size())
00140         {
00141           tmp.second = 0;
00142           while (tmp.second < (*this->map_)[tmp.first].size())
00143           {
00144             if (this->getPeakIntensity(tmp) > noise_threshold)
00145             {
00146               indices_.push_back(tmp);
00147             }
00148             ++tmp.second;
00149           }
00150           ++tmp.first;
00151         }
00152       }
00153       else
00154       {
00155         SignalToNoiseEstimatorMedian<typename MapType::SpectrumType> estimator;
00156         Param param(this->param_.copy("SignalToNoiseEstimationParameter:", true));
00157         estimator.setParameters(param);
00158 
00159         for (typename MapType::ConstIterator it = (*this->map_).begin(); it != (*this->map_).end(); ++it)
00160         {
00161           estimator.init(it->begin(), it->end());
00162           tmp.second = 0;
00163           for (typename MapType::SpectrumType::ConstIterator spec = it->begin(); spec != it->end(); ++spec)
00164           {
00165             if (estimator.getSignalToNoise(spec) > sn && this->getPeakIntensity(tmp) > noise_threshold)
00166             {
00167               indices_.push_back(tmp);
00168             }
00169             ++tmp.second;
00170           }
00171           ++tmp.first;
00172         }
00173       }
00174 
00175 #ifdef DEBUG_FEATUREFINDER
00176       std::cout << "Number of peaks above threshold (" << noise_threshold   << ") and S/N (" << sn << "): " << indices_.size() << std::endl;
00177 #endif
00178 
00179       // sort index vector by intensity of peaks (highest first)
00180       sort(indices_.begin(), indices_.end(),
00181            reverseComparator(Internal::IntensityLess<Base>(*this))
00182            );
00183 
00184       // progress logger
00185       this->ff_->startProgress(0, indices_.size(), "FeatureFinder");
00186 
00187       current_peak_ = indices_.begin();
00188 
00189       initialized_ = true;
00190     }
00191 
00193     std::vector<IndexPair> indices_;
00194 
00196     std::vector<IndexPair>::const_iterator current_peak_;
00197 
00199     bool initialized_;
00200 
00201 private:
00203     SimpleSeeder();
00205     SimpleSeeder & operator=(const SimpleSeeder &);
00207     SimpleSeeder(const SimpleSeeder &);
00208 
00209   };   // class SimpleSeeder
00210 
00211 } // namespace OpenMS
00212 
00213 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:44 using doxygen 1.7.1