ProteoWizard
Classes | Functions | Variables
SpectrumList_MetadataFixerTest.cpp File Reference
#include "SpectrumList_MetadataFixer.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/data/msdata/TextWriter.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

struct  TestMetadataFixer
 

Functions

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

Variables

ostream * os_ = 0
 
TestMetadataFixer testMetadataFixers []
 
const size_t testMetadataFixersSize = sizeof(testMetadataFixers) / sizeof(TestMetadataFixer)
 

Function Documentation

§ parseDoubleArray()

vector<double> parseDoubleArray ( const string &  doubleArray)

Definition at line 56 of file SpectrumList_MetadataFixerTest.cpp.

Referenced by test().

57 {
58  vector<double> doubleVector;
59  vector<string> tokens;
60  bal::split(tokens, doubleArray, bal::is_space());
61  if (!tokens.empty() && !tokens[0].empty())
62  for (size_t i=0; i < tokens.size(); ++i)
63  doubleVector.push_back(lexical_cast<double>(tokens[i]));
64  return doubleVector;
65 }

§ test()

void test ( )

Definition at line 67 of file SpectrumList_MetadataFixerTest.cpp.

References TestMetadataFixer::bpi, TestMetadataFixer::bpmz, TestMetadataFixer::inputIntensityArray, TestMetadataFixer::inputMZArray, MS_base_peak_intensity, MS_base_peak_m_z, MS_number_of_detector_counts, MS_TIC, parseDoubleArray(), pwiz::msdata::SpectrumListSimple::spectra, testMetadataFixersSize, TestMetadataFixer::tic, and unit_assert.

Referenced by main().

68 {
69  for (size_t i=0; i < testMetadataFixersSize; ++i)
70  {
72  SpectrumListPtr originalList(sl);
73 
74  // test once with no metadata
75  SpectrumPtr s0(new Spectrum);
76  sl->spectra.push_back(s0);
77 
79 
80  // test again with existing metadata to be overwritten
81  SpectrumPtr s1(new Spectrum);
82  s1->set(MS_TIC, t.tic + 1);
83  s1->set(MS_base_peak_intensity, t.bpi + 1);
84  s1->set(MS_base_peak_m_z, t.bpmz + 1);
85  sl->spectra.push_back(s1);
86 
87  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
88  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
89  s0->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
90  s1->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
91 
92  SpectrumListPtr fixer(new SpectrumList_MetadataFixer(originalList));
93 
94  SpectrumPtr fixedSpectrum = fixer->spectrum(0, true);
95  unit_assert(fixedSpectrum->cvParam(MS_TIC).valueAs<double>() == t.tic);
96  unit_assert(fixedSpectrum->cvParam(MS_base_peak_intensity).valueAs<double>() == t.bpi);
97  unit_assert(fixedSpectrum->cvParam(MS_base_peak_m_z).valueAs<double>() == t.bpmz);
98 
99  fixedSpectrum = fixer->spectrum(1, true);
100  unit_assert(fixedSpectrum->cvParam(MS_TIC).valueAs<double>() == t.tic);
101  unit_assert(fixedSpectrum->cvParam(MS_base_peak_intensity).valueAs<double>() == t.bpi);
102  unit_assert(fixedSpectrum->cvParam(MS_base_peak_m_z).valueAs<double>() == t.bpmz);
103  }
104 }
MS_TIC
TIC (total ion current): The sum of all the separate ion currents carried by the ions of different m/...
Definition: cv.hpp:1258
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:1969
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
const size_t testMetadataFixersSize
vector< double > parseDoubleArray(const string &doubleArray)
TestMetadataFixer testMetadataFixers[]
MS_base_peak_m_z
base peak m/z: M/z value of the signal of highest intensity in the mass spectrum. ...
Definition: cv.hpp:1966
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
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
SpectrumList implementation to add (or replace) base peak and total ion metadata with new values calc...
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

§ main()

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

Definition at line 106 of file SpectrumList_MetadataFixerTest.cpp.

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

107 {
108  TEST_PROLOG(argc, argv)
109 
110  try
111  {
112  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
113  test();
114  }
115  catch (exception& e)
116  {
117  TEST_FAILED(e.what())
118  }
119  catch (...)
120  {
121  TEST_FAILED("Caught unknown exception.")
122  }
123 
125 }
#define TEST_EPILOG
Definition: unit.hpp:182
#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 32 of file SpectrumList_MetadataFixerTest.cpp.

Referenced by main().

§ testMetadataFixers

TestMetadataFixer testMetadataFixers[]
Initial value:
=
{
{ "1 2 3 4 5", "10 20 30 40 50", 150, 50, 5 },
{ "1 2 3 4 5", "50 40 30 20 10", 150, 50, 1 },
{ "1 2 3 4 5", "10 20 30 20 10", 90, 30, 3 },
{ "1", "10", 10, 10, 1 }
}

Definition at line 46 of file SpectrumList_MetadataFixerTest.cpp.

§ testMetadataFixersSize

const size_t testMetadataFixersSize = sizeof(testMetadataFixers) / sizeof(TestMetadataFixer)

Definition at line 54 of file SpectrumList_MetadataFixerTest.cpp.

Referenced by test().