ProteoWizard
PeakDataTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2007 Spielberg Family Center for Applied Proteomics
8// Cedars Sinai Medical Center, Los Angeles, California 90048
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 "PeakData.hpp"
26#include <boost/filesystem/operations.hpp>
28
29
30using namespace pwiz::util;
31using namespace pwiz::minimxml;
32using namespace pwiz::math;
33using namespace pwiz::data::peakdata;
34
35
36ostream* os_ = 0;
37
39{
40 PeakFamily peakFamily;
41
42 peakFamily.mzMonoisotopic = 329.86;
43 peakFamily.charge = 3;
44 peakFamily.score = 0.11235811;
45
46 Peak peak;
47 Peak a;
48 Peak boo;
49
50 peak.mz = 329.86;
51 a.mz = 109.87;
52 boo.mz = 6.022141730;
53
54 peakFamily.peaks.push_back(peak);
55 peakFamily.peaks.push_back(a);
56 peakFamily.peaks.push_back(boo);
57
58 return peakFamily;
59
60}
61
63{
64 Scan scan;
65 scan.index = 12;
66 scan.nativeID = "24";
67 scan.scanNumber = 24;
68 scan.retentionTime = 12.345;
69 scan.observationDuration = 6.78;
70
71 scan.calibrationParameters.A = 987.654;
72 scan.calibrationParameters.B = 321.012;
73
74 PeakFamily flintstones = initializePeakFamily();
76
77 scan.peakFamilies.push_back(flintstones);
78 scan.peakFamilies.push_back(jetsons);
79
80 return scan;
81}
82
84{
85 Software software;
86 software.name = "World of Warcraft";
87 software.version = "Wrath of the Lich King";
88 software.source = "Blizzard Entertainment";
89
90 Software::Parameter parameter1("Burke ping","level 70");
91 Software::Parameter parameter2("Kate ping", "level 0");
92
93 software.parameters.push_back(parameter1);
94 software.parameters.push_back(parameter2);
95
96 return software;
97
98}
99
101{
102 PeakData pd;
103
104 Software software = initializeSoftware();
105 pd.software = software;
106
107 Scan scan = initializeScan();
108
109 pd.scans.push_back(scan);
110 pd.scans.push_back(scan);
111
112 return pd;
113
114}
115
117{
118 PeakelPtr pkl(new Peakel);
119 pkl->mz = 432.1;
120 pkl->retentionTime = 1234.56;
121 pkl->maxIntensity = 9876.54;
122 pkl->totalIntensity = 32123.45;
123 pkl->mzVariance = 6.023;
124
125 PeakFamily peakFamily = initializePeakFamily();
126
127 pkl->peaks = peakFamily.peaks;
128
129 return pkl;
130}
131
132
134{
135 if (os_) *os_ << "testPeakEquality()" <<endl;
136
137 Peak peak;
138
139 peak.id = 5;
140 peak.mz = 1;
141 peak.retentionTime = 1.5;
142 peak.intensity = 2;
143 peak.area = 3;
144 peak.error = 4;
145
146 Peak peak2 = peak;
147
148 unit_assert(peak == peak2);
150 unit_assert(peak != peak2);
151 peak2.attributes[Peak::Attribute_Phase] = 4.20;
152 peak2.attributes[Peak::Attribute_Decay] = 6.66;
153 unit_assert(peak != peak2);
155 unit_assert(peak == peak2);
156}
157
158
160{
161 if (os_) *os_ << "testPeak()" <<endl;
162
163 // instantiate a Peak
164
165 Peak peak;
166
167 peak.id = 5;
168 peak.mz = 1;
169 peak.retentionTime = 1.5;
170 peak.intensity = 2;
171 peak.area = 3;
172 peak.error = 4;
173
174 peak.data.push_back(OrderedPair(1,2));
175 peak.data.push_back(OrderedPair(3,4));
176
180
181 if (os_) *os_ << peak << endl;
182
183 // write out XML to a stream
184
185 ostringstream oss;
186 XMLWriter writer(oss);
187 peak.write(writer);
188
189 // allocate a new Peak
190
191 Peak peakIn;
192 unit_assert(peak != peakIn);
193
194 // read from stream into new Peak
195
196 istringstream iss(oss.str());
197 peakIn.read(iss);
198 if (os_) *os_ << peakIn << endl;
199
200 // verify that new Peak is the same as old Peak
201
202 unit_assert(peak == peakIn);
203}
204
205
207{
208 // initialize a PeakFamily
209
211
212 // write out XML to a stream
213
214 ostringstream oss;
215 XMLWriter writer(oss);
216
217
218 jetsons.write(writer);
219
220 // instantiate new PeakFamily
221
222 PeakFamily flintstones;
223
224 // read from stream into new PeakFamily
225 istringstream iss(oss.str());
226 flintstones.read(iss);
227
228 // verify that new PeakFamily is the same as old PeakFamily
229
230 unit_assert(flintstones == jetsons);
231 if (os_) *os_ << "Testing PeakFamily ... " << endl << oss.str() <<endl;
232}
233
235{
236 // initialize a new Scan
237
238 Scan scan = initializeScan();
239
240 // write out XML to a stream
241 ostringstream oss_scan;
242 XMLWriter writer_scan(oss_scan);
243 scan.write(writer_scan);
244
245 // instantiate a second Scan
246 Scan scan2;
247
248 // read it back in
249 istringstream iss_scan(oss_scan.str());
250 scan2.read(iss_scan);
251
252
253
254 // assert that the two Scans are equal
255
256 unit_assert(scan == scan2);
257 if (os_) *os_ << "Testing Scan ... " << endl << oss_scan.str() << endl;
258
259}
260
262{
263 // initialize a new Software
264
265 Software software = initializeSoftware();
266
267 // write out XML to a stream
268 ostringstream oss_soft;
269 XMLWriter writer_soft(oss_soft);
270 software.write(writer_soft);
271
272 // instantiate another Software
273 Software software2;
274
275 // read it back in
276 istringstream iss_soft(oss_soft.str());
277 software2.read(iss_soft);
278
279 // assert that the two Softwares are equal
280
281 unit_assert(software == software2);
282 if (os_) *os_ << "Testing Software ... " << endl << oss_soft.str() <<endl;
283
284}
285
287{
288 // initialize a PeakData
289
291
292 ostringstream oss_pd;
293 XMLWriter writer_pd(oss_pd);
294 pd.write(writer_pd);
295
296 // instantiate another PeakData
297
298 PeakData pd2;
299
300 // read into it
301
302 istringstream iss_pd(oss_pd.str());
303 pd2.read(iss_pd);
304
305 // assert that the two PeakData are equal
306
307 unit_assert(pd == pd2);
308 if (os_) *os_ << "Testing PeakData ... " << endl << oss_pd.str()<<endl;
309
310}
311
313{
314 // initialize a peakel
315
317
318 // write it out
319 ostringstream oss_pkl;
320 XMLWriter writer_pkl(oss_pkl);
321 dill->write(writer_pkl);
322
323 // instantiate another Peakel
324
325 Peakel gherkin;
326
327 // read into it
328 istringstream iss_pkl(oss_pkl.str());
329 gherkin.read(iss_pkl);
330
331 // assert that the two Peakels are equal
332
333 unit_assert(*dill == gherkin);
334 if (os_) *os_ << "Testing Peakel ... " << endl << oss_pkl.str() << endl;
335}
336
337
339{
340 Peakel p;
341 p.retentionTime = 420;
342 unit_assert(p.retentionTimeMin() == 420);
343 unit_assert(p.retentionTimeMax() == 420);
344
345 p.peaks.resize(2);
346 p.peaks[0].retentionTime = 666;
347 p.peaks[1].retentionTime = 667;
348 unit_assert(p.retentionTimeMin() == 666);
349 unit_assert(p.retentionTimeMax() == 667);
350}
351
352
354{
355 Peak peak(420, 666);
356 Peakel peakel(Peak(420,666));
357 unit_assert(peakel.mz == 420);
358 unit_assert(peakel.retentionTime == 666);
359 unit_assert(peakel.peaks.size() == 1);
360 unit_assert(peakel.peaks[0] == peak);
361}
362
363
365{
366 // initialize a new Feature
367
368 Feature feature;
369 feature.mz = 1863.0101;
370 feature.retentionTime = 1492.1012;
371 feature.charge = 3;
372 feature.totalIntensity = 1776.0704;
373 feature.rtVariance = 1969.0720;
374 feature.score = 420.0;
375 feature.error = 666.0;
376
377 PeakelPtr stateFair = initializePeakel();
379
380 feature.peakels.push_back(stateFair);
381 feature.peakels.push_back(deli);
382
383 // write it out
384 ostringstream oss_f;
385 XMLWriter writer_f(oss_f);
386 feature.write(writer_f);
387
388 // instantiate another feature
389
390 Feature feature2;
391
392 // read into it
393
394 istringstream iss(oss_f.str());
395 feature2.read(iss);
396
397 // assert that the two Features are equal
398
399 if (os_)
400 {
401 *os_ << "Testing Feature ... " << endl << oss_f.str() << endl;
402 *os_ << "feature2:\n";
403 XMLWriter writer(*os_);
404 feature2.write(writer);
405 }
406
407 unit_assert(feature == feature2);
408}
409
410
412{
413 Feature feature;
414 feature.retentionTime = 420;
415 unit_assert(feature.retentionTimeMin() == 420);
416 unit_assert(feature.retentionTimeMax() == 420);
417
418 // retention time ranges determined by first two peakels
419
420 PeakelPtr dill(new Peakel);
421 dill->peaks.push_back(Peak(666,419));
422 dill->peaks.push_back(Peak(666,423));
423
424 PeakelPtr sweet(new Peakel);
425 sweet->peaks.push_back(Peak(666,421));
426 sweet->peaks.push_back(Peak(666,424));
427
428 PeakelPtr gherkin(new Peakel);
429 gherkin->peaks.push_back(Peak(666,418));
430 gherkin->peaks.push_back(Peak(666,425));
431
432 feature.peakels.push_back(dill);
433 feature.peakels.push_back(sweet);
434 feature.peakels.push_back(gherkin);
435
436 unit_assert(feature.retentionTimeMin() == 419);
437 unit_assert(feature.retentionTimeMax() == 424);
438}
439
440
441void test()
442{
444 testPeak();
445
447 testScan();
448 testSoftware();
449 testPeakData();
450 testPeakel();
453 testFeature();
455}
456
457
458int main(int argc, char* argv[])
459{
460 TEST_PROLOG(argc, argv)
461
462 try
463 {
464 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
465 if (os_) *os_ << "PeakDataTest\n";
466
467 test();
468 }
469 catch (exception& e)
470 {
471 TEST_FAILED(e.what())
472 }
473 catch (...)
474 {
475 TEST_FAILED("Caught unknown exception.")
476 }
477
479}
480
481
PeakData initializePeakData()
int main(int argc, char *argv[])
void testFeatureAux()
void testPeakData()
void testPeakelConstruction()
void testScan()
void testPeakEquality()
Scan initializeScan()
void testPeakFamily()
void testPeakelAux()
void testPeakel()
PeakelPtr initializePeakel()
void testPeak()
ostream * os_
void testFeature()
void test()
PeakFamily initializePeakFamily()
Software initializeSoftware()
void testSoftware()
The XMLWriter class provides simple, tag-level XML syntax writing.
Definition XMLWriter.hpp:48
boost::shared_ptr< Peakel > PeakelPtr
Definition PeakData.hpp:242
void read(std::istream &is)
std::vector< PeakelPtr > peakels
Definition PeakData.hpp:274
void write(pwiz::minimxml::XMLWriter &xmlWriter) const
std::vector< Scan > scans
Definition PeakData.hpp:194
void write(pwiz::minimxml::XMLWriter &xmlWriter) const
void read(std::istream &is)
void write(minimxml::XMLWriter &writer) const
void read(std::istream &is)
void write(minimxml::XMLWriter &writer) const
void read(std::istream &is)
std::vector< pwiz::math::OrderedPair > data
Definition PeakData.hpp:63
struct for an eluted peak (PEAK ELution)
Definition PeakData.hpp:212
void read(std::istream &is)
double retentionTimeMin() const
std::vector< Peak > peaks
Definition PeakData.hpp:221
double retentionTimeMax() const
CalibrationParameters calibrationParameters
Definition PeakData.hpp:141
std::vector< PeakFamily > peakFamilies
Definition PeakData.hpp:142
void write(minimxml::XMLWriter &writer) const
void read(std::istream &is)
std::vector< Parameter > parameters
Definition PeakData.hpp:179
void write(minimxml::XMLWriter &xmlWriter) const
void read(std::istream &is)
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175