ProteoWizard
SpectrumList_mzML_Test.cpp
Go to the documentation of this file.
1 //
2 // $Id: SpectrumList_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 
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  pg1->cvParams.push_back(MS_full_scan);
69  dummy.paramGroupPtrs.push_back(pg1);
70 
71  ParamGroupPtr pg2(new ParamGroup);
72  pg2->id = "CommonMS2SpectrumParams";
73  pg2->cvParams.push_back(MS_positive_scan);
74  pg2->cvParams.push_back(MS_full_scan);
75  dummy.paramGroupPtrs.push_back(pg2);
76 
77  // so we don't have any dangling references
79  dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("CompassXtract processing")));
80 
81  Index_mzML_Ptr index(new Index_mzML(is, dummy));
82  SpectrumListPtr sl = SpectrumList_mzML::create(is, dummy, index);
83 
84  // check easy functions
85 
86  unit_assert(sl.get());
87  unit_assert(sl->size() == 5);
88  unit_assert(sl->find ("scan=19") == 0);
89  IndexList indexList = sl->findNameValue("scan", "19");
90  unit_assert(indexList.size()==1 && indexList[0]==0);
91  unit_assert(sl->find("scan=20") == 1);
92  indexList = sl->findNameValue("scan", "20");
93  unit_assert(indexList.size()==1 && indexList[0]==1);
94  unit_assert(sl->find("scan=21") == 2);
95  indexList = sl->findNameValue("scan", "21");
96  unit_assert(indexList.size()==1 && indexList[0]==2);
97  unit_assert(sl->find("sample=1 period=1 cycle=23 experiment=1") == 4);
98  indexList = sl->findNameValue("sample", "1");
99  unit_assert(indexList.size()==1 && indexList[0]==4);
100  indexList = sl->findNameValue("period", "1");
101  unit_assert(indexList.size()==1 && indexList[0]==4);
102  indexList = sl->findNameValue("cycle", "23");
103  unit_assert(indexList.size()==1 && indexList[0]==4);
104  indexList = sl->findNameValue("experiment", "1");
105  unit_assert(indexList.size()==1 && indexList[0]==4);
106 
107  unit_assert(sl->findSpotID("A1").empty());
108  IndexList spotIndexList = sl->findSpotID("A1,42x42,4242x4242");
109  unit_assert(spotIndexList.size() == 1);
110  unit_assert(spotIndexList[0] == 4);
111 
112 
113  // check scan 19
114 
115  SpectrumPtr s = sl->spectrum(0); // read without binary data
116  unit_assert(s.get());
117  unit_assert(s->id == "scan=19");
118  unit_assert(s->spotID.empty());
119  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
120  unit_assert(s->binaryDataArrayPtrs.empty());
121 
122  unit_assert(sl->spectrumIdentity(0).index == 0);
123  unit_assert(sl->spectrumIdentity(0).id == "scan=19");
124  unit_assert(sl->spectrumIdentity(0).spotID.empty());
125 
126  s = sl->spectrum(0, true); // read with binary data
127 
128  vector<MZIntensityPair> pairs;
129  s->getMZIntensityPairs(pairs);
130  unit_assert(pairs.size() == 15);
131  for (int i=0; i<15; i++)
132  unit_assert(pairs[i].mz==i && pairs[i].intensity==15-i);
133 
134  unit_assert(s->scanList.scans.size() == 1);
135  unit_assert(s->paramGroupPtrs.size() == 1);
136  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS1SpectrumParams");
137  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 2);
138 
139  // check scan 20
140 
141  s = sl->spectrum(1, true);
142  unit_assert(s.get());
143  unit_assert(s->id == "scan=20");
144  unit_assert(s->spotID.empty());
145  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
146 
147  unit_assert(sl->spectrumIdentity(1).index == 1);
148  unit_assert(sl->spectrumIdentity(1).id == "scan=20");
149  unit_assert(sl->spectrumIdentity(1).spotID.empty());
150 
151  pairs.clear();
152  s->getMZIntensityPairs(pairs);
153  unit_assert(pairs.size() == 10);
154  for (int i=0; i<10; i++)
155  unit_assert(pairs[i].mz==2*i && pairs[i].intensity==(10-i)*2);
156 
157  unit_assert(s->scanList.scans.size() == 1);
158  unit_assert(s->paramGroupPtrs.size() == 1);
159  unit_assert(s->paramGroupPtrs.back()->id == "CommonMS2SpectrumParams");
160  unit_assert(s->paramGroupPtrs.back()->cvParams.size() == 2);
161 
162  // check scan 22 (MALDI)
163  s = sl->spectrum(4, true);
164  unit_assert(s.get());
165  unit_assert(s->id == "sample=1 period=1 cycle=23 experiment=1");
166  unit_assert(s->spotID == "A1,42x42,4242x4242");
167  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
168 
169  unit_assert(sl->spectrumIdentity(4).index == 4);
170  unit_assert(sl->spectrumIdentity(4).id == "sample=1 period=1 cycle=23 experiment=1");
171  unit_assert(sl->spectrumIdentity(4).spotID == "A1,42x42,4242x4242");
172 }
173 
174 
175 void test()
176 {
177  bool indexed = true;
178  test(indexed);
179 
180  indexed = false;
181  test(indexed);
182 }
183 
184 
185 int main(int argc, char* argv[])
186 {
187  TEST_PROLOG(argc, argv)
188 
189  try
190  {
191  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
192  test();
193  }
194  catch (exception& e)
195  {
196  TEST_FAILED(e.what())
197  }
198  catch (...)
199  {
200  TEST_FAILED("Caught unknown exception.")
201  }
202 
204 }
205 
206 
PWIZ_API_DECL const CV & cv(const std::string &prefix)
returns a CV object for the specified namespace (prefix); currently supported namespaces are: MS UO ...
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
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...
MS_full_scan
full scan: Feature of the ion trap mass spectrometer where MS data is acquired over a mass range...
Definition: cv.hpp:1940
MSData &lt;-&gt; mzML stream serialization.
boost::shared_ptr< Index_mzML > Index_mzML_Ptr
Definition: Index_mzML.hpp:61
boost::shared_ptr< ParamGroup > ParamGroupPtr
Definition: ParamTypes.hpp:236
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:878
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:565
ostream * os_
#define TEST_EPILOG
Definition: unit.hpp:166
MS_positive_scan
positive scan: Polarity of the scan is positive.
Definition: cv.hpp:569
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:863
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1979
int main(int argc, char *argv[])
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:712
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:321
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:866
#define TEST_FAILED(x)
Definition: unit.hpp:160
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:881
bool indexed
(indexed==true): read/write with &lt;indexedmzML&gt; wrapper
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:158
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:850
#define unit_assert(x)
Definition: unit.hpp:82
boost::shared_ptr< SourceFile > SourceFilePtr
Description of the source file, including location and type.
Definition: MSData.hpp:75