ProteoWizard
Functions | Variables
SpectrumList_MGF_Test.cpp File Reference
#include "SpectrumList_MGF.hpp"
#include "TextWriter.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 ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0
const char * testMGF = "END IONS\n"

Function Documentation

void test ( )

Definition at line 58 of file SpectrumList_MGF_Test.cpp.

References e(), pwiz::msdata::MSData::instrumentConfigurationPtrs, MS_base_peak_intensity, MS_base_peak_m_z, MS_charge_state, MS_LCQ_Deca, MS_ms_level, MS_scan_start_time, MS_selected_ion_m_z, MS_spectrum_title, MS_total_ion_current, os_, testMGF, unit_assert, unit_assert_equal, and write().

{
if (os_) *os_ << "test()\n";
if (os_) *os_ << "mgf:\n" << testMGF << endl;
shared_ptr<istream> is(new istringstream(testMGF));
// dummy would normally be read in from file
MSData dummy;
dummy.instrumentConfigurationPtrs.back()->cvParams.push_back(MS_LCQ_Deca);
dummy.instrumentConfigurationPtrs.back()->userParams.push_back(UserParam("doobie", "420"));
SpectrumListPtr sl = SpectrumList_MGF::create(is, dummy);
if (os_)
{
write(*sl);
*os_ << endl;
}
// check easy functions
unit_assert(sl.get());
unit_assert(sl->size() == 2);
unit_assert(sl->find("index=0") == 0);
unit_assert(sl->find("index=1") == 1);
// find the second spectrum by TITLE field
IndexList list = sl->findSpotID("small.pwiz.0004.0004.2");
unit_assert(list.size() == 1);
unit_assert(list[0] == 1);
// look for a non-existent TITLE field
list.clear();
list = sl->findSpotID("fake title string");
unit_assert(list.size() == 0);
// check scan 0
unit_assert(sl->spectrumIdentity(0).index == 0);
unit_assert(sl->spectrumIdentity(0).id == "index=0");
unit_assert(sl->spectrumIdentity(0).sourceFilePosition != -1);
SpectrumPtr s = sl->spectrum(0, false);
unit_assert(s.get());
unit_assert(s->id == "index=0");
unit_assert(s->index == 0);
unit_assert(s->sourceFilePosition != -1);
unit_assert(s->cvParam(MS_spectrum_title).value == "small.pwiz.0003.0003.2");
unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
unit_assert_equal(s->cvParam(MS_total_ion_current).valueAs<double>(), 64.992226, 1e-5);
unit_assert_equal(s->cvParam(MS_base_peak_m_z).valueAs<double>(), 231.38884, 1e-5);
unit_assert_equal(s->cvParam(MS_base_peak_intensity).valueAs<double>(), 26.545113, 1e-5);
unit_assert(s->precursors.size() == 1);
Precursor& precursor0 = s->precursors[0];
unit_assert(precursor0.selectedIons.size() == 1);
unit_assert_equal(precursor0.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>(), 810.79, 1e-5);
unit_assert(s->defaultArrayLength == 3);
unit_assert(s->binaryDataArrayPtrs.empty());
s = sl->spectrum(0, true);
unit_assert(s->defaultArrayLength == 3);
unit_assert(s->binaryDataArrayPtrs.size() == 2);
unit_assert(!s->binaryDataArrayPtrs[0]->data.empty() && !s->binaryDataArrayPtrs[1]->data.empty());
vector<MZIntensityPair> pairs;
s->getMZIntensityPairs(pairs);
if (os_)
{
*os_ << "scan 0:\n";
copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
*os_ << endl;
}
// check scan 1
unit_assert(sl->spectrumIdentity(1).index == 1);
unit_assert(sl->spectrumIdentity(1).id == "index=1");
s = sl->spectrum(1, true);
unit_assert(s.get());
unit_assert(s->id == "index=1");
unit_assert(s->index == 1);
unit_assert(s->sourceFilePosition != -1);
unit_assert(s->cvParam(MS_spectrum_title).value == "small.pwiz.0004.0004.2");
unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);
unit_assert(s->scanList.scans.size() == 1);
unit_assert_equal(s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds(), 123.456, 1e-5);
unit_assert(s->precursors.size() == 1);
Precursor& precursor1 = s->precursors[0];
unit_assert(precursor1.selectedIons.size() == 1);
unit_assert_equal(precursor1.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>(), 837.34, 1e-5);
unit_assert(precursor1.selectedIons[0].cvParam(MS_charge_state).value == "2");
unit_assert(s->defaultArrayLength == 5);
pairs.clear();
s->getMZIntensityPairs(pairs);
unit_assert(s->defaultArrayLength == pairs.size());
if (os_)
{
*os_ << "scan 1:\n";
copy(pairs.begin(), pairs.end(), ostream_iterator<MZIntensityPair>(*os_, "\n"));
*os_ << endl;
}
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 178 of file SpectrumList_MGF_Test.cpp.

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

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

Variable Documentation

ostream* os_ = 0

Definition at line 36 of file SpectrumList_MGF_Test.cpp.

const char* testMGF = "END IONS\n"

Definition at line 38 of file SpectrumList_MGF_Test.cpp.

Referenced by test().