ProteoWizard
Serializer_MSn_Test.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Barbara Frewen <frewen@u.washington.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#include "Serializer_MSn.hpp"
23#include "Serializer_mzML.hpp"
24#include "Diff.hpp"
25#include "TextWriter.hpp"
27#include "boost/iostreams/positioning.hpp"
29#include <cstring>
30
31
32using namespace pwiz::util;
33using namespace pwiz::msdata;
34
35
36ostream* os_ = 0;
37
38
40{
44
45 SourceFilePtr sourceFile(new SourceFile);
47 sourceFile->set(MS_MS2_format);
48 msd.fileDescription.sourceFilePtrs.push_back(sourceFile);
49
50 shared_ptr<SpectrumListSimple> spectrumList(new SpectrumListSimple);
51 msd.run.spectrumListPtr = spectrumList;
52 spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
53
54 Spectrum& s20 = *spectrumList->spectra[0];
55 s20.id = "scan=1";
56 s20.index = 0;
57
59 s20.set(MS_ms_level, 1);
60
64 s20.set(MS_base_peak_m_z, 0);
66 s20.set(MS_total_ion_current, 110);
67
68 s20.scanList.scans.push_back(Scan());
69 Scan& s20scan = s20.scanList.scans.back();
70 s20scan.set(MS_scan_start_time, 4, UO_second);
71
72 s20.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_detector_counts);
73 BinaryData<double>& s20_mz = s20.getMZArray()->data;
74 BinaryData<double>& s20_intensity = s20.getIntensityArray()->data;
75
76 for (int i=0; i<10; i++)
77 s20_mz.push_back(i*2);
78
79 for (int i=0; i<10; i++)
80 s20_intensity.push_back((10-i)*2);
81
82 s20.defaultArrayLength = s20_mz.size();
83
84} // initializeTinyMS1()
85
87{
91
92 SourceFilePtr sourceFile(new SourceFile);
94 sourceFile->set(MS_MS2_format);
95 msd.fileDescription.sourceFilePtrs.push_back(sourceFile);
96
97 shared_ptr<SpectrumListSimple> spectrumList(new SpectrumListSimple);
98 msd.run.spectrumListPtr = spectrumList;
99 spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
100
101 Spectrum& s20 = *spectrumList->spectra[0];
102 s20.id = "scan=1";
103 s20.index = 0;
104
105 s20.set(MS_MSn_spectrum);
106 s20.set(MS_ms_level, 2);
107
111 s20.set(MS_base_peak_m_z, 0);
113 s20.set(MS_total_ion_current, 110);
114
115 s20.precursors.resize(1);
116 Precursor& precursor = s20.precursors.front();
117 precursor.selectedIons.resize(1);
118 precursor.selectedIons[0].set(MS_selected_ion_m_z, 445.34, MS_m_z);
119 precursor.selectedIons[0].set(MS_possible_charge_state, 2);
121
122 s20.scanList.scans.push_back(Scan());
123 Scan& s20scan = s20.scanList.scans.back();
124 s20scan.set(MS_scan_start_time, 4, UO_second);
125
126 s20.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_detector_counts);
127 BinaryData<double>& s20_mz = s20.getMZArray()->data;
128 BinaryData<double>& s20_intensity = s20.getIntensityArray()->data;
129
130 for (int i=0; i<10; i++)
131 s20_mz.push_back(i*2);
132
133 for (int i=0; i<10; i++)
134 s20_intensity.push_back((10-i)*2);
135
136 s20.defaultArrayLength = s20_mz.size();
137
138} // initializeTinyMS2()
139
140
141void testWriteReadMS1(const MSData& msd)
142{
143 Serializer_MSn serializer(MSn_Type_MS1);
144
145 ostringstream oss;
146 serializer.write(oss, msd);
147
148 if (os_) *os_ << "oss:\n" << oss.str() << endl;
149
150 MSData msd2;
151 shared_ptr<istream> iss(new istringstream(oss.str()));
152 serializer.read(iss, msd2);
153
154 DiffConfig config;
155 config.ignoreMetadata = true;
156 Diff<MSData, DiffConfig> diff(msd, msd2, config);
157
158 if (os_ && diff) *os_ << diff << endl;
160}
161
162void testWriteReadBMS1(const MSData& msd)
163{
164 Serializer_MSn serializer(MSn_Type_BMS1);
165
166 ostringstream oss;
167 serializer.write(oss, msd);
168
169 if (os_) *os_ << "oss:\n" << oss.str() << endl;
170
171 MSData msd2;
172 shared_ptr<istream> iss(new istringstream(oss.str()));
173 serializer.read(iss, msd2);
174
175 DiffConfig config;
176 config.ignoreMetadata = true;
177 config.ignoreDataProcessing = true;
178 Diff<MSData, DiffConfig> diff(msd, msd2, config);
179 if (os_ && diff) *os_ << diff << endl;
181}
182
183void testWriteReadCMS1(const MSData& msd)
184{
185 Serializer_MSn serializer(MSn_Type_CMS1);
186
187 ostringstream oss;
188 serializer.write(oss, msd);
189
190 if (os_) *os_ << "oss:\n" << oss.str() << endl;
191
192 MSData msd2;
193 shared_ptr<istream> iss(new istringstream(oss.str()));
194 serializer.read(iss, msd2);
195
196 DiffConfig config;
197 config.ignoreMetadata = true;
198 config.ignoreDataProcessing = true;
199 Diff<MSData, DiffConfig> diff(msd, msd2, config);
200 if (os_ && diff) *os_ << diff << endl;
202}
203
204void testWriteReadMS2(const MSData& msd)
205{
206 Serializer_MSn serializer(MSn_Type_MS2);
207
208 ostringstream oss;
209 serializer.write(oss, msd);
210
211 if (os_) *os_ << "oss:\n" << oss.str() << endl;
212
213 MSData msd2;
214 shared_ptr<istream> iss(new istringstream(oss.str()));
215 serializer.read(iss, msd2);
216
217 DiffConfig config;
218 config.ignoreMetadata = true;
219 Diff<MSData, DiffConfig> diff(msd, msd2, config);
220 if (os_ && diff) *os_ << diff << endl;
222}
223
224void testWriteReadBMS2(const MSData& msd)
225{
226 Serializer_MSn serializer(MSn_Type_BMS2);
227
228 ostringstream oss;
229 serializer.write(oss, msd);
230
231 if (os_) *os_ << "oss:\n" << oss.str() << endl;
232
233 MSData msd2;
234 shared_ptr<istream> iss(new istringstream(oss.str()));
235 serializer.read(iss, msd2);
236
237 DiffConfig config;
238 config.ignoreMetadata = true;
239 config.ignoreDataProcessing = true;
240 Diff<MSData, DiffConfig> diff(msd, msd2, config);
241 if (os_ && diff) *os_ << diff << endl;
243}
244
245void testWriteReadCMS2(const MSData& msd)
246{
247 Serializer_MSn serializer(MSn_Type_CMS2);
248
249 ostringstream oss;
250 serializer.write(oss, msd);
251
252 if (os_) *os_ << "oss:\n" << oss.str() << endl;
253
254 MSData msd2;
255 shared_ptr<istream> iss(new istringstream(oss.str()));
256 serializer.read(iss, msd2);
257
258 DiffConfig config;
259 config.ignoreMetadata = true;
260 config.ignoreDataProcessing = true;
261 Diff<MSData, DiffConfig> diff(msd, msd2, config);
262 if (os_ && diff) *os_ << diff << endl;
264}
265
267{
268 MSData msd1, msd2;
269
270 initializeTinyMS1(msd1);
271 initializeTinyMS2(msd2);
272
273 testWriteReadMS1(msd1);
274 testWriteReadBMS1(msd1);
275 testWriteReadCMS1(msd1);
276 testWriteReadMS2(msd2);
277 testWriteReadBMS2(msd2);
278 testWriteReadCMS2(msd2);
279}
280
281
282int main(int argc, char* argv[])
283{
284 TEST_PROLOG(argc, argv)
285
286 try
287 {
288 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
290 }
291 catch (exception& e)
292 {
293 TEST_FAILED(e.what())
294 }
295 catch (...)
296 {
297 TEST_FAILED("Caught unknown exception.")
298 }
299
301}
302
void diff(const string &filename1, const string &filename2)
void testWriteReadMS1(const MSData &msd)
void initializeTinyMS2(MSData &msd)
int main(int argc, char *argv[])
void testWriteReadMS2(const MSData &msd)
void testWriteReadBMS1(const MSData &msd)
void initializeTinyMS1(MSData &msd)
void testWriteReadCMS2(const MSData &msd)
void testWriteReadCMS1(const MSData &msd)
void testWriteReadBMS2(const MSData &msd)
ostream * os_
void testWriteRead()
MSData <-> MSn stream serialization.
void write(std::ostream &os, const MSData &msd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
write MSData object to ostream as MSn; iterationListenerRegistry may be used to receive progress upda...
void read(boost::shared_ptr< std::istream > is, MSData &msd) const
read in MSData object from an MGF istream note: istream may be managed by MSData's SpectrumList,...
A custom vector class that can store its contents in either a std::vector or a cli::array (when compi...
void push_back(const T &value)
MS_highest_observed_m_z
highest observed m/z: Highest m/z value observed in the m/z array.
Definition cv.hpp:2187
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_lowest_observed_m_z
lowest observed m/z: Lowest m/z value observed in the m/z array.
Definition cv.hpp:2190
MS_scan_number_only_nativeID_format
scan number only nativeID format: Native format defined by scan=xsd:nonNegativeInteger.
Definition cv.hpp:3000
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition cv.hpp:2139
MS_centroid_spectrum
centroid spectrum: Processing of profile data to produce spectra that contains discrete peaks of zero...
Definition cv.hpp:720
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition cv.hpp:2364
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition cv.hpp:384
MS_isolation_window_target_m_z
isolation window target m/z: The primary or reference m/z about which the isolation window is defined...
Definition cv.hpp:3180
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_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_MS2_format
MS2 format: MS2 file format for MS2 spectral data.
Definition cv.hpp:4794
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
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition cv.hpp:2121
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
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< Spectrum > SpectrumPtr
Definition MSData.hpp:573
boost::shared_ptr< SourceFile > SourceFilePtr
Description of the source file, including location and type.
Definition MSData.hpp:76
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
void set(CVID cvid, const std::string &value="", CVID units=CVID_Unknown)
set/add a CVParam (not recursive)
configuration struct for diffing MSData types
Definition Diff.hpp:206
bool ignoreMetadata
ignore all file level metadata, and most scan level metadata, i.e.
Definition Diff.hpp:214
This summarizes the different types of spectra that can be expected in the file. This is expected to ...
Definition MSData.hpp:50
FileContent fileContent
this summarizes the different types of spectra that can be expected in the file. This is expected to ...
Definition MSData.hpp:87
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from.
Definition MSData.hpp:90
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition MSData.hpp:850
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition MSData.hpp:886
FileDescription fileDescription
information pertaining to the entire mzML file (i.e. not specific to any part of the data set) is sto...
Definition MSData.hpp:862
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
IsolationWindow isolationWindow
this element captures the isolation (or 'selection') window configured to isolate one or more precurs...
Definition MSData.hpp:326
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
Scan or acquisition from original raw file used to create this peak list, as specified in sourceFile.
Definition MSData.hpp:370
std::vector< Scan > scans
Definition MSData.hpp:397
Description of the source file, including location and type.
Definition MSData.hpp:55
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
void setMZIntensityArrays(const std::vector< double > &mzArray, const std::vector< double > &intensityArray, CVID intensityUnits)
set m/z and intensity arrays separately (they must be the same size)
BinaryDataArrayPtr getIntensityArray() const
get intensity array (may be null)
size_t defaultArrayLength
default length of binary data arrays contained in this element.
Definition MSData.hpp:508
BinaryDataArrayPtr getMZArray() const
get m/z array (may be null)
ScanList scanList
list of scans
Definition MSData.hpp:517
std::vector< Precursor > precursors
list and descriptions of precursors to the spectrum currently being described.
Definition MSData.hpp:520
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition MSData.hpp:476
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition MSData.hpp:473
Simple writeable in-memory implementation of SpectrumList.
Definition MSData.hpp:717
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175