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.

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];
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));
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));
226 }

References pwiz::msdata::Precursor::activation, pwiz::data::ParamContainer::cvParams, pwiz::msdata::MSData::dataProcessingPtrs, pwiz::data::UserParam::empty(), pwiz::msdata::MSData::fileDescription, pwiz::data::ParamContainer::hasCVParam(), 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::Precursor::selectedIons, pwiz::msdata::MSData::softwarePtrs, pwiz::msdata::FileDescription::sourceFilePtrs, pwiz::msdata::Precursor::spectrumID, pwiz::data::UserParam::type, unit_assert, pwiz::data::ParamContainer::userParams, pwiz::data::UserParam::value, pwiz::identdata::IO::write(), and pwiz::msdata::Serializer_mzXML::write().

Referenced by main(), and test().

◆ test() [2/2]

void test ( )

Definition at line 229 of file SpectrumList_mzXML_Test.cpp.

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

References test().

◆ main()

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

Definition at line 239 of file SpectrumList_mzXML_Test.cpp.

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 }

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

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 38 of file SpectrumList_mzXML_Test.cpp.

Referenced by main(), and test().

pwiz::data::UserParam
Uncontrolled user parameters (essentially allowing free text). Before using these,...
Definition: ParamTypes.hpp:186
MS_LCQ_Deca
MS_LCQ_Deca
LCQ Deca: ThermoFinnigan LCQ Deca.
Definition: cv.hpp:2271
pwiz::data::UserParam::type
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
pwiz::msdata::SpectrumListPtr
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition: MSData.hpp:711
MS_Bruker_Agilent_YEP_format
MS_Bruker_Agilent_YEP_format
Bruker/Agilent YEP format: Bruker/Agilent YEP file format.
Definition: cv.hpp:2310
os_
ostream * os_
Definition: SpectrumList_mzXML_Test.cpp:38
MS_charge_state
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition: cv.hpp:396
pwiz::msdata::MSData::softwarePtrs
std::vector< SoftwarePtr > softwarePtrs
list and descriptions of software used to acquire and/or process the data in this mzML file.
Definition: MSData.hpp:871
MS_m_z_array
MS_m_z_array
m/z array: A data array of m/z values.
Definition: cv.hpp:2148
pwiz::msdata::Software
A piece of software.
Definition: MSData.hpp:180
pwiz::msdata::ProcessingMethod
Description of the default peak processing method. This element describes the base method used in the...
Definition: MSData.hpp:255
pwiz::msdata::SourceFile
Description of the source file, including location and type.
Definition: MSData.hpp:55
MS_ProteoWizard_software
MS_ProteoWizard_software
ProteoWizard software: ProteoWizard software for data processing and analysis. Primarily developed by...
Definition: cv.hpp:2505
pwiz::data::ParamContainer::userParams
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
MS_ETD
MS_ETD
ETD (electron transfer dissociation): A process to fragment ions in a mass spectrometer by inducing f...
Definition: cv.hpp:2451
MS_scan_start_time
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:309
pwiz::msdata::Scan::instrumentConfigurationPtr
InstrumentConfigurationPtr instrumentConfigurationPtr
this attribute MUST reference the 'id' attribute of the appropriate instrument configuration.
Definition: MSData.hpp:384
pwiz::msdata::FileDescription::sourceFilePtrs
std::vector< SourceFilePtr > sourceFilePtrs
list and descriptions of the source files this mzML document was generated or derived from.
Definition: MSData.hpp:90
pwiz::msdata::IndexList
Definition: MSData.hpp:628
MS_Conversion_to_mzML
MS_Conversion_to_mzML
Conversion to mzML: Conversion of a file format to Proteomics Standards Initiative mzML file format.
Definition: cv.hpp:2241
MS_positive_scan
MS_positive_scan
positive scan: Polarity of the scan is positive.
Definition: cv.hpp:738
pwiz::msdata::Precursor::spectrumID
std::string spectrumID
reference to the id attribute of the spectrum from which the precursor was selected.
Definition: MSData.hpp:323
pwiz::identdata::IO::write
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
pwiz::msdata::Serializer_mzXML::Config::indexed
bool indexed
(indexed==true): read/write with <index>
Definition: Serializer_mzXML.hpp:51
test
void test(bool indexed)
Definition: SpectrumList_mzXML_Test.cpp:41
MS_Bruker_Agilent_YEP_nativeID_format
MS_Bruker_Agilent_YEP_nativeID_format
Bruker/Agilent YEP nativeID format: Native format defined by scan=xsd:nonNegativeInteger.
Definition: cv.hpp:2985
MS_collision_energy
MS_collision_energy
collision energy: Energy for an ion experiencing collision with a stationary gas particle resulting i...
Definition: cv.hpp:411
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
pwiz::msdata::MSData::fileDescription
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:862
pwiz::data::ParamContainer::hasCVParam
bool hasCVParam(CVID cvid) const
returns true iff cvParams contains exact cvid (recursive)
pwiz::msdata::TextWriter
Definition: TextWriter.hpp:41
pwiz::identdata::examples::initializeTiny
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
pwiz::data::UserParam::value
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
pwiz::msdata::Precursor::activation
Activation activation
the type and energy level used for activation.
Definition: MSData.hpp:332
MS_intensity_array
MS_intensity_array
intensity array: A data array of intensity values.
Definition: cv.hpp:2151
MS_selected_ion_m_z
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2901
pwiz::msdata::Scan
Scan or acquisition from original raw file used to create this peak list, as specified in sourceFile.
Definition: MSData.hpp:370
pwiz::msdata::SourceFilePtr
boost::shared_ptr< SourceFile > SourceFilePtr
Description of the source file, including location and type.
Definition: MSData.hpp:76
pwiz::msdata::Serializer_mzXML
MSData <-> mzXML stream serialization.
Definition: Serializer_mzXML.hpp:40
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
pwiz::msdata::DataProcessingPtr
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: MSData.hpp:288
MS_ms_level
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
pwiz::chemistry::Ion::mz
double mz(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition: Ion.hpp:78
pwiz::msdata::MSData::dataProcessingPtrs
std::vector< DataProcessingPtr > dataProcessingPtrs
list and descriptions of data processing applied to this data.
Definition: MSData.hpp:880
pwiz::data::UserParam::empty
bool empty() const
returns true iff name, value, type, and units are all empty
MS_peak_intensity
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:402
pwiz::msdata::Serializer_mzXML::Config
Serializer_mzXML configuration.
Definition: Serializer_mzXML.hpp:45
pwiz::msdata::MSData::instrumentConfigurationPtrs
std::vector< InstrumentConfigurationPtr > instrumentConfigurationPtrs
list and descriptions of instrument configurations.
Definition: MSData.hpp:877
MS_base_peak_intensity
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:2121
pwiz::msdata::InstrumentConfiguration
Description of a particular hardware configuration of a mass spectrometer. Each configuration MUST ha...
Definition: MSData.hpp:230
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:850
pwiz::msdata::DataProcessing
Description of the way in which a particular software was used.
Definition: MSData.hpp:274
pwiz::msdata::Precursor::selectedIons
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition: MSData.hpp:329
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
pwiz::msdata::InstrumentConfigurationPtr
boost::shared_ptr< InstrumentConfiguration > InstrumentConfigurationPtr
Definition: MSData.hpp:250
pwiz::msdata::Precursor
The method of precursor ion selection and activation.
Definition: MSData.hpp:312
MS_CID
MS_CID
CID (collision-induced dissociation): The dissociation of an ion after collisional excitation....
Definition: cv.hpp:750
pwiz::data::UserParam::name
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
pwiz::msdata::SoftwarePtr
boost::shared_ptr< Software > SoftwarePtr
Definition: MSData.hpp:198
pwiz::data::ParamContainer::cvParams
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250