ProteoWizard
SpectrumListFactoryTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumListFactoryTest.cpp 6393 2014-06-17 20:02:26Z frenchwr $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars-Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #include "SpectrumListFactory.hpp"
27 #include <cstring>
28 
29 
30 using namespace pwiz::analysis;
31 using namespace pwiz::util;
32 using namespace pwiz::cv;
33 using namespace pwiz::msdata;
34 
35 
36 ostream* os_ = 0;
37 
38 
39 void testUsage()
40 {
41  if (os_) *os_ << "SpectrumListFactory::usage():\n" << SpectrumListFactory::usage() << endl;
42 }
43 
44 
45 void testWrap()
46 {
47  MSData msd;
49 
51 
52  unit_assert(sl.get());
53  unit_assert(sl->size() > 2);
54 
55  // CompassXtract and pwiz data processing
57  unit_assert_operator_equal(1, msd.allDataProcessingPtrs()[1]->processingMethods.size());
58 
59  SpectrumListFactory::wrap(msd, "scanNumber [19,20]");
60  unit_assert(sl->size() == 2);
61 
62  // make sure we can handle config file lines copied from commandline
63  // with quotes intact
64  SpectrumListFactory::wrap(msd, "'index [1,1]'");
65  unit_assert(sl->size() == 1);
66  unit_assert(sl->spectrumIdentity(0).id == "scan=20");
67 
68  vector<double> profileData(sl->spectrum(0)->getMZArray()->data);
69  unit_assert(profileData.size() == 10);
70  unit_assert(profileData[0] == 0);
71  unit_assert(profileData[9] == 18);
72 
74  unit_assert_operator_equal(1, msd.allDataProcessingPtrs()[1]->processingMethods.size());
75 
76  SpectrumListFactory::wrap(msd, "peakPicking true [1,6]"); // backwards compatible syntax
77  SpectrumListFactory::wrap(msd, "peakPicking false"); // backwards compatible syntax
78  SpectrumListFactory::wrap(msd, "peakPicking cwt msLevel=[1,6]");
79  SpectrumListFactory::wrap(msd, "peakPicking cwt snr=1.2 msLevel=2-");
80  SpectrumListFactory::wrap(msd, "peakPicking cwt peakSpace=0.05");
81 
82  vector<double> peakData(sl->spectrum(0)->getMZArray()->data);
83  unit_assert(peakData.size() == 1);
84  unit_assert(peakData[0] == 0);
85 
87  unit_assert_operator_equal(6, msd.allDataProcessingPtrs()[1]->processingMethods.size());
88 }
89 
90 
92 {
93  MSData msd;
95 
97  unit_assert(sl.get());
98  unit_assert(sl->size() > 2);
99 
100  double timeHighInSeconds = 5.9 * 60; // between first and second scan
101  ostringstream oss;
102  oss << "scanTime [0," << timeHighInSeconds << "]";
103  SpectrumListFactory::wrap(msd, oss.str());
104  unit_assert(sl->size() == 2);
105  unit_assert(sl->spectrumIdentity(0).id == "scan=19");
106  unit_assert(sl->spectrumIdentity(1).id == "sample=1 period=1 cycle=23 experiment=1"); // not in scan time order (42 seconds)
107 }
108 
109 
111 {
112  MSData msd;
114 
116  unit_assert(sl.get());
117  unit_assert(sl->size() == 5);
118 
119  sl->spectrum(0)->scanList.scans[0].set(MS_scan_start_time, 35, UO_second);
120  sl->spectrum(2)->scanList.scans[0].set(MS_scan_start_time, 0.5, UO_minute);
121 
122  SpectrumListFactory::wrap(msd, "sortByScanTime");
123  unit_assert(sl->size() == 5);
124  unit_assert(sl->spectrumIdentity(0).id == "scan=21");
125  unit_assert(sl->spectrumIdentity(1).id == "scan=19");
126  unit_assert(sl->spectrumIdentity(2).id == "sample=1 period=1 cycle=23 experiment=1");
127 }
128 
129 
131 {
132  MSData msd;
134 
136  unit_assert(sl.get() && sl->size()>2);
137  SpectrumPtr spectrum = sl->spectrum(0, true);
138  vector<MZIntensityPair> data;
139  spectrum->getMZIntensityPairs(data);
140  unit_assert(data.size() == 15);
141 
142  SpectrumListFactory::wrap(msd, "mzWindow [9.5,15]");
143 
144  spectrum = sl->spectrum(0, true);
145  spectrum->getMZIntensityPairs(data);
146  unit_assert(data.size() == 5);
147 
148  spectrum = sl->spectrum(1, true);
149  spectrum->getMZIntensityPairs(data);
150  unit_assert(data.size() == 3);
151 }
152 
153 
155 {
156  MSData msd;
158 
160  unit_assert(sl.get());
161  unit_assert_operator_equal(5, sl->size());
162 
163  SpectrumListFactory::wrap(msd, "msLevel 2");
164  unit_assert_operator_equal(2, sl->size());
165  unit_assert_operator_equal("scan=20", sl->spectrumIdentity(0).id);
166 }
167 
168 
170 {
171  {
172  MSData msd;
175 
176  SpectrumListFactory::wrap(msd, "chargeState 2");
177  unit_assert_operator_equal(2, sl->size());
178  unit_assert_operator_equal("scan=20", sl->spectrumIdentity(0).id);
179 
180  SpectrumListFactory::wrap(msd, "chargeState 1");
181  unit_assert_operator_equal(0, sl->size());
182  }
183 
184  {
185  MSData msd;
188 
189  SpectrumListFactory::wrap(msd, "chargeState 0-2");
190  unit_assert_operator_equal(2, sl->size());
191  unit_assert_operator_equal("scan=20", sl->spectrumIdentity(0).id);
192  }
193 }
194 
195 
197 {
198  // test that the minimum length is 1 (due to 0 being the "unset" value)
199  {
200  MSData msd;
202 
204  unit_assert(sl.get());
205  unit_assert(sl->size() == 5);
206 
207  SpectrumListFactory::wrap(msd, "defaultArrayLength 0-");
208  unit_assert(sl->size() == 4);
209  unit_assert(sl->find("scan=21") == sl->size());
210  }
211 
212  // test filtering out all spectra
213  {
214  MSData msd;
217 
218  SpectrumListFactory::wrap(msd, "defaultArrayLength 100-");
219  unit_assert(sl->size() == 0);
220  }
221 
222  // test filtering out empty spectra
223  {
224  MSData msd;
227 
228  SpectrumListFactory::wrap(msd, "defaultArrayLength 1-");
229  unit_assert(sl->size() == 4);
230  unit_assert(sl->find("scan=21") == sl->size());
231  }
232 
233  // test filtering out spectra with defaultArrayLength > 14
234  {
235  MSData msd;
238 
239  SpectrumListFactory::wrap(msd, "defaultArrayLength 15-");
240  unit_assert(sl->size() == 2);
241  unit_assert(sl->find("scan=20") == sl->size());
242  unit_assert(sl->find("scan=21") == sl->size());
243  }
244 
245  // test filtering out spectra with 0 < defaultArrayLength < 15
246  {
247  MSData msd;
250 
251  SpectrumListFactory::wrap(msd, "defaultArrayLength 1-14");
252  unit_assert(sl->size() == 2);
253  unit_assert(sl->find("scan=20") == 0);
254  }
255 }
256 
258 {
259  // test filter by CID activation
260  {
261  MSData msd;
263  SpectrumListFactory::wrap(msd, "msLevel 2-");
264  SpectrumListFactory::wrap(msd, "activation CID");
265  unit_assert(msd.run.spectrumListPtr->size() == 1);
266  }
267  // test filter by ETD activation
268  {
269  MSData msd;
271  SpectrumListFactory::wrap(msd, "msLevel 2-");
272  SpectrumListFactory::wrap(msd, "activation ETD");
273  unit_assert(msd.run.spectrumListPtr->size() == 1);
274  }
275  // test filter by HCD activation
276  {
277  MSData msd;
279  SpectrumListFactory::wrap(msd, "msLevel 2-");
280  SpectrumListFactory::wrap(msd, "activation HCD");
281  unit_assert(msd.run.spectrumListPtr->size() == 0);
282  }
283  // test filter by IRMPD activation
284  {
285  MSData msd;
287  SpectrumListFactory::wrap(msd, "msLevel 2-");
288  SpectrumListFactory::wrap(msd, "activation IRMPD");
289  unit_assert(msd.run.spectrumListPtr->size() == 0);
290  }
291  // test invalid argument
292  {
293  MSData msd;
295 
296  unit_assert_throws(SpectrumListFactory::wrap(msd, "activation UNEXPECTED_INPUT"), runtime_error);
297  }
298 }
299 
301 {
302  // test filter by ITMS analyzer type
303  {
304  MSData msd;
306 
307  SpectrumListFactory::wrap(msd, "analyzerType ITMS");
308  unit_assert(msd.run.spectrumListPtr->size() == 5);
309  }
310  // test filter by ITMS analyzer type (new syntax)
311  {
312  MSData msd;
314 
315  SpectrumListFactory::wrap(msd, "analyzerType it");
316  unit_assert(msd.run.spectrumListPtr->size() == 5);
317  }
318  // test filter by FTMS analyzer type
319  {
320  MSData msd;
322 
323  SpectrumListFactory::wrap(msd, "analyzer FTMS");
324  unit_assert(msd.run.spectrumListPtr->size() == 0);
325  }
326  // test filter by Orbi analyzer type
327  {
328  MSData msd;
330 
331  SpectrumListFactory::wrap(msd, "analyzer Orbi");
332  unit_assert(msd.run.spectrumListPtr->size() == 0);
333  }
334  // test filter by TOF analyzer type
335  {
336  MSData msd;
338 
339  SpectrumListFactory::wrap(msd, "analyzer TOF");
340  unit_assert(msd.run.spectrumListPtr->size() == 0);
341  }
342  // test invalid argument
343  {
344  MSData msd;
346 
347  unit_assert_throws(SpectrumListFactory::wrap(msd, "analyzer UNEXPECTED_INPUT"), runtime_error)
348  }
349 }
350 
352 {
353  // test filter by positive polarity
354  {
355  MSData msd;
357 
359  unit_assert(sl.get());
360  unit_assert(sl->size() == 5);
361 
362  SpectrumListFactory::wrap(msd, "polarity positive");
363  unit_assert(sl->size() == 3);
364  }
365  // test filter by + polarity
366  {
367  MSData msd;
369 
371  unit_assert(sl.get());
372  unit_assert(sl->size() == 5);
373 
374  SpectrumListFactory::wrap(msd, "polarity +");
375  unit_assert(sl->size() == 3);
376  }
377  // test filter by negative polarity
378  {
379  MSData msd;
381 
383  unit_assert(sl.get());
384  unit_assert(sl->size() == 5);
385 
386  SpectrumListFactory::wrap(msd, "polarity -");
387  unit_assert(sl->size() == 2);
388  }
389  // test invalid argument
390  {
391  MSData msd;
393 
395  unit_assert(sl.get());
396  unit_assert(sl->size() == 5);
397  unit_assert_throws(SpectrumListFactory::wrap(msd, "polarity UNEXPECTED_INPUT"), runtime_error)
398  }
399 }
400 
402 {
403  MSData msd;
405 
406  {
407  SpectrumListFactory::wrap(msd, "titleMaker <Id>");
409  unit_assert_operator_equal("scan=19", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
410  unit_assert_operator_equal("scan=20", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
411  unit_assert_operator_equal("scan=21", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
412  unit_assert_operator_equal("scan=22", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
413  unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
414  }
415 
416  {
417  // the outer titleMaker overrides the inner one
418  SpectrumListFactory::wrap(msd, "titleMaker <Index>; <SpectrumType>, <MsLevel>");
420  unit_assert_operator_equal("0; MS1 spectrum, 1", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
421  unit_assert_operator_equal("1; MSn spectrum, 2", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
422  unit_assert_operator_equal("2; MS1 spectrum, 1", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
423  unit_assert_operator_equal("3; MSn spectrum, 2", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
424  unit_assert_operator_equal("4; MS1 spectrum, 1", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
425  }
426 
427  {
428  SpectrumListFactory::wrap(msd, "titleMaker <ScanNumber> <MsLevel> <ActivationType> <ChargeState> <PrecursorSpectrumId>");
430  unit_assert_operator_equal("19 1 ", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
431  unit_assert_operator_equal("20 2 CID 2 scan=19", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
432  unit_assert_operator_equal("21 1 ", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
433  unit_assert_operator_equal("22 2 ETD/CID 2 scan=19", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
434  unit_assert_operator_equal("5 1 ", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
435  }
436 }
437 
438 void test()
439 {
440  testUsage();
441  testWrap();
445  testWrapMSLevel();
452 }
453 
454 
455 int main(int argc, char* argv[])
456 {
457  TEST_PROLOG(argc, argv)
458 
459  try
460  {
461  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
462  test();
463  }
464  catch (exception& e)
465  {
466  TEST_FAILED(e.what())
467  }
468  catch (...)
469  {
470  TEST_FAILED("Caught unknown exception.")
471  }
472 
474 }
475 
void testWrapScanTimeRange()
#define unit_assert_throws(x, exception)
Definition: unit.hpp:106
void testWrapMassAnalyzer()
void testWrapTitleMaker()
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
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
#define TEST_EPILOG
Definition: unit.hpp:182
void testWrapActivation()
void testWrapDefaultArrayLength()
void testUsage()
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
int main(int argc, char *argv[])
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
void testWrap()
static std::string usage(bool detailedHelp=true, const char *morehelp_prompt=NULL, int maxLineLength=80)
user-friendly documentation, with option of less or more detail
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
void testWrapMZWindow()
void testWrapMSLevel()
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:12589
ostream * os_
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here. Subsidiary data arrays are also both described and attached here.
Definition: MSData.hpp:823
std::vector< DataProcessingPtr > allDataProcessingPtrs() const
return dataProcessingPtrs augmented by the dataProcessingPtr() set in SpectrumList and/or Chromatogra...
MS_spectrum_title
spectrum title: A free-form text title describing a spectrum.
Definition: cv.hpp:2923
#define TEST_FAILED(x)
Definition: unit.hpp:176
void testWrapChargeState()
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
void testWrapSortScanTime()
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
static void wrap(msdata::MSData &msd, const std::string &wrapper, pwiz::util::IterationListenerRegistry *ilr=NULL)
instantiate the SpectrumListWrapper indicated by wrapper
void testWrapPolarity()
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:91