ProteoWizard
SpectrumList_LockmassRefinerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id$
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  {
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  int tests = 0;
93  for(const string& filepath : rawpaths)
94  {
95  if (bal::ends_with(filepath, "ATEHLSTLSEK_profile.raw"))
96  {
97  ++tests;
98  test(filepath, 684.3469, 0.1);
99  test(filepath, 0, 0.1);
100  }
101  }
102 
103  if (tests == 0)
104  throw runtime_error("did not run any tests");
105  }
106  catch (exception& e)
107  {
108  TEST_FAILED(e.what())
109  }
110  catch (...)
111  {
112  TEST_FAILED("Caught unknown exception.")
113  }
114 
116 }
pwiz::msdata::SpectrumListPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
main
int main(int argc, char *argv[])
Definition: SpectrumList_LockmassRefinerTest.cpp:82
pwiz::cv
Definition: cv.hpp:108
pwiz::analysis
Definition: ChromatogramList_Filter.hpp:37
pwiz::msdata::MSData::run
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition: MSData.hpp:886
SpectrumList_LockmassRefiner.hpp
pwiz::msdata
Definition: DemuxTypes.hpp:27
ExtendedReaderList.hpp
pwiz::data::Diff
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
pwiz::util
Definition: almost_equal.hpp:33
almost_equal.hpp
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
pwiz::msdata::Run::id
std::string id
a unique identifier for this run.
Definition: MSData.hpp:812
pwiz::msdata::DiffConfig::ignoreMetadata
bool ignoreMetadata
ignore all file level metadata, and most scan level metadata, i.e.
Definition: Diff.hpp:214
Std.hpp
diff
void diff(const string &filename1, const string &filename2)
Definition: FrequencyDataTest.cpp:40
pwiz::msdata::ExtendedReaderList
default ReaderList, extended to include vendor readers
Definition: ExtendedReaderList.hpp:37
os_
ostream * os_
Definition: SpectrumList_LockmassRefinerTest.cpp:37
pwiz::msdata::Run::spectrumListPtr
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition: MSData.hpp:827
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
pwiz::analysis::SpectrumList_LockmassRefiner
SpectrumList implementation to replace peak profiles with picked peaks.
Definition: SpectrumList_LockmassRefiner.hpp:36
MSDataFile.hpp
pwiz::msdata::MSDataFile
MSData object plus file I/O.
Definition: MSDataFile.hpp:40
test
void test(const string &filepath, double lockmassMz, double lockmassTolerance)
Definition: SpectrumList_LockmassRefinerTest.cpp:40
pwiz::msdata::DiffConfig
configuration struct for diffing MSData types
Definition: Diff.hpp:205
parseArgs
void parseArgs(const vector< string > &args, vector< string > &rawpaths)
Definition: SpectrumList_LockmassRefinerTest.cpp:71
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
Diff.hpp