OpenMS  2.4.0
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-2018.
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() :
135  position_(),
136  intensity_(0)
137  {}
138 
140  explicit Peak2D(const PositionType& pos, const IntensityType in) :
141  position_(pos),
142  intensity_(in)
143  {}
144 
146  Peak2D(const Peak2D & p) :
147  position_(p.position_),
148  intensity_(p.intensity_)
149  {}
150 
160  {}
162 
167  {
168  return intensity_;
169  }
170 
172  void setIntensity(IntensityType intensity)
173  {
174  intensity_ = intensity;
175  }
176 
178  PositionType const & getPosition() const
179  {
180  return position_;
181  }
182 
185  {
186  return position_;
187  }
188 
191  {
192  position_ = position;
193  }
194 
197  {
198  return position_[MZ];
199  }
200 
202  void setMZ(CoordinateType coordinate)
203  {
204  position_[MZ] = coordinate;
205  }
206 
209  {
210  return position_[RT];
211  }
212 
214  void setRT(CoordinateType coordinate)
215  {
216  position_[RT] = coordinate;
217  }
218 
220 
222  Peak2D & operator=(const Peak2D & rhs)
223  {
224  if (this == &rhs) return *this;
225 
226  intensity_ = rhs.intensity_;
227  position_ = rhs.position_;
228 
229  return *this;
230  }
231 
233  bool operator==(const Peak2D & rhs) const
234  {
235 #pragma clang diagnostic push
236 #pragma clang diagnostic ignored "-Wfloat-equal"
237  return intensity_ == rhs.intensity_ && position_ == rhs.position_;
238 #pragma clang diagnostic pop
239  }
240 
242  bool operator!=(const Peak2D & rhs) const
243  {
244  return !(operator==(rhs));
245  }
246 
252  struct IntensityLess :
255  std::binary_function<Peak2D, Peak2D, bool>
256  {
257  bool operator()(const Peak2D & left, const Peak2D & right) const
258  {
259  return left.getIntensity() < right.getIntensity();
260  }
261 
262  bool operator()(const Peak2D & left, IntensityType right) const
263  {
264  return left.getIntensity() < right;
265  }
266 
267  bool operator()(IntensityType left, const Peak2D & right) const
268  {
269  return left < right.getIntensity();
270  }
271 
272  bool operator()(IntensityType left, IntensityType right) const
273  {
274  return left < right;
275  }
276 
277  };
278 
280  struct RTLess :
281  std::binary_function<Peak2D, Peak2D, bool>
282  {
283  bool operator()(const Peak2D & left, const Peak2D & right) const
284  {
285  return left.getRT() < right.getRT();
286  }
287 
288  bool operator()(const Peak2D & left, CoordinateType right) const
289  {
290  return left.getRT() < right;
291  }
292 
293  bool operator()(CoordinateType left, const Peak2D & right) const
294  {
295  return left < right.getRT();
296  }
297 
298  bool operator()(CoordinateType left, CoordinateType right) const
299  {
300  return left < right;
301  }
302 
303  };
304 
306  struct MZLess :
307  std::binary_function<Peak2D, Peak2D, bool>
308  {
309  bool operator()(const Peak2D & left, const Peak2D & right) const
310  {
311  return left.getMZ() < right.getMZ();
312  }
313 
314  bool operator()(const Peak2D & left, CoordinateType right) const
315  {
316  return left.getMZ() < right;
317  }
318 
319  bool operator()(CoordinateType left, const Peak2D & right) const
320  {
321  return left < right.getMZ();
322  }
323 
324  bool operator()(CoordinateType left, CoordinateType right) const
325  {
326  return left < right;
327  }
328 
329  };
330 
332  struct PositionLess :
333  public std::binary_function<Peak2D, Peak2D, bool>
334  {
335  bool operator()(const Peak2D & left, const Peak2D & right) const
336  {
337  return left.getPosition() < right.getPosition();
338  }
339 
340  bool operator()(const Peak2D & left, const PositionType & right) const
341  {
342  return left.getPosition() < right;
343  }
344 
345  bool operator()(const PositionType & left, const Peak2D & right) const
346  {
347  return left < right.getPosition();
348  }
349 
350  bool operator()(const PositionType & left, const PositionType & right) const
351  {
352  return left < right;
353  }
354 
355  };
357 
358  friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
359 
360 protected:
361 
366  };
367 
369  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
370 
371 } // namespace OpenMS
372 
Peak2D(const PositionType &pos, const IntensityType in)
Member constructor.
Definition: Peak2D.h:140
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:309
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:202
DPosition< 2 > PositionType
Position type.
Definition: Peak2D.h:66
Size< TNeedle >::Type position(const PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:561
bool operator()(CoordinateType left, const Peak2D &right) const
Definition: Peak2D.h:319
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool operator()(IntensityType left, const Peak2D &right) const
Definition: Peak2D.h:267
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:257
bool operator()(const Peak2D &left, CoordinateType right) const
Definition: Peak2D.h:288
Peak2D & operator=(const Peak2D &rhs)
Assignment operator.
Definition: Peak2D.h:222
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
double CoordinateType
Coordinate type (of the position)
Definition: Peak2D.h:64
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
IntensityType getIntensity() const
Definition: Peak2D.h:166
bool operator()(const PositionType &left, const PositionType &right) const
Definition: Peak2D.h:350
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:172
Peak2D()
Definition: Peak2D.h:134
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition: Peak2D.h:332
PositionType position_
The data point position.
Definition: Peak2D.h:363
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:335
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:214
DimensionDescription
This enum maps the symbolic names of the dimensions to numbers.
Definition: Peak2D.h:73
bool operator()(IntensityType left, IntensityType right) const
Definition: Peak2D.h:272
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition: Peak2D.h:196
bool operator!=(const Peak2D &rhs) const
Equality operator.
Definition: Peak2D.h:242
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Peak2D(const Peak2D &p)
Copy constructor.
Definition: Peak2D.h:146
void setPosition(const PositionType &position)
Mutable access to the position.
Definition: Peak2D.h:190
float IntensityType
Intensity type.
Definition: Peak2D.h:62
bool operator()(CoordinateType left, CoordinateType right) const
Definition: Peak2D.h:324
~Peak2D()
Destructor.
Definition: Peak2D.h:159
Comparator by RT position.
Definition: Peak2D.h:280
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
bool operator()(const Peak2D &left, CoordinateType right) const
Definition: Peak2D.h:314
PositionType & getPosition()
Mutable access to the position.
Definition: Peak2D.h:184
bool operator()(CoordinateType left, const Peak2D &right) const
Definition: Peak2D.h:293
PositionType const & getPosition() const
Non-mutable access to the position.
Definition: Peak2D.h:178
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition: Peak2D.h:283
bool operator()(const Peak2D &left, IntensityType right) const
Definition: Peak2D.h:262
bool operator()(const Peak2D &left, const PositionType &right) const
Definition: Peak2D.h:340
bool operator()(CoordinateType left, CoordinateType right) const
Definition: Peak2D.h:298
IntensityType intensity_
The data point intensity.
Definition: Peak2D.h:365
Comparator by m/z position.
Definition: Peak2D.h:306
bool operator()(const PositionType &left, const Peak2D &right) const
Definition: Peak2D.h:345
bool operator==(const Peak2D &rhs) const
Equality operator.
Definition: Peak2D.h:233