ProteoWizard
Functions | Variables
SpectrumList_MGF_Test.cpp File Reference
#include "SpectrumList_MGF.hpp"
#include "TextWriter.hpp"
#include "pwiz/utility/minimxml/XMLWriter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

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

Variables

ostream * os_ = 0
 
const char * testMGF
 

Function Documentation

◆ test()

void test ( )

Definition at line 69 of file SpectrumList_MGF_Test.cpp.

References pwiz::msdata::MSData::instrumentConfigurationPtrs, MS_base_peak_intensity, MS_base_peak_m_z, MS_charge_state, MS_LCQ_Deca, MS_ms_level, MS_negative_scan, MS_possible_charge_state, MS_scan_start_time, MS_selected_ion_m_z, MS_spectrum_title, MS_total_ion_current, os_, testMGF, unit_assert, unit_assert_equal, unit_assert_operator_equal, and pwiz::identdata::IO::write().

Referenced by main().

70 {
71  if (os_) *os_ << "test()\n";
72 
73  if (os_) *os_ << "mgf:\n" << testMGF << endl;
74 
75  shared_ptr<istream> is(new istringstream(testMGF));
76 
77  // dummy would normally be read in from file
78 
79  MSData dummy;
81  dummy.instrumentConfigurationPtrs.back()->cvParams.push_back(MS_LCQ_Deca);
82  dummy.instrumentConfigurationPtrs.back()->userParams.push_back(UserParam("doobie", "420"));
83 
84  SpectrumListPtr sl = SpectrumList_MGF::create(is, dummy);
85 
86  if (os_)
87  {
89  write(*sl);
90  *os_ << endl;
91  }
92 
93  // check easy functions
94 
95  unit_assert(sl.get());
96  unit_assert(sl->size() == 3);
97  unit_assert(sl->find("index=0") == 0);
98  unit_assert(sl->find("index=1") == 1);
99  unit_assert(sl->find("index=2") == 2);
100 
101  // find the second spectrum by TITLE field
102  IndexList list = sl->findSpotID("small.pwiz.0004.0004.2");
103  unit_assert(list.size() == 1);
104  unit_assert(list[0] == 1);
105 
106  // look for a non-existent TITLE field
107  list.clear();
108  list = sl->findSpotID("fake title string");
109  unit_assert(list.size() == 0);
110 
111  // check scan 0
112 
113  unit_assert(sl->spectrumIdentity(0).index == 0);
114  unit_assert(sl->spectrumIdentity(0).id == "index=0");
115  unit_assert(sl->spectrumIdentity(0).sourceFilePosition != -1);
116 
117  SpectrumPtr s = sl->spectrum(0, false);
118 
119  unit_assert(s.get());
120  unit_assert(s->id == "index=0");
121  unit_assert(s->index == 0);
122  unit_assert(s->sourceFilePosition != -1);
123  unit_assert(s->cvParam(MS_spectrum_title).value == "small.pwiz.0003.0003.2");
124  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
125  unit_assert_equal(s->cvParam(MS_total_ion_current).valueAs<double>(), 64.992226, 1e-5);
126  unit_assert_equal(s->cvParam(MS_base_peak_m_z).valueAs<double>(), 231.38884, 1e-5);
127  unit_assert_equal(s->cvParam(MS_base_peak_intensity).valueAs<double>(), 26.545113, 1e-5);
128 
129  unit_assert(s->precursors.size() == 1);
130  Precursor& precursor0 = s->precursors[0];
131  unit_assert(precursor0.selectedIons.size() == 1);
132  unit_assert_equal(precursor0.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>(), 810.79, 1e-5);
133 
134  unit_assert(s->defaultArrayLength == 3);
135  unit_assert(s->binaryDataArrayPtrs.empty());
136 
137  s = sl->spectrum(0, true);
138  unit_assert(s->defaultArrayLength == 3);
139  unit_assert(s->binaryDataArrayPtrs.size() == 2);
140  unit_assert(!s->binaryDataArrayPtrs[0]->data.empty() && !s->binaryDataArrayPtrs[1]->data.empty());
141 
142  vector<MZIntensityPair> pairs;
143  s->getMZIntensityPairs(pairs);
144 
145  if (os_)
146  {
147  *os_ << "scan 0:\n";
148  copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
149  *os_ << endl;
150  }
151 
152 
153  // check scan 1
154 
155  unit_assert(sl->spectrumIdentity(1).index == 1);
156  unit_assert(sl->spectrumIdentity(1).id == "index=1");
157 
158  s = sl->spectrum(1, true);
159  unit_assert(s.get());
160  unit_assert(s->id == "index=1");
161  unit_assert(s->index == 1);
162  unit_assert(s->sourceFilePosition != -1);
163  unit_assert(s->cvParam(MS_spectrum_title).value == "small.pwiz.0004.0004.2");
164  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
165  unit_assert(s->scanList.scans.size() == 1);
166  unit_assert_equal(s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds(), 123.456, 1e-5);
167 
168  unit_assert(s->precursors.size() == 1);
169  Precursor& precursor1 = s->precursors[0];
170  unit_assert(precursor1.selectedIons.size() == 1);
171  unit_assert_equal(precursor1.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>(), 837.34, 1e-5);
172  unit_assert(precursor1.selectedIons[0].cvParam(MS_charge_state).value == "2");
173 
174  unit_assert(s->defaultArrayLength == 5);
175 
176  pairs.clear();
177  s->getMZIntensityPairs(pairs);
178 
179  unit_assert(s->defaultArrayLength == pairs.size());
180 
181  if (os_)
182  {
183  *os_ << "scan 1:\n";
184  copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
185  *os_ << endl;
186  }
187 
188  // check scan 2
189 
190  unit_assert(sl->spectrumIdentity(2).index == 2);
191  unit_assert(sl->spectrumIdentity(2).id == "index=2");
192 
193  s = sl->spectrum(2, true);
194  unit_assert(s.get());
195  unit_assert(s->id == "index=2");
196  unit_assert(s->index == 2);
197  unit_assert(s->sourceFilePosition != -1);
198  unit_assert(s->cvParam(MS_spectrum_title).value == "small.pwiz.0005.0005.2");
199  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
200  unit_assert(s->hasCVParam(MS_negative_scan));
201  unit_assert(s->precursors.size() == 1);
202  Precursor& precursor2 = s->precursors[0];
203  unit_assert(precursor2.selectedIons.size() == 1);
204  unit_assert_equal(precursor2.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>(), 123.45, 1e-5);
205  unit_assert_operator_equal("2", precursor2.selectedIons[0].cvParamChildren(MS_possible_charge_state)[0].value);
206  unit_assert_operator_equal("3", precursor2.selectedIons[0].cvParamChildren(MS_possible_charge_state)[1].value);
207 }
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:396
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:2121
std::vector< InstrumentConfigurationPtr > instrumentConfigurationPtrs
list and descriptions of instrument configurations.
Definition: MSData.hpp:877
The method of precursor ion selection and activation.
Definition: MSData.hpp:311
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
MS_total_ion_current
total ion current: The sum of all the separate ion currents carried by the ions of different m/z cont...
Definition: cv.hpp:1407
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
const char * testMGF
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
MS_LCQ_Deca
LCQ Deca: ThermoFinnigan LCQ Deca.
Definition: cv.hpp:2271
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2901
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
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:2118
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:229
boost::shared_ptr< InstrumentConfiguration > InstrumentConfigurationPtr
Definition: MSData.hpp:250
MS_possible_charge_state
possible charge state: A possible charge state of the ion in a situation where the charge of an ion i...
Definition: cv.hpp:2571
MS_spectrum_title
spectrum title: A free-form text title describing a spectrum.
Definition: cv.hpp:3075
ostream * os_
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
#define unit_assert(x)
Definition: unit.hpp:85
MS_negative_scan
negative scan: Polarity of the scan is negative.
Definition: cv.hpp:735

◆ main()

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

Definition at line 210 of file SpectrumList_MGF_Test.cpp.

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

211 {
212  TEST_PROLOG(argc, argv)
213 
214  try
215  {
216  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
217  test();
218  }
219  catch (exception& e)
220  {
221  TEST_FAILED(e.what())
222  }
223  catch (...)
224  {
225  TEST_FAILED("Caught unknown exception.")
226  }
227 
229 }
#define TEST_EPILOG
Definition: unit.hpp:183
#define TEST_FAILED(x)
Definition: unit.hpp:177
void test()
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
ostream * os_

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 36 of file SpectrumList_MGF_Test.cpp.

Referenced by main(), and test().

◆ testMGF

const char* testMGF
Initial value:
=
"BEGIN IONS\n"
"PEPMASS=810.790000\n"
"TITLE=small.pwiz.0003.0003.2\n"
"231.388840 26.545113\n"
"233.339828 20.447954\n"
"239.396149 17.999159\n"
"END IONS\n"
"BEGIN IONS\n"
"PEPMASS=837.340000\n"
"TITLE=small.pwiz.0004.0004.2\n"
"RTINSECONDS=123.456\n"
"CHARGE=2+\n"
"236.047043 11.674493\n"
"237.237091 24.431984\n"
"238.824036 10.019409\n"
"239.531403 6.842983\n"
"243.128693 89.586212\n"
"END IONS\n"
"BEGIN IONS\n"
"PEPMASS=123.45\n"
"TITLE=small.pwiz.0005.0005.2\n"
"RTINSECONDS=234.56\n"
"CHARGE=2- and 3-\n"
"236.047043 11.674493\n"
"237.237091 24.431984\n"
"238.824036 10.019409\n"
"239.531403 6.842983\n"
"243.128693 89.586212\n"
"END IONS\n"

Definition at line 38 of file SpectrumList_MGF_Test.cpp.

Referenced by test().