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

BernNorm.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: Mathias Walzer $
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 //
00035 #ifndef OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
00036 #define OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
00037 
00038 #include <OpenMS/KERNEL/StandardTypes.h>
00039 
00040 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00041 
00042 #include <map>
00043 
00044 namespace OpenMS
00045 {
00057   class OPENMS_DLLAPI BernNorm :
00058     public DefaultParamHandler
00059   {
00060 public:
00061 
00062     // @name Constructors and Destructors
00064 
00065     BernNorm();
00066 
00068     BernNorm(const BernNorm & source);
00069 
00071     virtual ~BernNorm();
00073 
00074     // @name Operators
00075     // @{
00077     BernNorm & operator=(const BernNorm & source);
00079 
00080     // @name Accessors
00081     // @{
00082 
00084     template <typename SpectrumType>
00085     void filterSpectrum(SpectrumType & spectrum)
00086     {
00087       typedef typename SpectrumType::Iterator Iterator;
00088       typedef typename SpectrumType::ConstIterator ConstIterator;
00089 
00090       c1_ = (DoubleReal)param_.getValue("C1");
00091       c2_ = (DoubleReal)param_.getValue("C2");
00092       th_ = (DoubleReal)param_.getValue("threshold");
00093 
00094       spectrum.sortByPosition();
00095 
00096       // find highest peak and ranking
00097       double maxint = 0;
00098       std::map<double, Size> peakranks;
00099       for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00100       {
00101         peakranks[it->getIntensity()] = 0;
00102         if (it->getIntensity() > maxint)
00103         {
00104           maxint = it->getIntensity();
00105         }
00106       }
00107       UInt rank = 0;
00108       for (std::map<double, Size>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
00109       {
00110         mit->second = ++rank;
00111       }
00112 
00113       // find maxmz i.e. significant (> threshold * maxpeak) peak with highest m/z
00114       double maxmz = 0;
00115       for (SignedSize i = spectrum.size() - 1; i >= 0; --i)
00116       {
00117         if (spectrum[i].getIntensity() > maxint * th_)
00118         {
00119           maxmz = spectrum[i].getMZ();
00120           break;
00121         }
00122       }
00123 
00124       // rank
00125       for (Iterator it = spectrum.begin(); it != spectrum.end(); )
00126       {
00127         double newint = c1_ - (c2_ / maxmz) * peakranks[it->getIntensity()];
00128         if (newint < 0)
00129         {
00130           it = spectrum.erase(it);
00131         }
00132         else
00133         {
00134           it->setIntensity(newint);
00135           ++it;
00136         }
00137       }
00138       return;
00139     }
00140 
00141     void filterPeakSpectrum(PeakSpectrum & spectrum);
00142 
00143     void filterPeakMap(PeakMap & exp);
00144     //TODO reimplement DefaultParamHandler::updateMembers_()
00145 
00146 private:
00147     DoubleReal c1_;
00148     DoubleReal c2_;
00149     DoubleReal th_;
00150 
00151     // @}
00152 
00153   };
00154 
00155 } // namespace OpenMS
00156 
00157 #endif //OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H

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