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
16
19
20#include <algorithm>
21#include <numeric>
22
23namespace OpenMS
24{
25 enum class DriftTimeUnit;
35 class OPENMS_DLLAPI Mobilogram final : public RangeManagerContainer<RangeMobility, RangeIntensity>
36 {
37 public:
39 struct OPENMS_DLLAPI RTLess {
40 bool operator()(const Mobilogram& a, const Mobilogram& b) const;
41 };
42
43
45
46
51 using ContainerType = std::vector<PeakType>;
57 typedef std::vector<FloatDataArray> FloatDataArrays;
60 typedef std::vector<StringDataArray> StringDataArrays;
63 typedef std::vector<IntegerDataArray> IntegerDataArrays;
65
67
68
69 using Iterator = ContainerType::iterator;
72 using ConstIterator = ContainerType::const_iterator;
75 using ReverseIterator = ContainerType::reverse_iterator;
78 using ConstReverseIterator = ContainerType::const_reverse_iterator;
81 /*using typename ContainerType::const_reference;
82 using typename ContainerType::difference_type;
83 using typename ContainerType::pointer;
84 using typename ContainerType::reference;
85 using typename ContainerType::size_type;
86 using typename ContainerType::value_type;*/
87
88 // rule of 6
89
91 Mobilogram() = default;
92
94 Mobilogram(const Mobilogram& source) = default;
95
97 Mobilogram(Mobilogram&&) noexcept = default;
98
100 Mobilogram& operator=(const Mobilogram& source) = default;
101
103 Mobilogram& operator=(Mobilogram&&) noexcept = default;
104
106 ~Mobilogram() = default;
107
108
110 bool operator==(const Mobilogram& rhs) const;
111
113 bool operator!=(const Mobilogram& rhs) const
114 {
115 return !(operator==(rhs));
116 }
117
119
121 {
122 return data_[i];
123 }
124 const MobilityPeak1D& operator[](Size i) const noexcept
125 {
126 return data_[i];
127 }
128
129
131 {
132 return data_.front();
133 }
134 const MobilityPeak1D& front() const noexcept
135 {
136 return data_.front();
137 }
138
140 {
141 return data_.back();
142 }
143 const MobilityPeak1D& back() const noexcept
144 {
145 return data_.back();
146 }
147
148 Iterator begin() noexcept
149 {
150 return data_.begin();
151 }
152 ConstIterator begin() const noexcept
153 {
154 return data_.begin();
155 }
156 ConstIterator cbegin() const noexcept
157 {
158 return data_.cbegin();
159 }
160
161 Iterator end() noexcept
162 {
163 return data_.end();
164 }
165 ConstIterator end() const noexcept
166 {
167 return data_.end();
168 }
169 ConstIterator cend() const noexcept
170 {
171 return data_.cend();
172 }
173
175 {
176 return data_.rbegin();
177 }
179 {
180 return data_.crbegin();
181 }
183 {
184 return data_.rend();
185 }
187 {
188 return data_.crend();
189 }
190
191 bool empty() const noexcept
192 {
193 return data_.empty();
194 }
196 {
197 return data_.erase(where);
198 }
199
201 {
202 data_.push_back(mb);
203 }
205 {
206 return data_.emplace_back(mb);
207 }
208 template<class... Args>
209 void emplace_back(Args&&... args)
210 {
211 data_.emplace_back(args...);
212 }
213
214 void pop_back()
215 {
216 data_.pop_back();
217 }
218
220 {
221 return data_.insert(where, first, last);
222 }
223
224 void resize(size_t new_size)
225 {
226 return data_.resize(new_size);
227 }
228 void reserve(size_t new_size)
229 {
230 return data_.reserve(new_size);
231 }
232
233 size_t size() const noexcept
234 {
235 return data_.size();
236 }
237
238 void swap(Mobilogram& mb) noexcept
239 {
240 data_.swap(mb.data_);
241 std::swap(retention_time_, mb.retention_time_);
242 std::swap(drift_time_unit_, mb.drift_time_unit_);
243 }
245
246 // Docu in base class (RangeManager)
247 void updateRanges() override;
248
250 double getRT() const noexcept
251 {
252 return retention_time_;
253 }
254
256 void setRT(double rt) noexcept
257 {
258 retention_time_ = rt;
259 }
260
265 {
266 return drift_time_unit_;
267 }
268
270 std::string getDriftTimeUnitAsString() const;
271
276
278
294
297
300 {
301 float_data_arrays_ = fda;
302 }
303
306
309
312 {
313 string_data_arrays_ = sda;
314 }
315
318
321
324 {
325 integer_data_arrays_ = ida;
326 }
327
329
331
332
337 void sortByIntensity(bool reverse = false);
338
346
348 bool isSorted() const;
349
354 template<class Predicate>
355 bool isSorted(const Predicate& lambda) const
356 {
357 auto value_2_index_wrapper = [this, &lambda](const PeakType& value1, const PeakType& value2) {
358 // translate values into indices (this relies on no copies being made!)
359 const Size index1 = (&value1) - (&this->front());
360 const Size index2 = (&value2) - (&this->front());
361 // just make sure the pointers above are actually pointing to a Peak inside our container
362 assert(index1 < this->size());
363 assert(index2 < this->size());
364 return lambda(index1, index2);
365 };
366 return std::is_sorted(this->begin(), this->end(), value_2_index_wrapper);
367 }
368
387 template<class Predicate>
388 void sort(const Predicate& lambda)
389 {
390 // Validate up front, before running the (possibly data-array-indexing) predicate, so a
391 // mis-sized array throws instead of being read out of bounds during the sort.
392 checkDataArraySizes_();
393 // The sorted indices are a permutation of [0, size): in range and duplicate-free by
394 // construction, so the unchecked path is safe and skips the redundant bounds re-scan.
395 selectUnchecked(Internal::stableSortedIndices(this->size(), lambda));
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
614 Mobilogram& select(const std::vector<Size>& indices);
615
631 Mobilogram& selectUnchecked(const std::vector<Size>& indices);
632
635 ConstIterator getBasePeak() const;
636
639 Iterator getBasePeak();
640
642 PeakType::IntensityType calculateTIC() const;
643
644 protected:
654 void checkDataArraySizes_() const;
655
657 std::vector<MobilityPeak1D> data_;
658
660 double retention_time_ = -1;
661
663 DriftTimeUnit drift_time_unit_ = DriftTimeUnit::NONE;
664
666 FloatDataArrays float_data_arrays_;
667
669 StringDataArrays string_data_arrays_;
670
672 IntegerDataArrays integer_data_arrays_;
673 };
674
675 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Mobilogram& mb);
676} // 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:36
ConstIterator const_iterator
Definition Mobilogram.h:73
void setIntegerDataArrays(const IntegerDataArrays &ida)
Sets the integer meta data arrays.
Definition Mobilogram.h:323
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:70
const MobilityPeak1D & front() const noexcept
Definition Mobilogram.h:134
void pop_back()
Definition Mobilogram.h:214
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:238
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:204
void setDriftTimeUnit(DriftTimeUnit dt) noexcept
Sets the ion mobility drift time unit.
MobilityPeak1D & operator[](Size i) noexcept
Definition Mobilogram.h:120
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:174
ConstReverseIterator crbegin() const
Definition Mobilogram.h:178
std::vector< StringDataArray > StringDataArrays
Definition Mobilogram.h:60
OpenMS::DataArrays::FloatDataArray FloatDataArray
Float data array vector type.
Definition Mobilogram.h:56
MobilityPeak1D & back() noexcept
Definition Mobilogram.h:139
ConstIterator MBBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
size_t size() const noexcept
Definition Mobilogram.h:233
bool empty() const noexcept
Definition Mobilogram.h:191
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition Mobilogram.h:78
Mobilogram()=default
Constructor.
ConstIterator begin() const noexcept
Definition Mobilogram.h:152
ConstIterator cbegin() const noexcept
Definition Mobilogram.h:156
ReverseIterator rend() noexcept
Definition Mobilogram.h:182
Iterator begin() noexcept
Definition Mobilogram.h:148
PeakType::CoordinateType CoordinateType
Coordinate (mobility) type.
Definition Mobilogram.h:49
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
const MobilityPeak1D & back() const noexcept
Definition Mobilogram.h:143
void resize(size_t new_size)
Definition Mobilogram.h:224
const MobilityPeak1D & operator[](Size i) const noexcept
Definition Mobilogram.h:124
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:219
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:228
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:256
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition Mobilogram.h:75
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:169
void sort(const Predicate &lambda)
Stably sorts the peaks (and all parallel data arrays) by a user-defined predicate.
Definition Mobilogram.h:388
OpenMS::DataArrays::StringDataArray StringDataArray
std::string data array vector type
Definition Mobilogram.h:59
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition Mobilogram.h:72
ConstIterator erase(ConstIterator where) noexcept
Definition Mobilogram.h:195
ConstReverseIterator const_reverse_iterator
Definition Mobilogram.h:79
ConstIterator PosBegin(ConstIterator begin, CoordinateType mb, ConstIterator end) const
Binary search for peak range begin.
ReverseIterator reverse_iterator
Definition Mobilogram.h:76
std::vector< PeakType > ContainerType
Mobilogram base type.
Definition Mobilogram.h:51
double getRT() const noexcept
Returns the retention time (in seconds)
Definition Mobilogram.h:250
ConstIterator end() const noexcept
Definition Mobilogram.h:165
bool isSorted(const Predicate &lambda) const
Definition Mobilogram.h:355
IntegerDataArrays & getIntegerDataArrays()
Returns a mutable reference to the integer meta data arrays.
void emplace_back(Args &&... args)
Definition Mobilogram.h:209
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:186
void setStringDataArrays(const StringDataArrays &sda)
Sets the string meta data arrays.
Definition Mobilogram.h:311
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:130
void push_back(MobilityPeak1D mb)
Definition Mobilogram.h:200
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:264
std::vector< FloatDataArray > FloatDataArrays
Definition Mobilogram.h:57
Mobilogram(const Mobilogram &source)=default
Copy constructor.
Iterator MBBegin(CoordinateType mb)
Binary search for peak range begin.
Iterator end() noexcept
Definition Mobilogram.h:161
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:62
std::vector< IntegerDataArray > IntegerDataArrays
Definition Mobilogram.h:63
void setFloatDataArrays(const FloatDataArrays &fda)
Sets the float meta data arrays.
Definition Mobilogram.h:299
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
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:179
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:39
bool operator()(const Mobilogram &a, const Mobilogram &b) const