ProteoWizard
Functions
MSDataTest.cpp File Reference
#include "MSData.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void testSpectrumListSimple ()
 
void testChromatograms ()
 
void testIDParsing ()
 
void testAllDataProcessing ()
 
int main (int argc, char *argv[])
 

Function Documentation

§ testSpectrumListSimple()

void testSpectrumListSimple ( )

Definition at line 33 of file MSDataTest.cpp.

References pwiz::msdata::SpectrumList::dataProcessingPtr(), pwiz::msdata::SpectrumList::find(), pwiz::msdata::SpectrumList::findAbbreviated(), pwiz::msdata::SpectrumList::findNameValue(), pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::SpectrumIdentity::index, pwiz::msdata::MZIntensityPair::intensity, MS_intensity_array, MS_ionization_type, MS_m_z_array, MS_MSn_spectrum, MS_number_of_detector_counts, pwiz::msdata::MZIntensityPair::mz, pwiz::msdata::MSData::run, pwiz::msdata::SpectrumList::size(), pwiz::msdata::SpectrumList::spectrum(), pwiz::msdata::SpectrumList::spectrumIdentity(), pwiz::msdata::Run::spectrumListPtr, unit_assert, and unit_assert_operator_equal.

Referenced by main().

34 {
35  // fill in SpectrumListSimple
36 
37  shared_ptr<SpectrumListSimple> spectrumListSimple(new SpectrumListSimple);
38 
39  unit_assert(spectrumListSimple->empty());
40  spectrumListSimple->dp = DataProcessingPtr(new DataProcessing("dp"));
41  unit_assert(!spectrumListSimple->empty());
42 
43  SpectrumPtr spectrum0(new Spectrum);
44  spectrum0->index = 0;
45  spectrum0->id = "sample=1 period=1 cycle=123 experiment=2";
46 
47  // add m/z values 0,...,9
49  for (unsigned int i=0; i<10; i++) bd_mz->data.push_back(i);
50  bd_mz->cvParams.push_back(MS_m_z_array);
51  double* buffer = &bd_mz->data[0];
52 
53  // add intensity values 10,...,1
54  BinaryDataArrayPtr bd_intensity(new BinaryDataArray);
55  for (unsigned int i=0; i<10; i++) bd_intensity->data.push_back(10-i);
56  bd_intensity->cvParams.push_back(MS_intensity_array);
57 
58  spectrum0->binaryDataArrayPtrs.push_back(bd_mz);
59  spectrum0->binaryDataArrayPtrs.push_back(bd_intensity);
60  spectrum0->defaultArrayLength = 10;
61 
62  SpectrumPtr spectrum1(new Spectrum);
63  spectrum1->index = 1;
64  spectrum1->id = "sample=1 period=1 cycle=345 experiment=2";
65  spectrum1->cvParams.push_back(MS_MSn_spectrum);
66  spectrum1->cvParams.push_back(CVParam(MS_ionization_type, 420));
67 
68  spectrumListSimple->spectra.push_back(spectrum0);
69  spectrumListSimple->spectra.push_back(spectrum1);
70 
71  // let an MSData object hold onto it as a SpectrumListPtr
72 
73  MSData data;
74  data.run.spectrumListPtr = spectrumListSimple;
75 
76  // test SpectrumList interface
77 
78  // verify index()
79  const SpectrumList& spectrumList = *data.run.spectrumListPtr;
80  unit_assert_operator_equal(2, spectrumList.size());
81  unit_assert_operator_equal(0, spectrumList.find("sample=1 period=1 cycle=123 experiment=2"));
82  unit_assert_operator_equal(1, spectrumList.find("sample=1 period=1 cycle=345 experiment=2"));
83 
84  // verify findAbbreviated()
85  unit_assert_operator_equal(0, spectrumList.findAbbreviated("1.1.123.2"));
86  unit_assert_operator_equal(1, spectrumList.findAbbreviated("1.1.345.2"));
87 
88  // verify findNameValue
89 
90  IndexList result = spectrumList.findNameValue("cycle", "123");
91  unit_assert(result.size()==1 && result[0]==0);
92 
93  result = spectrumList.findNameValue("cycle", "345");
94  unit_assert(result.size()==1 && result[0]==1);
95 
96  // verify spectrumIdentity()
97 
98  const SpectrumIdentity& identity0 = spectrumList.spectrumIdentity(0);
99  unit_assert(identity0.index == spectrum0->index);
100  unit_assert(identity0.id == spectrum0->id);
101 
102  const SpectrumIdentity& identity1 = spectrumList.spectrumIdentity(1);
103  unit_assert(identity1.index == spectrum1->index);
104  unit_assert(identity1.id == spectrum1->id);
105 
106  // verify spectrum 0
107  SpectrumPtr spectrum = spectrumList.spectrum(0);
108  unit_assert(spectrum->index == spectrum0->index);
109  unit_assert(spectrum->id == spectrum0->id);
110 
111  // verify no extra copying of binary data arrays
112  unit_assert(spectrum->binaryDataArrayPtrs.size() == 2);
113  unit_assert(&(spectrum->binaryDataArrayPtrs[0]->data[0]) == buffer);
114 
115  // verify getMZIntensityPairs()
116 
117  unit_assert(spectrum->binaryDataArrayPtrs[0]->hasCVParam(MS_m_z_array) == true);
118  unit_assert(spectrum->binaryDataArrayPtrs[1]->hasCVParam(MS_intensity_array) == true);
119 
120  vector<MZIntensityPair> mziPairs;
121  spectrum->getMZIntensityPairs(mziPairs);
122  unit_assert(mziPairs.size() == 10);
123 
124  vector<double> doubleArray;
125  unit_assert(spectrum->defaultArrayLength == 10);
126  doubleArray.resize(spectrum->defaultArrayLength*2);
127  spectrum->getMZIntensityPairs(reinterpret_cast<MZIntensityPair*>(&doubleArray[0]),
128  spectrum->defaultArrayLength);
129 
130  for (unsigned int i=0; i<10; i++)
131  {
132  const MZIntensityPair& p = mziPairs[i];
133  unit_assert(p.mz == i);
134  unit_assert(p.intensity == 10-i);
135  unit_assert(doubleArray[2*i] == i);
136  unit_assert(doubleArray[2*i+1] == 10-i);
137  }
138 
139  // verify setMZIntensityPairs()
140  spectrum->binaryDataArrayPtrs.clear();
141  unit_assert(spectrum->binaryDataArrayPtrs.empty());
142  vector<MZIntensityPair> mziPairs2;
143  for (unsigned int i=0; i<10; i++)
144  mziPairs2.push_back(MZIntensityPair(2*i, 3*i));
145  spectrum->setMZIntensityPairs(mziPairs2, MS_number_of_detector_counts);
146  unit_assert(spectrum->binaryDataArrayPtrs.size() == 2);
147  unit_assert(spectrum->binaryDataArrayPtrs[0]->hasCVParam(MS_m_z_array) == true);
148  unit_assert(spectrum->binaryDataArrayPtrs[1]->hasCVParam(MS_intensity_array) == true);
149  unit_assert(spectrum->binaryDataArrayPtrs[1]->cvParam(MS_intensity_array).units == MS_number_of_detector_counts);
150  unit_assert(spectrum->binaryDataArrayPtrs[0]->data.size() == 10);
151  unit_assert(spectrum->binaryDataArrayPtrs[1]->data.size() == 10);
152  for (unsigned int i=0; i<10; i++)
153  unit_assert(spectrum->binaryDataArrayPtrs[0]->data[i] == 2*i &&
154  spectrum->binaryDataArrayPtrs[1]->data[i] == 3*i);
155 
156  // verify spectrum 1
157  spectrum = spectrumList.spectrum(1);
158  unit_assert(spectrum->index == spectrum1->index);
159  unit_assert(spectrum->id == spectrum1->id);
160 
161  // verify DataProcessingPtr
162 
163  unit_assert(spectrumList.dataProcessingPtr().get() &&
164  spectrumList.dataProcessingPtr()->id == "dp");
165 }
virtual IndexList findNameValue(const std::string &name, const std::string &value) const
find all spectrum indexes with specified name/value pair
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
Description of the way in which a particular software was used.
Definition: MSData.hpp:272
virtual const SpectrumIdentity & spectrumIdentity(size_t index) const =0
access to a spectrum index
virtual const boost::shared_ptr< const DataProcessing > dataProcessingPtr() const
returns the data processing affecting spectra retrieved through this interface
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:287
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
virtual size_t size() const =0
returns the number of spectra
Interface for accessing spectra, which may be stored in memory or backed by a data file (RAW...
Definition: MSData.hpp:656
MS_intensity_array
intensity array: A data array of intensity values.
Definition: cv.hpp:1999
MS_m_z_array
m/z array: A data array of m/z values.
Definition: cv.hpp:1996
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition: MSData.hpp:475
The data point type of a mass spectrum.
Definition: MSData.hpp:421
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
virtual size_t find(const std::string &id) const
find id in the spectrum index (returns size() on failure)
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:124
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition: MSData.hpp:472
The structure into which encoded binary data goes. Byte ordering is always little endian (Intel style...
Definition: MSData.hpp:403
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here. Subsidiary data arrays are also both described and attached here.
Definition: MSData.hpp:823
Identifying information for a spectrum.
Definition: MSData.hpp:469
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
The structure that captures the generation of a peak list (including the underlying acquisitions) ...
Definition: MSData.hpp:504
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712
#define unit_assert(x)
Definition: unit.hpp:85
virtual size_t findAbbreviated(const std::string &abbreviatedId, char delimiter='.') const
find an abbreviated id (e.g. "1.1.123.2" for "sample=1 period=1 cycle=123 experiment=2") in the spect...
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: MSData.hpp:416
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testChromatograms()

void testChromatograms ( )

Definition at line 168 of file MSDataTest.cpp.

References pwiz::msdata::ChromatogramList::chromatogram(), pwiz::msdata::ChromatogramListSimple::chromatograms, pwiz::msdata::ChromatogramList::dataProcessingPtr(), pwiz::msdata::ChromatogramListSimple::dp, MS_number_of_detector_counts, pwiz::msdata::ChromatogramList::size(), unit_assert, and UO_second.

Referenced by main().

169 {
171 
172  for (int i=0; i<3; i++)
173  {
174  vector<TimeIntensityPair> pairs;
175  for (int j=0; j<10; j++) pairs.push_back(TimeIntensityPair(j, 10*i+j));
176  cls.chromatograms.push_back(ChromatogramPtr(new Chromatogram));
177  cls.chromatograms.back()->setTimeIntensityPairs(pairs, UO_second, MS_number_of_detector_counts);
178  }
179 
180  DataProcessingPtr dp(new DataProcessing("dp"));
181  cls.dp = dp;
182 
183  ChromatogramList& cl = cls;
184 
185  unit_assert(cl.size() == 3);
186 
187  for (size_t i=0; i<3; i++)
188  {
189  vector<TimeIntensityPair> result;
190  cl.chromatogram(i)->getTimeIntensityPairs(result);
191  unit_assert(result.size() == 10);
192  for (size_t j=0; j<10; j++)
193  unit_assert(result[j].time==j && result[j].intensity==10*i+j);
194  }
195 
196  unit_assert(cl.dataProcessingPtr().get() &&
197  cl.dataProcessingPtr()->id == "dp");
198 }
Interface for accessing chromatograms, which may be stored in memory or backed by a data file (RAW...
Definition: MSData.hpp:752
Description of the way in which a particular software was used.
Definition: MSData.hpp:272
virtual const boost::shared_ptr< const DataProcessing > dataProcessingPtr() const
returns the data processing affecting spectra retrieved through this interface
std::vector< ChromatogramPtr > chromatograms
Definition: MSData.hpp:788
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:287
A single chromatogram.
Definition: MSData.hpp:573
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:12526
Simple writeable in-memory implementation of ChromatogramList.
Definition: MSData.hpp:786
The data point type of a chromatogram.
Definition: MSData.hpp:445
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:580
virtual ChromatogramPtr chromatogram(size_t index, bool getBinaryData=false) const =0
retrieve a chromatogram by index
virtual size_t size() const =0
returns the number of chromatograms
#define unit_assert(x)
Definition: unit.hpp:85
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: MSData.hpp:620

§ testIDParsing()

void testIDParsing ( )

Definition at line 201 of file MSDataTest.cpp.

References pwiz::msdata::id::abbreviate(), CVID_Unknown, MS_Bruker_Agilent_YEP_nativeID_format, MS_Bruker_BAF_nativeID_format, MS_multiple_peak_list_nativeID_format, MS_no_nativeID_format, MS_scan_number_only_nativeID_format, MS_spectrum_identifier_nativeID_format, MS_Thermo_nativeID_format, MS_WIFF_nativeID_format, pwiz::msdata::id::parse(), pwiz::msdata::id::translateNativeIDToScanNumber(), pwiz::msdata::id::translateScanNumberToNativeID(), unit_assert, unit_assert_equal, and pwiz::msdata::id::value().

Referenced by main().

202 {
203  string id = "hair=blue favorite=420 age=36.175 upsideDown=1";
204 
205  map<string,string> parsedID = id::parse(id);
206  unit_assert(parsedID.size() == 4);
207 
208  unit_assert(id::value(id, "hair") == "blue");
209  unit_assert(id::valueAs<int>(id, "favorite") == 420);
210  unit_assert_equal(id::valueAs<double>(id, "age"), 36.175, 1e-6);
211  unit_assert(id::valueAs<bool>(id, "upsideDown") == true);
212 
213  unit_assert(id::abbreviate(id) == "blue.420.36.175.1");
214  unit_assert(id::abbreviate(id, ',') == "blue,420,36.175,1");
215 
216  id = "controllerType=0 controllerNumber=1 scan=123";
221  unit_assert(id::abbreviate(id) == "0.1.123");
222  unit_assert(id::abbreviate(id, ',') == "0,1,123");
223 
225 
226  id = "spectrum=123";
230 
231  id = "scan=123";
240  unit_assert(id::abbreviate(id) == "123");
241  unit_assert(id::abbreviate(id, ',') == "123");
242 
243  id = "sample=1 period=2 cycle=123 experiment=3";
246  unit_assert(id::abbreviate(id) == "1.2.123.3");
247  unit_assert(id::abbreviate(id, ',') == "1,2,123,3");
248 }
PWIZ_API_DECL std::string abbreviate(const std::string &id, char delimiter='.')
abbreviates a nativeID ("name1=value1 name2=value2" translates to "value1.value2") ...
MS_Bruker_Agilent_YEP_nativeID_format
Bruker/Agilent YEP nativeID format: Native format defined by scan=xsd:nonNegativeInteger.
Definition: cv.hpp:2833
MS_spectrum_identifier_nativeID_format
spectrum identifier nativeID format: Native format defined by spectrum=xsd:nonNegativeInteger.
Definition: cv.hpp:2851
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
MS_no_nativeID_format
no nativeID format: No nativeID format indicates that the file tagged with this term does not contain...
Definition: cv.hpp:3019
MS_Bruker_BAF_nativeID_format
Bruker BAF nativeID format: Native format defined by scan=xsd:nonNegativeInteger. ...
Definition: cv.hpp:2836
PWIZ_API_DECL std::map< std::string, std::string > parse(const std::string &id)
parses an id string into a map<string,string>
MS_WIFF_nativeID_format
WIFF nativeID format: Native format defined by sample=xsd:nonNegativeInteger period=xsd:nonNegativeIn...
Definition: cv.hpp:2830
MS_scan_number_only_nativeID_format
scan number only nativeID format: Native format defined by scan=xsd:nonNegativeInteger.
Definition: cv.hpp:2848
CVID_Unknown
Definition: cv.hpp:97
MS_Thermo_nativeID_format
Thermo nativeID format: Native format defined by controllerType=xsd:nonNegativeInteger controllerNumb...
Definition: cv.hpp:2824
MS_multiple_peak_list_nativeID_format
multiple peak list nativeID format: Native format defined by index=xsd:nonNegativeInteger.
Definition: cv.hpp:2842
PWIZ_API_DECL std::string value(const std::string &id, const std::string &name)
convenience function to extract a named value from an id string
PWIZ_API_DECL std::string translateNativeIDToScanNumber(CVID nativeIDFormat, const std::string &id)
translates a nativeID in the given nativeID format to a simple integer "scan number"; some nativeID f...
#define unit_assert(x)
Definition: unit.hpp:85
PWIZ_API_DECL std::string translateScanNumberToNativeID(CVID nativeIDFormat, const std::string &scanNumber)
translates a "scan number" to a string that is correct for the given nativeID format; semantic validi...

§ testAllDataProcessing()

void testAllDataProcessing ( )

Definition at line 251 of file MSDataTest.cpp.

References pwiz::msdata::MSData::allDataProcessingPtrs(), pwiz::msdata::MSData::dataProcessingPtrs, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, and unit_assert_operator_equal.

Referenced by main().

252 {
253  MSData msd;
255  msd.run.spectrumListPtr = sl;
256 
257  DataProcessingPtr realDeal(new DataProcessing("dp"));
258  DataProcessingPtr poser(new DataProcessing("dp"));
259 
260  msd.dataProcessingPtrs.push_back(realDeal);
261  sl->dp = poser;
262 
263  // test allDataProcessingPtrs()
264  vector<DataProcessingPtr> all = msd.allDataProcessingPtrs();
265  unit_assert_operator_equal(1, all.size());
266  unit_assert_operator_equal(realDeal, all[0]);
267 }
Description of the way in which a particular software was used.
Definition: MSData.hpp:272
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:287
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument...
Definition: MSData.hpp:882
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here. Subsidiary data arrays are also both described and attached here.
Definition: MSData.hpp:823
std::vector< DataProcessingPtr > allDataProcessingPtrs() const
return dataProcessingPtrs augmented by the dataProcessingPtr() set in SpectrumList and/or Chromatogra...
std::vector< DataProcessingPtr > dataProcessingPtrs
list and descriptions of data processing applied to this data.
Definition: MSData.hpp:876
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition: MSData.hpp:727
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:712

§ main()

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

Definition at line 270 of file MSDataTest.cpp.

References TEST_EPILOG, TEST_FAILED, TEST_PROLOG, testAllDataProcessing(), testChromatograms(), testIDParsing(), and testSpectrumListSimple().

271 {
272  TEST_PROLOG(argc, argv)
273 
274  try
275  {
278  testIDParsing();
280  }
281  catch (exception& e)
282  {
283  TEST_FAILED(e.what())
284  }
285  catch (...)
286  {
287  TEST_FAILED("Caught unknown exception.")
288  }
289 
291 }
#define TEST_EPILOG
Definition: unit.hpp:182
void testIDParsing()
Definition: MSDataTest.cpp:201
void testSpectrumListSimple()
Definition: MSDataTest.cpp:33
void testChromatograms()
Definition: MSDataTest.cpp:168
void testAllDataProcessing()
Definition: MSDataTest.cpp:251
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174