OpenMS
Loading...
Searching...
No Matches
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#include <algorithm>
20#include <numeric>
21
22namespace OpenMS
23{
24 enum class DriftTimeUnit;
34 class OPENMS_DLLAPI Mobilogram final : public RangeManagerContainer<RangeMobility, RangeIntensity>
35 {
36 public:
38 struct OPENMS_DLLAPI RTLess {
39 bool operator()(const Mobilogram& a, const Mobilogram& b) const;
40 };
41
42
44
45
50 using ContainerType = std::vector<PeakType>;
56 typedef std::vector<FloatDataArray> FloatDataArrays;
59 typedef std::vector<StringDataArray> StringDataArrays;
62 typedef std::vector<IntegerDataArray> IntegerDataArrays;
64
66
67
68 using Iterator = ContainerType::iterator;
71 using ConstIterator = ContainerType::const_iterator;
74 using ReverseIterator = ContainerType::reverse_iterator;
77 using ConstReverseIterator = ContainerType::const_reverse_iterator;
80 /*using typename ContainerType::const_reference;
81 using typename ContainerType::difference_type;
82 using typename ContainerType::pointer;
83 using typename ContainerType::reference;
84 using typename ContainerType::size_type;
85 using typename ContainerType::value_type;*/
86
87 // rule of 6
88
90 Mobilogram() = default;
91
93 Mobilogram(const Mobilogram& source) = default;
94
96 Mobilogram(Mobilogram&&) noexcept = default;
97
99 Mobilogram& operator=(const Mobilogram& source) = default;
100
102 Mobilogram& operator=(Mobilogram&&) noexcept = default;
103
105 ~Mobilogram() = default;
106
107
109 bool operator==(const Mobilogram& rhs) const;
110
112 bool operator!=(const Mobilogram& rhs) const
113 {
114 return !(operator==(rhs));
115 }
116
118
120 {
121 return data_[i];
122 }
123 const MobilityPeak1D& operator[](Size i) const noexcept
124 {
125 return data_[i];
126 }
127
128
130 {
131 return data_.front();
132 }
133 const MobilityPeak1D& front() const noexcept
134 {
135 return data_.front();
136 }
137
139 {
140 return data_.back();
141 }
142 const MobilityPeak1D& back() const noexcept
143 {
144 return data_.back();
145 }
146
147 Iterator begin() noexcept
148 {
149 return data_.begin();
150 }
151 ConstIterator begin() const noexcept
152 {
153 return data_.begin();
154 }
155 ConstIterator cbegin() const noexcept
156 {
157 return data_.cbegin();
158 }
159
160 Iterator end() noexcept
161 {
162 return data_.end();
163 }
164 ConstIterator end() const noexcept
165 {
166 return data_.end();
167 }
168 ConstIterator cend() const noexcept
169 {
170 return data_.cend();
171 }
172
174 {
175 return data_.rbegin();
176 }
178 {
179 return data_.crbegin();
180 }
182 {
183 return data_.rend();
184 }
186 {
187 return data_.crend();
188 }
189
190 bool empty() const noexcept
191 {
192 return data_.empty();
193 }
195 {
196 return data_.erase(where);
197 }
198
200 {
201 data_.push_back(mb);
202 }
204 {
205 return data_.emplace_back(mb);
206 }
207 template<class... Args>
208 void emplace_back(Args&&... args)
209 {
210 data_.emplace_back(args...);
211 }
212
213 void pop_back()
214 {
215 data_.pop_back();
216 }
217
219 {
220 return data_.insert(where, first, last);
221 }
222
223 void resize(size_t new_size)
224 {
225 return data_.resize(new_size);
226 }
227 void reserve(size_t new_size)
228 {
229 return data_.reserve(new_size);
230 }
231
232 size_t size() const noexcept
233 {
234 return data_.size();
235 }
236
237 void swap(Mobilogram& mb) noexcept
238 {
239 data_.swap(mb.data_);
240 std::swap(retention_time_, mb.retention_time_);
241 std::swap(drift_time_unit_, mb.drift_time_unit_);
242 }
244
245 // Docu in base class (RangeManager)
246 void updateRanges() override;
247
249 double getRT() const noexcept
250 {
251 return retention_time_;
252 }
253
255 void setRT(double rt) noexcept
256 {
257 retention_time_ = rt;
258 }
259
264 {
265 return drift_time_unit_;
266 }
267
269 std::string getDriftTimeUnitAsString() const;
270
275
277
293
296
299 {
300 float_data_arrays_ = fda;
301 }
302
305
308
311 {
312 string_data_arrays_ = sda;
313 }
314
317
320
323 {
324 integer_data_arrays_ = ida;
325 }
326
328
330
331
336 void sortByIntensity(bool reverse = false);
337
345
347 bool isSorted() const;
348
353 template<class Predicate>
354 bool isSorted(const Predicate& lambda) const
355 {
356 auto value_2_index_wrapper = [this, &lambda](const PeakType& value1, const PeakType& value2) {
357 // translate values into indices (this relies on no copies being made!)
358 const Size index1 = (&value1) - (&this->front());
359 const Size index2 = (&value2) - (&this->front());
360 // just make sure the pointers above are actually pointing to a Peak inside our container
361 assert(index1 < this->size());
362 assert(index2 < this->size());
363 return lambda(index1, index2);
364 };
365 return std::is_sorted(this->begin(), this->end(), value_2_index_wrapper);
366 }
367
386 template<class Predicate>
387 void sort(const Predicate& lambda)
388 {
389 // Validate up front, before running the (possibly data-array-indexing) predicate, so a
390 // mis-sized array throws instead of being read out of bounds during the sort.
391 checkDataArraySizes_();
392 std::vector<Size> indices(this->size());
393 std::iota(indices.begin(), indices.end(), 0);
394 std::stable_sort(indices.begin(), indices.end(), lambda);
395 select(indices);
396 }
397
399
402
413
426
440 Int findNearest(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
441
454 Int findHighestInWindow(CoordinateType mb, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
455
462
469
476
483
490
497
504
511
520
529
538
547
556
565
574
583
585
586
595 void clear() noexcept;
596
613 Mobilogram& select(const std::vector<Size>& indices);
614
617 ConstIterator getBasePeak() const;
618
621 Iterator getBasePeak();
622
624 PeakType::IntensityType calculateTIC() const;
625
626 protected:
636 void checkDataArraySizes_() const;
637
639 std::vector<MobilityPeak1D> data_;
640
642 double retention_time_ = -1;
643
645 DriftTimeUnit drift_time_unit_ = DriftTimeUnit::NONE;
646
648 FloatDataArrays float_data_arrays_;
649
651 StringDataArrays string_data_arrays_;
652
654 IntegerDataArrays integer_data_arrays_;
655 };
656
657 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Mobilogram& mb);
658} // namespace OpenMS
Float data array class.
Definition DataArrays.h:25
Integer data array class.
Definition DataArrays.h:75
std::string data array class
Definition DataArrays.h:125
A 1-dimensional raw data mobility point or peak. The unit (ms, 1/K_0, etc) is implicit.
Definition MobilityPeak1D.h:28
double CoordinateType
Coordinate type.
Definition MobilityPeak1D.h:39
The representation of a 1D ion mobilogram.
Definition Mobilogram.h:35
ConstIterator const_iterator
Definition Mobilogram.h:72
void setIntegerDataArrays(const IntegerDataArrays &ida)
Sets the integer meta data arrays.
Definition Mobilogram.h:322
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:69
const MobilityPeak1D & front() const noexcept
Definition Mobilogram.h:133
void pop_back()
Definition Mobilogram.h:213
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:237
ConstIterator PosEnd(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range end (returns the past-the-end iterator)
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
MobilityPeak1D & emplace_back(MobilityPeak1D mb)
Definition Mobilogram.h:203
void setDriftTimeUnit(DriftTimeUnit dt) noexcept
Sets the ion mobility drift time unit.
MobilityPeak1D & operator[](Size i) noexcept
Definition Mobilogram.h:119
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:173
ConstReverseIterator crbegin() const
Definition Mobilogram.h:177
std::vector< StringDataArray > StringDataArrays
Definition Mobilogram.h:59
OpenMS::DataArrays::FloatDataArray FloatDataArray
Float data array vector type.
Definition Mobilogram.h:55
MobilityPeak1D & back() noexcept
Definition Mobilogram.h:138
ConstIterator MBBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
size_t size() const noexcept
Definition Mobilogram.h:232
bool empty() const noexcept
Definition Mobilogram.h:190
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition Mobilogram.h:77
Mobilogram()=default
Constructor.
ConstIterator begin() const noexcept
Definition Mobilogram.h:151
ConstIterator cbegin() const noexcept
Definition Mobilogram.h:155
ReverseIterator rend() noexcept
Definition Mobilogram.h:181
Iterator begin() noexcept
Definition Mobilogram.h:147
PeakType::CoordinateType CoordinateType
Coordinate (mobility) type.
Definition Mobilogram.h:48
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
const MobilityPeak1D & back() const noexcept
Definition Mobilogram.h:142
void resize(size_t new_size)
Definition Mobilogram.h:223
const MobilityPeak1D & operator[](Size i) const noexcept
Definition Mobilogram.h:123
bool isSorted() const
Checks if all peaks are sorted with respect to ascending mobility.
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:218
ConstIterator PosEnd(CoordinateType mb) const
Binary search for peak range end (returns the past-the-end iterator)
Mobilogram(Mobilogram &&) noexcept=default
Move constructor.
void reserve(size_t new_size)
Definition Mobilogram.h:227
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:255
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition Mobilogram.h:74
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.
FloatDataArrays & getFloatDataArrays()
Returns a mutable reference to the float meta data arrays.
ConstIterator cend() const noexcept
Definition Mobilogram.h:168
void sort(const Predicate &lambda)
Stably sorts the peaks (and all parallel data arrays) by a user-defined predicate.
Definition Mobilogram.h:387
OpenMS::DataArrays::StringDataArray StringDataArray
std::string data array vector type
Definition Mobilogram.h:58
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition Mobilogram.h:71
ConstIterator erase(ConstIterator where) noexcept
Definition Mobilogram.h:194
ConstReverseIterator const_reverse_iterator
Definition Mobilogram.h:78
ConstIterator PosBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
ReverseIterator reverse_iterator
Definition Mobilogram.h:75
std::vector< PeakType > ContainerType
Mobilogram base type.
Definition Mobilogram.h:50
double getRT() const noexcept
Returns the retention time (in seconds)
Definition Mobilogram.h:249
ConstIterator end() const noexcept
Definition Mobilogram.h:164
bool isSorted(const Predicate &lambda) const
Definition Mobilogram.h:354
IntegerDataArrays & getIntegerDataArrays()
Returns a mutable reference to the integer meta data arrays.
void emplace_back(Args &&... args)
Definition Mobilogram.h:208
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:185
void setStringDataArrays(const StringDataArrays &sda)
Sets the string meta data arrays.
Definition Mobilogram.h:310
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 +/- ...
const FloatDataArrays & getFloatDataArrays() const
MobilityPeak1D & front() noexcept
Definition Mobilogram.h:129
void push_back(MobilityPeak1D mb)
Definition Mobilogram.h:199
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:263
std::vector< FloatDataArray > FloatDataArrays
Definition Mobilogram.h:56
Mobilogram(const Mobilogram &source)=default
Copy constructor.
Iterator MBBegin(CoordinateType mb)
Binary search for peak range begin.
Iterator end() noexcept
Definition Mobilogram.h:160
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:61
std::vector< IntegerDataArray > IntegerDataArrays
Definition Mobilogram.h:62
void setFloatDataArrays(const FloatDataArrays &fda)
Sets the float meta data arrays.
Definition Mobilogram.h:298
StringDataArrays & getStringDataArrays()
Returns a mutable reference to the string meta data arrays.
std::string getDriftTimeUnitAsString() const
returns the ion mobility drift time unit as string
Definition RangeManager.h:889
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition RangeManager.h:568
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)
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
DriftTimeUnit
Drift time unit for ion mobility.
Definition IMTypes.h:23
STL namespace.
Comparator for the RT of the mobilogram.
Definition Mobilogram.h:38
bool operator()(const Mobilogram &a, const Mobilogram &b) const