ProteoWizard
Functions | Variables
SpectrumList_PrecursorRecalculatorTest.cpp File Reference
#include "SpectrumList_PrecursorRecalculator.hpp"
#include "pwiz/data/msdata/MSDataFile.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "boost/filesystem/path.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Functions

void verifyPrecursorInfo (const Spectrum &spectrum, double precursorMZ, int precursorCharge)
 
void test5peptideFT (const bfs::path &datadir)
 
void test (const bfs::path &datadir)
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ verifyPrecursorInfo()

void verifyPrecursorInfo ( const Spectrum spectrum,
double  precursorMZ,
int  precursorCharge 
)

Definition at line 42 of file SpectrumList_PrecursorRecalculatorTest.cpp.

References epsilon, pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::SpectrumIdentity::index, MS_charge_state, MS_selected_ion_m_z, os_, pwiz::msdata::Spectrum::precursors, unit_assert, and unit_assert_equal.

Referenced by test5peptideFT().

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  const double epsilon = 1e-2;
50  if (os_)
51  {
52  *os_ << "[verifyPrecursorInfo] " << spectrum.index << " " << spectrum.id << " "
53  << precursorMZ << " " << precursorCharge << ": "
54  << selectedIon.cvParam(MS_selected_ion_m_z).value << " " << selectedIon.cvParam(MS_charge_state).value << endl;
55  }
56 
57  unit_assert_equal(selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>(), precursorMZ, epsilon);
58 
59  if (precursorCharge != 0)
60  unit_assert(selectedIon.cvParam(MS_charge_state).valueAs<int>() == precursorCharge);
61 }
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:235
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 unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
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
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition: MSData.hpp:472
#define unit_assert(x)
Definition: unit.hpp:85

§ test5peptideFT()

void test5peptideFT ( const bfs::path &  datadir)

Definition at line 64 of file SpectrumList_PrecursorRecalculatorTest.cpp.

References os_, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and verifyPrecursorInfo().

Referenced by test().

65 {
66  MSDataFile msd((datadir / "5peptideFT.mzML").string());
67 
68  unit_assert(msd.run.spectrumListPtr.get() && msd.run.spectrumListPtr->size()==7);
69  if (os_) *os_ << "original spectra:\n";
70  verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(2), 810.79, 0);
71  verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(3), 837.34, 0);
72  verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(4), 725.36, 0);
73  verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(5), 558.87, 0);
74  verifyPrecursorInfo(*msd.run.spectrumListPtr->spectrum(6), 812.33, 0);
75 
76  shared_ptr<SpectrumList_PrecursorRecalculator> spectrumListRecalculated(
78 
79  unit_assert(spectrumListRecalculated->size() == 7);
80  if (os_) *os_ << "recalculated spectra:\n";
81  verifyPrecursorInfo(*spectrumListRecalculated->spectrum(2), 810.42, 2);
82  verifyPrecursorInfo(*spectrumListRecalculated->spectrum(3), 836.96, 2);
83  verifyPrecursorInfo(*spectrumListRecalculated->spectrum(4), 724.91, 2);
84  verifyPrecursorInfo(*spectrumListRecalculated->spectrum(5), 558.31, 3);
85  verifyPrecursorInfo(*spectrumListRecalculated->spectrum(6), 810.42, 2);
86 }
SpectrumList wrapper that recalculates precursor info on spectrum() requests.
void verifyPrecursorInfo(const Spectrum &spectrum, double precursorMZ, int precursorCharge)
MSData object plus file I/O.
Definition: MSDataFile.hpp:40
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( const bfs::path &  datadir)

Definition at line 89 of file SpectrumList_PrecursorRecalculatorTest.cpp.

References test5peptideFT().

Referenced by main().

90 {
91  test5peptideFT(datadir);
92 }
void test5peptideFT(const bfs::path &datadir)

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 95 of file SpectrumList_PrecursorRecalculatorTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

96 {
97  TEST_PROLOG(argc, argv)
98 
99  try
100  {
101  bfs::path datadir = ".";
102 
103  for (int i=1; i<argc; i++)
104  {
105  if (!strcmp(argv[i],"-v"))
106  os_ = &cout;
107  else
108  // hack to allow running unit test from a different directory:
109  // Jamfile passes full path to specified input file.
110  // we want the path, so we can ignore filename
111  datadir = bfs::path(argv[i]).branch_path();
112  }
113 
114  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
115  test(datadir);
116  }
117  catch (exception& e)
118  {
119  TEST_FAILED(e.what())
120  }
121  catch (...)
122  {
123  TEST_FAILED("Caught unknown exception.")
124  }
125 
127 }
#define TEST_EPILOG
Definition: unit.hpp:182
void test(const bfs::path &datadir)
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0