Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
RangeUtils.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Stephan Aiche$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_RANGEUTILS_H
36 #define OPENMS_KERNEL_RANGEUTILS_H
37 
38 #include <functional>
39 #include <algorithm>
40 #include <vector>
41 #include <OpenMS/CONCEPT/Types.h>
44 
45 namespace OpenMS
46 {
95  template <class MetaContainer>
96  class HasMetaValue :
97  std::unary_function<MetaContainer, bool>
98  {
99 public:
106  HasMetaValue(String metavalue, bool reverse = false) :
107  metavalue_key_(metavalue),
108  reverse_(reverse)
109  {}
110 
111  inline bool operator()(const MetaContainer& s) const
112  {
113  bool has_meta_value = s.metaValueExists(metavalue_key_);
114  if (reverse_)
115  {
116  return !has_meta_value;
117  }
118  return has_meta_value;
119  }
120 
121 protected:
123  bool reverse_;
124  };
125 
126 
134  template <class SpectrumType>
135  class InRTRange :
136  std::unary_function<SpectrumType, bool>
137  {
138 public:
147  InRTRange(DoubleReal min, DoubleReal max, bool reverse = false) :
148  min_(min),
149  max_(max),
150  reverse_(reverse)
151  {}
152 
153  inline bool operator()(const SpectrumType& s) const
154  {
155  DoubleReal tmp = s.getRT();
156  if (reverse_)
157  {
158  return min_ > tmp || max_ < tmp;
159  }
160  return min_ <= tmp && max_ >= tmp;
161  }
162 
163 protected:
165  bool reverse_;
166  };
167 
175  template <class SpectrumType>
177  std::unary_function<SpectrumType, bool>
178  {
179 public:
187  InMSLevelRange(const IntList& levels, bool reverse = false) :
188  levels_(levels),
189  reverse_(reverse)
190  {}
191 
192  inline bool operator()(const SpectrumType& s) const
193  {
194  Int tmp = s.getMSLevel();
195  if (reverse_)
196  {
197  return std::find(levels_.begin(), levels_.end(), tmp) == levels_.end();
198  }
199  return std::find(levels_.begin(), levels_.end(), tmp) != levels_.end();
200  }
201 
202 protected:
204  bool reverse_;
205  };
206 
214  template <class SpectrumType>
215  class HasScanMode :
216  std::unary_function<SpectrumType, bool>
217  {
218 public:
226  HasScanMode(Int mode, bool reverse = false) :
227  mode_(mode),
228  reverse_(reverse)
229  {}
230 
231  inline bool operator()(const SpectrumType& s) const
232  {
233  if (reverse_)
234  {
235  return s.getInstrumentSettings().getScanMode() != mode_;
236  }
237  return s.getInstrumentSettings().getScanMode() == mode_;
238  }
239 
240 protected:
242  bool reverse_;
243  };
244 
252  template <class SpectrumType>
254  std::unary_function<SpectrumType, bool>
255  {
256 public:
262  explicit IsEmptySpectrum(bool reverse = false) :
263  reverse_(reverse)
264  {}
265 
266  inline bool operator()(const SpectrumType& s) const
267  {
268  if (reverse_)
269  {
270  return !s.empty();
271  }
272  return s.empty();
273  }
274 
275 protected:
276  bool reverse_;
277  };
278 
286  template <class SpectrumType>
288  std::unary_function<SpectrumType, bool>
289  {
290 public:
297  explicit IsZoomSpectrum(bool reverse = false) :
298  reverse_(reverse)
299  {}
300 
301  inline bool operator()(const SpectrumType& s) const
302  {
303  if (reverse_)
304  {
305  return !s.getInstrumentSettings().getZoomScan();
306  }
307  return s.getInstrumentSettings().getZoomScan();
308  }
309 
310 protected:
311  bool reverse_;
312  };
313 
314 
323  template <class SpectrumType>
325  std::unary_function<SpectrumType, bool>
326  {
327 public:
335  HasActivationMethod(const StringList& methods, bool reverse = false) :
336  methods_(methods),
337  reverse_(reverse)
338  {}
339 
340  inline bool operator()(const SpectrumType& s) const
341  {
342  for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
343  {
344  for (std::set<Precursor::ActivationMethod>::const_iterator it_a = it->getActivationMethods().begin();
345  it_a != it->getActivationMethods().end();
346  ++it_a)
347  {
349  {
350  // found matching activation method
351  if (reverse_) return false;
352  else return true;
353  }
354  }
355  }
356 
357  if (reverse_) return true;
358  else return false;
359  }
360 
361 protected:
363  bool reverse_;
364  };
365 
375  template <class SpectrumType>
377  std::unary_function<SpectrumType, bool>
378  {
379 public:
387  InPrecursorMZRange(const DoubleReal& mz_left, const DoubleReal& mz_right, bool reverse = false) :
388  mz_left_(mz_left),
389  mz_right_(mz_right),
390  reverse_(reverse)
391  {}
392 
393  inline bool operator()(const SpectrumType& s) const
394  {
395  for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
396  {
397  //std::cerr << mz_left_ << " " << mz_right_ << " " << it->getMZ() << "\n";
398  if (!(mz_left_ <= it->getMZ() && it->getMZ() <= mz_right_))
399  { // found PC outside of allowed window
400  if (reverse_) return true;
401  else return false;
402  }
403  }
404 
405  if (reverse_) return false;
406  else return true;
407  }
408 
409 protected:
412  bool reverse_;
413  };
414 
415 
424  template <class SpectrumType>
426  std::unary_function<SpectrumType, bool>
427  {
428 public:
436  HasPrecursorCharge(const IntList& charges, bool reverse = false) :
437  charges_(charges),
438  reverse_(reverse)
439  {}
440 
441  inline bool operator()(const SpectrumType& s) const
442  {
443  bool match = false;
444  for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
445  {
446  Int tmp = it->getCharge();
447  match = match || (std::find(charges_.begin(), charges_.end(), tmp) != charges_.end());
448  }
449 
450  if (reverse_) return !match;
451  else return match;
452  }
453 
454 protected:
456  bool reverse_;
457  };
458 
459 
469  template <class PeakType>
470  class InMzRange :
471  std::unary_function<PeakType, bool>
472  {
473 public:
482  InMzRange(DoubleReal min, DoubleReal max, bool reverse = false) :
483  min_(min),
484  max_(max),
485  reverse_(reverse)
486  {}
487 
488  inline bool operator()(const PeakType& p) const
489  {
490  DoubleReal tmp = p.getPosition()[0];
491  if (reverse_)
492  {
493  return min_ > tmp || max_ < tmp;
494  }
495  return min_ <= tmp && max_ >= tmp;
496  }
497 
498 protected:
500  bool reverse_;
501  };
502 
510  template <class PeakType>
512  std::unary_function<PeakType, bool>
513  {
514 public:
522  InIntensityRange(DoubleReal min, DoubleReal max, bool reverse = false) :
523  min_(min),
524  max_(max),
525  reverse_(reverse)
526  {}
527 
528  inline bool operator()(const PeakType& p) const
529  {
530  DoubleReal tmp = p.getIntensity();
531  if (reverse_)
532  {
533  return min_ > tmp || max_ < tmp;
534  }
535  return min_ <= tmp && max_ >= tmp;
536  }
537 
538 protected:
540  bool reverse_;
541  };
542 
550  template <class SpectrumType>
552  std::unary_function<SpectrumType, bool>
553  {
554 public:
562  IsInCollisionEnergyRange(DoubleReal min, DoubleReal max, bool reverse = false) :
563  min_energy_(min),
564  max_energy_(max),
565  reverse_(reverse)
566  {}
567 
568  inline bool operator()(const SpectrumType& s) const
569  {
570  // leave non-fragmentation spectra untouched
571  if (s.getMSLevel() == 1) return false;
572 
573  bool isIn = false;
574  bool hasCollisionEnergy = false;
575  for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
576  {
577  if (it->metaValueExists("collision energy"))
578  {
579  hasCollisionEnergy = true;
580  DoubleReal cE = it->getMetaValue("collision energy");
581  isIn |= !(cE > max_energy_ || cE < min_energy_);
582  }
583  }
584 
585  // we accept all spectra that have no collision energy value
586  if (!hasCollisionEnergy) return false;
587 
588  if (reverse_) return !isIn;
589  else return isIn;
590  }
591 
592 private:
594  bool reverse_;
595  };
596 
603  template <class SpectrumType>
605  std::unary_function<SpectrumType, bool>
606  {
607 
608 public:
616  IsInIsolationWindowSizeRange(DoubleReal min_size, DoubleReal max_size, bool reverse = false) :
617  min_size_(min_size),
618  max_size_(max_size),
619  reverse_(reverse)
620  {}
621 
622  inline bool operator()(const SpectrumType& s) const
623  {
624  // leave non-fragmentation spectra untouched
625  if (s.getMSLevel() == 1) return false;
626 
627  bool isIn = false;
628  for (std::vector<Precursor>::const_iterator it = s.getPrecursors().begin(); it != s.getPrecursors().end(); ++it)
629  {
630  const DoubleReal isolationWindowSize = it->getIsolationWindowUpperOffset() + it->getIsolationWindowLowerOffset();
631  isIn |= !(isolationWindowSize > max_size_ || isolationWindowSize < min_size_);
632  }
633 
634  if (reverse_) return !isIn;
635  else return isIn;
636  }
637 
638 private:
640  bool reverse_;
641  };
642 
643 } // namespace OpenMS
644 
645 #endif // OPENMS_KERNEL_RANGEUTILS_H
IntList levels_
Definition: RangeUtils.h:203
Predicate that determines if a spectrum lies inside/outside a specific retention time range...
Definition: RangeUtils.h:135
DoubleReal max_energy_
Definition: RangeUtils.h:593
PositionType const & getPosition() const
Non-mutable access to the position.
Definition: Peak2D.h:173
DoubleReal mz_left_
Definition: RangeUtils.h:410
bool reverse_
Definition: RangeUtils.h:594
InMSLevelRange(const IntList &levels, bool reverse=false)
Constructor.
Definition: RangeUtils.h:187
bool reverse_
Definition: RangeUtils.h:276
Predicate that determines if a class has a certain metavalue.
Definition: RangeUtils.h:96
A more convenient string class.
Definition: String.h:56
InPrecursorMZRange(const DoubleReal &mz_left, const DoubleReal &mz_right, bool reverse=false)
Constructor.
Definition: RangeUtils.h:387
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
DoubleReal max_
Definition: RangeUtils.h:539
bool contains(const String &s) const
Returns if a string is contained in the list.
String metavalue_key_
Definition: RangeUtils.h:122
IntensityType getIntensity() const
Definition: Peak2D.h:161
DoubleReal max_
Definition: RangeUtils.h:164
Predicate that determines if a spectrum has a certain scan mode.
Definition: RangeUtils.h:215
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:340
bool reverse_
Definition: RangeUtils.h:363
DoubleReal max_size_
Definition: RangeUtils.h:639
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:393
bool reverse_
Definition: RangeUtils.h:242
bool reverse_
Definition: RangeUtils.h:640
DoubleReal mz_right_
Definition: RangeUtils.h:411
DoubleReal min_size_
Definition: RangeUtils.h:639
bool operator()(const PeakType &p) const
Definition: RangeUtils.h:528
bool operator()(const PeakType &p) const
Definition: RangeUtils.h:488
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:622
IsInIsolationWindowSizeRange(DoubleReal min_size, DoubleReal max_size, bool reverse=false)
Constructor.
Definition: RangeUtils.h:616
InIntensityRange(DoubleReal min, DoubleReal max, bool reverse=false)
Constructor.
Definition: RangeUtils.h:522
static const std::string NamesOfActivationMethod[SIZE_OF_ACTIVATIONMETHOD]
Names of activation methods.
Definition: Precursor.h:82
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:266
DoubleReal max_
Definition: RangeUtils.h:499
DoubleReal min_
Definition: RangeUtils.h:539
bool reverse_
Definition: RangeUtils.h:412
InMzRange(DoubleReal min, DoubleReal max, bool reverse=false)
Constructor.
Definition: RangeUtils.h:482
HasScanMode(Int mode, bool reverse=false)
Constructor.
Definition: RangeUtils.h:226
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:153
IsZoomSpectrum(bool reverse=false)
Constructor.
Definition: RangeUtils.h:297
Predicate that determines if a spectrum lies inside/outside a specific MS level set.
Definition: RangeUtils.h:176
IsEmptySpectrum(bool reverse=false)
Constructor.
Definition: RangeUtils.h:262
bool reverse_
Definition: RangeUtils.h:165
bool operator()(const MetaContainer &s) const
Definition: RangeUtils.h:111
bool reverse_
Definition: RangeUtils.h:123
HasMetaValue(String metavalue, bool reverse=false)
Constructor.
Definition: RangeUtils.h:106
Predicate that determines if a spectrum has a certain precursor charge as given in the constructor li...
Definition: RangeUtils.h:425
bool reverse_
Definition: RangeUtils.h:311
Predicate that determines if a peak lies inside/outside a specific intensity range.
Definition: RangeUtils.h:511
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:231
bool reverse_
Definition: RangeUtils.h:204
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:441
Int mode_
Definition: RangeUtils.h:241
String list.
Definition: StringList.h:56
bool reverse_
Definition: RangeUtils.h:540
InRTRange(DoubleReal min, DoubleReal max, bool reverse=false)
Constructor.
Definition: RangeUtils.h:147
IntList charges_
Definition: RangeUtils.h:455
StringList methods_
Definition: RangeUtils.h:362
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:301
HasActivationMethod(const StringList &methods, bool reverse=false)
Constructor.
Definition: RangeUtils.h:335
Predicate that determines if the width of the isolation window of an MSn spectrum is in the given ran...
Definition: RangeUtils.h:604
bool reverse_
Definition: RangeUtils.h:456
DoubleReal min_
Definition: RangeUtils.h:164
HasPrecursorCharge(const IntList &charges, bool reverse=false)
Constructor.
Definition: RangeUtils.h:436
Predicate that determines if a peak lies inside/outside a specific m/z range.
Definition: RangeUtils.h:470
Predicate that determines if a spectrum&#39;s precursor is within a certain m/z range.
Definition: RangeUtils.h:376
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:568
bool reverse_
Definition: RangeUtils.h:500
Predicate that determines if a spectrum is a zoom (enhanced resolution) spectrum. ...
Definition: RangeUtils.h:287
bool operator()(const SpectrumType &s) const
Definition: RangeUtils.h:192
int Int
Signed integer type.
Definition: Types.h:100
DoubleReal min_
Definition: RangeUtils.h:499
Predicate that determines if a spectrum was generated using any activation method given in the constr...
Definition: RangeUtils.h:324
Predicate that determines if an MSn spectrum was generated with a collision energy in the given range...
Definition: RangeUtils.h:551
Predicate that determines if a spectrum is empty.
Definition: RangeUtils.h:253
IsInCollisionEnergyRange(DoubleReal min, DoubleReal max, bool reverse=false)
Constructor.
Definition: RangeUtils.h:562
Int list.
Definition: IntList.h:56
DoubleReal min_energy_
Definition: RangeUtils.h:593

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:20 using doxygen 1.8.5