ProteoWizard
SpectrumList_LockmassRefinerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_LockmassRefinerTest.cpp 9098 2015-11-01 04:11:45Z pcbrefugee $
3 //
4 //
5 // Original author: Matt Chambers <matt.chambers <a.t> vanderbilt.edu>
6 //
7 // Copyright 2015 Vanderbilt University - Nashville, TN 37232
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
29 #include "boost/foreach_field.hpp"
30 #include "boost/core/null_deleter.hpp"
31 
32 using namespace pwiz::util;
33 using namespace pwiz::cv;
34 using namespace pwiz::msdata;
35 using namespace pwiz::analysis;
36 
37 ostream* os_ = 0;
38 
39 
40 void test(const string& filepath, double lockmassMz, double lockmassTolerance)
41 {
42  ExtendedReaderList readerList;
43  MSDataFile msd(filepath, &readerList);
44 
45  bfs::path targetResultFilename = bfs::path(__FILE__).parent_path() / "SpectrumList_LockmassRefinerTest.data" / (msd.run.id + ".mzML");
46  if (!bfs::exists(targetResultFilename))
47  throw runtime_error("test result file does not exist: " + targetResultFilename.string());
48  MSDataFile targetResult(targetResultFilename.string());
49 
50  SpectrumList_LockmassRefiner lmr(msd.run.spectrumListPtr, lockmassMz, lockmassMz, lockmassTolerance);
51  SpectrumListPtr sl(&lmr, boost::null_deleter());
52  msd.run.spectrumListPtr = sl;
53 
54  DiffConfig config;
55  config.ignoreMetadata = true;
56 
57  Diff<MSData, DiffConfig> diff(msd, targetResult, config);
58 
59  if (lockmassMz == 0)
60  {
61  unit_assert(diff);
62  }
63  else
64  {
65  if (os_ && diff) *os_ << diff;
66  unit_assert(!diff);
67  }
68 }
69 
70 
71 void parseArgs(const vector<string>& args, vector<string>& rawpaths)
72 {
73  for (size_t i = 1; i < args.size(); ++i)
74  {
75  if (args[i] == "-v") os_ = &cout;
76  else if (bal::starts_with(args[i], "--")) continue;
77  else rawpaths.push_back(args[i]);
78  }
79 }
80 
81 
82 int main(int argc, char* argv[])
83 {
84  TEST_PROLOG(argc, argv)
85 
86  try
87  {
88  vector<string> args(argv, argv+argc);
89  vector<string> rawpaths;
90  parseArgs(args, rawpaths);
91 
92  BOOST_FOREACH(const string& filepath, rawpaths)
93  {
94  if (bal::ends_with(filepath, "091204_NFDM_008.raw"))
95  {
96  test(filepath, 615.38, 0.1);
97  test(filepath, 0, 0.1);
98  }
99  }
100  }
101  catch (exception& e)
102  {
103  TEST_FAILED(e.what())
104  }
105  catch (...)
106  {
107  TEST_FAILED("Caught unknown exception.")
108  }
109 
111 }
bool ignoreMetadata
ignore all file level metadata, and most scan level metadata, i.e.
Definition: Diff.hpp:214
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
#define TEST_EPILOG
Definition: unit.hpp:182
SpectrumList implementation to replace peak profiles with picked peaks.
default ReaderList, extended to include vendor readers
std::string id
a unique identifier for this run.
Definition: MSData.hpp:808
void diff(const string &filename1, const string &filename2)
void test(const string &filepath, double lockmassMz, double lockmassTolerance)
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
MSData object plus file I/O.
Definition: MSDataFile.hpp:40
configuration struct for diffing MSData types
Definition: Diff.hpp:205
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here. Subsidiary data arrays are also both described and attached here.
Definition: MSData.hpp:823
#define TEST_FAILED(x)
Definition: unit.hpp:176
void parseArgs(const vector< string > &args, vector< string > &rawpaths)
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
int main(int argc, char *argv[])
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:91