ProteoWizard
PeakelPickerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: PeakelPickerTest.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 "PeakelPicker.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 shared_ptr<PeakelField> createToyPeakelField()
39 {
40  //
41  // 0 1 2
42  // |.....:.....|.....:.....|
43  // 10 x x o
44  // 20 x x o x
45  // 30 x x o x
46  // 40 x x o <-- feature z==3, noise Peakel at mono+.5
47  // 50
48  // 60 x x
49  // 70 x x x
50  // 80 x x x
51  // 90 x <-- feature z==2
52  //
53 
54  shared_ptr<PeakelField> toy(new PeakelField);
55 
56  PeakelPtr battery(new Peakel(Peak(0,10)));
57  battery->peaks.push_back(Peak(0, 20));
58  battery->peaks.push_back(Peak(0, 30));
59  battery->peaks.push_back(Peak(0, 40));
60  toy->insert(battery);
61 
62  battery.reset(new Peakel(Peak(1./3 + 1e-6, 10)));
63  battery->peaks.push_back(Peak(1./3, 20));
64  battery->peaks.push_back(Peak(1./3, 30));
65  battery->peaks.push_back(Peak(1./3, 40));
66  toy->insert(battery);
67 
68  battery.reset(new Peakel(Peak(.5, 10)));
69  battery->peaks.push_back(Peak(.5, 20));
70  battery->peaks.push_back(Peak(.5, 30));
71  battery->peaks.push_back(Peak(.5, 40));
72  toy->insert(battery);
73 
74  battery.reset(new Peakel(Peak(2./3, 20)));
75  battery->peaks.push_back(Peak(2./3, 30));
76  toy->insert(battery);
77 
78  battery.reset(new Peakel(Peak(1./3, 60)));
79  battery->peaks.push_back(Peak(1./3, 70));
80  battery->peaks.push_back(Peak(1./3, 80));
81  battery->peaks.push_back(Peak(1./3, 90));
82  toy->insert(battery);
83 
84  battery.reset(new Peakel(Peak(1./3 + .5, 60)));
85  battery->peaks.push_back(Peak(1./3 + .5, 70));
86  battery->peaks.push_back(Peak(1./3 + .5, 80));
87  toy->insert(battery);
88 
89  battery.reset(new Peakel(Peak(1./3 + 1, 70)));
90  battery->peaks.push_back(Peak(1./3 + 1, 80));
91  toy->insert(battery);
92 
93  return toy;
94 }
95 
96 
97 void testToy()
98 {
99  PeakelPicker_Basic::Config config; // TODO: specify parameters?
100 
101  if (os_)
102  {
103  *os_ << "testToy()\n";
104  config.log = os_;
105  }
106 
107  PeakelPicker_Basic peterPiper(config);
108 
109  shared_ptr<PeakelField> peakels = createToyPeakelField();
110  unit_assert(peakels->size() == 7);
111 
112  FeatureField peck;
113  peterPiper.pick(*peakels, peck);
114 
115  unit_assert(peck.size() == 2);
116  unit_assert(peakels->size() == 1);
117 
118  FeatureField::const_iterator it = peck.begin();
119  unit_assert((*it)->mz == 0);
120  unit_assert((*it)->charge == 3);
121  unit_assert_equal((*it)->retentionTime, 25, 20);
122 
123  ++it;
124  unit_assert((*it)->mz == 1./3);
125  unit_assert((*it)->charge == 2);
126  unit_assert_equal((*it)->retentionTime, 75, 20);
127 }
128 
129 
130 void test()
131 {
132  testToy();
133 }
134 
135 
136 int main(int argc, char* argv[])
137 {
138  TEST_PROLOG(argc, argv)
139 
140  try
141  {
142  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
143  test();
144  }
145  catch (exception& e)
146  {
147  TEST_FAILED(e.what())
148  }
149  catch (...)
150  {
151  TEST_FAILED("Caught unknown exception.")
152  }
153 
155 }
156