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

§ test() [1/2]

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_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().

Referenced by main(), and test().

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 }
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
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
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
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
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
boost::shared_ptr< SourceFile > SourceFilePtr
Description of the source file, including location and type.
Definition: MSData.hpp:75

§ test() [2/2]

void test ( )

Definition at line 173 of file SpectrumList_mzML_Test.cpp.

References test().

174 {
175  bool indexed = true;
176  test(indexed);
177 
178  indexed = false;
179  test(indexed);
180 }
void test(bool indexed)

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 183 of file SpectrumList_mzML_Test.cpp.

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

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 }
void test(bool indexed)
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
ostream * os_

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 37 of file SpectrumList_mzML_Test.cpp.

Referenced by main(), and test().