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

SimpleSeeder.h (Maintainer: Marcel Grunert, Clemens Groepl)

Go to the documentation of this file.
00001 // -*- mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Marcel Grunert, Clemens Groepl$
00025 // --------------------------------------------------------------------------
00026 
00027 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinder.h>
00028 
00029 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00030 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00031 
00032 #include <OpenMS/CONCEPT/Types.h>
00033 #include <OpenMS/CONCEPT/Exception.h>
00034 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeaFiModule.h>
00035 
00036 
00037 #include <algorithm>
00038 #include <vector>
00039 #include <iostream>
00040 
00041 namespace OpenMS
00042 {
00053   template<class PeakType, class FeatureType> class SimpleSeeder :
00054     public FeaFiModule<PeakType, FeatureType>,
00055     public FeatureFinderDefs
00056   {
00057     public:
00058       typedef FeaFiModule<PeakType,FeatureType> Base;
00059 
00061       SimpleSeeder(const MSExperiment<PeakType>* map, FeatureMap<FeatureType>* features, FeatureFinder* ff) :
00062         Base(map,features,ff),
00063         initialized_(false)
00064       {
00065         this->setName("SimpleSeeder");        
00066         this->defaults_.setValue("min_intensity",1.0f, "Absolute value for the minimum intensity of a seed. If set to 0, a fixed percentage of the intensity of the largest peak is taken (see intensity_perc).", false);
00067         this->defaults_.setMinFloat("min_intensity",0.0);
00068         this->defaults_.setValue("intensity_perc",20.0f, "Minimum percentage of the intensity of the largest peak that a seed has to have (used only if min_intensity is set to 0).", false);
00069         this->defaults_.setMinFloat("intensity_perc",0.0);
00070         this->defaults_.setMaxFloat("intensity_perc",100.0);
00071         
00072         this->defaultsToParam_();
00073       }
00075       virtual ~SimpleSeeder()
00076       {
00077       }
00078 
00080       IndexPair nextSeed() throw (NoSuccessor)
00081       { 
00082         if (!initialized_)
00083         {
00084           initialize_();
00085         }
00086 
00087         // while the current peak is either already used or in a feature jump to next peak...
00088         while (current_peak_ != indices_.end() && this->ff_->getPeakFlag(*current_peak_) == USED) 
00089         {
00090           ++current_peak_;
00091         }
00092 
00093         if (current_peak_ == indices_.end()) 
00094         {
00095           throw NoSuccessor(__FILE__, __LINE__,__PRETTY_FUNCTION__, *current_peak_);
00096         }
00097 
00098         this->ff_->setProgress(current_peak_-indices_.begin());
00099 
00100         // set flag
00101         this->ff_->getPeakFlag(*current_peak_) = USED;
00102 
00103         return *(current_peak_++);
00104       } // nextSeed
00105 
00106     protected:
00107 
00108       void initialize_()
00109       {
00110         // determine mininum intensity for last seed
00111         typename FeatureType::IntensityType noise_threshold  = this->param_.getValue("min_intensity");
00112         if (noise_threshold == 0.0)
00113         {
00114           noise_threshold =
00115             typename FeatureType::IntensityType(this->param_.getValue("intensity_perc"))
00116             * (*this->map_).getMaxInt()
00117             / 100.0;
00118         }
00119         //#ifdef DEBUG_FEATUREFINDER
00120         std::cout << "Threshold: " << noise_threshold << std::endl;     
00121         //#endif
00122 
00123         // fill indices_ for peaks above noise threshold
00124         IndexPair tmp = std::make_pair(0,0);
00125         while (tmp.first < (*this->map_).size())
00126         {
00127           tmp.second = 0;
00128           while (tmp.second < (*this->map_)[tmp.first].size())
00129           {
00130             if (this->getPeakIntensity(tmp)>noise_threshold)
00131             {
00132               indices_.push_back(tmp);
00133             }
00134             ++tmp.second;
00135           }
00136           ++tmp.first;
00137         }
00138 
00139         //#ifdef DEBUG_FEATUREFINDER
00140         std::cout << "Number of peaks above threshold (" << noise_threshold << "): " << indices_.size() << std::endl;
00141         //#endif
00142 
00143         // sort index vector by intensity of peaks (highest first)
00144         sort(indices_.begin(),indices_.end(),
00145             reverseComparator(Internal::IntensityLess<Base>(*this))
00146             );
00147 
00148         // progress logger
00149         this->ff_->startProgress(0, indices_.size() , "FeatureFinder");
00150 
00151         current_peak_ = indices_.begin();
00152 
00153         initialized_ = true;
00154         return;
00155       }
00156 
00158       std::vector<IndexPair> indices_;
00159 
00161       std::vector<IndexPair>::const_iterator current_peak_;
00162 
00164       bool initialized_;
00165 
00166     private:
00168       SimpleSeeder();
00170       SimpleSeeder& operator=(const SimpleSeeder&);
00172       SimpleSeeder(const SimpleSeeder&);
00173 
00174   }; // class SimpleSeeder
00175 
00176 } // namespace OpenMS
00177 
00178 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00179 

Generated Tue Apr 1 15:36:38 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1