ProteoWizard
Classes | Functions | Variables
SpectrumList_ChargeStateCalculatorTest.cpp File Reference
#include "SpectrumList_ChargeStateCalculator.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_ChargeStateCalculatorTest.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 269 of file SpectrumList_ChargeStateCalculatorTest.cpp.

Referenced by test().

270 {
271  vector<double> doubleVector;
272  vector<string> tokens;
273  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
274  if (!tokens.empty())
275  for (size_t i=0; i < tokens.size(); ++i)
276  if (!tokens[i].empty())
277  doubleVector.push_back(lexical_cast<double>(tokens[i]));
278  return doubleVector;
279 }

§ parseCVTermArray()

vector<CVID> parseCVTermArray ( const string &  cvTermArray)

Definition at line 281 of file SpectrumList_ChargeStateCalculatorTest.cpp.

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

Referenced by test().

282 {
283  static pwiz::data::CVTranslator cvTranslator;
284  vector<CVID> cvTermVector;
285  vector<string> tokens;
286  bal::split(tokens, cvTermArray, bal::is_space());
287  if (!tokens.empty() && !tokens[0].empty())
288  for (size_t i=0; i < tokens.size(); ++i)
289  cvTermVector.push_back(cvTranslator.translate(tokens[i]));
290  return cvTermVector;
291 }
translates text to CV terms
cv::CVID translate(const std::string &text) const
translate text -> CVID

§ test()

int test ( )

Definition at line 293 of file SpectrumList_ChargeStateCalculatorTest.cpp.

References TestChargeStateCalculator::chargeStateArray, pwiz::data::CVParam::cvid, TestChargeStateCalculator::inputActivationTypeArray, TestChargeStateCalculator::inputChargeStateArray, TestChargeStateCalculator::inputIntensityArray, TestChargeStateCalculator::inputMZArray, TestChargeStateCalculator::inputPrecursorMZ, TestChargeStateCalculator::maxKnownCharge, TestChargeStateCalculator::maxMultipleCharge, TestChargeStateCalculator::minMultipleCharge, MS_charge_state, MS_ms_level, MS_MSn_spectrum, MS_number_of_detector_counts, MS_possible_charge_state, TestChargeStateCalculator::overrideExistingChargeState, parseCVTermArray(), parseDoubleArray(), TestChargeStateCalculator::singlyChargedFraction, pwiz::msdata::SpectrumListSimple::spectra, testChargeStateCalculatorsSize, unit_assert, unit_assert_operator_equal, TestChargeStateCalculator::useMakeMS2Behavior, and pwiz::data::CVParam::valueAs().

Referenced by main().

294 {
295  int failedTests = 0;
296  for (size_t i=0; i < testChargeStateCalculatorsSize; ++i)
297  {
299  SpectrumListPtr originalList(sl);
300  SpectrumPtr s(new Spectrum);
301  s->set(MS_MSn_spectrum);
302  s->set(MS_ms_level, 2);
303  sl->spectra.push_back(s);
304 
305  try
306  {
308 
309  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
310  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
311  s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
312 
313  s->precursors.push_back(Precursor(t.inputPrecursorMZ));
314  vector<double> inputChargeStateArray = parseDoubleArray(t.inputChargeStateArray);
315  CVID inputChargeStateTerm = inputChargeStateArray.size() > 1 ? MS_possible_charge_state : MS_charge_state;
316  BOOST_FOREACH(int z, inputChargeStateArray)
317  s->precursors[0].selectedIons[0].cvParams.push_back(CVParam(inputChargeStateTerm, z));
318 
319  vector<CVID> inputActivationTypes = parseCVTermArray(t.inputActivationTypeArray);
320  BOOST_FOREACH(CVID cvid, inputActivationTypes)
321  s->precursors[0].activation.set(cvid);
322 
324  originalList,
325  t.overrideExistingChargeState,
326  t.maxMultipleCharge,
327  t.minMultipleCharge,
328  t.singlyChargedFraction,
329  t.maxKnownCharge,
330  t.useMakeMS2Behavior));
331 
332  vector<double> outputChargeStateArray = parseDoubleArray(t.chargeStateArray);
333  CVID outputChargeStateTerm = outputChargeStateArray.size() > 1 ? MS_possible_charge_state : MS_charge_state;
334  SpectrumPtr calculatedSpectrum = calculator->spectrum(0, true);
335  BOOST_FOREACH(const CVParam& cvParam, calculatedSpectrum->precursors[0].selectedIons[0].cvParams)
336  {
337  if (cvParam.cvid != MS_charge_state && cvParam.cvid != MS_possible_charge_state)
338  continue;
339  unit_assert_operator_equal(outputChargeStateTerm, cvParam.cvid);
340  unit_assert(find(outputChargeStateArray.begin(), outputChargeStateArray.end(), cvParam.valueAs<int>()) != outputChargeStateArray.end());
341  }
342  }
343  catch (exception& e)
344  {
345  cerr << "Test case " << (i+1) << " failed:\n" << e.what() << endl;
346  ++failedTests;
347  }
348  }
349  return failedTests;
350 }
vector< CVID > parseCVTermArray(const string &cvTermArray)
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
TestChargeStateCalculator testChargeStateCalculators[]
SpectrumList implementation that assigns (probable) charge states to tandem mass spectra.
vector< double > parseDoubleArray(const string &doubleArray)
const size_t testChargeStateCalculatorsSize
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
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
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
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
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 353 of file SpectrumList_ChargeStateCalculatorTest.cpp.

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

354 {
355  TEST_PROLOG(argc, argv)
356 
357  try
358  {
359  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
360  int failedTests = test();
361  unit_assert_operator_equal(0, failedTests);
362  }
363  catch (exception& e)
364  {
365  TEST_FAILED(e.what())
366  }
367  catch (...)
368  {
369  TEST_FAILED("Caught unknown exception.")
370  }
371 
373 }
#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_ChargeStateCalculatorTest.cpp.

Referenced by main().

§ testChargeStateCalculators

TestChargeStateCalculator testChargeStateCalculators[]

Definition at line 64 of file SpectrumList_ChargeStateCalculatorTest.cpp.

§ testChargeStateCalculatorsSize

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

Definition at line 267 of file SpectrumList_ChargeStateCalculatorTest.cpp.

Referenced by test().