ProteoWizard
PeakExtractorTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: PeakExtractorTest.cpp 4129 2012-11-20 00:05:37Z chambm $
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 "PeakExtractor.hpp"
27 #include <cstring>
28 
29 
30 using namespace pwiz::math;
31 using namespace pwiz::util;
32 using namespace pwiz::analysis;
33 using namespace pwiz::data::peakdata;
34 
35 
36 ostream* os_ = 0;
37 
38 
39 const double testData_[] =
40 {
41  807.9820, 0.0000,
42  807.9860, 0.0000,
43  807.9899, 0.0000,
44  807.9939, 0.0000,
45  808.9221, 0.0000,
46  808.9261, 0.0000,
47  808.9300, 0.0000,
48  808.9340, 0.0000,
49  808.9379, 46.1869,
50  808.9419, 68.1574,
51  808.9459, 74.2945,
52  808.9498, 67.5736,
53  808.9538, 55.4186,
54  808.9577, 0.0000,
55  808.9617, 0.0000,
56  808.9656, 0.0000,
57  808.9696, 0.0000,
58  810.3800, 0.0000,
59  810.3840, 0.0000,
60  810.3880, 0.0000,
61  810.3919, 0.0000,
62  810.3959, 0.0000,
63  810.3999, 72.5160,
64  810.4038, 450.4998,
65  810.4078, 1138.1459,
66  810.4118, 1834.3859,
67  810.4158, 2075.0105,
68  810.4197, 1699.1493,
69  810.4237, 1021.4493,
70  810.4277, 500.8886,
71  810.4316, 276.2554,
72  810.4356, 179.6894,
73  810.4396, 127.4826,
74  810.4435, 91.4053,
75  810.4475, 55.3596,
76  810.4515, 0.0000,
77  810.4554, 0.0000,
78  810.4594, 0.0000,
79  810.4634, 0.0000,
80  810.8248, 0.0000,
81  810.8288, 0.0000,
82  810.8327, 0.0000,
83  810.8367, 0.0000,
84  810.8407, 32.4939,
85  810.8447, 66.3772,
86  810.8486, 89.7902,
87  810.8526, 70.5686,
88  810.8566, 16.7061,
89  810.8605, 0.0000,
90  810.8645, 32.4340,
91  810.8685, 71.6267,
92  810.8725, 91.5372,
93  810.8764, 81.2383,
94  810.8804, 52.8255,
95  810.8844, 0.0000,
96  810.8884, 0.0000,
97  810.8923, 0.0000,
98  810.8963, 0.0000,
99  810.9003, 0.0000,
100  810.9043, 54.5496,
101  810.9082, 532.4702,
102  810.9122, 1171.1777,
103  810.9162, 1586.9846,
104  810.9202, 1490.4944,
105  810.9241, 979.2804,
106  810.9281, 434.2267,
107  810.9321, 162.3475,
108  810.9361, 128.5575,
109  810.9400, 134.1554,
110  810.9440, 123.5086,
111  810.9480, 88.7253,
112  810.9520, 48.2328,
113  810.9559, 0.0000,
114  810.9599, 0.0000,
115  810.9639, 0.0000,
116  810.9678, 0.0000,
117  811.3854, 0.0000,
118  811.3894, 0.0000,
119  811.3934, 0.0000,
120  811.3973, 0.0000,
121  811.4013, 9.2748,
122  811.4053, 133.5402,
123  811.4093, 298.1690,
124  811.4132, 463.7706,
125  811.4172, 554.1553,
126  811.4212, 503.8234,
127  811.4252, 333.9661,
128  811.4292, 149.2269,
129  811.4331, 48.4688,
130  811.4371, 0.0000,
131  811.4411, 0.0000,
132  811.4451, 0.0000,
133  811.4491, 0.0000,
134  811.7675, 0.0000,
135  811.7715, 0.0000,
136  811.7755, 0.0000,
137  811.7795, 0.0000,
138  811.7835, 41.8127,
139  811.7874, 69.9106,
140  811.7914, 87.5734,
141  811.7954, 91.7424,
142  811.7994, 90.7267,
143  811.8034, 87.8043,
144  811.8074, 74.6657,
145  811.8113, 46.1904,
146  811.8153, 0.0000,
147  811.8193, 0.0000,
148  811.8233, 0.0000,
149  811.8273, 0.0000,
150  812.3853, 0.0000,
151  812.3893, 0.0000,
152  812.3933, 0.0000,
153  812.3972, 0.0000,
154  812.4012, 23.7360,
155  812.4052, 85.1701,
156  812.4092, 124.7133,
157  812.4132, 118.7524,
158  812.4172, 69.4944,
159  812.4212, 9.8729,
160  812.4252, 0.0000,
161  812.4292, 0.0000,
162  812.4331, 0.0000,
163  812.4371, 0.0000
164 };
165 
166 
167 const size_t testDataSize_ = sizeof(testData_)/sizeof(double);
168 
169 
170 void test()
171 {
172  if (os_) *os_ << "test()\n";
173 
174  shared_ptr<NoiseCalculator> noiseCalculator(new NoiseCalculator_2Pass);
175 
176  PeakFinder_SNR::Config pfsnrConfig;
177  pfsnrConfig.windowRadius = 2;
178  pfsnrConfig.zValueThreshold = 2;
179 
180  shared_ptr<PeakFinder> peakFinder(new PeakFinder_SNR(noiseCalculator, pfsnrConfig));
181 
182  PeakFitter_Parabola::Config pfpConfig;
183  pfpConfig.windowRadius = 1; // (windowRadius != 1) is not good for real data
184  shared_ptr<PeakFitter> peakFitter(new PeakFitter_Parabola(pfpConfig));
185 
186  PeakExtractor peakExtractor(peakFinder, peakFitter);
187 
189  vector<Peak> peaks;
190  peakExtractor.extractPeaks(data, peaks);
191 
192  if (os_)
193  {
194  *os_ << "peaks: " << peaks.size() << endl;
195  copy(peaks.begin(), peaks.end(), ostream_iterator<Peak>(*os_, "\n"));
196  }
197 
198  const double epsilon = .01;
199  unit_assert(peaks.size() == 3);
200  unit_assert_equal(peaks[0].mz, 810.41, epsilon);
201  unit_assert_equal(peaks[1].mz, 810.91, epsilon);
202  unit_assert_equal(peaks[2].mz, 811.41, epsilon);
203 }
204 
205 
206 int main(int argc, char* argv[])
207 {
208  TEST_PROLOG(argc, argv)
209 
210  try
211  {
212  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
213  test();
214  }
215  catch (exception& e)
216  {
217  TEST_FAILED(e.what())
218  }
219  catch (...)
220  {
221  TEST_FAILED("Caught unknown exception.")
222  }
223 
225 }
226