OpenMS  3.0.0
Mobilogram.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-2022.
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: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
41 
42 namespace OpenMS
43 {
44  enum class DriftTimeUnit;
54  class OPENMS_DLLAPI Mobilogram final : public RangeManagerContainer<RangeMobility, RangeIntensity>
55  {
56  public:
58  struct OPENMS_DLLAPI RTLess {
59  bool operator()(const Mobilogram& a, const Mobilogram& b) const;
60  };
61 
62 
64 
65  using PeakType = MobilityPeak1D;
70  using ContainerType = std::vector<PeakType>;
75 
77 
78  using Iterator = ContainerType::iterator;
80  using iterator = Iterator;
82  using ConstIterator = ContainerType::const_iterator;
85  using ReverseIterator = ContainerType::reverse_iterator;
88  using ConstReverseIterator = ContainerType::const_reverse_iterator;
91  /*using typename ContainerType::const_reference;
92  using typename ContainerType::difference_type;
93  using typename ContainerType::pointer;
94  using typename ContainerType::reference;
95  using typename ContainerType::size_type;
96  using typename ContainerType::value_type;*/
97 
98  // rule of 6
99 
101  Mobilogram() = default;
102 
104  Mobilogram(const Mobilogram& source) = default;
105 
107  Mobilogram(Mobilogram&&) noexcept = default;
108 
110  Mobilogram& operator=(const Mobilogram& source) = default;
111 
113  Mobilogram& operator=(Mobilogram&&) noexcept = default;
114 
116  ~Mobilogram() = default;
117 
118 
120  bool operator==(const Mobilogram& rhs) const;
121 
123  bool operator!=(const Mobilogram& rhs) const
124  {
125  return !(operator==(rhs));
126  }
127 
129 
131  {
132  return data_[i];
133  }
134  const MobilityPeak1D& operator[](Size i) const noexcept
135  {
136  return data_[i];
137  }
138 
139 
140  MobilityPeak1D& front() noexcept
141  {
142  return data_.front();
143  }
144  const MobilityPeak1D& front() const noexcept
145  {
146  return data_.front();
147  }
148 
149  MobilityPeak1D& back() noexcept
150  {
151  return data_.back();
152  }
153  const MobilityPeak1D& back() const noexcept
154  {
155  return data_.back();
156  }
157 
158  Iterator begin() noexcept
159  {
160  return data_.begin();
161  }
162  ConstIterator begin() const noexcept
163  {
164  return data_.begin();
165  }
166  ConstIterator cbegin() const noexcept
167  {
168  return data_.cbegin();
169  }
170 
171  Iterator end() noexcept
172  {
173  return data_.end();
174  }
175  ConstIterator end() const noexcept
176  {
177  return data_.end();
178  }
179  ConstIterator cend() const noexcept
180  {
181  return data_.cend();
182  }
183 
185  {
186  return data_.rbegin();
187  }
189  {
190  return data_.crbegin();
191  }
193  {
194  return data_.rend();
195  }
197  {
198  return data_.crend();
199  }
200 
201  bool empty() const noexcept
202  {
203  return data_.empty();
204  }
206  {
207  return data_.erase(where);
208  }
209 
211  {
212  data_.push_back(mb);
213  }
215  {
216  return data_.emplace_back(mb);
217  }
218  template<class... Args>
219  void emplace_back(Args&&... args)
220  {
221  data_.emplace_back(args...);
222  }
223 
224  void pop_back()
225  {
226  data_.pop_back();
227  }
228 
230  {
231  return data_.insert(where, first, last);
232  }
233 
234  void resize(size_t new_size)
235  {
236  return data_.resize(new_size);
237  }
238  void reserve(size_t new_size)
239  {
240  return data_.reserve(new_size);
241  }
242 
243  size_t size() const noexcept
244  {
245  return data_.size();
246  }
247 
248  void swap(Mobilogram& mb) noexcept
249  {
250  data_.swap(mb.data_);
251  std::swap(retention_time_, mb.retention_time_);
252  std::swap(drift_time_unit_, mb.drift_time_unit_);
253  }
255 
256  // Docu in base class (RangeManager)
257  void updateRanges() override;
258 
262  double getRT() const noexcept
263  {
264  return retention_time_;
265  }
266 
268  void setRT(double rt) noexcept
269  {
270  retention_time_ = rt;
271  }
272 
277  {
278  return drift_time_unit_;
279  }
280 
282  String getDriftTimeUnitAsString() const;
283 
287  void setDriftTimeUnit(DriftTimeUnit dt) noexcept;
288 
290 
291 
293 
294 
299  void sortByIntensity(bool reverse = false);
300 
306  void sortByPosition();
307 
309  bool isSorted() const;
310 
315  template<class Predicate>
316  bool isSorted(const Predicate& lambda) const
317  {
318  auto value_2_index_wrapper = [this, &lambda](const PeakType& value1, const PeakType& value2) {
319  // translate values into indices (this relies on no copies being made!)
320  const Size index1 = (&value1) - (&this->front());
321  const Size index2 = (&value2) - (&this->front());
322  // just make sure the pointers above are actually pointing to a Peak inside our container
323  assert(index1 < this->size());
324  assert(index2 < this->size());
325  return lambda(index1, index2);
326  };
327  return std::is_sorted(this->begin(), this->end(), value_2_index_wrapper);
328  }
329 
331 
334 
344  Size findNearest(CoordinateType mb) const;
345 
357  Int findNearest(CoordinateType mb, CoordinateType tolerance) const;
358 
372  Int findNearest(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
373 
385  Int findHighestInWindow(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
386 
392  Iterator MBBegin(CoordinateType mb);
393 
399  Iterator MBBegin(Iterator begin, CoordinateType mb, Iterator end);
400 
406  Iterator MBEnd(CoordinateType mb);
407 
413  Iterator MBEnd(Iterator begin, CoordinateType mb, Iterator end);
414 
420  ConstIterator MBBegin(CoordinateType mb) const;
421 
427  ConstIterator MBBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const;
428 
434  ConstIterator MBEnd(CoordinateType mb) const;
435 
441  ConstIterator MBEnd(ConstIterator begin, CoordinateType mb, ConstIterator end) const;
442 
450  Iterator PosBegin(CoordinateType mb);
451 
459  Iterator PosBegin(Iterator begin, CoordinateType mb, Iterator end);
460 
468  ConstIterator PosBegin(CoordinateType mb) const;
469 
477  ConstIterator PosBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const;
478 
486  Iterator PosEnd(CoordinateType mb);
487 
495  Iterator PosEnd(Iterator begin, CoordinateType mb, Iterator end);
496 
504  ConstIterator PosEnd(CoordinateType mb) const;
505 
513  ConstIterator PosEnd(ConstIterator begin, CoordinateType mb, ConstIterator end) const;
514 
516 
517 
523  void clear() noexcept;
524 
527  ConstIterator getBasePeak() const;
528 
531  Iterator getBasePeak();
532 
534  PeakType::IntensityType calculateTIC() const;
535 
536  protected:
538  std::vector<MobilityPeak1D> data_;
539 
541  double retention_time_ = -1;
542 
544  DriftTimeUnit drift_time_unit_ = DriftTimeUnit::NONE;
545  };
546 
547  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Mobilogram& mb);
548 } // namespace OpenMS
bool empty() const noexcept
Definition: Mobilogram.h:201
double getRT() const noexcept
Definition: Mobilogram.h:262
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: Mobilogram.h:82
DriftTimeUnit
Drift time unit for ion mobility.
Definition: IMTypes.h:48
A more convenient string class.
Definition: String.h:58
ReverseIterator rend() noexcept
Definition: Mobilogram.h:192
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
void swap(Mobilogram &mb) noexcept
Definition: Mobilogram.h:248
void reserve(size_t new_size)
Definition: Mobilogram.h:238
void setRT(double rt) noexcept
Sets the retention time (in seconds)
Definition: Mobilogram.h:268
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: Mobilogram.h:85
MobilityPeak1D & emplace_back(MobilityPeak1D mb)
Definition: Mobilogram.h:214
ConstIterator cend() const noexcept
Definition: Mobilogram.h:179
STL namespace.
ConstIterator end() const noexcept
Definition: Mobilogram.h:175
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
const MobilityPeak1D & back() const noexcept
Definition: Mobilogram.h:153
double CoordinateType
Coordinate type (of the position)
Definition: Peak2D.h:64
ConstReverseIterator crend() const
Definition: Mobilogram.h:196
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void pop_back()
Definition: Mobilogram.h:224
ConstIterator const_iterator
Definition: Mobilogram.h:83
MobilityPeak1D & front() noexcept
Definition: Mobilogram.h:140
bool isSorted(const Predicate &lambda) const
Definition: Mobilogram.h:316
Iterator begin() noexcept
Definition: Mobilogram.h:158
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: Mobilogram.h:88
ConstReverseIterator const_reverse_iterator
Definition: Mobilogram.h:89
ConstIterator begin() const noexcept
Definition: Mobilogram.h:162
ReverseIterator rbegin() noexcept
Definition: Mobilogram.h:184
ConstIterator erase(ConstIterator where) noexcept
Definition: Mobilogram.h:205
static String & reverse(String &this_s)
Definition: StringUtilsSimple.h:355
MobilityPeak1D & back() noexcept
Definition: Mobilogram.h:149
MobilityPeak1D & operator[](Size i) noexcept
Definition: Mobilogram.h:130
Iterator iterator
Definition: Mobilogram.h:80
size_t size() const noexcept
Definition: Mobilogram.h:243
DriftTimeUnit getDriftTimeUnit() const noexcept
Returns the ion mobility drift time unit.
Definition: Mobilogram.h:276
std::vector< PeakType > ContainerType
Mobilogram base type.
Definition: Mobilogram.h:70
ConstReverseIterator crbegin() const
Definition: Mobilogram.h:188
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
A 1-dimensional raw data mobility point or peak. The unit (ms, 1/K_0, etc) is implicit.
Definition: MobilityPeak1D.h:50
ContainerType::iterator Iterator
Mutable iterator.
Definition: Mobilogram.h:79
void emplace_back(Args &&... args)
Definition: Mobilogram.h:219
Iterator end() noexcept
Definition: Mobilogram.h:171
void resize(size_t new_size)
Definition: Mobilogram.h:234
Iterator insert(ConstIterator where, ConstIterator first, ConstIterator last)
Definition: Mobilogram.h:229
void push_back(MobilityPeak1D mb)
Definition: Mobilogram.h:210
Comparator for the RT of the mobilogram.
Definition: Mobilogram.h:58
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra...
Definition: RangeManager.h:565
const MobilityPeak1D & front() const noexcept
Definition: Mobilogram.h:144
ReverseIterator reverse_iterator
Definition: Mobilogram.h:86
Definition: RangeManager.h:896
custom arguments to allow for looping calls
Definition: WizardHelper.h:72
int Int
Signed integer type.
Definition: Types.h:102
ConstIterator cbegin() const noexcept
Definition: Mobilogram.h:166
The representation of a 1D ion mobilogram.
Definition: Mobilogram.h:54
const MobilityPeak1D & operator[](Size i) const noexcept
Definition: Mobilogram.h:134