~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/KERNEL/Peak2D.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework 
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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-2013.
 
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.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Stephan Aiche$
37
44
namespace OpenMS
38
45
{
39
46
 
40
 
        /**
41
 
                @brief A 2-dimensional raw data point or peak.
42
 
         
43
 
                This datastructure is intended for continuous data or peak data.
44
 
                If wou want to annotated single peaks with meta data, use RichPeak2D instead.
45
 
 
46
 
                @ingroup Kernel
47
 
        */
48
 
        class OPENMS_DLLAPI Peak2D
49
 
        {
50
 
         public:
51
 
                
52
 
                /** @name Type definitions
53
 
                 */
54
 
                //@{
55
 
    
 
47
  /**
 
48
    @brief A 2-dimensional raw data point or peak.
 
49
 
 
50
    This datastructure is intended for continuous data or peak data.
 
51
    If wou want to annotated single peaks with meta data, use RichPeak2D instead.
 
52
 
 
53
    @ingroup Kernel
 
54
  */
 
55
  class OPENMS_DLLAPI Peak2D
 
56
  {
 
57
public:
 
58
 
 
59
    ///@name Type definitions
 
60
    ///@{
 
61
 
56
62
    /// Intensity type
57
63
    typedef Real IntensityType;
58
64
    /// Coordinate type (of the position)
59
 
                typedef DoubleReal CoordinateType;
60
 
                /// Position type
61
 
                typedef DPosition<2> PositionType;
62
 
    //@}
63
 
 
64
 
                /// @name Dimension descriptions
65
 
                //@{
66
 
                
67
 
                /// This enum maps the symbolic names of the dimensions to numbers
68
 
                enum DimensionDescription
69
 
                {
70
 
                        RT = 0, ///< Retention time dimension id (0 if used as a const int)
71
 
                        MZ = 1, ///< Mass-to-charge dimension id (1 if used as a const int)
72
 
                        DIMENSION = 2 ///< Number of dimensions
73
 
                };
74
 
                
 
65
    typedef DoubleReal CoordinateType;
 
66
    /// Position type
 
67
    typedef DPosition<2> PositionType;
 
68
    ///@}
 
69
 
 
70
    /// @name Dimension descriptions
 
71
    ///@{
 
72
 
 
73
    /// This enum maps the symbolic names of the dimensions to numbers
 
74
    enum DimensionDescription
 
75
    {
 
76
      RT = 0,       ///< Retention time dimension id (0 if used as a const int)
 
77
      MZ = 1,       ///< Mass-to-charge dimension id (1 if used as a const int)
 
78
      DIMENSION = 2 ///< Number of dimensions
 
79
    };
 
80
 
75
81
    /// Short name of the dimension (abbreviated form)
76
82
    static char const * shortDimensionName(UInt const dim);
77
83
    /// Short name of the dimension (abbreviated form)
87
93
    static char const * fullDimensionNameMZ();
88
94
 
89
95
    /// Unit of measurement (abbreviated form)
90
 
                static char const * shortDimensionUnit(UInt const dim);
91
 
    /// Unit of measurement (abbreviated form)
92
 
                static char const * shortDimensionUnitRT();
93
 
    /// Unit of measurement (abbreviated form)
94
 
                static char const * shortDimensionUnitMZ();
95
 
 
96
 
    /// Unit of measurement (self-explanatory form)
97
 
                static char const * fullDimensionUnit(UInt const dim);
98
 
    /// Unit of measurement (self-explanatory form)
99
 
                static char const * fullDimensionUnitRT();
100
 
    /// Unit of measurement (self-explanatory form)
101
 
                static char const * fullDimensionUnitMZ();
102
 
 
103
 
                //@}
104
 
                
105
 
         protected:
106
 
                
107
 
                /// @name Dimension descriptions
108
 
                //@{
109
 
                
 
96
    static char const * shortDimensionUnit(UInt const dim);
 
97
    /// Unit of measurement (abbreviated form)
 
98
    static char const * shortDimensionUnitRT();
 
99
    /// Unit of measurement (abbreviated form)
 
100
    static char const * shortDimensionUnitMZ();
 
101
 
 
102
    /// Unit of measurement (self-explanatory form)
 
103
    static char const * fullDimensionUnit(UInt const dim);
 
104
    /// Unit of measurement (self-explanatory form)
 
105
    static char const * fullDimensionUnitRT();
 
106
    /// Unit of measurement (self-explanatory form)
 
107
    static char const * fullDimensionUnitMZ();
 
108
 
 
109
    ///@}
 
110
 
 
111
protected:
 
112
 
 
113
    /// @name Dimension descriptions
 
114
    ///@{
 
115
 
110
116
    /// Short name of the dimension (abbreviated form)
111
 
                static char const * const dimension_name_short_[DIMENSION];
112
 
                
 
117
    static char const * const dimension_name_short_[DIMENSION];
 
118
 
113
119
    /// Full name of the dimension (self-explanatory form)
114
120
    static char const * const dimension_name_full_[DIMENSION];
115
 
                
 
121
 
116
122
    /// Unit of measurement (abbreviated form)
117
123
    static char const * const dimension_unit_short_[DIMENSION];
118
 
                
 
124
 
119
125
    /// Unit of measurement (self-explanatory form)
120
126
    static char const * const dimension_unit_full_[DIMENSION];
121
 
    
122
 
                //@}
123
 
 
124
 
         public:
125
 
 
126
 
                /** @name Constructors and Destructor
127
 
                 */
128
 
                //@{
129
 
                /// Default constructor
130
 
                Peak2D() 
131
 
      : position_(), 
132
 
        intensity_(0) 
133
 
    {
134
 
    }
135
 
                /// Copy constructor
136
 
                Peak2D(const Peak2D& p) 
137
 
                        : position_(p.position_), 
138
 
        intensity_(p.intensity_)
139
 
                {
140
 
    }
141
 
                
142
 
    /**@brief Destructor
143
 
 
144
 
                  @note The destructor is non-virtual although many classes are derived from
145
 
                  Peak2D.  This is intentional, since otherwise we would "waste"
146
 
                  space for a vtable pointer in each instance. Normally you should not derive other classes from
147
 
                  Peak2D (unless you know what you are doing, of course).
148
 
                */
149
 
                ~Peak2D()
150
 
    {
151
 
    }
152
 
                //@}
153
 
                
154
 
                /**     
155
 
                        @name Accessors
156
 
                 */
157
 
                //@{
158
 
                /// Non-mutable access to the data point intensity (height)
159
 
                IntensityType getIntensity() const
160
 
                {
161
 
                        return intensity_;
162
 
                }
163
 
 
164
 
                /// Non-mutable access to the data point intensity (height)
165
 
                void setIntensity(IntensityType intensity)
166
 
                {
167
 
                        intensity_ = intensity;
168
 
                }
169
 
 
170
 
                /// Non-mutable access to the position
171
 
                PositionType const & getPosition() const 
172
 
    { 
173
 
      return position_; 
174
 
    }
175
 
                /// Mutable access to the position
176
 
                PositionType& getPosition() 
177
 
    {
178
 
      return position_; 
179
 
    }
180
 
                /// Mutable access to the position
181
 
                void setPosition(const PositionType& position) 
182
 
    { 
183
 
      position_ = position; 
 
127
 
 
128
    ///@}
 
129
 
 
130
public:
 
131
 
 
132
    ///@name Constructors and Destructor
 
133
    ///@{
 
134
    /// Default constructor
 
135
    Peak2D() :
 
136
      position_(),
 
137
      intensity_(0)
 
138
    {}
 
139
 
 
140
    /// Copy constructor
 
141
    Peak2D(const Peak2D & p) :
 
142
      position_(p.position_),
 
143
      intensity_(p.intensity_)
 
144
    {}
 
145
 
 
146
    /**
 
147
      @brief Destructor
 
148
 
 
149
      @note The destructor is non-virtual although many classes are derived from
 
150
      Peak2D.  This is intentional, since otherwise we would "waste"
 
151
      space for a vtable pointer in each instance. Normally you should not derive other classes from
 
152
      Peak2D (unless you know what you are doing, of course).
 
153
    */
 
154
    ~Peak2D()
 
155
    {}
 
156
    ///@}
 
157
 
 
158
    ///@name Accessors
 
159
    ///@{
 
160
    /// Non-mutable access to the data point intensity (height)
 
161
    IntensityType getIntensity() const
 
162
    {
 
163
      return intensity_;
 
164
    }
 
165
 
 
166
    /// Non-mutable access to the data point intensity (height)
 
167
    void setIntensity(IntensityType intensity)
 
168
    {
 
169
      intensity_ = intensity;
 
170
    }
 
171
 
 
172
    /// Non-mutable access to the position
 
173
    PositionType const & getPosition() const
 
174
    {
 
175
      return position_;
 
176
    }
 
177
 
 
178
    /// Mutable access to the position
 
179
    PositionType & getPosition()
 
180
    {
 
181
      return position_;
 
182
    }
 
183
 
 
184
    /// Mutable access to the position
 
185
    void setPosition(const PositionType & position)
 
186
    {
 
187
      position_ = position;
184
188
    }
185
189
 
186
190
    /// Returns the m/z coordinate (index 1)
187
 
                CoordinateType getMZ() const 
188
 
    { 
189
 
                        return position_[MZ];
 
191
    CoordinateType getMZ() const
 
192
    {
 
193
      return position_[MZ];
190
194
    }
 
195
 
191
196
    /// Mutable access to the m/z coordinate (index 1)
192
 
                void setMZ(CoordinateType coordinate) 
193
 
    { 
194
 
                        position_[MZ] = coordinate;
 
197
    void setMZ(CoordinateType coordinate)
 
198
    {
 
199
      position_[MZ] = coordinate;
195
200
    }
196
201
 
197
202
    /// Returns the RT coordinate (index 0)
198
 
                CoordinateType getRT() const 
199
 
    { 
200
 
                        return position_[RT];
 
203
    CoordinateType getRT() const
 
204
    {
 
205
      return position_[RT];
201
206
    }
 
207
 
202
208
    /// Mutable access to the RT coordinate (index 0)
203
 
                void setRT(CoordinateType coordinate) 
204
 
    { 
205
 
                        position_[RT] = coordinate;
206
 
    }
207
 
    
208
 
                //@}
209
 
 
210
 
                /// Assignment operator
211
 
                Peak2D& operator = (const Peak2D& rhs)
212
 
                {
213
 
                        if (this==&rhs) return *this;
214
 
                
215
 
                        intensity_ = rhs.intensity_;
216
 
                        position_ = rhs.position_;
217
 
        
218
 
                        return *this;
219
 
                }
220
 
                                
221
 
                /// Equality operator
222
 
                bool operator == (const Peak2D& rhs) const
223
 
                {
224
 
                        return  intensity_ == rhs.intensity_ && position_ == rhs.position_ ;
225
 
                }
226
 
 
227
 
                /// Equality operator
228
 
                bool operator != (const Peak2D& rhs) const
229
 
                {
230
 
                        return !( operator==(rhs) );
231
 
                }
232
 
 
233
 
                                                                        
234
 
                /**     @name   Comparator classes.
235
 
                                These classes implement binary predicates that can be used 
236
 
                                to compare two peaks with respect to their intensities, positions, etc.
237
 
                */
238
 
                //@{
239
 
                /// Comparator by intensity
240
 
                struct IntensityLess
241
 
                        : std::binary_function < Peak2D, Peak2D, bool >
242
 
                {
243
 
                        bool operator () ( const Peak2D& left, const Peak2D& right ) const
244
 
                        {
245
 
                                return ( left.getIntensity() < right.getIntensity() );
246
 
                        }
247
 
                        bool operator () ( const Peak2D& left, IntensityType right ) const
248
 
                        {
249
 
                                return ( left.getIntensity() < right );
250
 
                        }
251
 
                        bool operator () ( IntensityType left, const Peak2D& right ) const
252
 
                        {
253
 
                                return ( left< right.getIntensity() );
254
 
                        }
255
 
                        bool operator () ( IntensityType left, IntensityType right ) const
256
 
                        {
257
 
                                return ( left < right );
258
 
                        }
259
 
                };
260
 
 
261
 
                /// Comparator by RT position
262
 
                struct RTLess
263
 
                        : std::binary_function <Peak2D, Peak2D, bool>
264
 
                {
265
 
                        bool operator () (const Peak2D& left, const Peak2D& right ) const 
266
 
                        {
267
 
                                return (left.getRT() < right.getRT());
268
 
                        }
269
 
                        bool operator () ( const Peak2D& left, CoordinateType right ) const 
270
 
                        {
271
 
                                return (left.getRT() < right );
272
 
                        }
273
 
                        bool operator () ( CoordinateType left, const Peak2D& right ) const 
274
 
                        {
275
 
                                return (left < right.getRT() );
276
 
                        }
277
 
                        bool operator () ( CoordinateType left, CoordinateType right ) const 
278
 
                        {
279
 
                                return (left < right );
280
 
                        }
281
 
                };
282
 
                
283
 
                /// Comparator by m/z position
284
 
                struct MZLess
285
 
                        : std::binary_function <Peak2D, Peak2D, bool>
286
 
                {
287
 
                        bool operator () ( const Peak2D& left, const Peak2D& right ) const 
288
 
                        {
289
 
                                return (left.getMZ() < right.getMZ());
290
 
                        }
291
 
                        bool operator () ( const Peak2D& left, CoordinateType right ) const 
292
 
                        {
293
 
                                return (left.getMZ() < right );
294
 
                        }
295
 
                        bool operator () ( CoordinateType left, const Peak2D& right ) const 
296
 
                        {
297
 
                                return (left < right.getMZ() );
298
 
                        }
299
 
                        bool operator () ( CoordinateType left, CoordinateType right ) const 
300
 
                        {
301
 
                                return (left < right );
302
 
                        }
303
 
                };
304
 
                /// Comparator by position. Lexicographical comparison (first RT then m/z) is done.
305
 
                struct PositionLess
306
 
                        : public std::binary_function <Peak2D, Peak2D, bool>
307
 
                {
308
 
                        bool operator () ( const Peak2D& left, const Peak2D& right) const
309
 
                        {
310
 
                                return (left.getPosition() < right.getPosition());
311
 
                        }
312
 
                        bool operator () ( const Peak2D& left, const PositionType& right ) const 
313
 
                        {
314
 
                                return (left.getPosition() < right );
315
 
                        }
316
 
                        bool operator () ( const PositionType& left, const Peak2D& right ) const 
317
 
                        {
318
 
                                return (left < right.getPosition() );
319
 
                        }
320
 
                        bool operator () ( const PositionType& left, const PositionType& right ) const 
321
 
                        {
322
 
                                return (left < right );
323
 
                        }
324
 
                };
325
 
                //@}
326
 
                
327
 
                friend OPENMS_DLLAPI std::ostream& operator << (std::ostream& os, const Peak2D& point);
328
 
 
329
 
         protected:
330
 
                
331
 
                /// The data point position
332
 
                PositionType    position_;
333
 
                /// The data point intensity
334
 
                IntensityType intensity_;
335
 
        };
336
 
 
337
 
        ///Print the contents to a stream.
338
 
        OPENMS_DLLAPI std::ostream& operator << (std::ostream& os, const Peak2D& point);
 
209
    void setRT(CoordinateType coordinate)
 
210
    {
 
211
      position_[RT] = coordinate;
 
212
    }
 
213
 
 
214
    ///@}
 
215
 
 
216
    /// Assignment operator
 
217
    Peak2D & operator=(const Peak2D & rhs)
 
218
    {
 
219
      if (this == &rhs) return *this;
 
220
 
 
221
      intensity_ = rhs.intensity_;
 
222
      position_ = rhs.position_;
 
223
 
 
224
      return *this;
 
225
    }
 
226
 
 
227
    /// Equality operator
 
228
    bool operator==(const Peak2D & rhs) const
 
229
    {
 
230
      return intensity_ == rhs.intensity_ && position_ == rhs.position_;
 
231
    }
 
232
 
 
233
    /// Equality operator
 
234
    bool operator!=(const Peak2D & rhs) const
 
235
    {
 
236
      return !(operator==(rhs));
 
237
    }
 
238
 
 
239
    /**
 
240
      @name     Comparator classes.
 
241
      These classes implement binary predicates that can be used
 
242
      to compare two peaks with respect to their intensities, positions, etc.
 
243
    */
 
244
    ///@{
 
245
    /// Comparator by intensity
 
246
    struct IntensityLess :
 
247
      std::binary_function<Peak2D, Peak2D, bool>
 
248
    {
 
249
      bool operator()(const Peak2D & left, const Peak2D & right) const
 
250
      {
 
251
        return left.getIntensity() < right.getIntensity();
 
252
      }
 
253
 
 
254
      bool operator()(const Peak2D & left, IntensityType right) const
 
255
      {
 
256
        return left.getIntensity() < right;
 
257
      }
 
258
 
 
259
      bool operator()(IntensityType left, const Peak2D & right) const
 
260
      {
 
261
        return left < right.getIntensity();
 
262
      }
 
263
 
 
264
      bool operator()(IntensityType left, IntensityType right) const
 
265
      {
 
266
        return left < right;
 
267
      }
 
268
 
 
269
    };
 
270
 
 
271
    /// Comparator by RT position
 
272
    struct RTLess :
 
273
      std::binary_function<Peak2D, Peak2D, bool>
 
274
    {
 
275
      bool operator()(const Peak2D & left, const Peak2D & right) const
 
276
      {
 
277
        return left.getRT() < right.getRT();
 
278
      }
 
279
 
 
280
      bool operator()(const Peak2D & left, CoordinateType right) const
 
281
      {
 
282
        return left.getRT() < right;
 
283
      }
 
284
 
 
285
      bool operator()(CoordinateType left, const Peak2D & right) const
 
286
      {
 
287
        return left < right.getRT();
 
288
      }
 
289
 
 
290
      bool operator()(CoordinateType left, CoordinateType right) const
 
291
      {
 
292
        return left < right;
 
293
      }
 
294
 
 
295
    };
 
296
 
 
297
    /// Comparator by m/z position
 
298
    struct MZLess :
 
299
      std::binary_function<Peak2D, Peak2D, bool>
 
300
    {
 
301
      bool operator()(const Peak2D & left, const Peak2D & right) const
 
302
      {
 
303
        return left.getMZ() < right.getMZ();
 
304
      }
 
305
 
 
306
      bool operator()(const Peak2D & left, CoordinateType right) const
 
307
      {
 
308
        return left.getMZ() < right;
 
309
      }
 
310
 
 
311
      bool operator()(CoordinateType left, const Peak2D & right) const
 
312
      {
 
313
        return left < right.getMZ();
 
314
      }
 
315
 
 
316
      bool operator()(CoordinateType left, CoordinateType right) const
 
317
      {
 
318
        return left < right;
 
319
      }
 
320
 
 
321
    };
 
322
 
 
323
    /// Comparator by position. Lexicographical comparison (first RT then m/z) is done.
 
324
    struct PositionLess :
 
325
      public std::binary_function<Peak2D, Peak2D, bool>
 
326
    {
 
327
      bool operator()(const Peak2D & left, const Peak2D & right) const
 
328
      {
 
329
        return left.getPosition() < right.getPosition();
 
330
      }
 
331
 
 
332
      bool operator()(const Peak2D & left, const PositionType & right) const
 
333
      {
 
334
        return left.getPosition() < right;
 
335
      }
 
336
 
 
337
      bool operator()(const PositionType & left, const Peak2D & right) const
 
338
      {
 
339
        return left < right.getPosition();
 
340
      }
 
341
 
 
342
      bool operator()(const PositionType & left, const PositionType & right) const
 
343
      {
 
344
        return left < right;
 
345
      }
 
346
 
 
347
    };
 
348
    ///@}
 
349
 
 
350
    friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
 
351
 
 
352
protected:
 
353
 
 
354
    /// The data point position
 
355
    PositionType    position_;
 
356
    /// The data point intensity
 
357
    IntensityType intensity_;
 
358
  };
 
359
 
 
360
  /// Print the contents to a stream.
 
361
  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
339
362
 
340
363
} // namespace OpenMS
341
364