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

Go to the source code of this file.

Functions

void testUsage ()
void testWrap ()
void testWrapScanTimeRange ()
void testWrapSortScanTime ()
void testWrapMZWindow ()
void testWrapMSLevel ()
void testWrapDefaultArrayLength ()
void testWrapActivation ()
void testWrapMassAnalyzer ()
void testWrapPolarity ()
void testWrapTitleMaker ()
void test ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0

Function Documentation

void testUsage ( )

Definition at line 39 of file SpectrumListFactoryTest.cpp.

References os_, and pwiz::analysis::SpectrumListFactory::usage().

{
if (os_) *os_ << "SpectrumListFactory::usage():\n" << SpectrumListFactory::usage() << endl;
}
void testWrap ( )

Definition at line 45 of file SpectrumListFactoryTest.cpp.

References pwiz::msdata::MSData::allDataProcessingPtrs(), pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, unit_assert_operator_equal, and pwiz::analysis::SpectrumListFactory::wrap().

{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() > 2);
// CompassXtract and pwiz data processing
unit_assert_operator_equal(1, msd.allDataProcessingPtrs()[1]->processingMethods.size());
SpectrumListFactory::wrap(msd, "scanNumber [19,20]");
unit_assert(sl->size() == 2);
SpectrumListFactory::wrap(msd, "index [1,1]");
unit_assert(sl->size() == 1);
unit_assert(sl->spectrumIdentity(0).id == "scan=20");
vector<double> profileData(sl->spectrum(0)->getMZArray()->data);
unit_assert(profileData.size() == 10);
unit_assert(profileData[0] == 0);
unit_assert(profileData[9] == 18);
unit_assert_operator_equal(1, msd.allDataProcessingPtrs()[1]->processingMethods.size());
SpectrumListFactory::wrap(msd, "peakPicking true [1,6]");
vector<double> peakData(sl->spectrum(0)->getMZArray()->data);
unit_assert(peakData.size() == 1);
unit_assert(peakData[0] == 0);
unit_assert_operator_equal(2, msd.allDataProcessingPtrs()[1]->processingMethods.size());
}
void testWrapScanTimeRange ( )

Definition at line 85 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() > 2);
double timeHighInSeconds = 5.9 * 60; // between first and second scan
ostringstream oss;
oss << "scanTime [0," << timeHighInSeconds << "]";
SpectrumListFactory::wrap(msd, oss.str());
unit_assert(sl->size() == 2);
unit_assert(sl->spectrumIdentity(0).id == "scan=19");
unit_assert(sl->spectrumIdentity(1).id == "sample=1 period=1 cycle=23 experiment=1"); // not in scan time order (42 seconds)
}
void testWrapSortScanTime ( )

Definition at line 104 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), MS_scan_start_time, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, UO_minute, UO_second, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
sl->spectrum(0)->scanList.scans[0].set(MS_scan_start_time, 35, UO_second);
sl->spectrum(2)->scanList.scans[0].set(MS_scan_start_time, 0.5, UO_minute);
SpectrumListFactory::wrap(msd, "sortByScanTime");
unit_assert(sl->size() == 5);
unit_assert(sl->spectrumIdentity(0).id == "scan=21");
unit_assert(sl->spectrumIdentity(1).id == "scan=19");
unit_assert(sl->spectrumIdentity(2).id == "sample=1 period=1 cycle=23 experiment=1");
}
void testWrapMZWindow ( )

Definition at line 124 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
MSData msd;
unit_assert(sl.get() && sl->size()>2);
SpectrumPtr spectrum = sl->spectrum(0, true);
vector<MZIntensityPair> data;
spectrum->getMZIntensityPairs(data);
unit_assert(data.size() == 15);
SpectrumListFactory::wrap(msd, "mzWindow [9.5,15]");
spectrum = sl->spectrum(0, true);
spectrum->getMZIntensityPairs(data);
unit_assert(data.size() == 5);
spectrum = sl->spectrum(1, true);
spectrum->getMZIntensityPairs(data);
unit_assert(data.size() == 3);
}
void testWrapMSLevel ( )

Definition at line 148 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
ostringstream oss;
oss << "msLevel 2";
SpectrumListFactory::wrap(msd, oss.str());
unit_assert(sl->size() == 2);
unit_assert(sl->spectrumIdentity(0).id == "scan=20");
}
void testWrapDefaultArrayLength ( )

Definition at line 165 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
// test that the minimum length is 1 (due to 0 being the "unset" value)
{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
SpectrumListFactory::wrap(msd, "defaultArrayLength 0-");
unit_assert(sl->size() == 4);
unit_assert(sl->find("scan=21") == sl->size());
}
// test filtering out all spectra
{
MSData msd;
SpectrumListFactory::wrap(msd, "defaultArrayLength 100-");
unit_assert(sl->size() == 0);
}
// test filtering out empty spectra
{
MSData msd;
SpectrumListFactory::wrap(msd, "defaultArrayLength 1-");
unit_assert(sl->size() == 4);
unit_assert(sl->find("scan=21") == sl->size());
}
// test filtering out spectra with defaultArrayLength > 14
{
MSData msd;
SpectrumListFactory::wrap(msd, "defaultArrayLength 15-");
unit_assert(sl->size() == 2);
unit_assert(sl->find("scan=20") == sl->size());
unit_assert(sl->find("scan=21") == sl->size());
}
// test filtering out spectra with 0 < defaultArrayLength < 15
{
MSData msd;
SpectrumListFactory::wrap(msd, "defaultArrayLength 1-14");
unit_assert(sl->size() == 2);
unit_assert(sl->find("scan=20") == 0);
}
}
void testWrapActivation ( )

Definition at line 226 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, unit_assert_throws, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
// test filter by CID activation
{
MSData msd;
SpectrumListFactory::wrap(msd, "msLevel 2-");
SpectrumListFactory::wrap(msd, "activation CID");
unit_assert(msd.run.spectrumListPtr->size() == 1);
}
// test filter by ETD activation
{
MSData msd;
SpectrumListFactory::wrap(msd, "msLevel 2-");
SpectrumListFactory::wrap(msd, "activation ETD");
unit_assert(msd.run.spectrumListPtr->size() == 1);
}
// test filter by HCD activation
{
MSData msd;
SpectrumListFactory::wrap(msd, "msLevel 2-");
SpectrumListFactory::wrap(msd, "activation HCD");
unit_assert(msd.run.spectrumListPtr->size() == 0);
}
// test filter by IRMPD activation
{
MSData msd;
SpectrumListFactory::wrap(msd, "msLevel 2-");
SpectrumListFactory::wrap(msd, "activation IRMPD");
unit_assert(msd.run.spectrumListPtr->size() == 0);
}
// test invalid argument
{
MSData msd;
unit_assert_throws(SpectrumListFactory::wrap(msd, "activation UNEXPECTED_INPUT"), runtime_error);
}
}
void testWrapMassAnalyzer ( )

Definition at line 269 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, unit_assert_throws, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
// test filter by ITMS analyzer type
{
MSData msd;
SpectrumListFactory::wrap(msd, "analyzerType ITMS");
unit_assert(msd.run.spectrumListPtr->size() == 5);
}
// test filter by ITMS analyzer type (new syntax)
{
MSData msd;
SpectrumListFactory::wrap(msd, "analyzerType it");
unit_assert(msd.run.spectrumListPtr->size() == 5);
}
// test filter by FTMS analyzer type
{
MSData msd;
SpectrumListFactory::wrap(msd, "analyzer FTMS");
unit_assert(msd.run.spectrumListPtr->size() == 0);
}
// test filter by Orbi analyzer type
{
MSData msd;
SpectrumListFactory::wrap(msd, "analyzer Orbi");
unit_assert(msd.run.spectrumListPtr->size() == 0);
}
// test filter by TOF analyzer type
{
MSData msd;
SpectrumListFactory::wrap(msd, "analyzer TOF");
unit_assert(msd.run.spectrumListPtr->size() == 0);
}
// test invalid argument
{
MSData msd;
unit_assert_throws(SpectrumListFactory::wrap(msd, "analyzer UNEXPECTED_INPUT"), runtime_error)
}
}
void testWrapPolarity ( )

Definition at line 320 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert, unit_assert_throws, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
// test filter by positive polarity
{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
SpectrumListFactory::wrap(msd, "polarity positive");
unit_assert(sl->size() == 3);
}
// test filter by + polarity
{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
SpectrumListFactory::wrap(msd, "polarity +");
unit_assert(sl->size() == 3);
}
// test filter by negative polarity
{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
SpectrumListFactory::wrap(msd, "polarity -");
unit_assert(sl->size() == 2);
}
// test invalid argument
{
MSData msd;
unit_assert(sl.get());
unit_assert(sl->size() == 5);
unit_assert_throws(SpectrumListFactory::wrap(msd, "polarity UNEXPECTED_INPUT"), runtime_error)
}
}
void testWrapTitleMaker ( )

Definition at line 370 of file SpectrumListFactoryTest.cpp.

References pwiz::identdata::examples::initializeTiny(), MS_spectrum_title, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, unit_assert_operator_equal, and pwiz::analysis::SpectrumListFactory::wrap().

Referenced by test().

{
MSData msd;
{
SpectrumListFactory::wrap(msd, "titleMaker <Id>");
unit_assert_operator_equal("scan=19", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("scan=20", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("scan=21", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("scan=22", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
}
{
// the outer titleMaker overrides the inner one
SpectrumListFactory::wrap(msd, "titleMaker <Index>; <SpectrumType>, <MsLevel>");
unit_assert_operator_equal("0; MS1 spectrum, 1", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("1; MSn spectrum, 2", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("2; MS1 spectrum, 1", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("3; MSn spectrum, 2", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("4; MS1 spectrum, 1", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
}
{
SpectrumListFactory::wrap(msd, "titleMaker <ScanNumber> <MsLevel> <ActivationType> <ChargeState> <PrecursorSpectrumId>");
unit_assert_operator_equal("19 1 ", sl->spectrum(0)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("20 2 CID 2 scan=19", sl->spectrum(1)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("21 1 ", sl->spectrum(2)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("22 2 ETD/CID 2 scan=19", sl->spectrum(3)->cvParam(MS_spectrum_title).value);
unit_assert_operator_equal("5 1 ", sl->spectrum(4)->cvParam(MS_spectrum_title).value);
}
}
void test ( )
int main ( int  argc,
char *  argv[] 
)

Definition at line 423 of file SpectrumListFactoryTest.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 SpectrumListFactoryTest.cpp.