ProteoWizard
Classes | Functions | Variables
SpectrumList_ScanSummerTest.cpp File Reference
#include "SpectrumList_ScanSummer.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  TestScanSummerCalculator
 

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
 
TestScanSummerCalculator testScanSummerCalculators []
 
TestScanSummerCalculator goldStandard []
 
const size_t testScanSummerSize = sizeof(testScanSummerCalculators) / sizeof(TestScanSummerCalculator)
 
const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestScanSummerCalculator)
 

Function Documentation

◆ operator<<()

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

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

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

Referenced by test().

◆ test()

int test ( )

Definition at line 132 of file SpectrumList_ScanSummerTest.cpp.

133{
134 int failedTests = 0;
135
136 // create the spectrum list
138 SpectrumListPtr originalList(sl);
139
140 for (size_t i=0; i < testScanSummerSize; ++i)
141 {
143 SpectrumPtr s(new Spectrum);
144 s->set(MS_MSn_spectrum);
145 s->set(MS_ms_level,2);
146 s->index = i;
147 s->scanList.scans.push_back(Scan());
148 Scan& scanRef = s->scanList.scans[0];
149 scanRef.set(MS_scan_start_time,t.rTime,UO_second);
150 if (t.ionMobility > 0)
152 s->precursors.push_back(Precursor(t.inputPrecursorMZ));
153
154 vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
155 vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
156 s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
157 s->defaultArrayLength = inputMZArray.size();
158
159 scanRef.scanWindows.push_back(ScanWindow());
160 scanRef.scanWindows[0].set(MS_scan_window_lower_limit,inputMZArray[0]);
161 scanRef.scanWindows[0].set(MS_scan_window_upper_limit,inputMZArray[inputMZArray.size()-1]);
162
163 sl->spectra.push_back(s);
164 }
165
166
167 vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
168 vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
169
170 // run spectral summation
171 try
172 {
173
174 SpectrumListPtr calculator(new SpectrumList_ScanSummer(originalList, 0.05, 10, 0.5));
175
176 for (size_t i=0; i < calculator->size(); ++i)
177 {
178 SpectrumPtr s = calculator->spectrum(i,true);
179 BinaryData<double>& mzs = s->getMZArray()->data;
180 BinaryData<double>& intensities = s->getIntensityArray()->data;
181 Precursor& precursor = s->precursors[0];
182 SelectedIon& selectedIon = precursor.selectedIons[0];
183 double precursorMZ = selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>();
184 double rTime = s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds();
185 double ionMobility = s->scanList.scans[0].cvParamValueOrDefault(MS_inverse_reduced_ion_mobility, 0.0);
186
187 vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
188 vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
189
190 unit_assert_operator_equal(goldMZArray.size(), mzs.size());
191 unit_assert_operator_equal(goldIntensityArray.size(), intensities.size());
192 unit_assert_equal(goldStandard[i].inputPrecursorMZ, precursorMZ, 1e-8);
193 unit_assert_equal(goldStandard[i].rTime, rTime, 1e-8);
194 unit_assert_equal(goldStandard[i].ionMobility, ionMobility, 1e-8);
195
196 for (size_t j=0; j < mzs.size(); ++j)
197 {
198 unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
199 unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
200 }
201
202 }
203
204
205
206
207 }
208 catch (exception& e)
209 {
210 cerr << "Test failed:\n" << e.what() << endl;
211 ++failedTests;
212 }
213 return failedTests;
214}
vector< double > parseDoubleArray(const string &doubleArray)
TestScanSummerCalculator goldStandard[]
TestScanSummerCalculator testScanSummerCalculators[]
const size_t testScanSummerSize
Provides a custom-sorted spectrum list.
A custom vector class that can store its contents in either a std::vector or a cli::array (when compi...
MS_scan_window_lower_limit
scan window lower limit: The upper m/z bound of a mass spectrometer scan window.
Definition cv.hpp:2109
MS_scan_window_upper_limit
scan window upper limit: The lower m/z bound of a mass spectrometer scan window.
Definition cv.hpp:2106
MS_inverse_reduced_ion_mobility
inverse reduced ion mobility: Ion mobility measurement for an ion or spectrum of ions as measured in ...
Definition cv.hpp:8868
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_volt_second_per_square_centimeter
volt-second per square centimeter: An electrical mobility unit that equals the speed [cm/s] an ion re...
Definition cv.hpp:8862
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition cv.hpp:2901
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_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
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
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573
value_type valueAs() const
templated value access with type conversion
CVParam cvParam(CVID cvid) const
finds cvid in the container:
The method of precursor ion selection and activation.
Definition MSData.hpp:312
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition MSData.hpp:329
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_equal(x, y, epsilon)
Definition unit.hpp:99
#define unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92

References pwiz::data::ParamContainer::cvParam(), goldStandard, TestScanSummerCalculator::inputIntensityArray, TestScanSummerCalculator::inputMZArray, TestScanSummerCalculator::inputPrecursorMZ, TestScanSummerCalculator::ionMobility, MS_inverse_reduced_ion_mobility, MS_ms_level, MS_MSn_spectrum, MS_number_of_detector_counts, MS_scan_start_time, MS_scan_window_lower_limit, MS_scan_window_upper_limit, MS_selected_ion_m_z, MS_volt_second_per_square_centimeter, parseDoubleArray(), TestScanSummerCalculator::rTime, pwiz::msdata::Precursor::selectedIons, pwiz::util::BinaryData< T >::size(), pwiz::msdata::SpectrumListSimple::spectra, testScanSummerCalculators, testScanSummerSize, unit_assert_equal, unit_assert_operator_equal, UO_second, and pwiz::data::CVParam::valueAs().

Referenced by main().

◆ main()

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

Definition at line 217 of file SpectrumList_ScanSummerTest.cpp.

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

Referenced by main().

◆ testScanSummerCalculators

TestScanSummerCalculator testScanSummerCalculators[]

Definition at line 55 of file SpectrumList_ScanSummerTest.cpp.

56{
57
58 { "112 112.0000001 112.1 120 121 123 124 128 129",
59 " 3 2 5 0 1 4 2 1 7",
60 120.0,
61 20.0,
62 0.0},
63
64 { "112.0001 119 120 121 122 123 124 127 128 129",
65 " 1 4 5 6 7 8 9 10 11 12",
66 120.01,
67 20.1,
68 0.0},
69
70 { "200 200.1 200.2 200.9 202",
71 "1.0 3.0 1.0 0.0 3.0",
72 401.23,
73 21.1,
74 1.0},
75
76 { "120 126 127",
77 "7 7 7",
78 119.96,
79 21.05,
80 0.0},
81
82 { "200.1 200.2 200.3 200.8 200.9",
83 "1.0 3.0 1.0 1.0 4.0",
84 401.19,
85 21.2,
86 1.01},
87
88 { "200.1 200.2 200.3 200.8 200.9",
89 "1.0 3.0 1.0 1.0 4.0",
90 401.21,
91 21.3,
92 2.0},
93};

Referenced by test().

◆ goldStandard

TestScanSummerCalculator goldStandard[]
Initial value:
=
{
{ "112 112.1 119 120 121 122 123 124 126 127 128 129",
"6 5 4 12 7 7 12 11 7 17 12 19",
120.0,
20.1,
0.0},
{ "200 200.1 200.2 200.3 200.8 200.9 202",
"1.0 4.0 4.0 1.0 1.0 4.0 3.0",
401.21,
21.15,
1.005},
{ "200.1 200.2 200.3 200.8 200.9",
"1.0 3.0 1.0 1.0 4.0",
401.21,
21.3,
2.0},
}

Definition at line 95 of file SpectrumList_ScanSummerTest.cpp.

96{
97
98 { "112 112.1 119 120 121 122 123 124 126 127 128 129",
99 "6 5 4 12 7 7 12 11 7 17 12 19",
100 120.0,
101 20.1, // median of 20 20.1 21.05
102 0.0},
103
104 { "200 200.1 200.2 200.3 200.8 200.9 202",
105 "1.0 4.0 4.0 1.0 1.0 4.0 3.0",
106 401.21, // median of 401.19 401.23
107 21.15, // median of 21.1 21.2
108 1.005}, // median of 1 1.01
109
110 { "200.1 200.2 200.3 200.8 200.9",
111 "1.0 3.0 1.0 1.0 4.0",
112 401.21,
113 21.3,
114 2.0},
115};

Referenced by test().

◆ testScanSummerSize

const size_t testScanSummerSize = sizeof(testScanSummerCalculators) / sizeof(TestScanSummerCalculator)

Definition at line 117 of file SpectrumList_ScanSummerTest.cpp.

Referenced by test().

◆ goldStandardSize

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

Definition at line 118 of file SpectrumList_ScanSummerTest.cpp.