OpenMS
Mobilogram.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- 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 
12 
15 
16 namespace OpenMS
17 {
18  enum class DriftTimeUnit;
28  class OPENMS_DLLAPI Mobilogram final : public RangeManagerContainer<RangeMobility, RangeIntensity>
29  {
30  public:
32  struct OPENMS_DLLAPI RTLess {
33  bool operator()(const Mobilogram& a, const Mobilogram& b) const;
34  };
35 
36 
38 
39  using PeakType = MobilityPeak1D;
44  using ContainerType = std::vector<PeakType>;
49 
51 
52  using Iterator = ContainerType::iterator;
54  using iterator = Iterator;
56  using ConstIterator = ContainerType::const_iterator;
59  using ReverseIterator = ContainerType::reverse_iterator;
62  using ConstReverseIterator = ContainerType::const_reverse_iterator;
65  /*using typename ContainerType::const_reference;
66  using typename ContainerType::difference_type;
67  using typename ContainerType::pointer;
68  using typename ContainerType::reference;
69  using typename ContainerType::size_type;
70  using typename ContainerType::value_type;*/
71 
72  // rule of 6
73 
75  Mobilogram() = default;
76 
78  Mobilogram(const Mobilogram& source) = default;
79 
81  Mobilogram(Mobilogram&&) noexcept = default;
82 
84  Mobilogram& operator=(const Mobilogram& source) = default;
85 
87  Mobilogram& operator=(Mobilogram&&) noexcept = default;
88 
90  ~Mobilogram() = default;
91 
92 
94  bool operator==(const Mobilogram& rhs) const;
95 
97  bool operator!=(const Mobilogram& rhs) const
98  {
99  return !(operator==(rhs));
100  }
101 
103 
105  {
106  return data_[i];
107  }
108  const MobilityPeak1D& operator[](Size i) const noexcept
109  {
110  return data_[i];
111  }
112 
113 
114  MobilityPeak1D& front() noexcept
115  {
116  return data_.front();
117  }
118  const MobilityPeak1D& front() const noexcept
119  {
120  return data_.front();
121  }
122 
123  MobilityPeak1D& back() noexcept
124  {
125  return data_.back();
126  }
127  const MobilityPeak1D& back() const noexcept
128  {
129  return data_.back();
130  }
131 
132  Iterator begin() noexcept
133  {
134  return data_.begin();
135  }
136  ConstIterator begin() const noexcept
137  {
138  return data_.begin();
139  }
140  ConstIterator cbegin() const noexcept
141  {
142  return data_.cbegin();
143  }
144 
145  Iterator end() noexcept
146  {
147  return data_.end();
148  }
149  ConstIterator end() const noexcept
150  {
151  return data_.end();
152  }
153  ConstIterator cend() const noexcept
154  {
155  return data_.cend();
156  }
157 
159  {
160  return data_.rbegin();
161  }
163  {
164  return data_.crbegin();
165  }
167  {
168  return data_.rend();
169  }
171  {
172  return data_.crend();
173  }
174 
175  bool empty() const noexcept
176  {
177  return data_.empty();
178  }
180  {
181  return data_.erase(where);
182  }
183 
185  {
186  data_.push_back(mb);
187  }
189  {
190  return data_.emplace_back(mb);
191  }
192  template<class... Args>
193  void emplace_back(Args&&... args)
194  {
195  data_.emplace_back(args...);
196  }
197 
198  void pop_back()
199  {
200  data_.pop_back();
201  }
202 
204  {
205  return data_.insert(where, first, last);
206  }
207 
208  void resize(size_t new_size)
209  {
210  return data_.resize(new_size);
211  }
212  void reserve(size_t new_size)
213  {
214  return data_.reserve(new_size);
215  }
216 
217  size_t size() const noexcept
218  {
219  return data_.size();
220  }
221 
222  void swap(Mobilogram& mb) noexcept
223  {
224  data_.swap(mb.data_);
225  std::swap(retention_time_, mb.retention_time_);
226  std::swap(drift_time_unit_, mb.drift_time_unit_);
227  }
229 
230  // Docu in base class (RangeManager)
231  void updateRanges() override;
232 
236  double getRT() const noexcept
237  {
238  return retention_time_;
239  }
240 
242  void setRT(double rt) noexcept
243  {
244  retention_time_ = rt;
245  }
246 
251  {
252  return drift_time_unit_;
253  }
254 
257 
261  void setDriftTimeUnit(DriftTimeUnit dt) noexcept;
262 
264 
265 
267 
268 
273  void sortByIntensity(bool reverse = false);
274 
281 
283  bool isSorted() const;
284 
289  template<class Predicate>
290  bool isSorted(const Predicate& lambda) const
291  {
292  auto value_2_index_wrapper = [this, &lambda](const PeakType& value1, const PeakType& value2) {
293  // translate values into indices (this relies on no copies being made!)
294  const Size index1 = (&value1) - (&this->front());
295  const Size index2 = (&value2) - (&this->front());
296  // just make sure the pointers above are actually pointing to a Peak inside our container
297  assert(index1 < this->size());
298  assert(index2 < this->size());
299  return lambda(index1, index2);
300  };
301  return std::is_sorted(this->begin(), this->end(), value_2_index_wrapper);
302  }
303 
305 
308 
319 
332 
346  Int findNearest(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
347 
360  Int findHighestInWindow(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
361 
368 
375 
382 
389 
396 
403 
410 
417 
426 
435 
444 
453 
462 
471 
480 
489 
491 
492 
498  void clear() noexcept;
499 
502  ConstIterator getBasePeak() const;
503 
506  Iterator getBasePeak();
507 
509  PeakType::IntensityType calculateTIC() const;
510 
511  protected:
513  std::vector<MobilityPeak1D> data_;
514 
516  double retention_time_ = -1;
517 
519  DriftTimeUnit drift_time_unit_ = DriftTimeUnit::NONE;
520  };
521 
522  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Mobilogram& mb);
523 } // namespace OpenMS
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:29
ConstIterator const_iterator
Definition: Mobilogram.h:57
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:54
void pop_back()
Definition: Mobilogram.h:198
Iterator MBEnd(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range end (returns the past-the-end iterator)
void swap(Mobilogram &mb) noexcept
Definition: Mobilogram.h:222
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:158
ConstReverseIterator crbegin() const
Definition: Mobilogram.h:162
ConstIterator MBBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
size_t size() const noexcept
Definition: Mobilogram.h:217
bool empty() const noexcept
Definition: Mobilogram.h:175
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: Mobilogram.h:62
Mobilogram()=default
Constructor.
const MobilityPeak1D & front() const noexcept
Definition: Mobilogram.h:118
ConstIterator begin() const noexcept
Definition: Mobilogram.h:136
ConstIterator cbegin() const noexcept
Definition: Mobilogram.h:140
MobilityPeak1D & front() noexcept
Definition: Mobilogram.h:114
MobilityPeak1D & emplace_back(MobilityPeak1D mb)
Definition: Mobilogram.h:188
String getDriftTimeUnitAsString() const
returns the ion mobility drift time unit as string
ReverseIterator rend() noexcept
Definition: Mobilogram.h:166
const MobilityPeak1D & operator[](Size i) const noexcept
Definition: Mobilogram.h:108
Iterator begin() noexcept
Definition: Mobilogram.h:132
PeakType::CoordinateType CoordinateType
Coordinate (mobility) type.
Definition: Mobilogram.h:42
void resize(size_t new_size)
Definition: Mobilogram.h:208
bool isSorted() const
Checks if all peaks are sorted with respect to ascending mobility.
MobilityPeak1D & operator[](Size i) noexcept
Definition: Mobilogram.h:104
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:203
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:123
void reserve(size_t new_size)
Definition: Mobilogram.h:212
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:242
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: Mobilogram.h:59
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
Size findNearest(CoordinateType mb) const
Binary search for the peak nearest to a specific mobility.
ConstIterator cend() const noexcept
Definition: Mobilogram.h:153
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: Mobilogram.h:56
ConstIterator erase(ConstIterator where) noexcept
Definition: Mobilogram.h:179
ConstReverseIterator const_reverse_iterator
Definition: Mobilogram.h:63
ConstIterator PosBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
ReverseIterator reverse_iterator
Definition: Mobilogram.h:60
std::vector< PeakType > ContainerType
Mobilogram base type.
Definition: Mobilogram.h:44
double getRT() const noexcept
Definition: Mobilogram.h:236
ConstIterator end() const noexcept
Definition: Mobilogram.h:149
bool isSorted(const Predicate &lambda) const
Definition: Mobilogram.h:290
void emplace_back(Args &&... args)
Definition: Mobilogram.h:193
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:170
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:184
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:250
Mobilogram(const Mobilogram &source)=default
Copy constructor.
Iterator MBBegin(CoordinateType mb)
Binary search for peak range begin.
Iterator end() noexcept
Definition: Mobilogram.h:145
Iterator PosBegin(Iterator begin, CoordinateType mb, Iterator end)
Binary search for peak range begin.
void updateRanges() override
const MobilityPeak1D & back() const noexcept
Definition: Mobilogram.h:127
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:32
bool operator()(const Mobilogram &a, const Mobilogram &b) const