ProteoWizard
FeatureDetectorPeakelTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: FeatureDetectorPeakelTest.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 
27 #include "boost/filesystem/path.hpp"
29 
30 
31 using namespace pwiz::util;
32 using namespace pwiz::analysis;
33 using namespace pwiz::data;
34 using namespace pwiz::data::peakdata;
35 using namespace pwiz::msdata;
36 namespace bfs = boost::filesystem;
37 
38 
39 ostream* os_ = 0;
40 
41 
42 void verifyBombesinFeatures(const FeatureField& featureField)
43 {
44  const double epsilon = .01;
45 
46  const double mz_bomb2 = 810.415;
47  vector<FeaturePtr> bombesin_2_found = featureField.find(mz_bomb2, epsilon,
49  unit_assert(bombesin_2_found.size() == 1);
50  const Feature& bombesin_2 = *bombesin_2_found[0];
51  unit_assert(bombesin_2.charge == 2);
52  unit_assert(bombesin_2.peakels.size() == 5);
53  unit_assert_equal(bombesin_2.peakels[0]->mz, mz_bomb2, epsilon);
54  unit_assert_equal(bombesin_2.peakels[1]->mz, mz_bomb2+.5, epsilon);
55  unit_assert_equal(bombesin_2.peakels[2]->mz, mz_bomb2+1, epsilon);
56  unit_assert_equal(bombesin_2.peakels[3]->mz, mz_bomb2+1.5, epsilon);
57  unit_assert_equal(bombesin_2.peakels[4]->mz, mz_bomb2+2, epsilon);
58  //TODO: verify feature metadata
59 
60  const double mz_bomb3 = 540.612;
61  vector<FeaturePtr> bombesin_3_found = featureField.find(mz_bomb3, epsilon,
63  unit_assert(bombesin_3_found.size() == 1);
64  const Feature& bombesin_3 = *bombesin_3_found[0];
65  unit_assert(bombesin_3.charge == 3);
66  unit_assert(bombesin_3.peakels.size() == 3);
67  unit_assert_equal(bombesin_3.peakels[0]->mz, mz_bomb3, epsilon);
68  unit_assert_equal(bombesin_3.peakels[1]->mz, mz_bomb3+1./3, epsilon);
69  unit_assert_equal(bombesin_3.peakels[2]->mz, mz_bomb3+2./3, epsilon);
70  //TODO: verify feature metadata
71 }
72 
73 
74 shared_ptr<FeatureDetectorPeakel> createFeatureDetectorPeakel()
75 {
77 
78  // these are just the defaults, to demonstrate usage
79 
81 
82  config.peakFinder_SNR.windowRadius = 2;
85 
87 
90 
91  config.peakelPicker_Basic.log = 0; // ostream*
92  config.peakelPicker_Basic.minCharge = 2;
93  config.peakelPicker_Basic.maxCharge = 5;
95  config.peakelPicker_Basic.mzTolerance = MZTolerance(10, MZTolerance::PPM);
98 
99  return FeatureDetectorPeakel::create(config);
100 }
101 
102 
103 void testBombesin(const string& filename)
104 {
105  if (os_) *os_ << "testBombesin()" << endl;
106 
107  // open data file and check sanity
108 
109  MSDataFile msd(filename);
110  unit_assert(msd.run.spectrumListPtr.get());
111  unit_assert(msd.run.spectrumListPtr->size() == 8);
112 
113  // instantiate FeatureDetector
114 
115  shared_ptr<FeatureDetectorPeakel> featureDetectorPeakel = createFeatureDetectorPeakel();
116 
117  FeatureField featureField;
118  featureDetectorPeakel->detect(msd, featureField);
119 
120  if (os_) *os_ << "featureField:\n" << featureField << endl;
121  verifyBombesinFeatures(featureField);
122 }
123 
124 
125 void test(const bfs::path& datadir)
126 {
127  testBombesin((datadir / "FeatureDetectorTest_Bombesin.mzML").string());
128 }
129 
130 
131 int main(int argc, char* argv[])
132 {
133  TEST_PROLOG(argc, argv)
134 
135  try
136  {
137  bfs::path datadir = ".";
138 
139  for (int i=1; i<argc; i++)
140  {
141  if (!strcmp(argv[i],"-v"))
142  os_ = &cout;
143  else
144  // hack to allow running unit test from a different directory:
145  // Jamfile passes full path to specified input file.
146  // we want the path, so we can ignore filename
147  datadir = bfs::path(argv[i]).branch_path();
148  }
149 
150  test(datadir);
151  }
152  catch (exception& e)
153  {
154  TEST_FAILED(e.what())
155  }
156  catch (...)
157  {
158  TEST_FAILED("Caught unknown exception.")
159  }
160 
162 }
163