ProteoWizard
PeakFitterTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2009 Center for Applied Molecular Medicine
8// University of Southern California, Los Angeles, CA
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#include "PeakFitter.hpp"
27#include <cstring>
28
29
30using namespace pwiz::math;
31using namespace pwiz::util;
32using namespace pwiz::analysis;
33using namespace pwiz::data::peakdata;
34
35
36ostream* os_ = 0;
37
38
40{
41 if (os_) *os_ << "testParabola()\n";
42
43 const double center = 2.1;
44 const double height = 5;
45
46 vector<OrderedPair> pairs;
47 for (double i=0; i<5; i++)
48 pairs.push_back(OrderedPair(i, height-(i-center)*(i-center))); // sampled parabola
49
51 config.windowRadius = 1;
52
53 PeakFitter_Parabola fitter(config);
54 Peak peak;
55
56 fitter.fitPeak(pairs, 2, peak);
57
58 if (os_)
59 {
60 *os_ << peak;
61 copy(peak.data.begin(), peak.data.end(), ostream_iterator<OrderedPair>(*os_, " "));
62 *os_ << endl;
63 }
64
65 const double epsilon = 1e-6;
66 unit_assert_equal(peak.mz, center, epsilon);
67 unit_assert_equal(peak.intensity, 5, epsilon);
68 unit_assert_equal(peak.area, 12.97, epsilon);
69 unit_assert_equal(peak.error, 0, epsilon);
70 unit_assert_equal(peak.intensity, 5, epsilon);
71 unit_assert(!peak.data.empty());
72}
73
74
76{
77 if (os_) *os_ << "testMultiplePeaks()\n";
78
79 const double center = 2.1;
80 const double height = 5;
81
82 vector<OrderedPair> pairs;
83 for (double i=0; i<5; i++)
84 pairs.push_back(OrderedPair(i, height-(i-center)*(i-center))); // sampled parabola
85 for (double i=0; i<5; i++)
86 pairs.push_back(OrderedPair(i+5, height-(i-center)*(i-center))); // sampled parabola
87 for (double i=0; i<5; i++)
88 pairs.push_back(OrderedPair(i+10, height-(i-center)*(i-center))); // sampled parabola
89
90 vector<size_t> indices;
91 indices.push_back(2);
92 indices.push_back(7);
93 indices.push_back(12);
94
96 vector<Peak> peaks;
97
98 fitter.fitPeaks(pairs, indices, peaks);
99
100 if (os_)
101 {
102 for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
103 {
104 *os_ << *it;
105 copy(it->data.begin(), it->data.end(), ostream_iterator<OrderedPair>(*os_, " "));
106 *os_ << endl;
107 }
108 }
109
110 const double epsilon = 1e-6;
111 unit_assert(peaks.size() == 3);
112 unit_assert_equal(peaks[0].mz, center, epsilon);
113 unit_assert_equal(peaks[1].mz, center+5, epsilon);
114 unit_assert_equal(peaks[2].mz, center+10, epsilon);
115}
116
117
118void test()
119{
120 testParabola();
122}
123
124
125int main(int argc, char* argv[])
126{
127 TEST_PROLOG(argc, argv)
128
129 try
130 {
131 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
132 test();
133 }
134 catch (exception& e)
135 {
136 TEST_FAILED(e.what())
137 }
138 catch (...)
139 {
140 TEST_FAILED("Caught unknown exception.")
141 }
142
144}
145
int main(int argc, char *argv[])
void testMultiplePeaks()
ostream * os_
void test()
void testParabola()
PeakFitter implementation based on fitting a parabola.
virtual void fitPeak(const math::OrderedPairContainerRef &pairs, size_t index, Peak &result) const
void fitPeaks(const math::OrderedPairContainerRef &pairs, std::vector< size_t > &indices, std::vector< Peak > &result) const
const double epsilon
Definition DiffTest.cpp:41
represents some generic metadata about a peak detected in a signal
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175