ProteoWizard
Functions | Variables
SpectrumList_mzXML_Test.cpp File Reference
#include "SpectrumList_mzXML.hpp"
#include "Serializer_mzXML.hpp"
#include "TextWriter.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 41 of file SpectrumList_mzXML_Test.cpp.

References pwiz::msdata::MSData::dataProcessingPtrs, pwiz::data::UserParam::empty(), pwiz::msdata::MSData::fileDescription, pwiz::msdata::Serializer_mzXML::Config::indexed, pwiz::identdata::examples::initializeTiny(), pwiz::msdata::Scan::instrumentConfigurationPtr, pwiz::msdata::MSData::instrumentConfigurationPtrs, MS_base_peak_intensity, MS_Bruker_Agilent_YEP_format, MS_Bruker_Agilent_YEP_nativeID_format, MS_charge_state, MS_CID, MS_collision_energy, MS_Conversion_to_mzML, MS_ETD, MS_intensity_array, MS_LCQ_Deca, MS_m_z_array, MS_ms_level, MS_peak_intensity, MS_positive_scan, MS_ProteoWizard_software, MS_scan_start_time, MS_selected_ion_m_z, pwiz::chemistry::Ion::mz(), pwiz::data::UserParam::name, os_, pwiz::msdata::MSData::softwarePtrs, pwiz::msdata::FileDescription::sourceFilePtrs, pwiz::data::UserParam::type, unit_assert, pwiz::data::UserParam::value, pwiz::identdata::IO::write(), and pwiz::msdata::Serializer_mzXML::write().

Referenced by main(), and test().

42 {
43  if (os_) *os_ << "test(): indexed=\"" << boolalpha << indexed << "\"\n";
44 
45  MSData tiny;
47 
49  config.indexed = indexed;
50  Serializer_mzXML serializer(config);
51 
52  ostringstream oss;
53  serializer.write(oss, tiny);
54 
55  if (os_) *os_ << "oss:\n" << oss.str() << endl;
56 
57  shared_ptr<istream> is(new istringstream(oss.str()));
58 
59  // dummy would normally be read in from file
60 
61  MSData dummy;
62  dummy.fileDescription.sourceFilePtrs.push_back(SourceFilePtr(new SourceFile("tiny1.yep")));
65  dummy.softwarePtrs.push_back(SoftwarePtr(new Software("pwiz")));
66  dummy.softwarePtrs.back()->set(MS_ProteoWizard_software);
68  dummy.instrumentConfigurationPtrs.back()->set(MS_LCQ_Deca);
69  dummy.instrumentConfigurationPtrs.back()->userParams.push_back(UserParam("doobie", "420"));
70  dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("DP1")));
71  dummy.dataProcessingPtrs.back()->processingMethods.push_back(ProcessingMethod());
72  dummy.dataProcessingPtrs.back()->processingMethods.back().set(MS_Conversion_to_mzML);
73  dummy.dataProcessingPtrs.back()->processingMethods.back().softwarePtr = dummy.softwarePtrs.back();
74 
75  // note: used to have a test here to check that an exception would be thrown on
76  // on an unindexed input file, but index is an optional element so the right thing to
77  // do is just create it
78 
79  SpectrumListPtr sl = SpectrumList_mzXML::create(is, dummy, indexed);
80 
81  if (os_)
82  {
84  write(*sl);
85  *os_ << endl;
86  }
87 
88  // check easy functions
89 
90  unit_assert(sl.get());
91  unit_assert(sl->size() == 4);
92 
93  unit_assert(sl->find("scan=19") == 0);
94  IndexList indexList = sl->findNameValue("scan", "19");
95  unit_assert(indexList.size()==1 && indexList[0]==0);
96  unit_assert(sl->find("scan=20") == 1);
97  indexList = sl->findNameValue("scan", "20");
98  unit_assert(indexList.size()==1 && indexList[0]==1);
99  unit_assert(sl->find("scan=21") == 2);
100  indexList = sl->findNameValue("scan", "21");
101  unit_assert(indexList.size()==1 && indexList[0]==2);
102 
103  // check scan 19
104 
105  unit_assert(sl->spectrumIdentity(0).index == 0);
106  unit_assert(sl->spectrumIdentity(0).id == "scan=19");
107  unit_assert(sl->spectrumIdentity(0).sourceFilePosition != -1);
108 
109  SpectrumPtr s = sl->spectrum(0, false);
110 
111  unit_assert(s.get());
112  unit_assert(s->id == "scan=19");
113  unit_assert(s->index == 0);
114  unit_assert(s->sourceFilePosition != -1);
115  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
116  unit_assert(s->hasCVParam(MS_positive_scan));
117  unit_assert(s->scanList.scans.size() == 1);
118  Scan& scan = s->scanList.scans[0];
119  unit_assert(scan.hasCVParam(MS_scan_start_time));
120  //unit_assert(scan.cvParam(MS_preset_scan_configuration).valueAs<int>() == 3);
121  unit_assert(s->cvParam(MS_base_peak_intensity).value == "120053");
122  unit_assert(s->defaultArrayLength == 15);
123  unit_assert(s->binaryDataArrayPtrs.size() == 2);
124  unit_assert(s->binaryDataArrayPtrs[0]->hasCVParam(MS_m_z_array));
125  unit_assert(s->binaryDataArrayPtrs[1]->hasCVParam(MS_intensity_array));
126  unit_assert(s->binaryDataArrayPtrs[0]->data.empty() && s->binaryDataArrayPtrs[1]->data.empty());
127 
128  s = sl->spectrum(0, true);
129  unit_assert(s->defaultArrayLength == 15);
130  unit_assert(s->binaryDataArrayPtrs.size() == 2);
131  unit_assert(!s->binaryDataArrayPtrs[0]->data.empty() && !s->binaryDataArrayPtrs[1]->data.empty());
132 
133  vector<MZIntensityPair> pairs;
134  s->getMZIntensityPairs(pairs);
135 
136  if (os_)
137  {
138  *os_ << "scan 19:\n";
139  copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
140  *os_ << endl;
141  }
142 
143  unit_assert(pairs.size() == 15);
144  for (int i=0; i<15; i++)
145  unit_assert(pairs[i].mz==i && pairs[i].intensity==15-i);
146 
147  Scan& scan19 = s->scanList.scans[0];
149  InstrumentConfiguration& instrumentConfiguration = *scan19.instrumentConfigurationPtr;
150  unit_assert(!instrumentConfiguration.cvParams.empty()); // references resolved
151  unit_assert(instrumentConfiguration.userParams.size() == 1 &&
152  instrumentConfiguration.userParams[0].name == "doobie");
153 
154  // check scan 20
155 
156  unit_assert(sl->spectrumIdentity(1).index == 1);
157  unit_assert(sl->spectrumIdentity(1).id == "scan=20");
158 
159  s = sl->spectrum(1, true);
160  unit_assert(s.get());
161  unit_assert(s->id == "scan=20");
162  unit_assert(s->index == 1);
163  unit_assert(s->sourceFilePosition != -1);
164  unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
165 
166  unit_assert(s->scanList.scans.size() == 1);
167  //Scan& scan20 = s->scanList.scans[0];
168  //unit_assert(scan20.cvParam(MS_preset_scan_configuration).valueAs<int>() == 4);
169 
170  unit_assert(s->precursors.size() == 1);
171  Precursor& precursor = s->precursors[0];
172  unit_assert(precursor.selectedIons.size() == 1);
173  unit_assert(precursor.selectedIons[0].hasCVParam(MS_selected_ion_m_z));
174  unit_assert(precursor.selectedIons[0].hasCVParam(MS_peak_intensity));
175  unit_assert(precursor.selectedIons[0].hasCVParam(MS_charge_state));
176  unit_assert(precursor.activation.hasCVParam(MS_CID));
177  unit_assert(precursor.activation.hasCVParam(MS_collision_energy));
178  unit_assert(precursor.spectrumID == "scan=19"); // Serializer_mzXML::read() sets
179 
180  pairs.clear();
181  s->getMZIntensityPairs(pairs);
182 
183  if (os_)
184  {
185  *os_ << "scan 20:\n";
186  copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
187  *os_ << endl;
188  }
189 
190  unit_assert(pairs.size() == 10);
191  for (int i=0; i<10; i++)
192  unit_assert(pairs[i].mz==2*i && pairs[i].intensity==(10-i)*2);
193 
194 
195  // check scan 21 (for userParam <-> nameValue)
196 
197  unit_assert(sl->spectrumIdentity(2).index == 2);
198  unit_assert(sl->spectrumIdentity(2).id == "scan=21");
199 
200  s = sl->spectrum(2, false);
201  unit_assert(s.get());
202  unit_assert(s->id == "scan=21");
203  UserParam exampleUserParam = s->userParam("example");
204  unit_assert(!exampleUserParam.empty());
205  unit_assert(exampleUserParam.name == "example");
206  unit_assert(exampleUserParam.value == "spectrum with no data");
207  unit_assert(exampleUserParam.type == "xsd:string");
208 
209  // check scan 22 (for ETD precursor activation)
210 
211  unit_assert(sl->spectrumIdentity(3).index == 3);
212  unit_assert(sl->spectrumIdentity(3).id == "scan=22");
213 
214  s = sl->spectrum(3, false);
215  unit_assert(s.get());
216  unit_assert(s->id == "scan=22");
217  unit_assert(s->precursors.size() == 1);
218  Precursor& precursor22 = s->precursors[0];
219  unit_assert(precursor22.selectedIons.size() == 1);
220  unit_assert(precursor22.selectedIons[0].hasCVParam(MS_selected_ion_m_z));
221  unit_assert(precursor22.selectedIons[0].hasCVParam(MS_peak_intensity));
222  unit_assert(precursor22.selectedIons[0].hasCVParam(MS_charge_state));
223  unit_assert(precursor22.activation.hasCVParam(MS_ETD));
224  unit_assert(precursor22.activation.hasCVParam(MS_CID));
225  unit_assert(precursor22.activation.hasCVParam(MS_collision_energy));
226 }
ostream * os_
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged...
Definition: cv.hpp:235
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from...
Definition: MSData.hpp:89
MS_Bruker_Agilent_YEP_nativeID_format
Bruker/Agilent YEP nativeID format: Native format defined by scan=xsd:nonNegativeInteger.
Definition: cv.hpp:2833
Description of the way in which a particular software was used.
Definition: MSData.hpp:272
boost::shared_ptr< Software > SoftwarePtr
Definition: MSData.hpp:197
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:1969
Description of the source file, including location and type.
Definition: MSData.hpp:53
Scan or acquisition from original raw file used to create this peak list, as specified in sourceFile...
Definition: MSData.hpp:368
std::vector< InstrumentConfigurationPtr > instrumentConfigurationPtrs
list and descriptions of instrument configurations.
Definition: MSData.hpp:873
The method of precursor ion selection and activation.
Definition: MSData.hpp:310
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:569
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
MS_ProteoWizard_software
ProteoWizard software: ProteoWizard software for data processing and analysis. Primarily developed by...
Definition: cv.hpp:2353
MS_scan_start_time
scan start time: The time that an analyzer started a scan, relative to the start of the MS run...
Definition: cv.hpp:148
MS_positive_scan
positive scan: Polarity of the scan is positive.
Definition: cv.hpp:577
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:287
MS_CID
CID (collision-induced dissociation): The dissociation of an ion after collisional excitation...
Definition: cv.hpp:589
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_LCQ_Deca
LCQ Deca: ThermoFinnigan LCQ Deca.
Definition: cv.hpp:2119
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
MS_Bruker_Agilent_YEP_format
Bruker/Agilent YEP format: Bruker/Agilent YEP file format.
Definition: cv.hpp:2158
bool empty() const
returns true iff name, value, type, and units are all empty
MS_peak_intensity
peak intensity: Intensity of ions as measured by the height or area of a peak in a mass spectrum...
Definition: cv.hpp:241
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
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
MS_collision_energy
collision energy: Energy for an ion experiencing collision with a stationary gas particle resulting i...
Definition: cv.hpp:250
Description of the default peak processing method. This element describes the base method used in the...
Definition: MSData.hpp:253
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
MS_ETD
ETD (electron transfer dissociation): A process to fragment ions in a mass spectrometer by inducing f...
Definition: cv.hpp:2299
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 piece of software.
Definition: MSData.hpp:178
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
InstrumentConfigurationPtr instrumentConfigurationPtr
this attribute MUST reference the &#39;id&#39; attribute of the appropriate instrument configuration.
Definition: MSData.hpp:383
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
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
std::vector< SoftwarePtr > softwarePtrs
list and descriptions of software used to acquire and/or process the data in this mzML file...
Definition: MSData.hpp:867
std::vector< DataProcessingPtr > dataProcessingPtrs
list and descriptions of data processing applied to this data.
Definition: MSData.hpp:876
MSData <-> mzXML stream serialization.
Serializer_mzXML configuration.
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
MS_Conversion_to_mzML
Conversion to mzML: Conversion of a file format to Proteomics Standards Initiative mzML file format...
Definition: cv.hpp:2089
bool indexed
(indexed==true): read/write with <index>
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 229 of file SpectrumList_mzXML_Test.cpp.

References test().

230 {
231  bool indexed = true;
232  test(indexed);
233 
234  indexed = false;
235  test(indexed);
236 }
void test(bool indexed)

§ main()

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

Definition at line 239 of file SpectrumList_mzXML_Test.cpp.

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

240 {
241  TEST_PROLOG(argc, argv)
242 
243  try
244  {
245  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
246  test();
247  }
248  catch (exception& e)
249  {
250  TEST_FAILED(e.what())
251  }
252  catch (...)
253  {
254  TEST_FAILED("Caught unknown exception.")
255  }
256 
258 }
ostream * os_
#define TEST_EPILOG
Definition: unit.hpp:182
void test(bool indexed)
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 38 of file SpectrumList_mzXML_Test.cpp.

Referenced by main(), and test().