ProteoWizard
FeatureDetectorSimpleTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: FeatureDetectorSimpleTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Kate Hoff <Katherine.Hoff@cshs.org>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars-Sinai Medical Cnter, 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 
24 #include "PeakFamilyDetectorFT.hpp"
28 #include "boost/iostreams/positioning.hpp"
29 #include "boost/filesystem/path.hpp"
31 
32 using namespace pwiz::util;
33 using namespace pwiz::analysis;
34 using namespace pwiz::data;
35 using namespace pwiz::data::peakdata;
36 using namespace pwiz::msdata;
37 
38 namespace bfs = boost::filesystem;
39 
40 ostream* os_ = 0;
41 
42 double mz_epsilon = .005; // tolerance for mz differences
43 double rt_epsilon = 10; // tolerance for rt differences
44 
45 struct mzrtEqual
46 {
47 
49  : a(a_) {}
50 
51  bool operator()(FeaturePtr b) const // should be enough info to uniquely identify a feature
52  {
53  return fabs(a->mz-b->mz) < mz_epsilon &&
54  fabs(a->retentionTime - b->retentionTime) < rt_epsilon;
55 
56  }
57 
59 };
60 
61 void testFeatureDetectorSimple(const bfs::path& datadir)
62 {
63 
64  if (os_) *os_ << "testFeatureDetectorSimple() ... " << endl;
65 
66  // instantiate PeakFamilyDetectorFT
67  // (from PeakFamilyDetectorFTTest.cpp)
68 
69  ostream* os_log_ = 0; // don't log peak family detection
70 
72  config.log = os_log_;
73  config.cp = CalibrationParameters::thermo_FT();
74  boost::shared_ptr<PeakFamilyDetectorFT> detector(new PeakFamilyDetectorFT(config));
75  FeatureDetectorSimple fds(detector);
76 
77  // instantiate MSData from test file
78 
79  MSDataFile msd((datadir / "FeatureDetectorTest_Bombesin.mzML").string());
80 
81  FeatureField output_features;
82  fds.detect(msd, output_features);
83 
84  // instantiate the bombesin +2 feature that we know is correct, with calculated mzMonoisotopic and eyeballed retentionTime
85 
86  FeaturePtr bombesin2_truth(new Feature());
87  bombesin2_truth->mz = 810.4148;
88  bombesin2_truth->retentionTime = 1866;
89 
90  FeatureField::iterator bombesin2_hopeful = find_if(output_features.begin(), output_features.end(), mzrtEqual(bombesin2_truth));
91 
92  // assert that it is found, correctly, in the data
93  unit_assert(bombesin2_hopeful != output_features.end());
94 
95 
96  if (os_) *os_ << "\n[FeatureDetectorSimple] Bombesin detected at charge state +2 ... " << endl << *bombesin2_hopeful << endl;
97 
98 
99  // do the same for the +3 feature
100 
101  FeaturePtr bombesin3_truth(new Feature());
102  bombesin3_truth->mz = 540.6123;
103  bombesin3_truth->retentionTime = 1866;
104 
105  FeatureField::iterator bombesin3_hopeful = find_if(output_features.begin(), output_features.end(), mzrtEqual(bombesin3_truth));
106 
107  // assert that it is found, correctly, in the data
108  unit_assert(bombesin3_hopeful != output_features.end());
109 
110 
111  if (os_) *os_ << "\n[FeatureDetectorSimple] Bombesin detected at charge state +3 ... " << endl << *bombesin3_hopeful << endl;
112 
113  return;
114 
115 }
116 
117 int main(int argc, char* argv[])
118 {
119  TEST_PROLOG(argc, argv)
120 
121  try
122  {
123  bfs::path datadir = ".";
124 
125  for (int i=1; i<argc; i++)
126  {
127  if (!strcmp(argv[i],"-v"))
128  os_ = &cout;
129  else
130  // hack to allow running unit test from a different directory:
131  // Jamfile passes full path to specified input file.
132  // we want the path, so we can ignore filename
133  datadir = bfs::path(argv[i]).branch_path();
134  }
135 
136  testFeatureDetectorSimple(datadir);
137  }
138  catch (exception& e)
139  {
140  TEST_FAILED(e.what())
141  }
142  catch (...)
143  {
144  TEST_FAILED("Caught unknown exception.")
145  }
146 
148 }