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

ParentPeakMower.h (Maintainer: Andreas Bertsch)

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: Andreas Bertsch $
00025 // --------------------------------------------------------------------------
00026 //
00027 #ifndef OPENMS_FILTERING_TRANSFORMERS_PARENTPEAKMOWER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_PARENTPEAKMOWER_H
00029 
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <vector>
00032 
00033 namespace OpenMS
00034 {
00035 
00043   class ParentPeakMower : public PreprocessingFunctor
00044   {
00045   public:
00046 
00047     // @name Constructors and Destructors
00048     // @{
00050     ParentPeakMower();
00051 
00053     ParentPeakMower(const ParentPeakMower& source);
00054 
00056     virtual ~ParentPeakMower();
00057     // @}
00058 
00059     // @name Operators
00060     // @{
00062     ParentPeakMower& operator = (const ParentPeakMower& source);
00063     // @}
00064 
00065     // @name Accessors
00066     // @{
00068     static PreprocessingFunctor* create() { return new ParentPeakMower(); }
00069 
00071     template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00072     {
00073       typedef typename SpectrumType::ConstIterator ConstIterator;
00074       typedef typename SpectrumType::Iterator Iterator;
00075       
00076       if (spectrum.getMSLevel() == 1)
00077       {
00078         std::cerr << "Error: ParenPeakMower cannot be applied to MS-level 1" << std::endl;
00079         return;
00080       }
00081 
00082       //get precursor peak position precursorpeak
00083       double pre_pos = spectrum.getPrecursorPeak().getPosition()[0];
00084     
00085       if (pre_pos == 0)
00086       {
00087         std::cerr << "ParenPeakMower: Warning, Precursor Position not set" << std::endl;
00088         return;
00089       }
00090 
00091       UInt pre_charge = spectrum.getPrecursorPeak().getCharge();
00092       if (pre_charge == 0)
00093       {
00094         UInt default_charge = (unsigned int)param_.getValue("default_charge");
00095         std::cerr << "ParentPeakMower: Warning, Precursor charge not set, assuming default charge (" << default_charge << ")" << std::endl;
00096         pre_charge = default_charge;
00097       }
00098 
00099       pre_pos *= pre_charge;
00100       
00101       // get all other parameters 
00102       bool clean_all_charge_states = (Int)param_.getValue("clean_all_charge_states");
00103       bool consider_NH3_loss = (Int)param_.getValue("consider_NH3_loss");
00104       bool consider_H2O_loss = (Int)param_.getValue("consider_H2O_loss");
00105       double window_size = (double)param_.getValue("window_size");
00106       bool reduce_by_factor = (Int)param_.getValue("reduce_by_factor");
00107       double factor = (double)param_.getValue("factor");
00108       bool set_to_zero = (Int)param_.getValue("set_to_zero");
00109     
00110       // identify the ranges which are to be considered
00111       std::vector<DRange<1> > ranges;
00112       for (UInt z = 1; z <= pre_charge; ++z)
00113       {
00114         if (clean_all_charge_states || z == pre_charge)
00115         {
00116           // no adjusting needed for this charge
00117           DPosition<1> pre_z_pos, pos;
00118           DRange<1> range;
00119           
00120           // adjust the m/z by weight of precursor and charge
00121           pre_z_pos = DPosition<1>(pre_pos / double(z));
00122           range = DRange<1>(pre_z_pos - window_size, pre_z_pos + window_size);
00123           ranges.push_back(range);
00124                     
00125           if (consider_NH3_loss)
00126           {
00127             pos = DPosition<1>(pre_z_pos - 17.0 / double(z));
00128             range = DRange<1>(pos - window_size, pos + window_size);
00129             ranges.push_back(range);
00130           }
00131           if (consider_H2O_loss)
00132           {
00133             pos = DPosition<1>(pre_z_pos - 18.0 / double(z));
00134             range = DRange<1>(pos - window_size, pos + window_size);
00135             ranges.push_back(range);
00136           }
00137         }
00138       }
00139 
00140       for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
00141       {
00142         std::cerr << *rit << std::endl;
00143       }
00144       
00145       // apply the intensity reduction to the collected ranges
00146       for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
00147       {
00148         for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
00149         {
00150           if (rit->encloses(it->getPosition()))
00151           {
00152             if (reduce_by_factor)
00153             {
00154               it->setIntensity(it->getIntensity() / factor);
00155               break;
00156             }
00157 
00158             if (set_to_zero)
00159             {
00160               it->setIntensity(0.0);
00161               break;
00162             }
00163           }
00164         }
00165       }
00166       
00167       return;
00168     }
00169 
00170     void filterPeakSpectrum(PeakSpectrum& spectrum);
00171 
00172     void filterPeakMap(PeakMap& exp);
00173 
00175     static const String getProductName()
00176     {
00177       return "ParentPeakMower";
00178     }
00180   };
00181 
00182 }
00183 #endif // OPENMS_FILTERING/TRANSFORMERS_PARENTPEAKMOWER_H

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