ProteoWizard
Serializer_mzXML_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 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
35using namespace pwiz::util;
36using namespace pwiz::cv;
37using namespace pwiz::data;
38using namespace pwiz::msdata;
39
40
41ostream* os_ = 0;
42
43
44void 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;
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::";
75 TextWriter write(*os_);
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
93 testWriteRead(msd, config);
94
96 testWriteRead(msd, config);
97
98 config.indexed = false;
99 testWriteRead(msd, config);
100}
101
102
103int 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;
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
void diff(const string &filename1, const string &filename2)
int main(int argc, char *argv[])
ostream * os_
void testWriteRead()
MSData <-> mzML stream serialization.
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...
MSData <-> mzXML stream serialization.
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...
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's SpectrumList,...
PWIZ_API_DECL void initializeTiny(MSData &msd)
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
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 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
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition MSData.hpp:827
Serializer_mzXML configuration.
BinaryDataEncoder::Config binaryDataEncoderConfig
configuration for binary data encoding in write() note: byteOrder is ignored (mzXML always big endian...
bool indexed
(indexed==true): read/write with <index>
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