OpenMS
Peak2D.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-2023.
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: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <iosfwd>
41 #include <functional>
42 
43 namespace OpenMS
44 {
45 
54  class OPENMS_DLLAPI Peak2D
55  {
56 public:
57 
60 
62  typedef float IntensityType;
64  typedef double CoordinateType;
68 
71 
74  {
75  RT = 0,
76  MZ = 1,
77  DIMENSION = 2
78  };
79 
81  static char const * shortDimensionName(UInt const dim);
83  static char const * shortDimensionNameRT();
85  static char const * shortDimensionNameMZ();
86 
88  static char const * fullDimensionName(UInt const dim);
90  static char const * fullDimensionNameRT();
92  static char const * fullDimensionNameMZ();
93 
95  static char const * shortDimensionUnit(UInt const dim);
97  static char const * shortDimensionUnitRT();
99  static char const * shortDimensionUnitMZ();
100 
102  static char const * fullDimensionUnit(UInt const dim);
104  static char const * fullDimensionUnitRT();
106  static char const * fullDimensionUnitMZ();
107 
109 
110 protected:
111 
114 
116  static char const * const dimension_name_short_[DIMENSION];
117 
119  static char const * const dimension_name_full_[DIMENSION];
120 
122  static char const * const dimension_unit_short_[DIMENSION];
123 
125  static char const * const dimension_unit_full_[DIMENSION];
126 
128 
129 public:
130 
134  Peak2D() = default;
135 
137  explicit Peak2D(const PositionType& pos, const IntensityType in) :
138  position_(pos),
139  intensity_(in)
140  {}
141 
143  Peak2D(const Peak2D & p) = default;
144 
146  Peak2D(Peak2D&&) noexcept = default;
147 
149  Peak2D& operator=(const Peak2D& rhs) = default;
150 
152  Peak2D& operator=(Peak2D&&) noexcept = default;
161  ~Peak2D() noexcept = default;
162 
164 
168  IntensityType getIntensity() const
169  {
170  return intensity_;
171  }
172 
174  void setIntensity(IntensityType intensity)
175  {
176  intensity_ = intensity;
177  }
178 
180  PositionType const & getPosition() const
181  {
182  return position_;
183  }
184 
187  {
188  return position_;
189  }
190 
192  void setPosition(const PositionType & position)
193  {
194  position_ = position;
195  }
196 
199  {
200  return position_[MZ];
201  }
202 
204  void setMZ(CoordinateType coordinate)
205  {
206  position_[MZ] = coordinate;
207  }
208 
211  {
212  return position_[RT];
213  }
214 
216  void setRT(CoordinateType coordinate)
217  {
218  position_[RT] = coordinate;
219  }
220 
222 
224  bool operator==(const Peak2D & rhs) const
225  {
226 #pragma clang diagnostic push
227 #pragma clang diagnostic ignored "-Wfloat-equal"
228  return intensity_ == rhs.intensity_ && position_ == rhs.position_;
229 #pragma clang diagnostic pop
230  }
231 
233  bool operator!=(const Peak2D & rhs) const
234  {
235  return !(operator==(rhs));
236  }
237 
246  {
247  bool operator()(const Peak2D & left, const Peak2D & right) const
248  {
249  return left.getIntensity() < right.getIntensity();
250  }
251 
252  bool operator()(const Peak2D & left, IntensityType right) const
253  {
254  return left.getIntensity() < right;
255  }
256 
257  bool operator()(IntensityType left, const Peak2D & right) const
258  {
259  return left < right.getIntensity();
260  }
261 
262  bool operator()(IntensityType left, IntensityType right) const
263  {
264  return left < right;
265  }
266 
267  };
268 
270  struct RTLess
271  {
272  bool operator()(const Peak2D & left, const Peak2D & right) const
273  {
274  return left.getRT() < right.getRT();
275  }
276 
277  bool operator()(const Peak2D & left, CoordinateType right) const
278  {
279  return left.getRT() < right;
280  }
281 
282  bool operator()(CoordinateType left, const Peak2D & right) const
283  {
284  return left < right.getRT();
285  }
286 
287  bool operator()(CoordinateType left, CoordinateType right) const
288  {
289  return left < right;
290  }
291 
292  };
293 
295  struct MZLess
296  {
297  bool operator()(const Peak2D & left, const Peak2D & right) const
298  {
299  return left.getMZ() < right.getMZ();
300  }
301 
302  bool operator()(const Peak2D & left, CoordinateType right) const
303  {
304  return left.getMZ() < right;
305  }
306 
307  bool operator()(CoordinateType left, const Peak2D & right) const
308  {
309  return left < right.getMZ();
310  }
311 
312  bool operator()(CoordinateType left, CoordinateType right) const
313  {
314  return left < right;
315  }
316 
317  };
318 
321  {
322  bool operator()(const Peak2D & left, const Peak2D & right) const
323  {
324  return left.getPosition() < right.getPosition();
325  }
326 
327  bool operator()(const Peak2D & left, const PositionType & right) const
328  {
329  return left.getPosition() < right;
330  }
331 
332  bool operator()(const PositionType & left, const Peak2D & right) const
333  {
334  return left < right.getPosition();
335  }
336 
337  bool operator()(const PositionType & left, const PositionType & right) const
338  {
339  return left < right;
340  }
341 
342  };
344 
345  friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
346 
347 protected:
348 
350  PositionType position_{};
352  IntensityType intensity_{};
353  };
354 
356  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
357 
358 } // namespace OpenMS
359 
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:198
PositionType const & getPosition() const
Non-mutable access to the position.
Definition: Peak2D.h:180
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:204
Peak2D(Peak2D &&) noexcept=default
Move constructor.
Peak2D(const PositionType &pos, const IntensityType in)
Member constructor.
Definition: Peak2D.h:137
float IntensityType
Intensity type.
Definition: Peak2D.h:62
double CoordinateType
Coordinate type (of the position)
Definition: Peak2D.h:64
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:216
bool operator==(const Peak2D &rhs) const
Equality operator.
Definition: Peak2D.h:224
static char const * fullDimensionName(UInt const dim)
Full name of the dimension (self-explanatory form)
PositionType position_
The data point position.
Definition: Peak2D.h:350
static char const * shortDimensionUnitRT()
Unit of measurement (abbreviated form)
static char const * fullDimensionUnitRT()
Unit of measurement (self-explanatory form)
static char const * shortDimensionUnitMZ()
Unit of measurement (abbreviated form)
static char const * shortDimensionNameMZ()
Short name of the dimension (abbreviated form)
static char const * fullDimensionNameRT()
Full name of the dimension (self-explanatory form)
IntensityType getIntensity() const
Definition: Peak2D.h:168
static char const * shortDimensionUnit(UInt const dim)
Unit of measurement (abbreviated form)
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition: Peak2D.h:174
void setPosition(const PositionType &position)
Mutable access to the position.
Definition: Peak2D.h:192
DimensionDescription
This enum maps the symbolic names of the dimensions to numbers.
Definition: Peak2D.h:74
friend std::ostream & operator<<(std::ostream &os, const Peak2D &point)
Print the contents to a stream.
Peak2D()=default
DPosition< 2 > PositionType
Position type.
Definition: Peak2D.h:66
bool operator!=(const Peak2D &rhs) const
Equality operator.
Definition: Peak2D.h:233
static char const * shortDimensionName(UInt const dim)
Short name of the dimension (abbreviated form)
IntensityType intensity_
The data point intensity.
Definition: Peak2D.h:352
static char const * fullDimensionUnit(UInt const dim)
Unit of measurement (self-explanatory form)
static char const * fullDimensionNameMZ()
Full name of the dimension (self-explanatory form)
static char const * fullDimensionUnitMZ()
Unit of measurement (self-explanatory form)
static char const * shortDimensionNameRT()
Short name of the dimension (abbreviated form)
PositionType & getPosition()
Mutable access to the position.
Definition: Peak2D.h:186
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:210
Peak2D(const Peak2D &p)=default
Copy constructor.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
@ RT
RT in seconds.
Definition: Peak2D.h:246
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:247
bool operator()(const Peak2D &left, IntensityType right) const
Definition: Peak2D.h:252
bool operator()(IntensityType left, const Peak2D &right) const
Definition: Peak2D.h:257
bool operator()(IntensityType left, IntensityType right) const
Definition: Peak2D.h:262
Comparator by m/z position.
Definition: Peak2D.h:296
bool operator()(CoordinateType left, CoordinateType right) const
Definition: Peak2D.h:312
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:297
bool operator()(CoordinateType left, const Peak2D &right) const
Definition: Peak2D.h:307
bool operator()(const Peak2D &left, CoordinateType right) const
Definition: Peak2D.h:302
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition: Peak2D.h:321
bool operator()(const PositionType &left, const PositionType &right) const
Definition: Peak2D.h:337
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:322
bool operator()(const Peak2D &left, const PositionType &right) const
Definition: Peak2D.h:327
bool operator()(const PositionType &left, const Peak2D &right) const
Definition: Peak2D.h:332
Comparator by RT position.
Definition: Peak2D.h:271
bool operator()(CoordinateType left, CoordinateType right) const
Definition: Peak2D.h:287
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:272
bool operator()(CoordinateType left, const Peak2D &right) const
Definition: Peak2D.h:282
bool operator()(const Peak2D &left, CoordinateType right) const
Definition: Peak2D.h:277