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.

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 }

Referenced by test().

◆ parseCVTermArray()

vector<CVID> parseCVTermArray ( const string &  cvTermArray)

Definition at line 135 of file SpectrumList_ChargeFromIsotopeTest.cpp.

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 }

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

◆ test()

int test ( )

Definition at line 147 of file SpectrumList_ChargeFromIsotopeTest.cpp.

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 }

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, testChargeStateCalculators, testChargeStateCalculatorsSize, TestChargeStateCalculator::trueCharge, unit_assert, unit_assert_operator_equal, UO_second, and pwiz::data::CVParam::valueAs().

Referenced by main().

◆ main()

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

Definition at line 218 of file SpectrumList_ChargeFromIsotopeTest.cpp.

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 }

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

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.

Referenced by test().

◆ testChargeStateCalculatorsSize

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

Definition at line 121 of file SpectrumList_ChargeFromIsotopeTest.cpp.

Referenced by test().

TestChargeStateCalculator::defaultMaxCharge
int defaultMaxCharge
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:61
pwiz::msdata::SpectrumListPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
MS_charge_state
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition: cv.hpp:396
MS_number_of_detector_counts
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:741
pwiz::msdata::Spectrum
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition: MSData.hpp:505
TestChargeStateCalculator::inputPrecursorMZ
double inputPrecursorMZ
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:50
pwiz::data::peakdata::Scan
Definition: PeakData.hpp:134
MS_scan_start_time
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:309
MS_MSn_spectrum
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2364
TestChargeStateCalculator::defaultMinCharge
int defaultMinCharge
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:60
TestChargeStateCalculator::trueCharge
int trueCharge
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:51
parseDoubleArray
vector< double > parseDoubleArray(const string &doubleArray)
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:123
pwiz::msdata::MSData::run
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition: MSData.hpp:886
UO_second
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:13833
unit_assert_operator_equal
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
TestChargeStateCalculator
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:45
pwiz::data::CVParam::valueAs
value_type valueAs() const
templated value access with type conversion
Definition: ParamTypes.hpp:112
TestChargeStateCalculator::minCharge
int minCharge
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:55
testChargeStateCalculatorsSize
const size_t testChargeStateCalculatorsSize
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:121
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
TestChargeStateCalculator::MS2rTime
double MS2rTime
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:53
TestChargeStateCalculator::inputIntensityArray
const char * inputIntensityArray
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:49
pwiz::data::CVTranslator
translates text to CV terms
Definition: CVTranslator.hpp:39
TestChargeStateCalculator::parentsAfter
int parentsAfter
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:58
TestChargeStateCalculator::parentsBefore
int parentsBefore
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:57
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
TestChargeStateCalculator::inputMZArray
const char * inputMZArray
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:48
pwiz::msdata::SpectrumListSimple
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:716
TestChargeStateCalculator::halfIsolationWidth
double halfIsolationWidth
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:59
pwiz::msdata::Run::spectrumListPtr
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition: MSData.hpp:827
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
testChargeStateCalculators
TestChargeStateCalculator testChargeStateCalculators[]
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:65
TestChargeStateCalculator::MS1rTime
double MS1rTime
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:52
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
MS_ms_level
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
MS_profile_spectrum
MS_profile_spectrum
profile spectrum: A profile mass spectrum is created when data is recorded with ion current (counts p...
Definition: cv.hpp:726
test
int test()
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:147
pwiz::data::CVTranslator::translate
cv::CVID translate(const std::string &text) const
translate text -> CVID
os_
ostream * os_
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:34
pwiz::analysis::SpectrumList_ChargeFromIsotope
SpectrumList implementation that assigns (probable) charge states to tandem mass spectra.
Definition: SpectrumList_ChargeFromIsotope.hpp:68
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
pwiz::data::CVParam::cvid
CVID cvid
Definition: ParamTypes.hpp:46
TestChargeStateCalculator::maxCharge
int maxCharge
Definition: SpectrumList_ChargeFromIsotopeTest.cpp:56
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
MS_preset_scan_configuration
MS_preset_scan_configuration
preset scan configuration: A user-defined scan configuration that specifies the instrumental settings...
Definition: cv.hpp:2511
pwiz::msdata::Precursor
The method of precursor ion selection and activation.
Definition: MSData.hpp:311
pwiz::msdata::SpectrumListSimple::spectra
std::vector< SpectrumPtr > spectra
Definition: MSData.hpp:718
MS_possible_charge_state
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:2571
pwiz::data::CVParam
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44