ProteoWizard
Classes | Functions | Variables
ParamTypesTest.cpp File Reference
#include "ParamTypes.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Classes

class  WriteCVParam
 

Functions

void test ()
 
void testIs ()
 
void testIsChildOf ()
 
void testParamContainer ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
const char * mzmlScanTime
 
const char * mzmlCollisionEnergy
 

Function Documentation

§ test()

void test ( )

Definition at line 75 of file ParamTypesTest.cpp.

References MS_collision_energy, MS_deisotoping, MS_highest_observed_m_z, MS_lowest_observed_m_z, MS_m_z, MS_peak_picking, MS_scan_start_time, mzmlCollisionEnergy, mzmlScanTime, os_, pwiz::data::CVParam::timeInSeconds(), unit_assert, unit_assert_equal, UO_electronvolt, UO_minute, and pwiz::msdata::id::value().

Referenced by main().

76 {
77  vector<CVParam> params;
78 
79  params.push_back(CVParam(MS_lowest_observed_m_z, 420));
80  params.push_back(CVParam(MS_highest_observed_m_z, 2000.012345));
81  params.push_back(CVParam(MS_m_z, "goober"));
82  params.push_back(CVParam(MS_scan_start_time, 5.890500, UO_minute));
83  params.push_back(CVParam(MS_collision_energy, 35.00, UO_electronvolt));
84  params.push_back(CVParam(MS_deisotoping, true));
85  params.push_back(CVParam(MS_peak_picking, false));
86 
87  if (os_)
88  {
89  *os_ << "params:\n";
90  copy(params.begin(), params.end(), ostream_iterator<CVParam>(*os_, "\n"));
91  *os_ << endl;
92 
93  *os_ << "as mzML <cvParam> elements:\n";
94  for_each(params.begin(), params.end(), WriteCVParam(*os_));
95  *os_ << endl;
96 
97  *os_ << "value casting:\n";
98  int temp = params[0].valueAs<int>();
99  *os_ << temp << endl;
100  float temp2 = params[1].valueAs<float>();
101  *os_ << temp2 << endl;
102  string temp3 = params[2].valueAs<string>();
103  *os_ << temp3 << "\n\n";
104  }
105 
106  // verify simple things
107  unit_assert(420 == params[0].valueAs<int>());
108  unit_assert(2000.012345 == params[1].valueAs<double>());
109  unit_assert("goober" == params[2].value);
110  unit_assert(5.890500 == params[3].valueAs<double>());
111  unit_assert(35.00 == params[4].valueAs<double>());
112  unit_assert(params[0] == CVParam(MS_lowest_observed_m_z, 420));
113  unit_assert(params[1] != CVParam(MS_lowest_observed_m_z, 420));
115  unit_assert(params[5].valueAs<bool>() == true);
116  unit_assert(params[6].valueAs<bool>() == false);
117 
118  // verify manual mzml writing -- this is to verify that we have enough
119  // info to write <cvParam> elements as required by mzML
120 
121  ostringstream ossScanTime;
122  CVParam scanTime(MS_scan_start_time, "5.890500", UO_minute);
123  (WriteCVParam(ossScanTime))(scanTime);
124  if (os_) *os_ << "mzmlScanTime: " << mzmlScanTime << endl
125  << "ossScanTime: " << ossScanTime.str() << endl;
126  unit_assert(ossScanTime.str() == mzmlScanTime);
127  if (os_) *os_ << "scan time in seconds: " << scanTime.timeInSeconds() << endl;
128  unit_assert_equal(scanTime.timeInSeconds(), 5.8905 * 60, 1e-10);
129 
130  ostringstream ossCollisionEnergy;
131  (WriteCVParam(ossCollisionEnergy))(CVParam(MS_collision_energy, "35.00", UO_electronvolt));
132  if (os_) *os_ << "mzmlCollisionEnergy: " << mzmlCollisionEnergy << endl
133  << "ossCollisionEnergy: " << ossCollisionEnergy.str() << endl;
134  unit_assert(ossCollisionEnergy.str() == mzmlCollisionEnergy);
135 }
MS_deisotoping
deisotoping: The removal of isotope peaks to represent the fragment ion as one data point and is comm...
Definition: cv.hpp:202
MS_highest_observed_m_z
highest observed m/z: Highest m/z value observed in the m/z array.
Definition: cv.hpp:2035
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
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
MS_collision_energy
collision energy: Energy for an ion experiencing collision with a stationary gas particle resulting i...
Definition: cv.hpp:250
const char * mzmlScanTime
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:223
ostream * os_
const char * mzmlCollisionEnergy
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:12589
UO_electronvolt
electronvolt: A non-SI unit of energy (eV) defined as the energy acquired by a single unbound electro...
Definition: cv.hpp:13288
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
MS_lowest_observed_m_z
lowest observed m/z: Lowest m/z value observed in the m/z array.
Definition: cv.hpp:2038
#define unit_assert(x)
Definition: unit.hpp:85
MS_peak_picking
peak picking: Spectral peak processing conducted on the acquired data to convert profile data to cent...
Definition: cv.hpp:208
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testIs()

void testIs ( )

Definition at line 138 of file ParamTypesTest.cpp.

References MS_collision_induced_dissociation, MS_lowest_observed_m_z, MS_plasma_desorption, and unit_assert.

Referenced by main().

139 {
140  vector<CVParam> params;
141  params.push_back(CVParam(MS_plasma_desorption));
142  params.push_back(CVParam(MS_lowest_observed_m_z, 420));
143  params.push_back(CVParam(MS_collision_induced_dissociation));
144 
145  vector<CVParam>::const_iterator it =
146  find_if(params.begin(), params.end(), CVParamIs(MS_lowest_observed_m_z));
147 
148  unit_assert(it->value == "420");
149 }
MS_plasma_desorption
plasma desorption: The ionization of material in a solid sample by bombarding it with ionic or neutra...
Definition: cv.hpp:598
MS_collision_induced_dissociation
collision-induced dissociation: The dissociation of an ion after collisional excitation. The term collisional-activated dissociation is not recommended.
Definition: cv.hpp:586
MS_lowest_observed_m_z
lowest observed m/z: Lowest m/z value observed in the m/z array.
Definition: cv.hpp:2038
functor for finding CVParam with specified exact CVID in a collection of CVParams: ...
Definition: ParamTypes.hpp:151
#define unit_assert(x)
Definition: unit.hpp:85
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testIsChildOf()

void testIsChildOf ( )

Definition at line 152 of file ParamTypesTest.cpp.

References pwiz::cv::cvTermInfo(), MS_collision_induced_dissociation, MS_dissociation_method, MS_highest_observed_m_z, MS_lowest_observed_m_z, MS_plasma_desorption, pwiz::cv::CVTermInfo::name, os_, unit_assert, UO_electronvolt, and UO_unit.

Referenced by main().

153 {
154  // example of how to search through a collection of CVParams
155  // to find the first one whose cvid IsA specified CVID
156 
157  vector<CVParam> params;
158  params.push_back(CVParam(MS_lowest_observed_m_z, 420));
159  params.push_back(CVParam(MS_plasma_desorption));
160  params.push_back(CVParam(MS_collision_induced_dissociation));
161  params.push_back(CVParam(UO_electronvolt));
162  params.push_back(CVParam(MS_highest_observed_m_z, 2400.0));
163 
164  vector<CVParam>::const_iterator itDiss =
165  find_if(params.begin(), params.end(), CVParamIsChildOf(MS_dissociation_method));
166 
167  vector<CVParam>::const_iterator itUnit =
168  find_if(params.begin(), params.end(), CVParamIsChildOf(UO_unit));
169 
170  if (os_)
171  {
172  *os_ << "find dissociation method: "
173  << (itDiss!=params.end() ? cvTermInfo(itDiss->cvid).name : "not found")
174  << endl;
175 
176  *os_ << "find unit: "
177  << (itUnit!=params.end() ? cvTermInfo(itUnit->cvid).name : "not found")
178  << endl;
179 
180  }
181 
182  unit_assert(itDiss!=params.end() && itDiss->cvid==MS_plasma_desorption);
183  unit_assert(itUnit!=params.end() && itUnit->cvid==UO_electronvolt);
184 }
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
MS_plasma_desorption
plasma desorption: The ionization of material in a solid sample by bombarding it with ionic or neutra...
Definition: cv.hpp:598
MS_highest_observed_m_z
highest observed m/z: Highest m/z value observed in the m/z array.
Definition: cv.hpp:2035
MS_collision_induced_dissociation
collision-induced dissociation: The dissociation of an ion after collisional excitation. The term collisional-activated dissociation is not recommended.
Definition: cv.hpp:586
functor for finding children of a specified CVID in a collection of CVParams:
Definition: ParamTypes.hpp:164
std::string name
Definition: cv.hpp:13385
ostream * os_
UO_unit
unit: A unit of measurement is a standardized quantity of a physical quality.
Definition: cv.hpp:12496
UO_electronvolt
electronvolt: A non-SI unit of energy (eV) defined as the energy acquired by a single unbound electro...
Definition: cv.hpp:13288
MS_dissociation_method
dissociation method: Fragmentation method used for dissociation or fragmentation. ...
Definition: cv.hpp:247
MS_lowest_observed_m_z
lowest observed m/z: Lowest m/z value observed in the m/z array.
Definition: cv.hpp:2038
#define unit_assert(x)
Definition: unit.hpp:85
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ testParamContainer()

void testParamContainer ( )

Definition at line 187 of file ParamTypesTest.cpp.

References pwiz::data::CVParam::cvid, CVID_Unknown, pwiz::data::ParamContainer::cvParam(), pwiz::data::ParamContainer::cvParamChild(), pwiz::data::ParamContainer::cvParamChildren(), pwiz::data::ParamContainer::cvParams, pwiz::data::UserParam::empty(), pwiz::data::ParamContainer::hasCVParam(), pwiz::data::ParamContainer::hasCVParamChild(), MS_CID, MS_deisotoping, MS_dissociation_method, MS_ETD, MS_ionization_type, MS_ms_level, MS_MSn_spectrum, MS_PQD, MS_reflectron_off, MS_reflectron_on, MS_selected_ion_m_z, MS_spectrum_type, pwiz::data::ParamContainer::paramGroupPtrs, pwiz::data::ParamContainer::set(), unit_assert, UO_dalton, UO_mass_unit, UO_minute, UO_second, pwiz::data::ParamContainer::userParam(), pwiz::data::ParamContainer::userParams, pwiz::data::CVParam::value, pwiz::data::CVParam::valueAs(), and pwiz::data::UserParam::valueAs().

Referenced by main().

188 {
189  ParamContainer pc;
190  pc.cvParams.push_back(MS_reflectron_on);
191  pc.cvParams.push_back(MS_MSn_spectrum);
192  pc.cvParams.push_back(MS_reflectron_off);
193  pc.cvParams.push_back(CVParam(MS_ionization_type, 420));
194  pc.userParams.push_back(UserParam("name1", "1", "type1", UO_second));
195  pc.userParams.push_back(UserParam("name2", "2", "type2", UO_minute));
196 
197  ParamGroupPtr pg(new ParamGroup);
198  pg->cvParams.push_back(CVParam(UO_dalton, 666));
199  pc.paramGroupPtrs.push_back(pg);
200 
205 
208 
213 
216 
217  string result = "goober";
218  result = pc.cvParam(MS_selected_ion_m_z).value;
219  unit_assert(result == "");
220  result = pc.cvParam(MS_ionization_type).value;
221  unit_assert(result == "420");
222  result = pc.cvParam(UO_dalton).value;
223  unit_assert(result == "666");
224 
225  UserParam userParam = pc.userParam("name");
226  unit_assert(userParam.empty());
227  userParam = pc.userParam("name1");
228  unit_assert(userParam.name == "name1");
229  unit_assert(userParam.valueAs<int>() == 1);
230  unit_assert(userParam.type == "type1");
231  unit_assert(userParam.units == UO_second);
232  userParam = pc.userParam("name2");
233  unit_assert(userParam.name == "name2");
234  unit_assert(userParam.valueAs<double>() == 2);
235  unit_assert(userParam.type == "type2");
236  unit_assert(userParam.units == UO_minute);
237  unit_assert(pc.userParam("goober").valueAs<int>() == 0);
238 
239  pc.set(MS_ms_level, 2);
240  unit_assert(pc.cvParam(MS_ms_level).valueAs<int>() == 2);
241  pc.set(MS_ms_level, 3);
242  unit_assert(pc.cvParam(MS_ms_level).valueAs<int>() == 3);
243 
244  pc.set(MS_deisotoping, true);
245  unit_assert(pc.cvParam(MS_deisotoping).valueAs<bool>() == true);
246  pc.set(MS_deisotoping, false);
247  unit_assert(pc.cvParam(MS_deisotoping).valueAs<bool>() == false);
248 
249  pc.set(MS_CID);
250  pc.set(MS_ETD);
251  pg->set(MS_PQD);
252  vector<CVParam> dissociationMethods = pc.cvParamChildren(MS_dissociation_method);
253  unit_assert(dissociationMethods.size() == 3);
254  unit_assert(dissociationMethods[0] == MS_CID);
255  unit_assert(dissociationMethods[1] == MS_ETD);
256  unit_assert(dissociationMethods[2] == MS_PQD);
257 }
MS_deisotoping
deisotoping: The removal of isotope peaks to represent the fragment ion as one data point and is comm...
Definition: cv.hpp:202
std::string value
Definition: ParamTypes.hpp:47
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2212
MS_PQD
PQD (pulsed q dissociation): A process that involves precursor ion activation at high Q...
Definition: cv.hpp:2305
CVParam cvParam(CVID cvid) const
finds cvid in the container:
boost::shared_ptr< ParamGroup > ParamGroupPtr
Definition: ParamTypes.hpp:239
std::vector< CVParam > cvParamChildren(CVID cvid) const
finds all children of cvid in the container:
MS_CID
CID (collision-induced dissociation): The dissociation of an ion after collisional excitation...
Definition: cv.hpp:589
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:1987
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
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2749
UserParam userParam(const std::string &) const
finds UserParam with specified name
bool empty() const
returns true iff name, value, type, and units are all empty
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
bool hasCVParam(CVID cvid) const
returns true iff cvParams contains exact cvid (recursive)
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
UO_mass_unit
mass unit: A unit which is a standard measure of the amount of matter/energy of a physical object...
Definition: cv.hpp:12502
MS_ionization_type
ionization type: The method by which gas phase ions are generated from the sample.
Definition: cv.hpp:124
The base class for elements that may contain cvParams, userParams, or paramGroup references.
Definition: ParamTypes.hpp:244
MS_ETD
ETD (electron transfer dissociation): A process to fragment ions in a mass spectrometer by inducing f...
Definition: cv.hpp:2299
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250
std::vector< ParamGroupPtr > paramGroupPtrs
a collection of references to ParamGroups
Definition: ParamTypes.hpp:247
UO_dalton
dalton: An independently to the base SI units defined mass unit which is equal to one twelfth of the ...
Definition: cv.hpp:13153
MS_reflectron_on
reflectron on: Reflectron is on.
Definition: cv.hpp:475
MS_spectrum_type
spectrum type: Spectrum type.
Definition: cv.hpp:2134
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...
Definition: ParamTypes.hpp:324
UO_minute
minute: A time unit which is equal to 60 seconds.
Definition: cv.hpp:12589
value_type valueAs() const
Templated value access with type conversion.
Definition: ParamTypes.hpp:214
CVID_Unknown
Definition: cv.hpp:97
bool hasCVParamChild(CVID cvid) const
returns true iff cvParams contains a child (is_a) of cvid (recursive)
void set(CVID cvid, const std::string &value="", CVID units=CVID_Unknown)
set/add a CVParam (not recursive)
MS_dissociation_method
dissociation method: Fragmentation method used for dissociation or fragmentation. ...
Definition: cv.hpp:247
MS_reflectron_off
reflectron off: Reflectron is off.
Definition: cv.hpp:472
CVParam cvParamChild(CVID cvid) const
finds child of cvid in the container:
value_type valueAs() const
templated value access with type conversion
Definition: ParamTypes.hpp:112
#define unit_assert(x)
Definition: unit.hpp:85
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44

§ main()

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

Definition at line 260 of file ParamTypesTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, TEST_PROLOG, testIs(), testIsChildOf(), and testParamContainer().

261 {
262  TEST_PROLOG(argc, argv)
263 
264  try
265  {
266  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
267  test();
268  testIs();
269  testIsChildOf();
271  }
272  catch (exception& e)
273  {
274  TEST_FAILED(e.what())
275  }
276  catch (...)
277  {
278  TEST_FAILED("Caught unknown exception.")
279  }
280 
282 }
void testParamContainer()
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
ostream * os_
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
void testIs()
void testIsChildOf()

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 35 of file ParamTypesTest.cpp.

Referenced by main(), WriteCVParam::operator()(), test(), and testIsChildOf().

§ mzmlScanTime

const char* mzmlScanTime
Initial value:
=
"<cvParam cvLabel=\"MS\" accession=\"MS:1000016\" name=\"scan start time\" value=\"5.890500\" "
"unitAccession=\"UO:0000031\" unitName=\"minute\"/>\n"

Definition at line 66 of file ParamTypesTest.cpp.

Referenced by test().

§ mzmlCollisionEnergy

const char* mzmlCollisionEnergy
Initial value:
=
"<cvParam cvLabel=\"MS\" accession=\"MS:1000045\" name=\"collision energy\" value=\"35.00\" "
"unitAccession=\"UO:0000266\" unitName=\"electronvolt\"/>\n"

Definition at line 70 of file ParamTypesTest.cpp.

Referenced by test().