ProteoWizard
Classes | Functions | Variables
IOTest.cpp File Reference
#include "IO.hpp"
#include "Diff.hpp"
#include "References.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

class  TestIterationListener
class  TestIterationListener_WithCancel

Functions

template<typename object_type >
void testObject (const object_type &a)
template<typename object_type >
void testObjectWithMSData (const object_type &a, const MSData &msd)
void testObject_SpectrumList (const SpectrumList &a)
void testObject_ChromatogramList (const ChromatogramList &a)
void testCV ()
void testUserParam ()
void testCVParam ()
void testParamGroup ()
template<typename object_type >
void testNamedParamContainer ()
void testSourceFile ()
void testFileDescription ()
void testSample ()
void testComponent ()
void testComponentList ()
void testSoftware ()
void testInstrumentConfiguration ()
void testProcessingMethod ()
void testDataProcessing ()
void testScanSettings ()
void testPrecursor ()
void testProduct ()
void testScan ()
void testScanList ()
void testBinaryDataArray (const BinaryDataEncoder::Config &config)
void testBinaryDataArray ()
void testBinaryDataArrayExternalMetadata ()
void testSpectrum ()
void testChromatogram ()
void testSpectrumList ()
void testSpectrumListWithPositions ()
void testSpectrumListWriteProgress ()
void testChromatogramList ()
void testChromatogramListWithPositions ()
void testRun ()
void initializeTestData (MSData &msd)
void testMSData ()
void test ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0
const char * bdaWithExternalMetadata

Function Documentation

template<typename object_type >
void testObject ( const object_type &  a)

Definition at line 42 of file IOTest.cpp.

References diff(), os_, pwiz::identdata::IO::read(), unit_assert, and write().

{
if (os_) *os_ << "testObject(): " << typeid(a).name() << endl;
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
object_type b;
istringstream iss(oss.str());
IO::read(iss, b);
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
}
template<typename object_type >
void testObjectWithMSData ( const object_type &  a,
const MSData msd 
)

Definition at line 68 of file IOTest.cpp.

References diff(), os_, pwiz::identdata::IO::read(), unit_assert, and write().

Referenced by testScan(), and testScanList().

{
if (os_) *os_ << "testObject(): " << typeid(a).name() << endl;
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a, msd);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
object_type b;
istringstream iss(oss.str());
IO::read(iss, b);
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
}
void testObject_SpectrumList ( const SpectrumList a)

Definition at line 93 of file IOTest.cpp.

References diff(), os_, pwiz::identdata::IO::read(), unit_assert, and write().

Referenced by testSpectrumList().

{
if (os_) *os_ << "testObject_SpectrumList(): " << endl;
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
MSData dummy;
IO::write(writer, a, dummy);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
istringstream iss(oss.str());
IO::read(iss, b);
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
}
void testObject_ChromatogramList ( const ChromatogramList a)

Definition at line 120 of file IOTest.cpp.

References diff(), os_, pwiz::identdata::IO::read(), unit_assert, and write().

Referenced by testChromatogramList().

{
if (os_) *os_ << "testObject_ChromatogramList(): " << endl;
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
istringstream iss(oss.str());
IO::read(iss, b);
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
}
void testCV ( )

Definition at line 146 of file IOTest.cpp.

References pwiz::cv::CV::fullName, pwiz::cv::CV::id, testObject(), pwiz::cv::CV::URI, and pwiz::cv::CV::version.

{
CV a;
a.URI = "abcd";
a.id = "efgh";
a.fullName = "ijkl";
a.version = "mnop";
}
void testUserParam ( )
void testCVParam ( )

Definition at line 170 of file IOTest.cpp.

References MS_m_z, MS_selected_ion_m_z, testObject(), and UO_second.

{
CVParam b(UO_second, "123.45");
}
void testParamGroup ( )

Definition at line 180 of file IOTest.cpp.

References pwiz::data::ParamContainer::cvParams, MS_ionization_type, MS_m_z, MS_selected_ion_m_z, pwiz::data::ParamContainer::paramGroupPtrs, testObject(), and pwiz::data::ParamContainer::userParams.

{
ParamGroup a("pg");
a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
a.paramGroupPtrs.push_back(ParamGroupPtr(new ParamGroup("pgp")));
}
template<typename object_type >
void testNamedParamContainer ( )

Definition at line 192 of file IOTest.cpp.

References MS_ionization_type, MS_m_z, MS_selected_ion_m_z, and testObject().

{
object_type a;
a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
a.paramGroupPtrs.push_back(ParamGroupPtr(new ParamGroup("pgp")));
}
void testSourceFile ( )

Definition at line 203 of file IOTest.cpp.

References pwiz::data::ParamContainer::cvParams, MS_ionization_type, MS_m_z, MS_selected_ion_m_z, pwiz::data::ParamContainer::paramGroupPtrs, testObject(), and pwiz::data::ParamContainer::userParams.

{
SourceFile a("id123", "name456", "location789");
a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
a.paramGroupPtrs.push_back(ParamGroupPtr(new ParamGroup("pgp")));
}
void testFileDescription ( )

Definition at line 214 of file IOTest.cpp.

References pwiz::msdata::FileDescription::contacts, pwiz::data::ParamContainer::cvParams, pwiz::msdata::FileDescription::fileContent, MS_contact_name, MS_MSn_spectrum, MS_SHA_1, MS_Thermo_RAW_file, pwiz::msdata::FileDescription::sourceFilePtrs, and testObject().

{
SourceFilePtr sf(new SourceFile("1", "tiny1.RAW", "file://F:/data/Exp01"));
sf->cvParams.push_back(MS_Thermo_RAW_file);
sf->cvParams.push_back(MS_SHA_1);
a.sourceFilePtrs.push_back(sf);
Contact contact;
contact.cvParams.push_back(CVParam(MS_contact_name, "Darren"));
a.contacts.push_back(contact);
}
void testSample ( )

Definition at line 232 of file IOTest.cpp.

References pwiz::data::ParamContainer::cvParams, MS_ionization_type, MS_m_z, MS_selected_ion_m_z, pwiz::data::ParamContainer::paramGroupPtrs, testObject(), and pwiz::data::ParamContainer::userParams.

{
Sample a("id123", "name456");
a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
a.paramGroupPtrs.push_back(ParamGroupPtr(new ParamGroup("pgp")));
}
void testComponent ( )

Definition at line 243 of file IOTest.cpp.

References pwiz::msdata::ComponentType_Source, pwiz::data::ParamContainer::cvParams, MS_ionization_type, MS_m_z, MS_selected_ion_m_z, pwiz::data::ParamContainer::paramGroupPtrs, testObject(), and pwiz::data::ParamContainer::userParams.

{
a.userParams.push_back(UserParam("goober", "goo", "peanuts"));
a.cvParams.push_back(CVParam(MS_ionization_type, "420"));
a.cvParams.push_back(CVParam(MS_selected_ion_m_z, "666", MS_m_z));
a.paramGroupPtrs.push_back(ParamGroupPtr(new ParamGroup("pgp")));
}
void testComponentList ( )
void testSoftware ( )
void testInstrumentConfiguration ( )
void testProcessingMethod ( )
void testDataProcessing ( )
void testScanSettings ( )
void testPrecursor ( )
void testProduct ( )
void testScan ( )
void testScanList ( )
void testBinaryDataArray ( const BinaryDataEncoder::Config config)

Definition at line 412 of file IOTest.cpp.

References pwiz::msdata::BinaryDataArray::data, pwiz::msdata::BinaryDataArray::dataProcessingPtr, diff(), os_, pwiz::identdata::IO::read(), unit_assert, and write().

{
if (os_) *os_ << "testBinaryDataArray():\n";
for (int i=0; i<10; i++) a.data.push_back(i);
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a, config);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
istringstream iss(oss.str());
IO::read(iss, b);
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
}
void testBinaryDataArray ( )

Definition at line 441 of file IOTest.cpp.

References pwiz::msdata::BinaryDataEncoder::Config::byteOrder, pwiz::msdata::BinaryDataEncoder::Config::precision, and testBinaryDataArray().

{
config.precision = BinaryDataEncoder::Precision_32;
config.byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
config.precision = BinaryDataEncoder::Precision_64;
config.byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
//config.precision = BinaryDataEncoder::Precision_64;
//config.compression = BinaryDataEncoder::Compression_Zlib;
//testBinaryDataArray(config);
}
void testBinaryDataArrayExternalMetadata ( )

Definition at line 466 of file IOTest.cpp.

References bdaWithExternalMetadata, pwiz::msdata::BinaryDataArray::data, MS_64_bit_float, MS_m_z_array, MS_no_compression, pwiz::msdata::MSData::paramGroupPtrs, pwiz::identdata::IO::read(), and unit_assert.

Referenced by test().

{
// instantiate an MSData object with the binary array metadata held in a ParamGroup
MSData msd;
pg->id = "mz_params";
pg->cvParams.push_back(MS_m_z_array);
pg->cvParams.push_back(MS_64_bit_float);
pg->cvParams.push_back(MS_no_compression);
msd.paramGroupPtrs.push_back(pg);
istringstream is(bdaWithExternalMetadata);
// test read with MSData reference
IO::read(is, bda, &msd);
unit_assert(bda.data.size() == 15);
for (size_t i=0; i<15; i++)
unit_assert(bda.data[i] == i);
}
void testSpectrum ( )

Definition at line 491 of file IOTest.cpp.

References pwiz::msdata::Spectrum::binaryDataArrayPtrs, pwiz::data::ParamContainer::cvParams, pwiz::msdata::Spectrum::dataProcessingPtr, pwiz::msdata::Spectrum::defaultArrayLength, diff(), pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::SpectrumIdentity::index, MS_charge_state, MS_collision_energy, MS_collision_induced_dissociation, MS_filter_string, MS_intensity_array, MS_ionization_type, MS_m_z, MS_m_z_array, MS_MSn_spectrum, MS_reflectron_on, MS_scan_start_time, MS_selected_ion_m_z, os_, pwiz::msdata::Spectrum::precursors, pwiz::msdata::Spectrum::products, pwiz::identdata::IO::read(), ReadBinaryData, pwiz::msdata::Spectrum::scanList, pwiz::msdata::ScanList::scans, pwiz::data::ParamContainer::set(), pwiz::msdata::SpectrumIdentity::sourceFilePosition, pwiz::msdata::Spectrum::sourceFilePtr, unit_assert, UO_electronvolt, and write().

{
if (os_) *os_ << "testSpectrum():\n";
a.index = 123;
a.id = "goo";
for (size_t i=0; i<a.defaultArrayLength; i++)
a.binaryDataArrayPtrs.back()->data.push_back(i);
for (size_t i=0; i<a.defaultArrayLength; i++)
a.binaryDataArrayPtrs.back()->data.push_back(i*2);
a.cvParams.push_back(MS_reflectron_on);
a.cvParams.push_back(MS_MSn_spectrum);
a.precursors.push_back(Precursor());
a.precursors.back().spectrumID = "19";
a.precursors.back().selectedIons.resize(1);
a.precursors.back().selectedIons[0].set(MS_selected_ion_m_z, 445.34, MS_m_z);
a.precursors.back().selectedIons[0].set(MS_charge_state, 2);
a.precursors.back().activation.set(MS_collision_energy, 35.00, UO_electronvolt);
a.products.push_back(Product());
a.products.back().isolationWindow.set(MS_ionization_type, "420");
a.scanList.scans.push_back(Scan());
Scan& scan = a.scanList.scans.back();
scan.set(MS_scan_start_time, 4.20);
scan.set(MS_filter_string, "doobie");
a.scanList.scans.push_back(Scan());
Scan& scan2 = a.scanList.scans.back();
scan2.set(MS_scan_start_time, 4.21);
scan2.set(MS_filter_string, "doo");
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
MSData dummy;
IO::write(writer, a, dummy);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
istringstream iss(oss.str());
unit_assert(b.sourceFilePosition == 0); // not -1
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
// test IgnoreBinaryData
iss.seekg(0);
IO::read(iss, c); // default = IgnoreBinaryData
unit_assert(c.sourceFilePosition == 0); // not -1
diff(a, c);
}
void testChromatogram ( )

Definition at line 569 of file IOTest.cpp.

References pwiz::msdata::Chromatogram::binaryDataArrayPtrs, pwiz::data::ParamContainer::cvParams, pwiz::msdata::Chromatogram::dataProcessingPtr, pwiz::msdata::Chromatogram::defaultArrayLength, diff(), pwiz::msdata::ChromatogramIdentity::id, pwiz::msdata::ChromatogramIdentity::index, MS_intensity_array, MS_time_array, MS_total_ion_current_chromatogram, os_, pwiz::identdata::IO::read(), ReadBinaryData, pwiz::msdata::ChromatogramIdentity::sourceFilePosition, unit_assert, and write().

{
if (os_) *os_ << "testChromatogram():\n";
a.index = 123;
a.id = "goo";
for (size_t i=0; i<a.defaultArrayLength; i++)
a.binaryDataArrayPtrs.back()->data.push_back(i);
for (size_t i=0; i<a.defaultArrayLength; i++)
a.binaryDataArrayPtrs.back()->data.push_back(i*2);
a.cvParams.push_back(MS_total_ion_current_chromatogram); // TODO: fix when CV has appropriate terms
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream
istringstream iss(oss.str());
unit_assert(b.sourceFilePosition == 0); // not -1
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
// test IgnoreBinaryData
iss.seekg(0);
IO::read(iss, c); // default = IgnoreBinaryData
unit_assert(c.sourceFilePosition == 0); // not -1
diff(a, c);
}
void testSpectrumList ( )

Definition at line 623 of file IOTest.cpp.

References pwiz::msdata::SpectrumListSimple::dp, pwiz::msdata::SpectrumListSimple::spectra, and testObject_SpectrumList().

{
SpectrumPtr spectrum1(new Spectrum);
spectrum1->id = "goober";
spectrum1->index = 0;
spectrum1->defaultArrayLength = 666;
spectrum1->userParams.push_back(UserParam("description1"));
SpectrumPtr spectrum2(new Spectrum);
spectrum2->id = "raisinet";
spectrum2->index = 1;
spectrum2->defaultArrayLength = 667;
spectrum2->userParams.push_back(UserParam("description2"));
a.spectra.push_back(spectrum1);
a.spectra.push_back(spectrum2);
}
void testSpectrumListWithPositions ( )

Definition at line 647 of file IOTest.cpp.

References os_, pwiz::msdata::SpectrumListSimple::spectra, unit_assert, and write().

Referenced by test().

{
if (os_) *os_ << "testSpectrumListWithPositions()\n ";
SpectrumPtr spectrum1(new Spectrum);
spectrum1->id = "goober";
spectrum1->index = 0;
spectrum1->defaultArrayLength = 666;
spectrum1->userParams.push_back(UserParam("description1"));
SpectrumPtr spectrum2(new Spectrum);
spectrum2->id = "raisinet";
spectrum2->index = 1;
spectrum2->defaultArrayLength = 667;
spectrum2->userParams.push_back(UserParam("description2"));
a.spectra.push_back(spectrum1);
a.spectra.push_back(spectrum2);
ostringstream oss;
XMLWriter writer(oss);
vector<stream_offset> positions;
MSData dummy;
IO::write(writer, a, dummy, BinaryDataEncoder::Config(), &positions);
if (os_)
{
copy(positions.begin(), positions.end(), ostream_iterator<stream_offset>(*os_, " "));
*os_ << endl << oss.str() << endl;
*os_ << "\n\n";
}
unit_assert(positions.size() == 2);
unit_assert(positions[0] == 27);
unit_assert(positions[1] == 179);
}
void testSpectrumListWriteProgress ( )

Definition at line 722 of file IOTest.cpp.

References pwiz::util::IterationListenerRegistry::addListener(), TestIterationListener::indices(), TestIterationListener_WithCancel::indices(), boost::lexical_cast(), os_, pwiz::msdata::SpectrumListSimple::spectra, unit_assert, and write().

Referenced by test().

{
if (os_) *os_ << "testSpectrumListWriteProgress()\n ";
for (size_t i=0; i<11; i++)
{
SpectrumPtr spectrum(new Spectrum);
spectrum->id = "goober_" + lexical_cast<string>(i);
spectrum->index = i;
spectrum->defaultArrayLength = 666;
a.spectra.push_back(spectrum);
}
ostringstream oss;
XMLWriter writer(oss);
TestIterationListener& listener = *boost::static_pointer_cast<TestIterationListener>(listenerPtr);
registry.addListener(listenerPtr, 3); // callbacks: 0,2,5,8,10
MSData dummy;
IO::write(writer, a, dummy, BinaryDataEncoder::Config(), 0, &registry);
if (os_)
{
*os_ << "callback indices: ";
copy(listener.indices().begin(), listener.indices().end(),
ostream_iterator<size_t>(*os_, " "));
*os_ << "\n\n";
}
unit_assert(listener.indices().size() == 5);
unit_assert(listener.indices()[0] == 0);
unit_assert(listener.indices()[1] == 2);
unit_assert(listener.indices()[2] == 5);
unit_assert(listener.indices()[3] == 8);
unit_assert(listener.indices()[4] == 10);
// test #2, this time with cancel at index 6
TestIterationListener_WithCancel& cancelListener = *boost::static_pointer_cast<TestIterationListener_WithCancel>(cancelListenerPtr);
registry2.addListener(cancelListenerPtr, 3); // callbacks: 0,2, cancel at 5
ostringstream oss2;
XMLWriter writer2(oss2);
IO::write(writer2, a, dummy, BinaryDataEncoder::Config(), 0, &registry2);
if (os_)
{
*os_ << "callback indices: ";
copy(cancelListener.indices().begin(), cancelListener.indices().end(),
ostream_iterator<size_t>(*os_, " "));
*os_ << "\n\n";
}
unit_assert(cancelListener.indices().size() == 2);
unit_assert(cancelListener.indices()[0] == 0);
unit_assert(cancelListener.indices()[1] == 2);
}
void testChromatogramList ( )

Definition at line 788 of file IOTest.cpp.

References pwiz::msdata::ChromatogramListSimple::chromatograms, pwiz::msdata::ChromatogramListSimple::dp, and testObject_ChromatogramList().

{
ChromatogramPtr chromatogram1(new Chromatogram);
chromatogram1->id = "goober";
chromatogram1->index = 0;
chromatogram1->defaultArrayLength = 666;
ChromatogramPtr chromatogram2(new Chromatogram);
chromatogram2->id = "raisinet";
chromatogram2->index = 1;
chromatogram2->defaultArrayLength = 667;
a.chromatograms.push_back(chromatogram1);
a.chromatograms.push_back(chromatogram2);
}
void testChromatogramListWithPositions ( )

Definition at line 810 of file IOTest.cpp.

References pwiz::msdata::ChromatogramListSimple::chromatograms, os_, unit_assert, and write().

Referenced by test().

{
if (os_) *os_ << "testChromatogramListWithPositions()\n ";
ChromatogramPtr chromatogram1(new Chromatogram);
chromatogram1->id = "goober";
chromatogram1->index = 0;
chromatogram1->defaultArrayLength = 666;
ChromatogramPtr chromatogram2(new Chromatogram);
chromatogram2->id = "raisinet";
chromatogram2->index = 1;
chromatogram2->defaultArrayLength = 667;
a.chromatograms.push_back(chromatogram1);
a.chromatograms.push_back(chromatogram2);
ostringstream oss;
XMLWriter writer(oss);
vector<stream_offset> positions;
IO::write(writer, a, BinaryDataEncoder::Config(), &positions);
if (os_)
{
copy(positions.begin(), positions.end(), ostream_iterator<stream_offset>(*os_, " "));
*os_ << endl << oss.str() << endl;
*os_ << "\n\n";
}
unit_assert(positions.size() == 2);
unit_assert(positions[0] == 31);
unit_assert(positions[1] == 113);
}
void testRun ( )

Definition at line 847 of file IOTest.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::msdata::Run::chromatogramListPtr, pwiz::msdata::Run::defaultInstrumentConfigurationPtr, pwiz::msdata::Run::defaultSourceFilePtr, diff(), pwiz::msdata::Run::id, IgnoreSpectrumList, os_, pwiz::identdata::IO::read(), pwiz::msdata::Run::samplePtr, pwiz::msdata::Run::spectrumListPtr, pwiz::msdata::Run::startTimeStamp, unit_assert, and write().

{
if (os_) *os_ << "testRun():\n";
Run a;
a.id = "goober";
a.samplePtr = SamplePtr(new Sample("sample"));
a.startTimeStamp = "20 April 2004 4:20pm";
// spectrumList
shared_ptr<SpectrumListSimple> spectrumListSimple(new SpectrumListSimple);
SpectrumPtr spectrum1(new Spectrum);
spectrum1->id = "goober";
spectrum1->index = 0;
spectrum1->defaultArrayLength = 666;
spectrum1->userParams.push_back(UserParam("description1"));
SpectrumPtr spectrum2(new Spectrum);
spectrum2->id = "raisinet";
spectrum2->index = 1;
spectrum2->defaultArrayLength = 667;
spectrum2->userParams.push_back(UserParam("description2"));
spectrumListSimple->spectra.push_back(spectrum1);
spectrumListSimple->spectra.push_back(spectrum2);
a.spectrumListPtr = spectrumListSimple;
// chromatogramList
shared_ptr<ChromatogramListSimple> chromatogramListSimple(new ChromatogramListSimple);
ChromatogramPtr chromatogram1(new Chromatogram);
chromatogram1->id = "goober";
chromatogram1->index = 0;
chromatogram1->defaultArrayLength = 666;
ChromatogramPtr chromatogram2(new Chromatogram);
chromatogram2->id = "raisinet";
chromatogram2->index = 1;
chromatogram2->defaultArrayLength = 667;
chromatogramListSimple->chromatograms.push_back(chromatogram1);
chromatogramListSimple->chromatograms.push_back(chromatogram2);
a.chromatogramListPtr = chromatogramListSimple;
// write 'a' out to a stream
MSData dummy;
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a, dummy);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream, ignoring SpectrumList (default)
Run b;
istringstream iss(oss.str());
IO::read(iss, b, IO::IgnoreSpectrumList); // IO::IgnoreSpectrumList
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
unit_assert(diff.a_b.spectrumListPtr.get());
unit_assert(diff.a_b.spectrumListPtr->size() == 1);
unit_assert(diff.a_b.spectrumListPtr->spectrum(0)->userParams.size() == 1);
// read 'c' in from stream, reading SpectrumList
Run c;
iss.seekg(0);
IO::read(iss, c, IO::ReadSpectrumList);
// compare 'a' and 'c'
diff(a,c);
if (diff && os_) *os_ << "diff:\n" << diff << endl;
// remove SpectrumList and ChromatogramList from a, and compare to b
a.spectrumListPtr.reset();
diff(a, b);
}
void initializeTestData ( MSData msd)

Definition at line 944 of file IOTest.cpp.

References pwiz::msdata::MSData::accession, pwiz::msdata::Precursor::activation, pwiz::msdata::Spectrum::binaryDataArrayPtrs, pwiz::msdata::Chromatogram::binaryDataArrayPtrs, pwiz::msdata::Run::chromatogramListPtr, pwiz::msdata::FileDescription::contacts, pwiz::cv::cv(), pwiz::data::ParamContainer::cvParams, pwiz::msdata::MSData::cvs, pwiz::msdata::MSData::dataProcessingPtrs, pwiz::msdata::Spectrum::defaultArrayLength, pwiz::msdata::Chromatogram::defaultArrayLength, pwiz::msdata::Run::defaultInstrumentConfigurationPtr, pwiz::msdata::Run::defaultSourceFilePtr, e(), pwiz::msdata::FileDescription::fileContent, pwiz::msdata::MSData::fileDescription, pwiz::cv::CV::fullName, pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::ChromatogramIdentity::id, pwiz::msdata::Run::id, pwiz::msdata::MSData::id, pwiz::cv::CV::id, pwiz::msdata::SpectrumIdentity::index, pwiz::msdata::ChromatogramIdentity::index, pwiz::msdata::Scan::instrumentConfigurationPtr, pwiz::msdata::MSData::instrumentConfigurationPtrs, MS_base_peak_intensity, MS_base_peak_m_z, MS_Bioworks, MS_centroid_spectrum, MS_charge_deconvolution, MS_charge_state, MS_collision_energy, MS_collision_induced_dissociation, MS_contact_address, MS_contact_email, MS_contact_name, MS_contact_URL, MS_Conversion_to_mzML, MS_deisotoping, MS_electron_multiplier, MS_filter_string, MS_full_scan, MS_highest_observed_m_z, MS_instrument_serial_number, MS_intensity_array, MS_LCQ_Deca, MS_lowest_observed_m_z, MS_m_z, MS_m_z_array, MS_ms_level, MS_MSn_spectrum, MS_nanoelectrospray, MS_peak_picking, MS_positive_scan, MS_pwiz, MS_quadrupole_ion_trap, MS_scan_start_time, MS_scan_window_lower_limit, MS_scan_window_upper_limit, MS_selected_ion_m_z, MS_SHA_1, MS_Thermo_RAW_file, MS_time_array, MS_total_ion_current, MS_total_ion_current_chromatogram, MS_Xcalibur, pwiz::msdata::ProcessingMethod::order, pwiz::data::ParamContainer::paramGroupPtrs, pwiz::msdata::MSData::paramGroupPtrs, pwiz::msdata::Spectrum::precursors, pwiz::msdata::MSData::run, pwiz::msdata::Run::samplePtr, pwiz::msdata::MSData::samplePtrs, pwiz::msdata::Spectrum::scanList, pwiz::msdata::ScanList::scans, pwiz::msdata::MSData::scanSettingsPtrs, pwiz::msdata::Scan::scanWindows, pwiz::msdata::Precursor::selectedIons, pwiz::data::ParamContainer::set(), pwiz::msdata::ProcessingMethod::softwarePtr, pwiz::msdata::MSData::softwarePtrs, pwiz::msdata::FileDescription::sourceFilePtrs, pwiz::msdata::Precursor::spectrumID, pwiz::msdata::Run::spectrumListPtr, pwiz::msdata::Run::startTimeStamp, UO_electronvolt, UO_minute, pwiz::cv::CV::URI, pwiz::data::ParamContainer::userParams, and pwiz::cv::CV::version.

Referenced by testMSData().

{
msd.accession = "test accession";
msd.id = "test id";
// cvList
msd.cvs.resize(1);
CV& cv = msd.cvs.front();
cv.URI = "http://psidev.sourceforge.net/ms/xml/mzdata/psi-ms.2.0.2.obo";
cv.id = "MS";
cv.fullName = "Proteomics Standards Initiative Mass Spectrometry Ontology";
cv.version = "2.0.2";
// fileDescription
fc.cvParams.push_back(MS_MSn_spectrum);
fc.userParams.push_back(UserParam("number of cats", "4"));
sfp->id = "1";
sfp->name = "tiny1.RAW";
sfp->location = "file://F:/data/Exp01";
sfp->cvParams.push_back(MS_Thermo_RAW_file);
sfp->cvParams.push_back(CVParam(MS_SHA_1,"71be39fb2700ab2f3c8b2234b91274968b6899b1"));
msd.fileDescription.sourceFilePtrs.push_back(sfp);
SourceFilePtr sfp_parameters(new SourceFile("sf_parameters", "parameters.par", "file:///C:/settings/"));
msd.fileDescription.sourceFilePtrs.push_back(sfp_parameters);
msd.fileDescription.contacts.resize(1);
Contact& contact = msd.fileDescription.contacts.front();
contact.cvParams.push_back(CVParam(MS_contact_name, "William Pennington"));
contact.cvParams.push_back(CVParam(MS_contact_address,
"Higglesworth University, 12 Higglesworth Avenue, 12045, HI, USA"));
contact.cvParams.push_back(CVParam(MS_contact_URL, "http://www.higglesworth.edu/"));
contact.cvParams.push_back(CVParam(MS_contact_email, "wpennington@higglesworth.edu"));
// paramGroupList
pg1->id = "CommonMS1SpectrumParams";
pg1->cvParams.push_back(MS_positive_scan);
pg1->cvParams.push_back(MS_full_scan);
msd.paramGroupPtrs.push_back(pg1);
pg2->id = "CommonMS2SpectrumParams";
pg2->cvParams.push_back(MS_positive_scan);
pg2->cvParams.push_back(MS_full_scan);
msd.paramGroupPtrs.push_back(pg2);
// sampleList
SamplePtr samplePtr(new Sample);
samplePtr->id = "1";
samplePtr->name = "Sample1";
msd.samplePtrs.push_back(samplePtr);
// instrumentConfigurationList
InstrumentConfigurationPtr instrumentConfigurationPtr(new InstrumentConfiguration);
instrumentConfigurationPtr->id = "LCQ Deca";
instrumentConfigurationPtr->cvParams.push_back(MS_LCQ_Deca);
instrumentConfigurationPtr->cvParams.push_back(CVParam(MS_instrument_serial_number,"23433"));
instrumentConfigurationPtr->componentList.push_back(Component(MS_nanoelectrospray, 1));
instrumentConfigurationPtr->componentList.push_back(Component(MS_quadrupole_ion_trap, 2));
instrumentConfigurationPtr->componentList.push_back(Component(MS_electron_multiplier, 3));
SoftwarePtr softwareXcalibur(new Software);
softwareXcalibur->id = "Xcalibur";
softwareXcalibur->set(MS_Xcalibur);
softwareXcalibur->version = "2.0.5";
instrumentConfigurationPtr->softwarePtr = softwareXcalibur;
msd.instrumentConfigurationPtrs.push_back(instrumentConfigurationPtr);
// softwareList
SoftwarePtr softwareBioworks(new Software);
softwareBioworks->id = "Bioworks";
softwareBioworks->set(MS_Bioworks);
softwareBioworks->version = "3.3.1 sp1";
SoftwarePtr software_pwiz(new Software);
software_pwiz->id = "pwiz";
software_pwiz->set(MS_pwiz);
software_pwiz->version = "1.0";
msd.softwarePtrs.push_back(softwareBioworks);
msd.softwarePtrs.push_back(software_pwiz);
msd.softwarePtrs.push_back(softwareXcalibur);
// dataProcessingList
dpXcalibur->id = "Xcalibur Processing";
ProcessingMethod procXcal;
procXcal.order = 1;
procXcal.softwarePtr = softwareXcalibur;
procXcal.cvParams.push_back(CVParam(MS_deisotoping, false));
procXcal.cvParams.push_back(CVParam(MS_charge_deconvolution, false));
procXcal.cvParams.push_back(CVParam(MS_peak_picking, true));
dpXcalibur->processingMethods.push_back(procXcal);
DataProcessingPtr dp_msconvert(new DataProcessing);
dp_msconvert->id = "pwiz conversion";
ProcessingMethod proc_msconvert;
proc_msconvert.order = 2;
proc_msconvert.softwarePtr = software_pwiz;
proc_msconvert.cvParams.push_back(MS_Conversion_to_mzML);
dp_msconvert->processingMethods.push_back(proc_msconvert);
msd.dataProcessingPtrs.push_back(dpXcalibur);
msd.dataProcessingPtrs.push_back(dp_msconvert);
ScanSettingsPtr as1(new ScanSettings("as1"));
as1->sourceFilePtrs.push_back(sfp_parameters);
Target t1;
t1.set(MS_m_z, 1000);
Target t2;
t2.set(MS_m_z, 1200);
as1->targets.push_back(t1);
as1->targets.push_back(t2);
msd.scanSettingsPtrs.push_back(as1);
// run
msd.run.id = "Exp01";
msd.run.defaultInstrumentConfigurationPtr = instrumentConfigurationPtr;
msd.run.samplePtr = samplePtr;
msd.run.startTimeStamp = "2007-06-27T15:23:45.00035";
shared_ptr<SpectrumListSimple> spectrumList(new SpectrumListSimple);
msd.run.spectrumListPtr = spectrumList;
spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
Spectrum& s19 = *spectrumList->spectra[0];
s19.id = "S19";
s19.index = 0;
s19.cvParams.push_back(MS_MSn_spectrum);
s19.set(MS_ms_level, 1);
s19.cvParams.push_back(CVParam(MS_lowest_observed_m_z, 400.39));
s19.cvParams.push_back(CVParam(MS_highest_observed_m_z, 1795.56));
s19.cvParams.push_back(CVParam(MS_base_peak_m_z, 445.347));
s19.cvParams.push_back(CVParam(MS_base_peak_intensity, 120053));
s19.cvParams.push_back(CVParam(MS_total_ion_current, 1.66755e+007));
s19.scanList.scans.push_back(Scan());
Scan& s19scan = s19.scanList.scans.back();
s19scan.instrumentConfigurationPtr = instrumentConfigurationPtr;
s19scan.paramGroupPtrs.push_back(pg1);
s19scan.cvParams.push_back(CVParam(MS_scan_start_time, 5.890500, UO_minute));
s19scan.cvParams.push_back(CVParam(MS_filter_string, "+ c NSI Full ms [ 400.00-1800.00]"));
s19scan.scanWindows.resize(1);
ScanWindow& window = s19scan.scanWindows.front();
window.cvParams.push_back(CVParam(MS_scan_window_lower_limit, 400.000000));
window.cvParams.push_back(CVParam(MS_scan_window_upper_limit, 1800.000000));
s19_mz->dataProcessingPtr = dpXcalibur;
s19_mz->cvParams.push_back(MS_m_z_array);
s19_mz->data.resize(10);
for (int i=0; i<10; i++)
s19_mz->data[i] = i;
BinaryDataArrayPtr s19_intensity(new BinaryDataArray);
s19_intensity->dataProcessingPtr = dpXcalibur;
s19_intensity->cvParams.push_back(MS_intensity_array);
s19_intensity->data.resize(10);
for (int i=0; i<10; i++)
s19_intensity->data[i] = 10-i;
s19.binaryDataArrayPtrs.push_back(s19_mz);
s19.binaryDataArrayPtrs.push_back(s19_intensity);
Spectrum& s20 = *spectrumList->spectra[1];
s20.id = "S20";
s20.index = 1;
s20.cvParams.push_back(MS_MSn_spectrum);
s20.set(MS_ms_level, 2);
s20.cvParams.push_back(CVParam(MS_lowest_observed_m_z, 320.39));
s20.cvParams.push_back(CVParam(MS_highest_observed_m_z, 1003.56));
s20.cvParams.push_back(CVParam(MS_base_peak_m_z, 456.347));
s20.cvParams.push_back(CVParam(MS_base_peak_intensity, 23433));
s20.cvParams.push_back(CVParam(MS_total_ion_current, 1.66755e+007));
s20.precursors.resize(1);
Precursor& precursor = s20.precursors.front();
precursor.spectrumID= s19.id;
precursor.selectedIons.resize(1);
precursor.selectedIons[0].cvParams.push_back(CVParam(MS_selected_ion_m_z, 445.34));
precursor.selectedIons[0].cvParams.push_back(CVParam(MS_charge_state, 2));
s20.scanList.scans.push_back(Scan());
Scan& s20scan = s20.scanList.scans.back();
s20scan.instrumentConfigurationPtr = instrumentConfigurationPtr;
s20scan.paramGroupPtrs.push_back(pg2);
s20scan.cvParams.push_back(CVParam(MS_scan_start_time, 5.990500, UO_minute));
s20scan.cvParams.push_back(CVParam(MS_filter_string, "+ c d Full ms2 445.35@cid35.00 [ 110.00-905.00]"));
s20scan.scanWindows.resize(1);
ScanWindow& window2 = s20scan.scanWindows.front();
window2.cvParams.push_back(CVParam(MS_scan_window_lower_limit, 110.000000));
window2.cvParams.push_back(CVParam(MS_scan_window_upper_limit, 905.000000));
s20_mz->dataProcessingPtr = dpXcalibur;
s20_mz->cvParams.push_back(MS_m_z_array);
s20_mz->data.resize(10);
for (int i=0; i<10; i++)
s20_mz->data[i] = i;
BinaryDataArrayPtr s20_intensity(new BinaryDataArray);
s20_intensity->dataProcessingPtr = dpXcalibur;
s20_intensity->cvParams.push_back(MS_intensity_array);
s20_intensity->data.resize(10);
for (int i=0; i<10; i++)
s20_intensity->data[i] = 10-i;
s20.binaryDataArrayPtrs.push_back(s20_mz);
s20.binaryDataArrayPtrs.push_back(s20_intensity);
// chromatograms
shared_ptr<ChromatogramListSimple> chromatogramList(new ChromatogramListSimple);
msd.run.chromatogramListPtr = chromatogramList;
chromatogramList->chromatograms.push_back(ChromatogramPtr(new Chromatogram));
Chromatogram& tic = *chromatogramList->chromatograms[0];
tic.id = "tic";
tic.index = 0;
tic_time->dataProcessingPtr = dp_msconvert;
tic_time->cvParams.push_back(MS_time_array);
tic_time->data.resize(10);
for (int i=0; i<10; i++)
tic_time->data[i] = i;
BinaryDataArrayPtr tic_intensity(new BinaryDataArray);
tic_intensity->dataProcessingPtr = dp_msconvert;
tic_intensity->cvParams.push_back(MS_intensity_array);
tic_intensity->data.resize(10);
for (int i=0; i<10; i++)
tic_intensity->data[i] = 10-i;
tic.binaryDataArrayPtrs.push_back(tic_time);
tic.binaryDataArrayPtrs.push_back(tic_intensity);
}
void testMSData ( )

Definition at line 1213 of file IOTest.cpp.

References pwiz::data::Diff< object_type, config_type, object_result_type >::a_b, pwiz::msdata::Run::chromatogramListPtr, diff(), initializeTestData(), os_, pwiz::identdata::IO::read(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and write().

{
if (os_) *os_ << "testMSData():\n";
MSData a;
// write 'a' out to a stream
ostringstream oss;
XMLWriter writer(oss);
IO::write(writer, a);
if (os_) *os_ << oss.str() << endl;
// read 'b' in from stream, ignoring SpectrumList (default)
MSData b;
istringstream iss(oss.str());
IO::read(iss, b); // IO::IgnoreSpectrumList
// compare 'a' and 'b'
if (diff && os_) *os_ << "diff:\n" << diff << endl;
unit_assert(diff.a_b.run.spectrumListPtr.get());
unit_assert(diff.a_b.run.spectrumListPtr->size() == 1);
unit_assert(diff.a_b.run.spectrumListPtr->spectrum(0)->userParams.size() == 1);
// read 'c' in from stream, reading SpectrumList
MSData c;
iss.seekg(0);
IO::read(iss, c, IO::ReadSpectrumList);
// compare 'a' and 'c'
diff(a,c);
if (diff && os_) *os_ << "diff:\n" << diff << endl;
// remove SpectrumList and ChromatogramList from a, and compare to b
a.run.spectrumListPtr.reset();
diff(a, b);
}
void test ( )

Definition at line 1263 of file IOTest.cpp.

References testBinaryDataArray(), testBinaryDataArrayExternalMetadata(), testChromatogram(), testChromatogramList(), testChromatogramListWithPositions(), testComponent(), testComponentList(), testCV(), testCVParam(), testDataProcessing(), testFileDescription(), testInstrumentConfiguration(), testMSData(), testParamGroup(), testPrecursor(), testProcessingMethod(), testProduct(), testRun(), testSample(), testScan(), testScanList(), testScanSettings(), testSoftware(), testSourceFile(), testSpectrum, testSpectrumList(), testSpectrumListWithPositions(), testSpectrumListWriteProgress(), and testUserParam().

{
testCV();
testNamedParamContainer<FileContent>();
testNamedParamContainer<Contact>();
testNamedParamContainer<Target>();
testNamedParamContainer<IsolationWindow>();
testNamedParamContainer<SelectedIon>();
testNamedParamContainer<Activation>();
testNamedParamContainer<ScanWindow>();
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 1304 of file IOTest.cpp.

References e(), os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG_EX.

{
TEST_PROLOG_EX(argc, argv, "_MSData")
try
{
if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
test();
if (os_) *os_ << "ok\n";
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 38 of file IOTest.cpp.

const char* bdaWithExternalMetadata
Initial value:
"\
<binaryDataArray encodedLength=\"160\" arrayLength=\"15\"> \
<referenceableParamGroupRef ref=\"mz_params\"/> \
<binary>AAAAAAAAAAAAAAAAAADwPwAAAAAAAABAAAAAAAAACEAAAAAAAAAQQAAAAAAAABRAAAAAAAAAGEAAAAAAAAAcQAAAAAAAACBAAAAAAAAAIkAAAAAAAAAkQAAAAAAAACZAAAAAAAAAKEAAAAAAAAAqQAAAAAAAACxA</binary> \
</binaryDataArray>"

Definition at line 459 of file IOTest.cpp.

Referenced by testBinaryDataArrayExternalMetadata().