00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
00398 if (!(mz_left_ <= it->getMZ() && it->getMZ() <= mz_right_))
00399 {
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 }
00545
00546 #endif // OPENMS_KERNEL_RANGEUTILS_H