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

ParentPeakMower.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_PARENTPEAKMOWER_H
00036 #define OPENMS_FILTERING_TRANSFORMERS_PARENTPEAKMOWER_H
00037 
00038 #include <OpenMS/KERNEL/StandardTypes.h>
00039 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00040 
00041 #include <vector>
00042 
00043 namespace OpenMS
00044 {
00045 
00053   class OPENMS_DLLAPI ParentPeakMower :
00054     public DefaultParamHandler
00055   {
00056 public:
00057 
00058     // @name Constructors and Destructors
00059     // @{
00061     ParentPeakMower();
00062 
00064     ParentPeakMower(const ParentPeakMower& source);
00065 
00067     virtual ~ParentPeakMower();
00068     // @}
00069 
00070     // @name Operators
00071     // @{
00073     ParentPeakMower& operator=(const ParentPeakMower& source);
00074     // @}
00075 
00076     // @name Accessors
00077     // @{
00079 
00081     template <typename SpectrumType>
00082     void filterSpectrum(SpectrumType& spectrum)
00083     {
00084       typedef typename SpectrumType::Iterator Iterator;
00085 
00086       clean_all_charge_states_ = (Int)param_.getValue("clean_all_charge_states");
00087       consider_NH3_loss_ = (Int)param_.getValue("consider_NH3_loss");
00088       consider_H2O_loss_ = (Int)param_.getValue("consider_H2O_loss");
00089       window_size_ = (DoubleReal)param_.getValue("window_size");
00090       reduce_by_factor_ = (Int)param_.getValue("reduce_by_factor");
00091       factor_ = (DoubleReal)param_.getValue("factor");
00092       set_to_zero_ = (Int)param_.getValue("set_to_zero");
00093 
00094       if (spectrum.getMSLevel() == 1)
00095       {
00096         std::cerr << "Error: ParentPeakMower cannot be applied to MS level 1" << std::endl;
00097         return;
00098       }
00099 
00100       //get precursor peak position precursorpeak
00101       double pre_pos = 0.0;
00102       if (!spectrum.getPrecursors().empty()) pre_pos = spectrum.getPrecursors()[0].getMZ();
00103 
00104       if (pre_pos == 0)
00105       {
00106         std::cerr << "ParentPeakMower: Warning, Precursor Position not set" << std::endl;
00107         return;
00108       }
00109 
00110       Size pre_charge = spectrum.getPrecursors()[0].getCharge();
00111       if (pre_charge == 0)
00112       {
00113         default_charge_ = (Size)param_.getValue("default_charge");
00114         std::cerr << "ParentPeakMower: Warning, Precursor charge not set, assuming default charge (" << default_charge_ << ")" << std::endl;
00115         pre_charge = default_charge_;
00116       }
00117 
00118       pre_pos *= pre_charge;
00119 
00120       // identify the ranges which are to be considered
00121       std::vector<DRange<1> > ranges;
00122       for (Size z = 1; z <= pre_charge; ++z)
00123       {
00124         if (clean_all_charge_states_ || z == pre_charge)
00125         {
00126           // no adjusting needed for this charge
00127           DPosition<1> pre_z_pos, pos;
00128           DRange<1> range;
00129 
00130           // adjust the m/z by weight of precursor and charge
00131           pre_z_pos = DPosition<1>(pre_pos / double(z));
00132           range = DRange<1>(pre_z_pos - window_size_, pre_z_pos + window_size_);
00133           ranges.push_back(range);
00134 
00135           if (consider_NH3_loss_)
00136           {
00137             pos = DPosition<1>(pre_z_pos - 17.0 / double(z));
00138             range = DRange<1>(pos - window_size_, pos + window_size_);
00139             ranges.push_back(range);
00140           }
00141           if (consider_H2O_loss_)
00142           {
00143             pos = DPosition<1>(pre_z_pos - 18.0 / double(z));
00144             range = DRange<1>(pos - window_size_, pos + window_size_);
00145             ranges.push_back(range);
00146           }
00147         }
00148       }
00149 
00150 //for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
00151 //{
00152 //std::cerr << *rit << std::endl;
00153 //}
00154 
00155       // apply the intensity reduction to the collected ranges
00156       for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
00157       {
00158         for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
00159         {
00160           if (rit->encloses(it->getPosition()))
00161           {
00162             if (reduce_by_factor_)
00163             {
00164               it->setIntensity(it->getIntensity() / factor_);
00165               break;
00166             }
00167 
00168             if (set_to_zero_)
00169             {
00170               it->setIntensity(0.0);
00171               break;
00172             }
00173           }
00174         }
00175       }
00176 
00177       return;
00178     }
00179 
00180     void filterPeakSpectrum(PeakSpectrum& spectrum);
00181 
00182     void filterPeakMap(PeakMap& exp);
00183 
00184     //TODO reimplement DefaultParamHandler::updateMembers_()
00185 
00187 
00188 private:
00189     Size default_charge_;
00190     bool clean_all_charge_states_;
00191     bool consider_NH3_loss_;
00192     bool consider_H2O_loss_;
00193     DoubleReal window_size_;
00194     bool reduce_by_factor_;
00195     DoubleReal factor_;
00196     bool set_to_zero_;
00197 
00198   };
00199 
00200 }
00201 #endif // OPENMS_FILTERING/TRANSFORMERS_PARENTPEAKMOWER_H

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