ProteoWizard
ChromatogramList_mzML_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
25#include "Serializer_mzML.hpp" // depends on Serializer_mzML::write() only
26#include "examples.hpp"
30
31using namespace pwiz::cv;
32using namespace pwiz::msdata;
33using namespace pwiz::util;
34using namespace pwiz::minimxml;
35
36
37ostream* os_ = 0;
38
39
40void test(bool indexed)
41{
42 if (os_) *os_ << "test(): indexed=\"" << boolalpha << indexed << "\"\n";
43
44 MSData tiny;
46
48 config.indexed = indexed;
49 Serializer_mzML serializer(config);
50
51 ostringstream oss;
52 serializer.write(oss, tiny);
53
54 if (os_) *os_ << "oss:\n" << oss.str() << endl;
55
56 shared_ptr<istream> is(new istringstream(oss.str()));
57
58 // dummy would normally be read in from file
59
60 MSData dummy;
61
62 // so we don't have any dangling references
63 //dummy.instrumentPtrs.push_back(InstrumentPtr(new Instrument("LCQ_Deca")));
64 dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("pwiz_processing")));
65 dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("CompassXtract processing")));
66
67 Index_mzML_Ptr index(new Index_mzML(is, dummy));
69
70 // check easy functions
71
72 unit_assert(sl.get());
73 unit_assert(sl->size() == 2);
74 unit_assert(sl->find("tic") == 0);
75 unit_assert(sl->find("sic") == 1);
76
77 // check tic
78
79 ChromatogramPtr s = sl->chromatogram(0); // read without binary data
80 unit_assert(s.get());
81 unit_assert(s->id == "tic");
82 unit_assert(s->binaryDataArrayPtrs.empty());
83
84 unit_assert(sl->chromatogramIdentity(0).index == 0);
85 unit_assert(sl->chromatogramIdentity(0).id == "tic");
86
87 s = sl->chromatogram(0, true); // read with binary data
88
89 vector<TimeIntensityPair> pairs;
90 s->getTimeIntensityPairs(pairs);
91 unit_assert(pairs.size() == 15);
92 for (int i=0; i<15; i++)
93 unit_assert(pairs[i].time==i && pairs[i].intensity==15-i);
94
95 // check sic
96
97 s = sl->chromatogram(1, true);
98 unit_assert(s.get());
99 unit_assert(s->id == "sic");
100
101 unit_assert(sl->chromatogramIdentity(1).index == 1);
102 unit_assert(sl->chromatogramIdentity(1).id == "sic");
103
104 pairs.clear();
105 s->getTimeIntensityPairs(pairs);
106 unit_assert(pairs.size() == 10);
107 for (int i=0; i<10; i++)
108 unit_assert(pairs[i].time==i && pairs[i].intensity==(10-i));
109}
110
111
112void test()
113{
114 bool indexed = true;
115 test(indexed);
116
117 indexed = false;
118 test(indexed);
119}
120
121
122int main(int argc, char* argv[])
123{
124 TEST_PROLOG(argc, argv)
125
126 try
127 {
128 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
129 test();
130 }
131 catch (exception& e)
132 {
133 TEST_FAILED(e.what())
134 }
135 catch (...)
136 {
137 TEST_FAILED("Caught unknown exception.")
138 }
139
141}
142
143
int main(int argc, char *argv[])
ostream * os_
static ChromatogramListPtr create(boost::shared_ptr< std::istream > is, const MSData &msd, const Index_mzML_Ptr &indexPtr)
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...
PWIZ_API_DECL void initializeTiny(MSData &msd)
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition MSData.hpp:288
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition MSData.hpp:624
boost::shared_ptr< ChromatogramList > ChromatogramListPtr
Definition MSData.hpp:785
boost::shared_ptr< Index_mzML > Index_mzML_Ptr
Description of the way in which a particular software was used.
Definition MSData.hpp:274
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition MSData.hpp:850
std::vector< DataProcessingPtr > dataProcessingPtrs
list and descriptions of data processing applied to this data.
Definition MSData.hpp:880
Serializer_mzML configuration.
bool indexed
(indexed==true): read/write with <indexedmzML> wrapper
#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