ProteoWizard
PeakelGrowerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: PeakelGrowerTest.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 "PeakelGrower.hpp"
27 #include <cstring>
28 
29 
30 using namespace pwiz::util;
31 using namespace pwiz::analysis;
32 using namespace pwiz::data::peakdata;
33 
34 
35 ostream* os_ = 0;
36 
37 
38 vector< vector<Peak> > createToyPeaks()
39 {
40  // rt\mz 1000 1001 1002
41  // 0 x x
42  // 1 x x x
43  // 2 x x
44  // 3 x x x
45  // 4 x x
46 
47  vector< vector<Peak> > peaks(5);
48  Peak peak;
49 
50  peak.retentionTime = 0;
51  peak.mz = 1000; peaks[0].push_back(peak);
52  peak.mz = 1002; peaks[0].push_back(peak);
53 
54  peak.retentionTime = 1;
55  peak.mz = 1000.01; peaks[1].push_back(peak);
56  peak.mz = 1001; peaks[1].push_back(peak);
57  peak.mz = 1002.01; peaks[1].push_back(peak);
58 
59  peak.retentionTime = 2;
60  peak.mz = 1001.01; peaks[2].push_back(peak);
61  peak.mz = 1002-.01; peaks[2].push_back(peak);
62 
63  peak.retentionTime = 3;
64  peak.mz = 1000; peaks[3].push_back(peak);
65  peak.mz = 1001-.01; peaks[3].push_back(peak);
66  peak.mz = 1002.02; peaks[3].push_back(peak);
67 
68  peak.retentionTime = 4;
69  peak.mz = 1000.01; peaks[4].push_back(peak);
70  peak.mz = 1002-.02; peaks[4].push_back(peak);
71 
72  return peaks;
73 }
74 
75 
77 {
78  vector< vector<Peak> > peaks = createToyPeaks();
79 
81  config.mzTolerance = .1;
82  config.rtTolerance = 1.5;
83 
84  PeakelGrower_Proximity peakelGrower(config);
85 
86  PeakelField field;
87  peakelGrower.sowPeaks(field, peaks);
88 
89  const double epsilon = .1;
90  unit_assert(field.size() == 4);
91 
92  PeakelField::const_iterator it = field.begin();
93 
94  unit_assert_equal((*it)->mz, 1000, epsilon);
95  unit_assert_equal((*it)->retentionTime, 0, epsilon);
96 
97  ++it;
98  unit_assert_equal((*it)->mz, 1000, epsilon);
99  unit_assert_equal((*it)->retentionTime, 3, epsilon);
100 
101  ++it;
102  unit_assert_equal((*it)->mz, 1001, epsilon);
103  unit_assert_equal((*it)->retentionTime, 1, epsilon);
104 
105  ++it;
106  unit_assert_equal((*it)->mz, 1002, epsilon);
107  unit_assert_equal((*it)->retentionTime, 0, epsilon);
108 }
109 
110 
111 void test()
112 {
113  testToyExample();
114 }
115 
116 
117 int main(int argc, char* argv[])
118 {
119  TEST_PROLOG(argc, argv)
120 
121  try
122  {
123  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
124  test();
125  }
126  catch (exception& e)
127  {
128  TEST_FAILED(e.what())
129  }
130  catch (...)
131  {
132  TEST_FAILED("Caught unknown exception.")
133  }
134 
136 }
137