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

FeatureFinderAlgorithmSimplest.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 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H
00036 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H
00037 
00038 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithm.h>
00039 
00040 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/SimpleSeeder.h>
00041 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/SimpleExtender.h>
00042 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/ModelFitter.h>
00043 
00044 namespace OpenMS
00045 {
00057   template <class PeakType, class FeatureType>
00058   class FeatureFinderAlgorithmSimplest :
00059     public FeatureFinderAlgorithm<PeakType, FeatureType>,
00060     public FeatureFinderDefs
00061   {
00062 
00063 public:
00065     FeatureFinderAlgorithmSimplest() :
00066       FeatureFinderAlgorithm<PeakType, FeatureType>()
00067     {
00068       this->defaults_ = getDefaultParameters();
00069       this->check_defaults_ =  false;
00070     }
00071 
00072     virtual Param getDefaultParameters() const
00073     {
00074       Param tmp;
00075 
00076       SimpleSeeder<PeakType, FeatureType> seeder(this->map_, this->features_, this->ff_);
00077       tmp.insert("seeder:", seeder.getParameters());
00078       tmp.setSectionDescription("seeder", "Settings for the seeder (Determines potential feature regions)");
00079 
00080       SimpleExtender<PeakType, FeatureType> extender(this->map_, this->features_, this->ff_);
00081       tmp.insert("extender:", extender.getParameters());
00082       tmp.setSectionDescription("extender", "Settings for the extender (Collects all peaks belonging to a feature)");
00083 
00084       ModelFitter<PeakType, FeatureType> fitter(this->map_, this->features_, this->ff_);
00085       tmp.insert("fitter:", fitter.getParameters());
00086       tmp.setSectionDescription("fitter", "Settings for the modefitter (Fits a model to the data determinging the probapility that they represent a feature.)");
00087 
00088       return tmp;
00089     }
00090 
00091     virtual void run()
00092     {
00093 #ifdef DEBUG_FEATUREFINDER
00094       UInt seed_nr = 0;
00095 #endif
00096       SimpleSeeder<PeakType, FeatureType> seeder(this->map_, this->features_, this->ff_);
00097       seeder.setParameters(this->getParameters().copy("seeder:", true));
00098 
00099       SimpleExtender<PeakType, FeatureType> extender(this->map_, this->features_, this->ff_);
00100       extender.setParameters(this->getParameters().copy("extender:", true));
00101 
00102       ModelFitter<PeakType, FeatureType> fitter(this->map_, this->features_, this->ff_);
00103       Param params;
00104       params.setDefaults(this->getParameters().copy("fitter:", true));
00105       params.setValue("fit_algorithm", "simplest");
00106       fitter.setParameters(params);
00107 
00109       Summary summary;
00110 
00111       try
00112       {
00113         for (;; )
00114         {
00115 #ifdef DEBUG_FEATUREFINDER
00116           std::cout << "===============================" << std::endl;
00117           std::cout << "### Seeder (seed # " << ++seed_nr << ")..." << std::endl;
00118 #endif
00119           IndexPair seed = seeder.nextSeed();
00120 
00121 #ifdef DEBUG_FEATUREFINDER
00122           std::cout << "seed ... " << seed.first << " - " << seed.second << std::endl;
00123           std::cout << "### Extender..." << std::endl;
00124 #endif
00125           ChargedIndexSet index_set;
00126           index_set.insert(seed);
00127           ChargedIndexSet region;
00128           extender.extend(index_set, region);
00129 
00130 #ifdef DEBUG_FEATUREFINDER
00131           std::cout << "### ModelFitter..." << std::endl;
00132 #endif
00133           try
00134           {
00135             this->features_->push_back(fitter.fit(region));
00136 
00137             // gather information for fitting summary
00138             {
00139               const Feature & f = this->features_->back();
00140 
00141               // quality, correlation
00142               DoubleReal corr = f.getOverallQuality();
00143               summary.corr_mean += corr;
00144               if (corr < summary.corr_min) summary.corr_min = corr;
00145               if (corr > summary.corr_max) summary.corr_max = corr;
00146 
00147               // charge
00148               UInt ch = f.getCharge();
00149               if (ch >= summary.charge.size())
00150               {
00151                 summary.charge.resize(ch + 1);
00152               }
00153               summary.charge[ch]++;
00154 
00155               // MZ model type
00156               const Param & p = f.getModelDescription().getParam();
00157               ++summary.mz_model[p.getValue("MZ")];
00158 
00159               // standard deviation of isotopic peaks
00160               if (p.exists("MZ:isotope:stdev") && p.getValue("MZ:isotope:stdev") != DataValue::EMPTY)
00161               {
00162                 ++summary.mz_stdev[p.getValue("MZ:isotope:stdev")];
00163               }
00164             }
00165           }
00166           catch (Exception::UnableToFit ex)
00167           {
00168             std::cout << "UnableToFit: " << ex.what() << std::endl;
00169 
00170             // set unused flag for all data points
00171             for (IndexSet::const_iterator it = region.begin(); it != region.end(); ++it)
00172             {
00173               this->ff_->getPeakFlag(*it) = UNUSED;
00174             }
00175 
00176             // gather information for fitting summary
00177             {
00178               ++summary.no_exceptions;
00179               ++summary.exception[ex.getName()];
00180             }
00181           }
00182         }             // for
00183       }           // try
00184       catch (NoSuccessor ex)
00185       {
00186       }
00187 
00188       this->ff_->endProgress();
00189 
00190       // print fitting summary
00191       {
00192         Size size = this->features_->size();
00193         std::cout << size << " features were found. " << std::endl;
00194 
00195         // compute corr_mean
00196         summary.corr_mean /= size;
00197 
00198         std::cout << "FeatureFinder summary:\n"
00199                   << "Correlation:\n\tminimum: " << summary.corr_min << "\n\tmean: " << summary.corr_mean
00200                   << "\n\tmaximum: " << summary.corr_max << std::endl;
00201 
00202         std::cout << "Exceptions:\n";
00203         for (std::map<String, UInt>::const_iterator it = summary.exception.begin(); it != summary.exception.end(); ++it)
00204         {
00205           std::cout << "\t" << it->first << ": " << it->second * 100 / summary.no_exceptions << "% (" << it->second << ")\n";
00206         }
00207 
00208         std::cout << "Chosen mz models:\n";
00209         for (std::map<String, UInt>::const_iterator it = summary.mz_model.begin(); it != summary.mz_model.end(); ++it)
00210         {
00211           std::cout << "\t" << it->first << ": " << it->second * 100 / size << "% (" << it->second << ")\n";
00212         }
00213 
00214         std::cout << "Chosen mz stdevs:\n";
00215         for (std::map<float, UInt>::const_iterator it = summary.mz_stdev.begin(); it != summary.mz_stdev.end(); ++it)
00216         {
00217           std::cout << "\t" << it->first << ": " << it->second * 100 / (size - summary.charge[0]) << "% (" << it->second << ")\n";
00218         }
00219 
00220         std::cout << "Charges:\n";
00221         for (Size i = 1; i < summary.charge.size(); ++i)
00222         {
00223           if (summary.charge[i] != 0)
00224           {
00225             std::cout << "\t+" << i << ": " << summary.charge[i] * 100 / (size - summary.charge[0]) << "% (" << summary.charge[i] << ")\n";
00226           }
00227         }
00228       }
00229     }         // run
00230 
00231     static FeatureFinderAlgorithm<PeakType, FeatureType> * create()
00232     {
00233       return new FeatureFinderAlgorithmSimplest();
00234     }
00235 
00236     static const String getProductName()
00237     {
00238       return "simplest";
00239     }
00240 
00241 private:
00243     FeatureFinderAlgorithmSimplest & operator=(const FeatureFinderAlgorithmSimplest &);
00245     FeatureFinderAlgorithmSimplest(const FeatureFinderAlgorithmSimplest &);
00246 
00247   };   // FeatureFinderAlgorithmSimplest
00248 
00249 } // namespace OpenMS
00250 
00251 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLEST_H

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