ProteoWizard
SpectrumList_mzML_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_mzML_Test.cpp 6478 2014-07-08 20:01:38Z 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 
24 #include "SpectrumList_mzML.hpp"
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  dummy.fileDescription.sourceFilePtrs.push_back(SourceFilePtr(new SourceFile("tiny1.yep")));
63  dummy.fileDescription.sourceFilePtrs.push_back(SourceFilePtr(new SourceFile("tiny.wiff")));
64 
65  ParamGroupPtr pg1(new ParamGroup);
66  pg1->id = "CommonMS1SpectrumParams";
67  pg1->cvParams.push_back(MS_positive_scan);
68  dummy.paramGroupPtrs.push_back(pg1);
69 
70  ParamGroupPtr pg2(new ParamGroup);
71  pg2->id = "CommonMS2SpectrumParams";
72  pg2->cvParams.push_back(MS_positive_scan);
73  dummy.paramGroupPtrs.push_back(pg2);
74 
75  // so we don't have any dangling references
77  dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("CompassXtract processing")));
78 
79  Index_mzML_Ptr index(new Index_mzML(is, dummy));
80  SpectrumListPtr sl = SpectrumList_mzML::create(is, dummy, index);
81 
82  // check easy functions
83 
84  unit_assert(sl.get());
85  unit_assert(sl->size() == 5);
86  unit_assert(sl->find ("scan=19") == 0);
87  IndexList indexList = sl->findNameValue("scan", "19");
88  unit_assert(indexList.size()==1 && indexList[0]==0);
89  unit_assert(sl->find("scan=20") == 1);
90  indexList = sl->findNameValue("scan", "20");
91  unit_assert(indexList.size()==1 && indexList[0]==1);
92  unit_assert(sl->find("scan=21") == 2);
93  indexList = sl->findNameValue("scan", "21");
94  unit_assert(indexList.size()==1 && indexList[0]==2);
95  unit_assert(sl->find("sample=1 period=1 cycle=23 experiment=1") == 4);
96  indexList = sl->findNameValue("sample", "1");
97  unit_assert(indexList.size()==1 && indexList[0]==4);
98  indexList = sl->findNameValue("period", "1");
99  unit_assert(indexList.size()==1 && indexList[0]==4);
100  indexList = sl->findNameValue("cycle", "23");
101  unit_assert(indexList.size()==1 && indexList[0]==4);
102  indexList = sl->findNameValue("experiment", "1");
103  unit_assert(indexList.size()==1 && indexList[0]==4);
104 
105  unit_assert(sl->findSpotID("A1").empty());
106  IndexList spotIndexList = sl->findSpotID("A1,42x42,4242x4242");
107  unit_assert(spotIndexList.size() == 1);
108  unit_assert(spotIndexList[0] == 4);
109 
110 
111  // check scan 19
112 
113  SpectrumPtr s = sl->spectrum(0); // read without binary data
114  unit_assert(s.get());
115  unit_assert(s->id == "scan=19");
116  unit_assert(s->spotID.empty());
117  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
118  unit_assert(s->binaryDataArrayPtrs.empty());
119 
120  unit_assert(sl->spectrumIdentity(0).index == 0);
121  unit_assert(sl->spectrumIdentity(0).id == "scan=19");
122  unit_assert(sl->spectrumIdentity(0).spotID.empty());
123 
124  s = sl->spectrum(0, true); // read with binary data
125 
126  vector<MZIntensityPair> pairs;
127  s->getMZIntensityPairs(pairs);
128  unit_assert(pairs.size() == 15);
129  for (int i=0; i<15; i++)
130  unit_assert(pairs[i].mz==i && pairs[i].intensity==15-i);
131 
132  unit_assert(s->scanList.scans.size() == 1);
133  unit_assert(s->paramGroupPtrs.size() == 1);
134  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS1SpectrumParams");
135  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 1);
136 
137  // check scan 20
138 
139  s = sl->spectrum(1, true);
140  unit_assert(s.get());
141  unit_assert(s->id == "scan=20");
142  unit_assert(s->spotID.empty());
143  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
144 
145  unit_assert(sl->spectrumIdentity(1).index == 1);
146  unit_assert(sl->spectrumIdentity(1).id == "scan=20");
147  unit_assert(sl->spectrumIdentity(1).spotID.empty());
148 
149  pairs.clear();
150  s->getMZIntensityPairs(pairs);
151  unit_assert(pairs.size() == 10);
152  for (int i=0; i<10; i++)
153  unit_assert(pairs[i].mz==2*i && pairs[i].intensity==(10-i)*2);
154 
155  unit_assert(s->scanList.scans.size() == 1);
156  unit_assert(s->paramGroupPtrs.size() == 1);
157  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS2SpectrumParams");
158  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 1);
159 
160  // check scan 22 (MALDI)
161  s = sl->spectrum(4, true);
162  unit_assert(s.get());
163  unit_assert(s->id == "sample=1 period=1 cycle=23 experiment=1");
164  unit_assert(s->spotID == "A1,42x42,4242x4242");
165  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
166 
167  unit_assert(sl->spectrumIdentity(4).index == 4);
168  unit_assert(sl->spectrumIdentity(4).id == "sample=1 period=1 cycle=23 experiment=1");
169  unit_assert(sl->spectrumIdentity(4).spotID == "A1,42x42,4242x4242");
170 }
171 
172 
173 void test()
174 {
175  bool indexed = true;
176  test(indexed);
177 
178  indexed = false;
179  test(indexed);
180 }
181 
182 
183 int main(int argc, char* argv[])
184 {
185  TEST_PROLOG(argc, argv)
186 
187  try
188  {
189  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
190  test();
191  }
192  catch (exception& e)
193  {
194  TEST_FAILED(e.what())
195  }
196  catch (...)
197  {
198  TEST_FAILED("Caught unknown exception.")
199  }
200 
202 }
203 
204 
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from...
Definition: MSData.hpp:89
Description of the way in which a particular software was used.
Definition: MSData.hpp:272
MSData <-> mzML stream serialization.
boost::shared_ptr< Index_mzML > Index_mzML_Ptr
Definition: Index_mzML.hpp:61
boost::shared_ptr< ParamGroup > ParamGroupPtr
Definition: ParamTypes.hpp:239
Description of the source file, including location and type.
Definition: MSData.hpp:53
std::vector< InstrumentConfigurationPtr > instrumentConfigurationPtrs
list and descriptions of instrument configurations.
Definition: MSData.hpp:873
void test(bool indexed)
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
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...
#define TEST_EPILOG
Definition: unit.hpp:182
MS_positive_scan
positive scan: Polarity of the scan is positive.
Definition: cv.hpp:577
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:287
FileDescription fileDescription
information pertaining to the entire mzML file (i.e. not specific to any part of the data set) is sto...
Definition: MSData.hpp:858
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:707
double mz(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition: Ion.hpp:78
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...
Definition: ParamTypes.hpp:324
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:228
boost::shared_ptr< InstrumentConfiguration > InstrumentConfigurationPtr
Definition: MSData.hpp:249
std::vector< ParamGroupPtr > paramGroupPtrs
container for a list of referenceableParamGroups
Definition: MSData.hpp:861
#define TEST_FAILED(x)
Definition: unit.hpp:176
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
Serializer_mzML configuration.
std::vector< DataProcessingPtr > dataProcessingPtrs
list and descriptions of data processing applied to this data.
Definition: MSData.hpp:876
bool indexed
(indexed==true): read/write with <indexedmzML> wrapper
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
int main(int argc, char *argv[])
ostream * os_
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
#define unit_assert(x)
Definition: unit.hpp:85
Definition: cv.hpp:91
boost::shared_ptr< SourceFile > SourceFilePtr
Description of the source file, including location and type.
Definition: MSData.hpp:75