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

« back to all changes in this revision

Viewing changes to include/OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithmPickedHelperStructs.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 $
62
69
      Real intensity;
63
70
 
64
71
      /// Comparison operator
65
 
      bool operator<(const Seed& rhs) const
 
72
      bool operator<(const Seed & rhs) const
66
73
      {
67
 
        return intensity<rhs.intensity;
 
74
        return intensity < rhs.intensity;
68
75
      }
 
76
 
69
77
    };
70
78
 
71
79
    /**
72
80
     * @brief Helper struct for mass traces used in FeatureFinderAlgorithmPicked
73
81
     */
74
 
    template<class PeakType>
 
82
    template <class PeakType>
75
83
    struct MassTrace
76
84
    {
77
85
      ///Maximum peak pointer
78
 
      const PeakType* max_peak;
 
86
      const PeakType * max_peak;
79
87
      ///RT of maximum peak
80
88
      DoubleReal max_rt;
81
89
 
83
91
      DoubleReal theoretical_int;
84
92
 
85
93
      ///Contained peaks (pair of RT and pointer to peak)
86
 
      std::vector<std::pair<DoubleReal, const PeakType*> > peaks;
 
94
      std::vector<std::pair<DoubleReal, const PeakType *> > peaks;
87
95
 
88
96
      ///determines the convex hull of the trace
89
97
      ConvexHull2D getConvexhull() const
90
98
      {
91
99
        ConvexHull2D::PointArrayType hull_points(peaks.size());
92
 
        for (Size i=0; i<peaks.size(); ++i)
 
100
        for (Size i = 0; i < peaks.size(); ++i)
93
101
        {
94
102
          hull_points[i][0] = peaks[i].first;
95
103
          hull_points[i][1] = peaks[i].second->getMZ();
96
104
        }
97
 
                                ConvexHull2D hull;
98
 
                                hull.addPoints(hull_points);
 
105
        ConvexHull2D hull;
 
106
        hull.addPoints(hull_points);
99
107
        return hull;
100
108
      }
101
109
 
107
115
        max_rt = peaks.begin()->first;
108
116
        max_peak = peaks.begin()->second;
109
117
 
110
 
        for (Size i=1; i<peaks.size(); ++i)
 
118
        for (Size i = 1; i < peaks.size(); ++i)
111
119
        {
112
 
          if (peaks[i].second->getIntensity()>max_peak->getIntensity())
 
120
          if (peaks[i].second->getIntensity() > max_peak->getIntensity())
113
121
          {
114
122
            max_rt = peaks[i].first;
115
123
            max_peak = peaks[i].second;
122
130
      {
123
131
        DoubleReal sum = 0.0;
124
132
        DoubleReal intensities = 0.0;
125
 
        for (Size i=0; i<peaks.size(); ++i)
 
133
        for (Size i = 0; i < peaks.size(); ++i)
126
134
        {
127
 
          sum += peaks[i].second->getMZ()*peaks[i].second->getIntensity();
 
135
          sum += peaks[i].second->getMZ() * peaks[i].second->getIntensity();
128
136
          intensities += peaks[i].second->getIntensity();
129
137
        }
130
138
        return sum / intensities;
133
141
      ///Checks if this Trace is valid (has more than 2 points)
134
142
      bool isValid() const
135
143
      {
136
 
        return (peaks.size()>=3);
 
144
        return peaks.size() >= 3;
137
145
      }
138
146
 
139
147
    };
141
149
    /**
142
150
     * @brief Helper struct for a collection of mass traces used in FeatureFinderAlgorithmPicked
143
151
     */
144
 
    template<class PeakType>
145
 
    struct MassTraces
146
 
      : public std::vector< MassTrace<PeakType> >
 
152
    template <class PeakType>
 
153
    struct MassTraces :
 
154
      public std::vector<MassTrace<PeakType> >
147
155
    {
148
156
      /// Constructor
149
 
      MassTraces()
150
 
        : max_trace(0)
 
157
      MassTraces() :
 
158
        max_trace(0)
151
159
      {
152
160
      }
153
161
 
155
163
      Size getPeakCount() const
156
164
      {
157
165
        Size sum = 0;
158
 
        for (Size i=0; i<this->size(); ++i)
 
166
        for (Size i = 0; i < this->size(); ++i)
159
167
        {
160
168
          sum += this->at(i).peaks.size();
161
169
        }
166
174
      bool isValid(DoubleReal seed_mz, DoubleReal trace_tolerance)
167
175
      {
168
176
        //Abort if too few traces were found
169
 
        if (this->size()<2) return false;
 
177
        if (this->size() < 2) return false;
170
178
 
171
179
        //Abort if the seed was removed
172
 
        for (Size j=0; j<this->size(); ++j)
 
180
        for (Size j = 0; j < this->size(); ++j)
173
181
        {
174
 
          if (std::fabs(seed_mz-this->at(j).getAvgMZ())<=trace_tolerance)
 
182
          if (std::fabs(seed_mz - this->at(j).getAvgMZ()) <= trace_tolerance)
175
183
          {
176
184
            return true;
177
185
          }
188
196
      {
189
197
        if (!this->size())
190
198
        {
191
 
          throw Exception::Precondition(__FILE__,__LINE__,__PRETTY_FUNCTION__,"There must be at least one trace to determine the theoretical maximum trace!");
 
199
          throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "There must be at least one trace to determine the theoretical maximum trace!");
192
200
        }
193
201
 
194
 
        Size max=0;
195
 
        DoubleReal max_int=this->at(0).theoretical_int;
196
 
        for (Size i=1; i<this->size(); ++i)
 
202
        Size max = 0;
 
203
        DoubleReal max_int = this->at(0).theoretical_int;
 
204
        for (Size i = 1; i < this->size(); ++i)
197
205
        {
198
 
          if (this->at(i).theoretical_int>max_int)
 
206
          if (this->at(i).theoretical_int > max_int)
199
207
          {
200
208
            max_int = this->at(i).theoretical_int;
201
209
            max = i;
213
221
          return;
214
222
        }
215
223
        bool first = true;
216
 
        for (Size i=0 ; i < this->size() ; ++i)
 
224
        for (Size i = 0; i < this->size(); ++i)
217
225
        {
218
 
          for (Size j=0 ; j < this->at(i).peaks.size() ; ++j)
 
226
          for (Size j = 0; j < this->at(i).peaks.size(); ++j)
219
227
          {
220
228
            if (first)
221
229
            {
235
243
 
236
244
        @exception Exception::Precondition is thrown if there are no mass traces (not only in debug mode)
237
245
      */
238
 
      std::pair<DoubleReal,DoubleReal> getRTBounds() const
 
246
      std::pair<DoubleReal, DoubleReal> getRTBounds() const
239
247
      {
240
248
        if (!this->size())
241
249
        {
242
 
          throw Exception::Precondition(__FILE__,__LINE__,__PRETTY_FUNCTION__,"There must be at least one trace to determine the RT boundaries!");
 
250
          throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "There must be at least one trace to determine the RT boundaries!");
243
251
        }
244
252
 
245
253
        DoubleReal min = std::numeric_limits<DoubleReal>::max();
246
254
        DoubleReal max = -std::numeric_limits<DoubleReal>::max();
247
255
        //Abort if the seed was removed
248
 
        for (Size i=0; i<this->size(); ++i)
 
256
        for (Size i = 0; i < this->size(); ++i)
249
257
        {
250
 
          for (Size j=0; j<this->at(i).peaks.size(); ++j)
 
258
          for (Size j = 0; j < this->at(i).peaks.size(); ++j)
251
259
          {
252
260
            DoubleReal rt = this->at(i).peaks[j].first;
253
 
            if (rt>max) max = rt;
254
 
            if (rt<min) min = rt;
 
261
            if (rt > max) max = rt;
 
262
            if (rt < min) min = rt;
255
263
          }
256
264
        }
257
 
        return std::make_pair(min,max);
 
265
        return std::make_pair(min, max);
258
266
      }
259
267
 
260
268
      /// Maximum intensity trace
283
291
      {
284
292
        return intensity.size();
285
293
      }
 
294
 
286
295
    };
287
296
 
288
297
    /**
304
313
      TheoreticalIsotopePattern theoretical_pattern;
305
314
 
306
315
      /// Constructor that resizes the internal vectors
307
 
      IsotopePattern(Size size)
308
 
        : peak(size,-1),
309
 
          spectrum(size),
310
 
          intensity(size),
311
 
          mz_score(size),
312
 
          theoretical_mz(size)
 
316
      IsotopePattern(Size size) :
 
317
        peak(size, -1),
 
318
        spectrum(size),
 
319
        intensity(size),
 
320
        mz_score(size),
 
321
        theoretical_mz(size)
313
322
      {
314
323
      }
 
324
 
315
325
    };
316
326
 
317
327
  };