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

RangeUtils.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: Stephan Aiche$
00032 // $Authors: Marc Sturm $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_KERNEL_RANGEUTILS_H
00036 #define OPENMS_KERNEL_RANGEUTILS_H
00037 
00038 #include <functional>
00039 #include <algorithm>
00040 #include <vector>
00041 #include <OpenMS/CONCEPT/Types.h>
00042 #include <OpenMS/DATASTRUCTURES/IntList.h>
00043 #include <OpenMS/METADATA/Precursor.h>
00044 
00045 namespace OpenMS
00046 {
00095   template <class MetaContainer>
00096   class HasMetaValue :
00097     std::unary_function<MetaContainer, bool>
00098   {
00099 public:
00106     HasMetaValue(String metavalue, bool reverse = false) :
00107       metavalue_key_(metavalue),
00108       reverse_(reverse)
00109     {}
00110 
00111     inline bool operator()(const MetaContainer & s) const
00112     {
00113       bool has_meta_value = s.metaValueExists(metavalue_key_);
00114       if (reverse_)
00115       {
00116         return !has_meta_value;
00117       }
00118       return has_meta_value;
00119     }
00120 
00121 protected:
00122     String metavalue_key_;
00123     bool reverse_;
00124   };
00125 
00126 
00134   template <class SpectrumType>
00135   class InRTRange :
00136     std::unary_function<SpectrumType, bool>
00137   {
00138 public:
00147     InRTRange(DoubleReal min, DoubleReal max, bool reverse = false) :
00148       min_(min),
00149       max_(max),
00150       reverse_(reverse)
00151     {}
00152 
00153     inline bool operator()(const SpectrumType & s) const
00154     {
00155       DoubleReal tmp = s.getRT();
00156       if (reverse_)
00157       {
00158         return min_ > tmp || max_ < tmp;
00159       }
00160       return min_ <= tmp && max_ >= tmp;
00161     }
00162 
00163 protected:
00164     DoubleReal min_, max_;
00165     bool reverse_;
00166   };
00167 
00175   template <class SpectrumType>
00176   class InMSLevelRange :
00177     std::unary_function<SpectrumType, bool>
00178   {
00179 public:
00187     InMSLevelRange(const IntList & levels, bool reverse = false) :
00188       levels_(levels),
00189       reverse_(reverse)
00190     {}
00191 
00192     inline bool operator()(const SpectrumType & s) const
00193     {
00194       Int tmp = s.getMSLevel();
00195       if (reverse_)
00196       {
00197         return std::find(levels_.begin(), levels_.end(), tmp) == levels_.end();
00198       }
00199       return std::find(levels_.begin(), levels_.end(), tmp) != levels_.end();
00200     }
00201 
00202 protected:
00203     IntList levels_;
00204     bool reverse_;
00205   };
00206 
00214   template <class SpectrumType>
00215   class HasScanMode :
00216     std::unary_function<SpectrumType, bool>
00217   {
00218 public:
00226     HasScanMode(Int mode, bool reverse = false) :
00227       mode_(mode),
00228       reverse_(reverse)
00229     {}
00230 
00231     inline bool operator()(const SpectrumType & s) const
00232     {
00233       if (reverse_)
00234       {
00235         return s.getInstrumentSettings().getScanMode() != mode_;
00236       }
00237       return s.getInstrumentSettings().getScanMode() == mode_;
00238     }
00239 
00240 protected:
00241     Int mode_;
00242     bool reverse_;
00243   };
00244 
00252   template <class SpectrumType>
00253   class IsEmptySpectrum :
00254     std::unary_function<SpectrumType, bool>
00255   {
00256 public:
00262     explicit IsEmptySpectrum(bool reverse = false) :
00263       reverse_(reverse)
00264     {}
00265 
00266     inline bool operator()(const SpectrumType & s) const
00267     {
00268       if (reverse_)
00269       {
00270         return !s.empty();
00271       }
00272       return s.empty();
00273     }
00274 
00275 protected:
00276     bool reverse_;
00277   };
00278 
00286   template <class SpectrumType>
00287   class IsZoomSpectrum :
00288     std::unary_function<SpectrumType, bool>
00289   {
00290 public:
00297     explicit IsZoomSpectrum(bool reverse = false) :
00298       reverse_(reverse)
00299     {}
00300 
00301     inline bool operator()(const SpectrumType & s) const
00302     {
00303       if (reverse_)
00304       {
00305         return !s.getInstrumentSettings().getZoomScan();
00306       }
00307       return s.getInstrumentSettings().getZoomScan();
00308     }
00309 
00310 protected:
00311     bool reverse_;
00312   };
00313 
00314 
00323   template <class SpectrumType>
00324   class HasActivationMethod :
00325     std::unary_function<SpectrumType, bool>
00326   {
00327 public:
00335     HasActivationMethod(const StringList & methods, bool reverse = false) :
00336       methods_(methods),
00337       reverse_(reverse)
00338     {}
00339 
00340     inline bool operator()(const SpectrumType & s) const
00341     {
00342       for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
00343       {
00344         for (std::set<Precursor::ActivationMethod>::const_iterator it_a = it->getActivationMethods().begin();
00345              it_a != it->getActivationMethods().end();
00346              ++it_a)
00347         {
00348           if (methods_.contains(Precursor::NamesOfActivationMethod[*it_a]))
00349           {
00350             // found matching activation method
00351             if (reverse_) return false;
00352             else return true;
00353           }
00354         }
00355       }
00356 
00357       if (reverse_) return true;
00358       else return false;
00359     }
00360 
00361 protected:
00362     StringList methods_;
00363     bool reverse_;
00364   };
00365 
00375   template <class SpectrumType>
00376   class InPrecursorMZRange :
00377     std::unary_function<SpectrumType, bool>
00378   {
00379 public:
00387     InPrecursorMZRange(const DoubleReal& mz_left, const DoubleReal& mz_right, bool reverse = false) :
00388       mz_left_(mz_left),
00389       mz_right_(mz_right),
00390       reverse_(reverse)
00391     {}
00392 
00393     inline bool operator()(const SpectrumType & s) const
00394     {
00395       for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
00396       {
00397         //std::cerr << mz_left_ << " " << mz_right_ << " " << it->getMZ() << "\n";
00398         if (!(mz_left_ <= it->getMZ() && it->getMZ() <= mz_right_))
00399         { // found PC outside of allowed window
00400           if (reverse_) return true;
00401           else return false;
00402         }
00403       }
00404 
00405       if (reverse_) return false;
00406       else return true;
00407     }
00408 
00409 protected:
00410     DoubleReal mz_left_;
00411     DoubleReal mz_right_;
00412     bool reverse_;
00413   };
00414 
00415 
00424   template <class SpectrumType>
00425   class HasPrecursorCharge :
00426     std::unary_function<SpectrumType, bool>
00427   {
00428 public:
00436     HasPrecursorCharge(const IntList & charges, bool reverse = false) :
00437       charges_(charges),
00438       reverse_(reverse)
00439     {}
00440 
00441     inline bool operator()(const SpectrumType & s) const
00442     {
00443       bool match = false;
00444       for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
00445       {
00446 
00447         Int tmp = it->getCharge();
00448         match = match || (std::find(charges_.begin(), charges_.end(), tmp) != charges_.end());
00449       }
00450 
00451       if (reverse_) return !match;
00452       else return match;
00453     }
00454 
00455 protected:
00456     IntList charges_;
00457     bool reverse_;
00458   };
00459 
00460 
00470   template <class PeakType>
00471   class InMzRange :
00472     std::unary_function<PeakType, bool>
00473   {
00474 public:
00483     InMzRange(DoubleReal min, DoubleReal max, bool reverse = false) :
00484       min_(min),
00485       max_(max),
00486       reverse_(reverse)
00487     {}
00488 
00489     inline bool operator()(const PeakType & p) const
00490     {
00491       DoubleReal tmp = p.getPosition()[0];
00492       if (reverse_)
00493       {
00494         return min_ > tmp || max_ < tmp;
00495       }
00496       return min_ <= tmp && max_ >= tmp;
00497     }
00498 
00499 protected:
00500     DoubleReal min_, max_;
00501     bool reverse_;
00502   };
00503 
00511   template <class PeakType>
00512   class InIntensityRange :
00513     std::unary_function<PeakType, bool>
00514   {
00515 public:
00523     InIntensityRange(DoubleReal min, DoubleReal max, bool reverse = false) :
00524       min_(min),
00525       max_(max),
00526       reverse_(reverse)
00527     {}
00528 
00529     inline bool operator()(const PeakType & p) const
00530     {
00531       DoubleReal tmp = p.getIntensity();
00532       if (reverse_)
00533       {
00534         return min_ > tmp || max_ < tmp;
00535       }
00536       return min_ <= tmp && max_ >= tmp;
00537     }
00538 
00539 protected:
00540     DoubleReal min_, max_;
00541     bool reverse_;
00542   };
00543 
00544 } // namespace OpenMS
00545 
00546 #endif // OPENMS_KERNEL_RANGEUTILS_H

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