ProteoWizard
ChromatogramList_mzML_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: ChromatogramList_mzML_Test.cpp 4129 2012-11-20 00:05:37Z chambm $
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 
31 using namespace pwiz::cv;
32 using namespace pwiz::msdata;
33 using namespace pwiz::util;
34 using namespace pwiz::minimxml;
35 
36 
37 ostream* os_ = 0;
38 
39 
40 void 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));
68  ChromatogramListPtr sl = ChromatogramList_mzML::create(is, dummy, index);
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 
112 void test()
113 {
114  bool indexed = true;
115  test(indexed);
116 
117  indexed = false;
118  test(indexed);
119 }
120 
121 
122 int 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