ProteoWizard
Functions | Variables
SpectrumList_mzML_Test.cpp File Reference
#include "SpectrumList_mzML.hpp"
#include "Serializer_mzML.hpp"
#include "examples.hpp"
#include "pwiz/utility/minimxml/XMLWriter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void test (bool indexed)
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

void test ( bool  indexed)

Definition at line 40 of file SpectrumList_mzML_Test.cpp.

References pwiz::msdata::MSData::dataProcessingPtrs, pwiz::msdata::MSData::fileDescription, pwiz::msdata::Serializer_mzML::Config::indexed, pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::instrumentConfigurationPtrs, MS_full_scan, MS_ms_level, MS_positive_scan, pwiz::chemistry::Ion::mz(), os_, pwiz::msdata::MSData::paramGroupPtrs, pwiz::msdata::FileDescription::sourceFilePtrs, unit_assert, and pwiz::msdata::Serializer_mzML::write().

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 }
void test ( )

Definition at line 175 of file SpectrumList_mzML_Test.cpp.

References test().

176 {
177  bool indexed = true;
178  test(indexed);
179 
180  indexed = false;
181  test(indexed);
182 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 185 of file SpectrumList_mzML_Test.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

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 }

Variable Documentation

ostream* os_ = 0

Definition at line 37 of file SpectrumList_mzML_Test.cpp.