OpenMS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Mobilogram.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
15 
18 
19 namespace OpenMS
20 {
21  enum class DriftTimeUnit;
31  class OPENMS_DLLAPI Mobilogram final : public RangeManagerContainer<RangeMobility, RangeIntensity>
32  {
33  public:
35  struct OPENMS_DLLAPI RTLess {
36  bool operator()(const Mobilogram& a, const Mobilogram& b) const;
37  };
38 
39 
41 
42  using PeakType = MobilityPeak1D;
47  using ContainerType = std::vector<PeakType>;
53  typedef std::vector<FloatDataArray> FloatDataArrays;
56  typedef std::vector<StringDataArray> StringDataArrays;
59  typedef std::vector<IntegerDataArray> IntegerDataArrays;
61 
63 
64  using Iterator = ContainerType::iterator;
66  using iterator = Iterator;
68  using ConstIterator = ContainerType::const_iterator;
71  using ReverseIterator = ContainerType::reverse_iterator;
74  using ConstReverseIterator = ContainerType::const_reverse_iterator;
77  /*using typename ContainerType::const_reference;
78  using typename ContainerType::difference_type;
79  using typename ContainerType::pointer;
80  using typename ContainerType::reference;
81  using typename ContainerType::size_type;
82  using typename ContainerType::value_type;*/
83 
84  // rule of 6
85 
87  Mobilogram() = default;
88 
90  Mobilogram(const Mobilogram& source) = default;
91 
93  Mobilogram(Mobilogram&&) noexcept = default;
94 
96  Mobilogram& operator=(const Mobilogram& source) = default;
97 
99  Mobilogram& operator=(Mobilogram&&) noexcept = default;
100 
102  ~Mobilogram() = default;
103 
104 
106  bool operator==(const Mobilogram& rhs) const;
107 
109  bool operator!=(const Mobilogram& rhs) const
110  {
111  return !(operator==(rhs));
112  }
113 
115 
117  {
118  return data_[i];
119  }
120  const MobilityPeak1D& operator[](Size i) const noexcept
121  {
122  return data_[i];
123  }
124 
125 
126  MobilityPeak1D& front() noexcept
127  {
128  return data_.front();
129  }
130  const MobilityPeak1D& front() const noexcept
131  {
132  return data_.front();
133  }
134 
135  MobilityPeak1D& back() noexcept
136  {
137  return data_.back();
138  }
139  const MobilityPeak1D& back() const noexcept
140  {
141  return data_.back();
142  }
143 
144  Iterator begin() noexcept
145  {
146  return data_.begin();
147  }
148  ConstIterator begin() const noexcept
149  {
150  return data_.begin();
151  }
152  ConstIterator cbegin() const noexcept
153  {
154  return data_.cbegin();
155  }
156 
157  Iterator end() noexcept
158  {
159  return data_.end();
160  }
161  ConstIterator end() const noexcept
162  {
163  return data_.end();
164  }
165  ConstIterator cend() const noexcept
166  {
167  return data_.cend();
168  }
169 
171  {
172  return data_.rbegin();
173  }
175  {
176  return data_.crbegin();
177  }
179  {
180  return data_.rend();
181  }
183  {
184  return data_.crend();
185  }
186 
187  bool empty() const noexcept
188  {
189  return data_.empty();
190  }
192  {
193  return data_.erase(where);
194  }
195 
197  {
198  data_.push_back(mb);
199  }
201  {
202  return data_.emplace_back(mb);
203  }
204  template<class... Args>
205  void emplace_back(Args&&... args)
206  {
207  data_.emplace_back(args...);
208  }
209 
210  void pop_back()
211  {
212  data_.pop_back();
213  }
214 
216  {
217  return data_.insert(where, first, last);
218  }
219 
220  void resize(size_t new_size)
221  {
222  return data_.resize(new_size);
223  }
224  void reserve(size_t new_size)
225  {
226  return data_.reserve(new_size);
227  }
228 
229  size_t size() const noexcept
230  {
231  return data_.size();
232  }
233 
234  void swap(Mobilogram& mb) noexcept
235  {
236  data_.swap(mb.data_);
237  std::swap(retention_time_, mb.retention_time_);
238  std::swap(drift_time_unit_, mb.drift_time_unit_);
239  }
241 
242  // Docu in base class (RangeManager)
243  void updateRanges() override;
244 
246  double getRT() const noexcept
247  {
248  return retention_time_;
249  }
250 
252  void setRT(double rt) noexcept
253  {
254  retention_time_ = rt;
255  }
256 
261  {
262  return drift_time_unit_;
263  }
264 
267 
271  void setDriftTimeUnit(DriftTimeUnit dt) noexcept;
272 
274 
290 
293 
296  {
297  float_data_arrays_ = fda;
298  }
299 
302 
305 
308  {
309  string_data_arrays_ = sda;
310  }
311 
314 
317 
320  {
321  integer_data_arrays_ = ida;
322  }
323 
325 
327 
328 
333  void sortByIntensity(bool reverse = false);
334 
341 
343  bool isSorted() const;
344 
349  template<class Predicate>
350  bool isSorted(const Predicate& lambda) const
351  {
352  auto value_2_index_wrapper = [this, &lambda](const PeakType& value1, const PeakType& value2) {
353  // translate values into indices (this relies on no copies being made!)
354  const Size index1 = (&value1) - (&this->front());
355  const Size index2 = (&value2) - (&this->front());
356  // just make sure the pointers above are actually pointing to a Peak inside our container
357  assert(index1 < this->size());
358  assert(index2 < this->size());
359  return lambda(index1, index2);
360  };
361  return std::is_sorted(this->begin(), this->end(), value_2_index_wrapper);
362  }
363 
365 
368 
379 
392 
406  Int findNearest(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
407 
420  Int findHighestInWindow(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
421 
428 
435 
442 
449 
456 
463 
470 
477 
486 
495 
504 
513 
522 
531 
540 
549 
551 
552 
558  void clear() noexcept;
559 
562  ConstIterator getBasePeak() const;
563 
566  Iterator getBasePeak();
567 
569  PeakType::IntensityType calculateTIC() const;
570 
571  protected:
573  std::vector<MobilityPeak1D> data_;
574 
576  double retention_time_ = -1;
577 
579  DriftTimeUnit drift_time_unit_ = DriftTimeUnit::NONE;
580 
582  FloatDataArrays float_data_arrays_;
583 
585  StringDataArrays string_data_arrays_;
586 
588  IntegerDataArrays integer_data_arrays_;
589  };
590 
591  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Mobilogram& mb);
592 } // namespace OpenMS
Float data array class.
Definition: DataArrays.h:22
Integer data array class.
Definition: DataArrays.h:30
String data array class.
Definition: DataArrays.h:38
A 1-dimensional raw data mobility point or peak. The unit (ms, 1/K_0, etc) is implicit.
Definition: MobilityPeak1D.h:25
The representation of a 1D ion mobilogram.
Definition: Mobilogram.h:32
ConstIterator const_iterator
Definition: Mobilogram.h:69
void setIntegerDataArrays(const IntegerDataArrays &ida)
Sets the integer meta data arrays.
Definition: Mobilogram.h:319
Int findNearest(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const
Search for the peak nearest to a specific mobility given two +/- tolerance windows.
void clear() noexcept
Clears all data and ranges.
Iterator iterator
Definition: Mobilogram.h:66
void pop_back()
Definition: Mobilogram.h:210
Iterator MBEnd(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range end (returns the past-the-end iterator)
FloatDataArrays & getFloatDataArrays()
Returns a mutable reference to the float meta data arrays.
void swap(Mobilogram &mb) noexcept
Definition: Mobilogram.h:234
ConstIterator PosEnd(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range end (returns the past-the-end iterator)
void setDriftTimeUnit(DriftTimeUnit dt) noexcept
Sets the ion mobility drift time unit.
Iterator PosBegin(CoordinateType mb)
Binary search for peak range begin.
ConstIterator MBBegin(CoordinateType mb) const
Binary search for peak range begin.
Iterator PosEnd(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range end (returns the past-the-end iterator)
ReverseIterator rbegin() noexcept
Definition: Mobilogram.h:170
ConstReverseIterator crbegin() const
Definition: Mobilogram.h:174
std::vector< StringDataArray > StringDataArrays
Definition: Mobilogram.h:56
OpenMS::DataArrays::FloatDataArray FloatDataArray
Float data array vector type.
Definition: Mobilogram.h:52
ConstIterator MBBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
size_t size() const noexcept
Definition: Mobilogram.h:229
bool empty() const noexcept
Definition: Mobilogram.h:187
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: Mobilogram.h:74
Mobilogram()=default
Constructor.
const MobilityPeak1D & front() const noexcept
Definition: Mobilogram.h:130
ConstIterator begin() const noexcept
Definition: Mobilogram.h:148
ConstIterator cbegin() const noexcept
Definition: Mobilogram.h:152
MobilityPeak1D & front() noexcept
Definition: Mobilogram.h:126
MobilityPeak1D & emplace_back(MobilityPeak1D mb)
Definition: Mobilogram.h:200
String getDriftTimeUnitAsString() const
returns the ion mobility drift time unit as string
ReverseIterator rend() noexcept
Definition: Mobilogram.h:178
StringDataArrays & getStringDataArrays()
Returns a mutable reference to the string meta data arrays.
const MobilityPeak1D & operator[](Size i) const noexcept
Definition: Mobilogram.h:120
Iterator begin() noexcept
Definition: Mobilogram.h:144
PeakType::CoordinateType CoordinateType
Coordinate (mobility) type.
Definition: Mobilogram.h:45
void resize(size_t new_size)
Definition: Mobilogram.h:220
bool isSorted() const
Checks if all peaks are sorted with respect to ascending mobility.
MobilityPeak1D & operator[](Size i) noexcept
Definition: Mobilogram.h:116
ConstIterator MBEnd(CoordinateType mb) const
Binary search for peak range end (returns the past-the-end iterator)
Iterator insert(ConstIterator where, ConstIterator first, ConstIterator last)
Definition: Mobilogram.h:215
ConstIterator PosEnd(CoordinateType mb) const
Binary search for peak range end (returns the past-the-end iterator)
Mobilogram(Mobilogram &&) noexcept=default
Move constructor.
MobilityPeak1D & back() noexcept
Definition: Mobilogram.h:135
void reserve(size_t new_size)
Definition: Mobilogram.h:224
ConstIterator PosBegin(CoordinateType mb) const
Binary search for peak range begin.
Iterator MBEnd(CoordinateType mb)
Binary search for peak range end (returns the past-the-end iterator)
void sortByPosition()
Lexicographically sorts the peaks by their position (mobility).
void setRT(double rt) noexcept
Sets the retention time (in seconds)
Definition: Mobilogram.h:252
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: Mobilogram.h:71
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
Size findNearest(CoordinateType mb) const
Binary search for the peak nearest to a specific mobility.
ConstIterator cend() const noexcept
Definition: Mobilogram.h:165
OpenMS::DataArrays::StringDataArray StringDataArray
String data array vector type.
Definition: Mobilogram.h:55
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: Mobilogram.h:68
ConstIterator erase(ConstIterator where) noexcept
Definition: Mobilogram.h:191
ConstReverseIterator const_reverse_iterator
Definition: Mobilogram.h:75
ConstIterator PosBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
ReverseIterator reverse_iterator
Definition: Mobilogram.h:72
std::vector< PeakType > ContainerType
Mobilogram base type.
Definition: Mobilogram.h:47
double getRT() const noexcept
Returns the retention time (in seconds)
Definition: Mobilogram.h:246
ConstIterator end() const noexcept
Definition: Mobilogram.h:161
bool isSorted(const Predicate &lambda) const
Definition: Mobilogram.h:350
void emplace_back(Args &&... args)
Definition: Mobilogram.h:205
ConstIterator MBEnd(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range end (returns the past-the-end iterator)
Iterator PosEnd(CoordinateType mb)
Binary search for peak range end (returns the past-the-end iterator)
ConstReverseIterator crend() const
Definition: Mobilogram.h:182
const FloatDataArrays & getFloatDataArrays() const
void setStringDataArrays(const StringDataArrays &sda)
Sets the string meta data arrays.
Definition: Mobilogram.h:307
Iterator MBBegin(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range begin.
Int findHighestInWindow(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const
Search for the peak with highest intensity among the peaks near to a specific mobility given two +/- ...
void push_back(MobilityPeak1D mb)
Definition: Mobilogram.h:196
Int findNearest(CoordinateType mb, CoordinateType tolerance) const
Binary search for the peak nearest to a specific mobility given a +/- tolerance windows.
DriftTimeUnit getDriftTimeUnit() const noexcept
Returns the ion mobility drift time unit.
Definition: Mobilogram.h:260
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
std::vector< FloatDataArray > FloatDataArrays
Definition: Mobilogram.h:53
Mobilogram(const Mobilogram &source)=default
Copy constructor.
Iterator MBBegin(CoordinateType mb)
Binary search for peak range begin.
Iterator end() noexcept
Definition: Mobilogram.h:157
Iterator PosBegin(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range begin.
void updateRanges() override
OpenMS::DataArrays::IntegerDataArray IntegerDataArray
Integer data array vector type.
Definition: Mobilogram.h:58
std::vector< IntegerDataArray > IntegerDataArrays
Definition: Mobilogram.h:59
IntegerDataArrays & getIntegerDataArrays()
Returns a mutable reference to the integer meta data arrays.
void setFloatDataArrays(const FloatDataArrays &fda)
Sets the float meta data arrays.
Definition: Mobilogram.h:295
const MobilityPeak1D & back() const noexcept
Definition: Mobilogram.h:139
double CoordinateType
Coordinate type (of the position)
Definition: Peak2D.h:38
Definition: RangeManager.h:871
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:550
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
custom arguments to allow for looping calls
Definition: WizardHelper.h:47
static String & reverse(String &this_s)
Definition: StringUtilsSimple.h:330
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
DriftTimeUnit
Drift time unit for ion mobility.
Definition: IMTypes.h:23
Comparator for the RT of the mobilogram.
Definition: Mobilogram.h:35
bool operator()(const Mobilogram &a, const Mobilogram &b) const