ProteoWizard
SpectrumList_MGF_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id$
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 "SpectrumList_MGF.hpp"
25 #include "TextWriter.hpp"
29 
30 using namespace pwiz::cv;
31 using namespace pwiz::msdata;
32 using namespace pwiz::util;
33 using namespace pwiz::minimxml;
34 
35 
36 ostream* os_ = 0;
37 
38 const char* testMGF =
39 "BEGIN IONS\n"
40 "PEPMASS=810.790000\n"
41 "TITLE=small.pwiz.0003.0003.2\n"
42 "231.388840 26.545113\n"
43 "233.339828 20.447954\n"
44 "239.396149 17.999159\n"
45 "END IONS\n"
46 "BEGIN IONS\n"
47 "PEPMASS=837.340000\n"
48 "TITLE=small.pwiz.0004.0004.2\n"
49 "RTINSECONDS=123.456\n"
50 "CHARGE=2+\n"
51 "236.047043 11.674493\n"
52 "237.237091 24.431984\n"
53 "238.824036 10.019409\n"
54 "239.531403 6.842983\n"
55 "243.128693 89.586212\n"
56 "END IONS\n"
57 "BEGIN IONS\n"
58 "PEPMASS=123.45\n"
59 "TITLE=small.pwiz.0005.0005.2\n"
60 "RTINSECONDS=234.56\n"
61 "CHARGE=2- and 3-\n"
62 "236.047043 11.674493\n"
63 "237.237091 24.431984\n"
64 "238.824036 10.019409\n"
65 "239.531403 6.842983\n"
66 "243.128693 89.586212\n"
67 "END IONS\n";
68 
69 void test()
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 }
208 
209 
210 int main(int argc, char* argv[])
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 }
230 
231 
pwiz::data::UserParam
Uncontrolled user parameters (essentially allowing free text). Before using these,...
Definition: ParamTypes.hpp:186
MS_LCQ_Deca
MS_LCQ_Deca
LCQ Deca: ThermoFinnigan LCQ Deca.
Definition: cv.hpp:2271
testMGF
const char * testMGF
Definition: SpectrumList_MGF_Test.cpp:38
pwiz::msdata::SpectrumListPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
MS_charge_state
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition: cv.hpp:396
unit_assert_equal
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
pwiz::cv
Definition: cv.hpp:108
TextWriter.hpp
MS_base_peak_m_z
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
MS_scan_start_time
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
pwiz::msdata::IndexList
Definition: MSData.hpp:628
MS_total_ion_current
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
pwiz::msdata
Definition: DemuxTypes.hpp:27
MS_negative_scan
MS_negative_scan
negative scan: Polarity of the scan is negative.
Definition: cv.hpp:735
unit_assert_operator_equal
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
pwiz::identdata::IO::write
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
pwiz::util
Definition: almost_equal.hpp:33
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
XMLWriter.hpp
Std.hpp
pwiz::msdata::TextWriter
Definition: TextWriter.hpp:41
SpectrumList_MGF.hpp
pwiz::minimxml
Definition: SAXParser.hpp:43
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
test
void test()
Definition: SpectrumList_MGF_Test.cpp:69
MS_selected_ion_m_z
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2901
main
int main(int argc, char *argv[])
Definition: SpectrumList_MGF_Test.cpp:210
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
MS_ms_level
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
os_
ostream * os_
Definition: SpectrumList_MGF_Test.cpp:36
pwiz::msdata::MSData::instrumentConfigurationPtrs
std::vector< InstrumentConfigurationPtr > instrumentConfigurationPtrs
list and descriptions of instrument configurations.
Definition: MSData.hpp:877
MS_base_peak_intensity
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:2121
pwiz::msdata::InstrumentConfiguration
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:230
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:850
pwiz::msdata::Precursor::selectedIons
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition: MSData.hpp:329
unit.hpp
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::msdata::InstrumentConfigurationPtr
boost::shared_ptr< InstrumentConfiguration > InstrumentConfigurationPtr
Definition: MSData.hpp:250
pwiz::msdata::Precursor
The method of precursor ion selection and activation.
Definition: MSData.hpp:312
MS_possible_charge_state
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
MS_spectrum_title
spectrum title: A free-form text title describing a spectrum.
Definition: cv.hpp:3075