ProteoWizard
Classes | Functions | Variables
SpectrumList_ChargeFromIsotopeTest.cpp File Reference
#include "SpectrumList_ChargeFromIsotope.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  TestChargeStateCalculator
 

Functions

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

Variables

ostream * os_ = 0
 
TestChargeStateCalculator testChargeStateCalculators []
 
const size_t testChargeStateCalculatorsSize = sizeof(testChargeStateCalculators) / sizeof(TestChargeStateCalculator)
 

Function Documentation

§ operator<<()

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

Definition at line 36 of file SpectrumList_ChargeFromIsotopeTest.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 123 of file SpectrumList_ChargeFromIsotopeTest.cpp.

Referenced by test().

124 {
125  vector<double> doubleVector;
126  vector<string> tokens;
127  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
128  if (!tokens.empty())
129  for (size_t i=0; i < tokens.size(); ++i)
130  if (!tokens[i].empty())
131  doubleVector.push_back(lexical_cast<double>(tokens[i]));
132  return doubleVector;
133 }

§ parseCVTermArray()

vector<CVID> parseCVTermArray ( const string &  cvTermArray)

Definition at line 135 of file SpectrumList_ChargeFromIsotopeTest.cpp.

References pwiz::data::CVTranslator::translate().

136 {
137  static pwiz::data::CVTranslator cvTranslator;
138  vector<CVID> cvTermVector;
139  vector<string> tokens;
140  bal::split(tokens, cvTermArray, bal::is_space());
141  if (!tokens.empty() && !tokens[0].empty())
142  for (size_t i=0; i < tokens.size(); ++i)
143  cvTermVector.push_back(cvTranslator.translate(tokens[i]));
144  return cvTermVector;
145 }
translates text to CV terms
cv::CVID translate(const std::string &text) const
translate text -> CVID

§ test()

int test ( )

Definition at line 147 of file SpectrumList_ChargeFromIsotopeTest.cpp.

References pwiz::data::CVParam::cvid, TestChargeStateCalculator::defaultMaxCharge, TestChargeStateCalculator::defaultMinCharge, TestChargeStateCalculator::halfIsolationWidth, TestChargeStateCalculator::inputIntensityArray, TestChargeStateCalculator::inputMZArray, TestChargeStateCalculator::inputPrecursorMZ, TestChargeStateCalculator::maxCharge, TestChargeStateCalculator::minCharge, TestChargeStateCalculator::MS1rTime, TestChargeStateCalculator::MS2rTime, MS_charge_state, MS_ms_level, MS_MSn_spectrum, MS_number_of_detector_counts, MS_possible_charge_state, MS_preset_scan_configuration, MS_profile_spectrum, MS_scan_start_time, TestChargeStateCalculator::parentsAfter, TestChargeStateCalculator::parentsBefore, parseDoubleArray(), pwiz::msdata::MSData::run, pwiz::msdata::SpectrumListSimple::spectra, pwiz::msdata::Run::spectrumListPtr, testChargeStateCalculatorsSize, TestChargeStateCalculator::trueCharge, unit_assert, unit_assert_operator_equal, UO_second, and pwiz::data::CVParam::valueAs().

Referenced by main().

148 {
149  int failedTests = 0;
150  for (size_t i=0; i < testChargeStateCalculatorsSize; ++i)
151  {
152 
153  try
154  {
155 
157 
158  MSData msd;
159 
160  SpectrumListSimple* sl = new SpectrumListSimple; // create new spectrumListSimple object, s1
161  SpectrumListPtr originalList(sl); // create pointer (originalList) to s1
162  msd.run.spectrumListPtr = originalList;
163 
164  // create an MS1 (parent) spectrum
165  SpectrumPtr sPar(new Spectrum);
166  sPar->set(MS_MSn_spectrum);
167  sPar->set(MS_ms_level,1);
168  sPar->set(MS_profile_spectrum);
169  sPar->scanList.scans.push_back(Scan());
170  Scan& scanRef = sPar->scanList.scans[0];
171  scanRef.set(MS_scan_start_time,t.MS1rTime,UO_second);
172  scanRef.set(MS_preset_scan_configuration,1);
173  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
174  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
175  sPar->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
176  sPar->defaultArrayLength = inputMZArray.size();
177  sl->spectra.push_back(sPar); // add ms1 spectrum to spectrumList
178 
179  // The MS2 spectrum
180  SpectrumPtr s(new Spectrum); // create pointer (s) to spectrum object
181  s->set(MS_MSn_spectrum); // set spectrum attribute, MS_MSn_spectrum
182  s->set(MS_ms_level, 2); // set spectrum level
183  s->set(MS_profile_spectrum);
184  s->scanList.scans.push_back(Scan());
185  Scan& scanRef2 = s->scanList.scans[0];
186  scanRef2.set(MS_scan_start_time,t.MS2rTime,UO_second);
187  scanRef2.set(MS_preset_scan_configuration,2);
188  s->precursors.push_back(Precursor(t.inputPrecursorMZ)); // set precursor m/z in spectrum s
189  s->defaultArrayLength = 10; // arbitrary non-zero value so that it can pass through the filter
190  sl->spectra.push_back(s); // add ms2 spectrum to spectrumList
191 
192  // Run Turbocharger
196 
197  // Check results
198  CVID outputChargeStateTerm = MS_charge_state;
199  SpectrumPtr calculatedSpectrum = calculator->spectrum(1, true); // index 1 returns the MS2 spectrum
200  BOOST_FOREACH(const CVParam& cvParam, calculatedSpectrum->precursors[0].selectedIons[0].cvParams)
201  {
202  if (cvParam.cvid != MS_charge_state && cvParam.cvid != MS_possible_charge_state)
203  continue;
204  unit_assert_operator_equal(outputChargeStateTerm, cvParam.cvid); // tests whether MS_charge_state was reported
205  unit_assert(cvParam.valueAs<int>() == t.trueCharge); // tests whether the correct charge was recorded
206  }
207  }
208  catch (exception& e)
209  {
210  cerr << "Test case " << (i+1) << " failed:\n" << e.what() << endl;
211  ++failedTests;
212  }
213  }
214  return failedTests;
215 }
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:235
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
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
MS_profile_spectrum
profile spectrum: A profile mass spectrum is created when data is recorded with ion current (counts p...
Definition: cv.hpp:565
vector< double > parseDoubleArray(const string &doubleArray)
SpectrumList implementation that assigns (probable) charge states to tandem mass spectra.
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
const size_t testChargeStateCalculatorsSize
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
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
MS_preset_scan_configuration
preset scan configuration: A user-defined scan configuration that specifies the instrumental settings...
Definition: cv.hpp:2359
MS_possible_charge_state
possible charge state: A possible charge state of the ion in a situation where the charge of an ion i...
Definition: cv.hpp:2419
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
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
TestChargeStateCalculator testChargeStateCalculators[]
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
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ main()

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

Definition at line 218 of file SpectrumList_ChargeFromIsotopeTest.cpp.

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

219 {
220  TEST_PROLOG(argc, argv)
221 
222  try
223  {
224  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
225  int failedTests = test();
226  unit_assert_operator_equal(0, failedTests);
227  }
228  catch (exception& e)
229  {
230  TEST_FAILED(e.what())
231  }
232  catch (...)
233  {
234  TEST_FAILED("Caught unknown exception.")
235  }
236 
238 }
#define TEST_EPILOG
Definition: unit.hpp:182
#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_ChargeFromIsotopeTest.cpp.

Referenced by main().

§ testChargeStateCalculators

TestChargeStateCalculator testChargeStateCalculators[]

Definition at line 65 of file SpectrumList_ChargeFromIsotopeTest.cpp.

§ testChargeStateCalculatorsSize

const size_t testChargeStateCalculatorsSize = sizeof(testChargeStateCalculators) / sizeof(TestChargeStateCalculator)

Definition at line 121 of file SpectrumList_ChargeFromIsotopeTest.cpp.

Referenced by test().