ProteoWizard
SpectrumList_PrecursorRefineTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_PrecursorRefineTest.cpp 4457 2013-03-29 19:33:27Z pcbrefugee $
3 //
4 //
5 // Original author: Chris Paulse <cpaulse@systemsbiology.org>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars-Sinai Medical Center, 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 
23 
27 #include "boost/filesystem/path.hpp"
29 #include <cstring>
30 
31 
32 using namespace pwiz::cv;
33 using namespace pwiz::msdata;
34 using namespace pwiz::util;
35 using namespace pwiz::analysis;
36 namespace bfs = boost::filesystem;
37 
38 
39 ostream* os_ = 0;
40 
41 
42 void verifyPrecursorMZ(const Spectrum& spectrum, double precursorMZ)
43 {
44  unit_assert(!spectrum.precursors.empty());
45  const Precursor& precursor = spectrum.precursors[0];
46  unit_assert(!precursor.selectedIons.empty());
47  const SelectedIon& selectedIon = precursor.selectedIons[0];
48 
49  double foo = selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>();
50  foo++; // quiet an "initalized but not used" warning
51 
52  const double epsilon = 1e-4;
53  if (os_)
54  {
55  *os_ << "[verifyPrecursorMZ] " << spectrum.index << " " << spectrum.id << " "
56  << precursorMZ << ": "
57  << selectedIon.cvParam(MS_selected_ion_m_z).value << " " << selectedIon.cvParam(MS_charge_state).value << endl;
58  }
59 
60  unit_assert_equal(selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>(), precursorMZ, epsilon);
61 
62 }
63 
64 
65 void testPrecursorRefine(const bfs::path& datadir)
66 {
67  MSDataFile msd((datadir / "PrecursorRefineOrbi.mzML").string());
68 
69  unit_assert(msd.run.spectrumListPtr.get() && msd.run.spectrumListPtr->size()==51);
70  if (os_) *os_ << "original spectra:\n";
71  verifyPrecursorMZ(*msd.run.spectrumListPtr->spectrum(21), 747.37225);
72  verifyPrecursorMZ(*msd.run.spectrumListPtr->spectrum(22), 614.867065);
73  verifyPrecursorMZ(*msd.run.spectrumListPtr->spectrum(24), 547.2510);
74  verifyPrecursorMZ(*msd.run.spectrumListPtr->spectrum(25), 533.2534);
75  verifyPrecursorMZ(*msd.run.spectrumListPtr->spectrum(26), 401.22787);
76 
77  shared_ptr<SpectrumList_PrecursorRefine> spectrumListRecalculated(
79 
80  unit_assert(spectrumListRecalculated->size() == 51);
81  if (os_) *os_ << "recalculated spectra:\n";
82  verifyPrecursorMZ(*spectrumListRecalculated->spectrum(21), 747.37078);
83  verifyPrecursorMZ(*spectrumListRecalculated->spectrum(22), 614.86648);
84  verifyPrecursorMZ(*spectrumListRecalculated->spectrum(24), 547.2507);
85  verifyPrecursorMZ(*spectrumListRecalculated->spectrum(25), 533.2534);
86  verifyPrecursorMZ(*spectrumListRecalculated->spectrum(26), 401.226957);
87 }
88 
89 
90 void test(const bfs::path& datadir)
91 {
92  testPrecursorRefine(datadir);
93 }
94 
95 
96 int main(int argc, char* argv[])
97 {
98  TEST_PROLOG(argc, argv)
99 
100  try
101  {
102  bfs::path datadir = ".";
103 
104  for (int i=1; i<argc; i++)
105  {
106  if (!strcmp(argv[i],"-v"))
107  os_ = &cout;
108  else
109  // hack to allow running unit test from a different directory:
110  // Jamfile passes full path to specified input file.
111  // we want the path, so we can ignore filename
112  datadir = bfs::path(argv[i]).branch_path();
113  }
114 
115  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
116  test(datadir);
117  }
118  catch (exception& e)
119  {
120  TEST_FAILED(e.what())
121  }
122  catch (...)
123  {
124  TEST_FAILED("Caught unknown exception.")
125  }
126 
128 }
129 
130 
void testPrecursorRefine(const bfs::path &datadir)
int main(int argc, char *argv[])
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:235
CVParam cvParam(CVID cvid) const
finds cvid in the container:
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
const double epsilon
Definition: DiffTest.cpp:41
std::vector< Precursor > precursors
list and descriptions of precursors to the spectrum currently being described.
Definition: MSData.hpp:519
#define TEST_EPILOG
Definition: unit.hpp:182
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
void test(const bfs::path &datadir)
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition: MSData.hpp:475
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition: MSData.hpp:472
void verifyPrecursorMZ(const Spectrum &spectrum, double precursorMZ)
MSData object plus file I/O.
Definition: MSDataFile.hpp:40
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
SpectrumList wrapper that recalculates precursor info on spectrum() requests.
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
value_type valueAs() const
templated value access with type conversion
Definition: ParamTypes.hpp:112
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:91