ProteoWizard
Serializer_mzXML_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: Serializer_mzXML_Test.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2007 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 "Serializer_mzXML.hpp"
25 #include "Serializer_mzML.hpp"
26 #include "Diff.hpp"
27 #include "TextWriter.hpp"
28 #include "examples.hpp"
30 #include "boost/iostreams/positioning.hpp"
32 #include <cstring>
33 
34 
35 using namespace pwiz::util;
36 using namespace pwiz::cv;
37 using namespace pwiz::data;
38 using namespace pwiz::msdata;
39 
40 
41 ostream* os_ = 0;
42 
43 
44 void testWriteRead(const MSData& msd, const Serializer_mzXML::Config& config)
45 {
46  if (os_) *os_ << "testWriteRead() " << config << endl;
47 
48  Serializer_mzXML mzxmlSerializer(config);
49 
50  ostringstream oss;
51  mzxmlSerializer.write(oss, msd);
52 
53  if (os_) *os_ << "oss:\n" << oss.str() << endl;
54 
55  shared_ptr<istringstream> iss(new istringstream(oss.str()));
56  MSData msd2;
57  mzxmlSerializer.read(iss, msd2);
58 
59  DiffConfig diffConfig;
60  diffConfig.ignoreMetadata = true;
61  diffConfig.ignoreChromatograms = true;
62 
63  Diff<MSData, DiffConfig> diff(msd, msd2, diffConfig);
64  if (os_ && diff) *os_ << diff << endl;
65  unit_assert(!diff);
66 
67  if (os_)
68  {
69  *os_ << "msd2:\n";
70  Serializer_mzML mzmlSerializer;
71  mzmlSerializer.write(*os_, msd2);
72  *os_ << endl;
73 
74  *os_ << "msd2::";
76  write(msd2);
77 
78  *os_ << endl;
79  }
80 }
81 
82 
84 {
85  MSData msd;
87 
88  // remove s22 since it is not written to mzXML
89  static_cast<SpectrumListSimple&>(*msd.run.spectrumListPtr).spectra.pop_back();
90 
92  unit_assert(config.binaryDataEncoderConfig.precision == BinaryDataEncoder::Precision_64);
93  testWriteRead(msd, config);
94 
95  config.binaryDataEncoderConfig.precision = BinaryDataEncoder::Precision_32;
96  testWriteRead(msd, config);
97 
98  config.indexed = false;
99  testWriteRead(msd, config);
100 }
101 
102 
103 int main(int argc, char* argv[])
104 {
105  TEST_PROLOG(argc, argv)
106 
107  try
108  {
109  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
110  testWriteRead();
111  }
112  catch (exception& e)
113  {
114  TEST_FAILED(e.what())
115  }
116  catch (...)
117  {
118  TEST_FAILED("Caught unknown exception.")
119  }
120 
122 }
123 
MSData <-> mzML stream serialization.
bool ignoreMetadata
ignore all file level metadata, and most scan level metadata, i.e.
Definition: Diff.hpp:214
void write(std::ostream &os, const MSData &msd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
write MSData object to ostream as mzML; iterationListenerRegistry may be used to receive progress upd...
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
#define TEST_EPILOG
Definition: unit.hpp:182
BinaryDataEncoder::Config binaryDataEncoderConfig
configuration for binary data encoding in write() note: byteOrder is ignored (mzXML always big endian...
int main(int argc, char *argv[])
void diff(const string &filename1, const string &filename2)
void read(boost::shared_ptr< std::istream > is, MSData &msd) const
read in MSData object from an mzXML istream note: istream may be managed by MSData&#39;s SpectrumList...
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
configuration struct for diffing MSData types
Definition: Diff.hpp:205
void write(std::ostream &os, const MSData &msd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
write MSData object to ostream as mzXML; iterationListenerRegistry may be used to receive progress up...
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
#define TEST_FAILED(x)
Definition: unit.hpp:176
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
MSData <-> mzXML stream serialization.
void testWriteRead(const MSData &msd, const Serializer_mzXML::Config &config)
Serializer_mzXML configuration.
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
ostream * os_
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
bool indexed
(indexed==true): read/write with <index>
Definition: cv.hpp:91