ProteoWizard
SpectrumList_ScanSummerTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_ScanSummerTest.cpp 6389 2014-06-13 19:46:19Z frenchwr $
3 //
4 //
5 // Original author: William French <william.r.french <a.t> vanderbilt.edu>
6 //
7 // Copyright 2008 Vanderbilt University - Nashville, TN 37232
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
29 
30 using namespace pwiz::util;
31 using namespace pwiz::msdata;
32 using namespace pwiz::analysis;
33 
34 ostream* os_ = 0;
35 
36 ostream& operator<< (ostream& os, const vector<double>& v)
37 {
38  os << "(";
39  for (size_t i=0; i < v.size(); ++i)
40  os << " " << v[i];
41  os << " )";
42  return os;
43 }
44 
46 {
47  // space-delimited doubles
48  const char* inputMZArray;
49  const char* inputIntensityArray;
51  double rTime;
52 
53 };
54 
56 {
57 
58  { "112 120 121 123 124 128 129",
59  "7 0 1 4 2 1 7",
60  120.0,
61  20.0},
62 
63  { "119 120 121 122 123 124 127 128 129",
64  "4 5 6 7 8 9 10 11 12",
65  120.01,
66  20.1},
67 
68  { "200 200.01 200.02 200.09 200.20",
69  "1.0 3.0 1.0 0.0 3.0",
70  401.23,
71  21.01},
72 
73  { "120 126 127",
74  "7 7 7",
75  119.96,
76  21.05},
77 
78  { "200.01 200.02 200.03 200.08 200.09",
79  "1.0 3.0 1.0 1.0 4.0",
80  401.19,
81  21.1},
82 
83 };
84 
86 {
87 
88  { "112 119 120 121 122 123 124 126 127 128 129",
89  "7 4 12 7 7 12 11 7 17 12 19",
90  120.0,
91  20.0},
92 
93  { "200 200.01 200.02 200.03 200.08 200.09 200.20",
94  "1.0 4.0 4.0 1.0 1.0 4.0 3.0",
95  401.23,
96  21.01},
97 
98 };
99 
101 const size_t goldStandardSize = sizeof(goldStandard) / sizeof(TestScanSummerCalculator);
102 
103 vector<double> parseDoubleArray(const string& doubleArray)
104 {
105  vector<double> doubleVector;
106  vector<string> tokens;
107  bal::split(tokens, doubleArray, bal::is_space(), bal::token_compress_on);
108  if (!tokens.empty())
109  for (size_t i=0; i < tokens.size(); ++i)
110  if (!tokens[i].empty())
111  doubleVector.push_back(lexical_cast<double>(tokens[i]));
112  return doubleVector;
113 }
114 
115 int test()
116 {
117  int failedTests = 0;
118 
119  // create the spectrum list
121  SpectrumListPtr originalList(sl);
122 
123  for (size_t i=0; i < testScanSummerSize; ++i)
124  {
125  TestScanSummerCalculator& t = testScanSummerCalculators[i];
126  SpectrumPtr s(new Spectrum);
127  s->set(MS_MSn_spectrum);
128  s->set(MS_ms_level,2);
129  s->index = i;
130  s->scanList.scans.push_back(Scan());
131  Scan& scanRef = s->scanList.scans[0];
132  scanRef.set(MS_scan_start_time,t.rTime,UO_second);
133  s->precursors.push_back(Precursor(t.inputPrecursorMZ));
134 
135  vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
136  vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
137  s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
138  s->defaultArrayLength = inputMZArray.size();
139 
140  scanRef.scanWindows.push_back(ScanWindow());
141  scanRef.scanWindows[0].set(MS_scan_window_lower_limit,inputMZArray[0]);
142  scanRef.scanWindows[0].set(MS_scan_window_upper_limit,inputMZArray[inputMZArray.size()-1]);
143 
144  sl->spectra.push_back(s);
145  }
146 
147 
148  vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
149  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
150 
151  // run spectral summation
152  try
153  {
154 
155  SpectrumListPtr calculator(new SpectrumList_ScanSummer(originalList,0.05,10));
156 
157  for (size_t i=0; i < calculator->size(); ++i)
158  {
159  SpectrumPtr s = calculator->spectrum(i,true);
160  vector<double>& mzs = s->getMZArray()->data;
161  vector<double>& intensities = s->getIntensityArray()->data;
162  Precursor& precursor = s->precursors[0];
163  SelectedIon& selectedIon = precursor.selectedIons[0];
164  double precursorMZ = selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>();
165  double rTime = s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds();
166 
167  vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
168  vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
169 
170  unit_assert(mzs.size() == goldMZArray.size());
171  unit_assert(intensities.size() == goldIntensityArray.size());
172  unit_assert(precursorMZ == goldStandard[i].inputPrecursorMZ);
173  unit_assert(rTime == goldStandard[i].rTime);
174 
175  for (size_t j=0; j < mzs.size(); ++j)
176  {
177  unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
178  unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
179  }
180 
181  }
182 
183 
184 
185 
186  }
187  catch (exception& e)
188  {
189  cerr << "Test failed:\n" << e.what() << endl;
190  ++failedTests;
191  }
192  return failedTests;
193 }
194 
195 
196 int main(int argc, char* argv[])
197 {
198  TEST_PROLOG(argc, argv)
199 
200  try
201  {
202  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
203  int failedTests = test();
204  unit_assert_operator_equal(0, failedTests);
205  }
206  catch (exception& e)
207  {
208  TEST_FAILED(e.what())
209  }
210  catch (...)
211  {
212  TEST_FAILED("Caught unknown exception.")
213  }
214 
216 }
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
CVParam cvParam(CVID cvid) const
finds cvid in the container:
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
int main(int argc, char *argv[])
TestScanSummerCalculator goldStandard[]
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
Provides a custom-sorted spectrum list.
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:148
const size_t goldStandardSize
#define TEST_EPILOG
Definition: unit.hpp:182
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
MS_scan_window_upper_limit
scan window upper limit: The lower m/z bound of a mass spectrometer scan window.
Definition: cv.hpp:1954
ostream * os_
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
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:12526
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
vector< double > parseDoubleArray(const string &doubleArray)
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
MS_scan_window_lower_limit
scan window lower limit: The upper m/z bound of a mass spectrometer scan window.
Definition: cv.hpp:1957
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
const size_t testScanSummerSize
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition: MSData.hpp:328
std::vector< SpectrumPtr > spectra
Definition: MSData.hpp:714
#define TEST_FAILED(x)
Definition: unit.hpp:176
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
TestScanSummerCalculator testScanSummerCalculators[]
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
value_type valueAs() const
templated value access with type conversion
Definition: ParamTypes.hpp:112
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85