ProteoWizard
Classes | Functions | Variables
SpectrumList_ScanSummerTest.cpp File Reference
#include "SpectrumList_ScanSummer.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/data/msdata/examples.hpp"
#include "pwiz/data/msdata/TextWriter.hpp"
#include "pwiz/data/common/CVTranslator.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

struct  TestScanSummerCalculator
 

Functions

ostream & operator<< (ostream &os, const vector< double > &v)
 
vector< double > parseDoubleArray (const string &doubleArray)
 
int test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
TestScanSummerCalculator testScanSummerCalculators []
 
TestScanSummerCalculator goldStandard []
 
const size_t testScanSummerSize = sizeof(testScanSummerCalculators) / sizeof(TestScanSummerCalculator)
 
const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestScanSummerCalculator)
 

Function Documentation

§ operator<<()

ostream& operator<< ( ostream &  os,
const vector< double > &  v 
)

Definition at line 36 of file SpectrumList_ScanSummerTest.cpp.

37 {
38  os << "(";
39  for (size_t i=0; i < v.size(); ++i)
40  os << " " << v[i];
41  os << " )";
42  return os;
43 }

§ parseDoubleArray()

vector<double> parseDoubleArray ( const string &  doubleArray)

Definition at line 103 of file SpectrumList_ScanSummerTest.cpp.

Referenced by test().

104 {
105  vector<double> doubleVector;
106  vector<string> tokens;
107  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
108  if (!tokens.empty())
109  for (size_t i=0; i < tokens.size(); ++i)
110  if (!tokens[i].empty())
111  doubleVector.push_back(lexical_cast<double>(tokens[i]));
112  return doubleVector;
113 }

§ test()

int test ( )

Definition at line 115 of file SpectrumList_ScanSummerTest.cpp.

References pwiz::data::ParamContainer::cvParam(), TestScanSummerCalculator::inputIntensityArray, TestScanSummerCalculator::inputMZArray, TestScanSummerCalculator::inputPrecursorMZ, MS_ms_level, MS_MSn_spectrum, MS_number_of_detector_counts, MS_scan_start_time, MS_scan_window_lower_limit, MS_scan_window_upper_limit, MS_selected_ion_m_z, parseDoubleArray(), TestScanSummerCalculator::rTime, pwiz::msdata::Precursor::selectedIons, pwiz::msdata::SpectrumListSimple::spectra, testScanSummerSize, unit_assert, unit_assert_equal, UO_second, and pwiz::data::CVParam::valueAs().

Referenced by main().

116 {
117  int failedTests = 0;
118 
119  // create the spectrum list
121  SpectrumListPtr originalList(sl);
122 
123  for (size_t i=0; i < testScanSummerSize; ++i)
124  {
126  SpectrumPtr s(new Spectrum);
127  s->set(MS_MSn_spectrum);
128  s->set(MS_ms_level,2);
129  s->index = i;
130  s->scanList.scans.push_back(Scan());
131  Scan& scanRef = s->scanList.scans[0];
132  scanRef.set(MS_scan_start_time,t.rTime,UO_second);
133  s->precursors.push_back(Precursor(t.inputPrecursorMZ));
134 
135  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
136  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
137  s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
138  s->defaultArrayLength = inputMZArray.size();
139 
140  scanRef.scanWindows.push_back(ScanWindow());
141  scanRef.scanWindows[0].set(MS_scan_window_lower_limit,inputMZArray[0]);
142  scanRef.scanWindows[0].set(MS_scan_window_upper_limit,inputMZArray[inputMZArray.size()-1]);
143 
144  sl->spectra.push_back(s);
145  }
146 
147 
148  vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
149  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
150 
151  // run spectral summation
152  try
153  {
154 
155  SpectrumListPtr calculator(new SpectrumList_ScanSummer(originalList,0.05,10));
156 
157  for (size_t i=0; i < calculator->size(); ++i)
158  {
159  SpectrumPtr s = calculator->spectrum(i,true);
160  vector<double>& mzs = s->getMZArray()->data;
161  vector<double>& intensities = s->getIntensityArray()->data;
162  Precursor& precursor = s->precursors[0];
163  SelectedIon& selectedIon = precursor.selectedIons[0];
164  double precursorMZ = selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>();
165  double rTime = s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds();
166 
167  vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
168  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
169 
170  unit_assert(mzs.size() == goldMZArray.size());
171  unit_assert(intensities.size() == goldIntensityArray.size());
172  unit_assert(precursorMZ == goldStandard[i].inputPrecursorMZ);
173  unit_assert(rTime == goldStandard[i].rTime);
174 
175  for (size_t j=0; j < mzs.size(); ++j)
176  {
177  unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
178  unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
179  }
180 
181  }
182 
183 
184 
185 
186  }
187  catch (exception& e)
188  {
189  cerr << "Test failed:\n" << e.what() << endl;
190  ++failedTests;
191  }
192  return failedTests;
193 }
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
CVParam cvParam(CVID cvid) const
finds cvid in the container:
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
TestScanSummerCalculator goldStandard[]
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
Provides a custom-sorted spectrum list.
MS_scan_start_time
scan start time: The time that an analyzer started a scan, relative to the start of the MS run...
Definition: cv.hpp:148
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
MS_scan_window_upper_limit
scan window upper limit: The lower m/z bound of a mass spectrometer scan window.
Definition: cv.hpp:1954
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:12526
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
vector< double > parseDoubleArray(const string &doubleArray)
MS_scan_window_lower_limit
scan window lower limit: The upper m/z bound of a mass spectrometer scan window.
Definition: cv.hpp:1957
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
const size_t testScanSummerSize
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition: MSData.hpp:328
std::vector< SpectrumPtr > spectra
Definition: MSData.hpp:714
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
TestScanSummerCalculator testScanSummerCalculators[]
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
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

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

Definition at line 196 of file SpectrumList_ScanSummerTest.cpp.

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

197 {
198  TEST_PROLOG(argc, argv)
199 
200  try
201  {
202  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
203  int failedTests = test();
204  unit_assert_operator_equal(0, failedTests);
205  }
206  catch (exception& e)
207  {
208  TEST_FAILED(e.what())
209  }
210  catch (...)
211  {
212  TEST_FAILED("Caught unknown exception.")
213  }
214 
216 }
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 34 of file SpectrumList_ScanSummerTest.cpp.

Referenced by main().

§ testScanSummerCalculators

TestScanSummerCalculator testScanSummerCalculators[]
Initial value:
=
{
{ "112 120 121 123 124 128 129",
"7 0 1 4 2 1 7",
120.0,
20.0},
{ "119 120 121 122 123 124 127 128 129",
"4 5 6 7 8 9 10 11 12",
120.01,
20.1},
{ "200 200.01 200.02 200.09 200.20",
"1.0 3.0 1.0 0.0 3.0",
401.23,
21.01},
{ "120 126 127",
"7 7 7",
119.96,
21.05},
{ "200.01 200.02 200.03 200.08 200.09",
"1.0 3.0 1.0 1.0 4.0",
401.19,
21.1},
}

Definition at line 55 of file SpectrumList_ScanSummerTest.cpp.

§ goldStandard

TestScanSummerCalculator goldStandard[]
Initial value:
=
{
{ "112 119 120 121 122 123 124 126 127 128 129",
"7 4 12 7 7 12 11 7 17 12 19",
120.0,
20.0},
{ "200 200.01 200.02 200.03 200.08 200.09 200.20",
"1.0 4.0 4.0 1.0 1.0 4.0 3.0",
401.23,
21.01},
}

Definition at line 85 of file SpectrumList_ScanSummerTest.cpp.

§ testScanSummerSize

const size_t testScanSummerSize = sizeof(testScanSummerCalculators) / sizeof(TestScanSummerCalculator)

Definition at line 100 of file SpectrumList_ScanSummerTest.cpp.

Referenced by test().

§ goldStandardSize

const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestScanSummerCalculator)

Definition at line 101 of file SpectrumList_ScanSummerTest.cpp.