ProteoWizard
SpectrumList_mz5_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_mz5_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 "SpectrumList_mz5.hpp"
26 #include "Serializer_mz5.hpp"
27 #include "examples.hpp"
31 
32 
33 using namespace pwiz::cv;
34 using namespace pwiz::msdata;
35 using namespace pwiz::util;
36 using namespace pwiz::minimxml;
37 
38 
39 ostream* os_ = 0;
40 const char* testFilename = "SpectrumList_mz5_Test.mz5";
41 
42 
43 void test()
44 {
45  {
46  MSData tiny;
48 
49  MSDataFile::WriteConfig writeConfig;
50  Serializer_mz5 serializer(writeConfig);
51 
53  serializer.write(testFilename, tiny, &ilr);
54 
55  MSData dummy;
56  serializer.read(testFilename, dummy);
57 
58  dummy.fileDescription.sourceFilePtrs.push_back(SourceFilePtr(new SourceFile("tiny1.yep")));
59  dummy.fileDescription.sourceFilePtrs.push_back(SourceFilePtr(new SourceFile("tiny.wiff")));
60 
61  ParamGroupPtr pg1(new ParamGroup);
62  pg1->id = "CommonMS1SpectrumParams";
63  pg1->cvParams.push_back(MS_positive_scan);
64  pg1->cvParams.push_back(MS_full_scan);
65  dummy.paramGroupPtrs.push_back(pg1);
66 
67  ParamGroupPtr pg2(new ParamGroup);
68  pg2->id = "CommonMS2SpectrumParams";
69  pg2->cvParams.push_back(MS_positive_scan);
70  pg2->cvParams.push_back(MS_full_scan);
71  dummy.paramGroupPtrs.push_back(pg2);
72 
73  // so we don't have any dangling references
75  new InstrumentConfiguration("LCQ Deca")));
77  "CompassXtract processing")));
78 
80 
81  // check easy functions
82 
83  unit_assert(sl.get());
84  unit_assert(sl->size() == 5);
85  unit_assert(sl->find("scan=19") == 0);
86  IndexList indexList = sl->findNameValue("scan", "19");
87  unit_assert(indexList.size() == 1 && indexList[0] == 0);
88  unit_assert(sl->find("scan=20") == 1);
89  indexList = sl->findNameValue("scan", "20");
90  unit_assert(indexList.size() == 1 && indexList[0] == 1);
91  unit_assert(sl->find("scan=21") == 2);
92  indexList = sl->findNameValue("scan", "21");
93  unit_assert(indexList.size() == 1 && indexList[0] == 2);
94  unit_assert(sl->find("sample=1 period=1 cycle=23 experiment=1") == 4);
95  indexList = sl->findNameValue("sample", "1");
96  unit_assert(indexList.size() == 1 && indexList[0] == 4);
97  indexList = sl->findNameValue("period", "1");
98  unit_assert(indexList.size() == 1 && indexList[0] == 4);
99  indexList = sl->findNameValue("cycle", "23");
100  unit_assert(indexList.size() == 1 && indexList[0] == 4);
101  indexList = sl->findNameValue("experiment", "1");
102  unit_assert(indexList.size() == 1 && indexList[0] == 4);
103 
104  unit_assert(sl->findSpotID("A1").empty());
105  IndexList spotIndexList = sl->findSpotID("A1,42x42,4242x4242");
106  unit_assert(spotIndexList.size() == 1);
107  unit_assert(spotIndexList[0] == 4);
108 
109  // check scan 19
110 
111  SpectrumPtr s = sl->spectrum(0); // read without binary data
112  unit_assert(s.get());
113  unit_assert(s->id == "scan=19");
114  unit_assert(s->spotID.empty());
115  unit_assert(s->cvParam(MS_ms_level).valueAs<int> () == 1);
116  unit_assert(s->binaryDataArrayPtrs.empty());
117 
118  unit_assert(sl->spectrumIdentity(0).index == 0);
119  unit_assert(sl->spectrumIdentity(0).id == "scan=19");
120  unit_assert(sl->spectrumIdentity(0).spotID.empty());
121 
122  s = sl->spectrum(0, true); // read with binary data
123 
124  vector < MZIntensityPair > pairs;
125  s->getMZIntensityPairs(pairs);
126  unit_assert(pairs.size() == 15);
127  for (int i = 0; i < 15; i++)
128  unit_assert(pairs[i].mz == i && pairs[i].intensity == 15 - i);
129 
130  unit_assert(s->scanList.scans.size() == 1);
131  unit_assert(s->paramGroupPtrs.size() == 1);
132  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS1SpectrumParams");
133  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 2);
134 
135  // check scan 20
136 
137  s = sl->spectrum(1, true);
138  unit_assert(s.get());
139  unit_assert(s->id == "scan=20");
140  unit_assert(s->spotID.empty());
141  unit_assert(s->cvParam(MS_ms_level).valueAs<int> () == 2);
142 
143  unit_assert(sl->spectrumIdentity(1).index == 1);
144  unit_assert(sl->spectrumIdentity(1).id == "scan=20");
145  unit_assert(sl->spectrumIdentity(1).spotID.empty());
146 
147  pairs.clear();
148  s->getMZIntensityPairs(pairs);
149  unit_assert(pairs.size() == 10);
150  for (int i = 0; i < 10; i++)
151  unit_assert(pairs[i].mz == 2 * i && pairs[i].intensity == (10 - i) * 2);
152 
153  unit_assert(s->scanList.scans.size() == 1);
154  unit_assert(s->paramGroupPtrs.size() == 1);
155  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS2SpectrumParams");
156  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 2);
157 
158  // check scan 22 (MALDI)
159  s = sl->spectrum(4, true);
160  unit_assert(s.get());
161  unit_assert(s->id == "sample=1 period=1 cycle=23 experiment=1");
162  unit_assert(s->spotID == "A1,42x42,4242x4242");
163  unit_assert(s->cvParam(MS_ms_level).valueAs<int> () == 1);
164 
165  unit_assert(sl->spectrumIdentity(4).index == 4);
166  unit_assert(sl->spectrumIdentity(4).id == "sample=1 period=1 cycle=23 experiment=1");
167  unit_assert(sl->spectrumIdentity(4).spotID == "A1,42x42,4242x4242");
168 
169  }
170  bfs::remove(testFilename);
171 }
172 
173 int main(int argc, char* argv[])
174 {
175  TEST_PROLOG(argc, argv)
176 
177  try
178  {
179  if (argc > 1 && !strcmp(argv[1], "-v")) os_ = &cout;
180  test();
181  }
182  catch (exception& e)
183  {
184  TEST_FAILED(e.what())
185  }
186  catch (...)
187  {
188  TEST_FAILED("Caught unknown exception.")
189  }
190 
192 }
193