ProteoWizard
Classes | Functions | Variables
MS2DeisotoperTest.cpp File Reference
#include "MS2Deisotoper.hpp"
#include "SpectrumList_PeakFilter.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  TestDeisotopeCalculator
 

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
 
TestDeisotopeCalculator testDeisotopeCalculators []
 
TestDeisotopeCalculator goldStandard []
 
const size_t testDeisotopeSize = sizeof(testDeisotopeCalculators) / sizeof(TestDeisotopeCalculator)
 
const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestDeisotopeCalculator)
 

Function Documentation

◆ operator<<()

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

Definition at line 37 of file MS2DeisotoperTest.cpp.

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

◆ parseDoubleArray()

vector< double > parseDoubleArray ( const string &  doubleArray)

Definition at line 86 of file MS2DeisotoperTest.cpp.

87{
88 vector<double> doubleVector;
89 vector<string> tokens;
90 bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
91 if (!tokens.empty())
92 for (size_t i=0; i < tokens.size(); ++i)
93 if (!tokens[i].empty())
94 doubleVector.push_back(lexical_cast<double>(tokens[i]));
95 return doubleVector;
96}

Referenced by test().

◆ test()

int test ( )

Definition at line 98 of file MS2DeisotoperTest.cpp.

99{
100 int failedTests = 0;
101
102 // create the spectrum list
104 SpectrumListPtr originalList(sl);
105
106 for (size_t i=0; i < testDeisotopeSize; ++i)
107 {
109 // attach all the data to the spectrum list
110 SpectrumPtr s(new Spectrum);
111 s->set(MS_MSn_spectrum);
112 s->set(MS_ms_level,2);
113 s->precursors.push_back(Precursor(100.0)); // dummy precursor m/z
114
115 vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
116 vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
117 s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
118 s->defaultArrayLength = inputMZArray.size();
119
120 sl->spectra.push_back(s);
121
122 }
123
124 vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
125 vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
126
127 // construct the filter
128 bool hires = false;
129 MZTolerance mzt(hires? 0.01 : 0.5);
130 bool poisson = true;
131 int maxCharge = 3, minCharge = 1;
132 SpectrumDataFilterPtr filter = SpectrumDataFilterPtr(new MS2Deisotoper(MS2Deisotoper::Config(mzt, hires, poisson, maxCharge, minCharge)));
133
134 // run spectral summation
135 try
136 {
137
138 SpectrumListPtr calculator(new SpectrumList_PeakFilter(originalList,filter));
139
140 for (size_t i=0; i < calculator->size(); ++i)
141 {
142 SpectrumPtr s = calculator->spectrum(i,true);
143 BinaryData<double>& mzs = s->getMZArray()->data;
144 BinaryData<double>& intensities = s->getIntensityArray()->data;
145
146 vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
147 vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
148
149 unit_assert(mzs.size() == goldMZArray.size());
150 unit_assert(intensities.size() == goldIntensityArray.size());
151
152 for (size_t j=0; j < mzs.size(); ++j)
153 {
154 unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
155 unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
156 }
157
158 }
159
160
161
162
163 }
164 catch (exception& e)
165 {
166 cerr << "Test failed:\n" << e.what() << endl;
167 ++failedTests;
168 }
169 return failedTests;
170}
vector< double > parseDoubleArray(const string &doubleArray)
TestDeisotopeCalculator goldStandard[]
TestDeisotopeCalculator testDeisotopeCalculators[]
const size_t testDeisotopeSize
SpectrumList implementation that returns spectra with the specified SpectrumDataFilter operation appl...
A custom vector class that can store its contents in either a std::vector or a cli::array (when compi...
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition cv.hpp:2139
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition cv.hpp:2364
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
boost::shared_ptr< SpectrumDataFilter > SpectrumDataFilterPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
void filter(const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
Applies linear convolution (filtering) to a univariate time series.
Definition filter.hpp:112
PrecursorMassFilter's parameters.
struct for expressing m/z tolerance in either amu or ppm
The method of precursor ion selection and activation.
Definition MSData.hpp:312
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Simple writeable in-memory implementation of SpectrumList.
Definition MSData.hpp:717
std::vector< SpectrumPtr > spectra
Definition MSData.hpp:718
#define unit_assert(x)
Definition unit.hpp:85
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References goldStandard, TestDeisotopeCalculator::inputIntensityArray, TestDeisotopeCalculator::inputMZArray, MS_ms_level, MS_MSn_spectrum, MS_number_of_detector_counts, parseDoubleArray(), pwiz::util::BinaryData< T >::size(), pwiz::msdata::SpectrumListSimple::spectra, testDeisotopeCalculators, testDeisotopeSize, unit_assert, and unit_assert_equal.

Referenced by main().

◆ main()

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

Definition at line 173 of file MS2DeisotoperTest.cpp.

174{
175 TEST_PROLOG(argc, argv)
176
177 try
178 {
179 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
180 int failedTests = test();
181 unit_assert_operator_equal(0, failedTests);
182 }
183 catch (exception& e)
184 {
185 TEST_FAILED(e.what())
186 }
187 catch (...)
188 {
189 TEST_FAILED("Caught unknown exception.")
190 }
191
193}
int test()
ostream * os_
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

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

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 35 of file MS2DeisotoperTest.cpp.

Referenced by main().

◆ testDeisotopeCalculators

TestDeisotopeCalculator testDeisotopeCalculators[]
Initial value:
=
{
{ "300.0 302.1 303.11 304.12 305.20",
"1.0 85.0 15.0 3.0 3.0"},
{ "299.5 300.01 300.52 301.03",
"10.0 75.0 25.0 40.0"},
{ "302.1 302.435 302.77 302.94 303.11",
"61.0 31.0 8.0 45.0 40.0"},
}

Definition at line 54 of file MS2DeisotoperTest.cpp.

55{
56
57 { "300.0 302.1 303.11 304.12 305.20",
58 "1.0 85.0 15.0 3.0 3.0"},
59
60 { "299.5 300.01 300.52 301.03",
61 "10.0 75.0 25.0 40.0"},
62
63 { "302.1 302.435 302.77 302.94 303.11",
64 "61.0 31.0 8.0 45.0 40.0"},
65
66};

Referenced by test().

◆ goldStandard

TestDeisotopeCalculator goldStandard[]
Initial value:
=
{
{ "300.0 302.1 305.20",
"1.0 85.0 3.0"},
{ "299.5 300.01 301.03",
"10.0 75.0 40.0"},
{ "302.1 302.94 303.11",
"61.0 45.0 40.0"},
}

Definition at line 68 of file MS2DeisotoperTest.cpp.

69{
70
71 { "300.0 302.1 305.20",
72 "1.0 85.0 3.0"},
73
74 { "299.5 300.01 301.03",
75 "10.0 75.0 40.0"},
76
77 { "302.1 302.94 303.11",
78 "61.0 45.0 40.0"},
79
80
81};

Referenced by test().

◆ testDeisotopeSize

const size_t testDeisotopeSize = sizeof(testDeisotopeCalculators) / sizeof(TestDeisotopeCalculator)

Definition at line 83 of file MS2DeisotoperTest.cpp.

Referenced by test().

◆ goldStandardSize

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

Definition at line 84 of file MS2DeisotoperTest.cpp.