ProteoWizard
Classes | Functions | Variables
PrecursorRecalculatorDefaultTest.cpp File Reference
#include "PrecursorRecalculatorDefault.hpp"
#include "pwiz/data/msdata/BinaryDataEncoder.hpp"
#include "pwiz/analysis/peakdetect/PeakFamilyDetectorFT.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/filesystem/fstream.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Classes

struct  TestInfo

Functions

void test ()
void test2 ()
vector< MZIntensityPairreadData (const bfs::path &filename)
shared_ptr
< PrecursorRecalculatorDefault
createPrecursorRecalculator_msprefix ()
void validateRecalculation (const MZIntensityPair *begin, const MZIntensityPair *end, PrecursorRecalculatorDefault &pr, const TestInfo &testInfo)
void test5peptide (const bfs::path &datadir)
void runSpecialTest (const bfs::path &filename, size_t pairCount, const TestInfo &testInfo)
void runTests (const bfs::path &datadir)
int main (int argc, char *argv[])

Variables

ostream * os_ = 0
double testData_ []
const size_t testDataSize_ = sizeof(testData_)/sizeof(double)
const MZIntensityPairtestDataBegin_ = reinterpret_cast<MZIntensityPair*>(testData_)
const MZIntensityPairtestDataEnd_ = reinterpret_cast<MZIntensityPair*>(testData_+testDataSize_)

Function Documentation

void test ( )

Definition at line 389 of file PrecursorRecalculatorDefaultTest.cpp.

References pwiz::analysis::PeakFamilyDetectorFT::Config::cp, e(), pwiz::analysis::PrecursorRecalculator::PrecursorInfo::mz, pwiz::chemistry::Ion::mz(), pwiz::analysis::PrecursorRecalculatorDefault::Config::mzLeftWidth, pwiz::analysis::PrecursorRecalculatorDefault::Config::mzRightWidth, os_, pwiz::analysis::PrecursorRecalculatorDefault::Config::peakFamilyDetector, pwiz::analysis::PrecursorRecalculatorDefault::recalculate(), testDataBegin_, testDataEnd_, pwiz::data::CalibrationParameters::thermo_FT(), unit_assert, and unit_assert_equal.

{
if (os_) *os_ << "test()\n" << flush;
// instantiate PeakFamilyDetector
pfdftConfig.cp = CalibrationParameters::thermo_FT();
shared_ptr<PeakFamilyDetector> pfd(new PeakFamilyDetectorFT(pfdftConfig));
// instantiate PrecursorRecalculatorDefault
config.peakFamilyDetector = pfd;
config.mzLeftWidth = 1;
config.mzRightWidth = 2.5;
// recalculate
initialEstimate.mz = 821.92;
vector<PrecursorRecalculator::PrecursorInfo> result;
pr.recalculate(testDataBegin_, testDataEnd_, initialEstimate, result);
// validate result
unit_assert(result.size() == 1);
unit_assert_equal(result[0].mz, 821.41, 1e-2);
}
void test2 ( )

Definition at line 421 of file PrecursorRecalculatorDefaultTest.cpp.

References pwiz::analysis::PeakFamilyDetectorFT::Config::cp, e(), pwiz::analysis::PrecursorRecalculator::PrecursorInfo::mz, pwiz::chemistry::Ion::mz(), pwiz::analysis::PrecursorRecalculatorDefault::Config::mzLeftWidth, pwiz::analysis::PrecursorRecalculatorDefault::Config::mzRightWidth, os_, pwiz::analysis::PrecursorRecalculatorDefault::Config::peakFamilyDetector, pwiz::analysis::PrecursorRecalculatorDefault::recalculate(), testDataBegin_, testDataEnd_, pwiz::data::CalibrationParameters::thermo_FT(), unit_assert, and unit_assert_equal.

Referenced by main(), and runTests().

{
if (os_) *os_ << "test2()\n" << flush;
// instantiate PeakFamilyDetector
pfdftConfig.cp = CalibrationParameters::thermo_FT();
shared_ptr<PeakFamilyDetector> pfd(new PeakFamilyDetectorFT(pfdftConfig));
// instantiate PrecursorRecalculatorDefault
config.peakFamilyDetector = pfd;
config.mzLeftWidth = 4;
config.mzRightWidth = 2.5;
// recalculate
initialEstimate.mz = 821.92;
vector<PrecursorRecalculator::PrecursorInfo> result;
pr.recalculate(testDataBegin_, testDataEnd_, initialEstimate, result);
// validate result
unit_assert(result.size() == 2);
unit_assert_equal(result[0].mz, 821.41, 1e-2);
unit_assert_equal(result[1].mz, 818.42, 1e-2);
}
vector<MZIntensityPair> readData ( const bfs::path &  filename)

Definition at line 454 of file PrecursorRecalculatorDefaultTest.cpp.

References pwiz::msdata::BinaryDataEncoder::Config::byteOrder, pwiz::msdata::BinaryDataEncoder::ByteOrder_BigEndian, pwiz::msdata::BinaryDataEncoder::Config::compression, pwiz::msdata::BinaryDataEncoder::Compression_Zlib, pwiz::msdata::BinaryDataEncoder::decode(), pwiz::msdata::BinaryDataEncoder::Config::precision, pwiz::msdata::BinaryDataEncoder::Precision_32, and unit_assert.

Referenced by runSpecialTest(), and test5peptide().

{
// data stored as 32-bit big-endian zlib m/z-intensity pairs (mzXML with zlib)
bfs::ifstream is(filename);
if (!is) throw runtime_error(("[PrecursorRecalculatorDefaultTest::readData()] Unable to open file " + filename.string()).c_str());
string encoded;
is >> encoded;
bdeConfig.precision = BinaryDataEncoder::Precision_32;
bdeConfig.byteOrder = BinaryDataEncoder::ByteOrder_BigEndian;
bdeConfig.compression = BinaryDataEncoder::Compression_Zlib;
BinaryDataEncoder encoder(bdeConfig);
vector<double> data;
encoder.decode(encoded, data);
unit_assert(!data.empty() && data.size()%2 == 0);
vector<MZIntensityPair> result(data.size()/2);
copy(data.begin(), data.end(), reinterpret_cast<double*>(&result[0]));
return result;
}
shared_ptr<PrecursorRecalculatorDefault> createPrecursorRecalculator_msprefix ( )

Definition at line 479 of file PrecursorRecalculatorDefaultTest.cpp.

References pwiz::analysis::PeakFamilyDetectorFT::Config::cp, pwiz::analysis::PrecursorRecalculatorDefault::Config::mzLeftWidth, pwiz::analysis::PrecursorRecalculatorDefault::Config::mzRightWidth, pwiz::analysis::PrecursorRecalculatorDefault::Config::peakFamilyDetector, and pwiz::data::CalibrationParameters::thermo_FT().

Referenced by runSpecialTest(), and test5peptide().

{
// instantiate PeakFamilyDetector
pfdftConfig.cp = CalibrationParameters::thermo_FT();
shared_ptr<PeakFamilyDetector> pfd(new PeakFamilyDetectorFT(pfdftConfig));
// instantiate PrecursorRecalculatorDefault
config.peakFamilyDetector = pfd;
config.mzLeftWidth = 3;
config.mzRightWidth = 1.6;
return shared_ptr<PrecursorRecalculatorDefault>(new PrecursorRecalculatorDefault(config));
}
void validateRecalculation ( const MZIntensityPair begin,
const MZIntensityPair end,
PrecursorRecalculatorDefault pr,
const TestInfo testInfo 
)

Definition at line 513 of file PrecursorRecalculatorDefaultTest.cpp.

References TestInfo::chargeTrue, e(), pwiz::analysis::PrecursorRecalculator::PrecursorInfo::mz, pwiz::chemistry::Ion::mz(), TestInfo::mzInitialEstimate, TestInfo::mzTrue, os_, pwiz::analysis::PrecursorRecalculatorDefault::recalculate(), unit_assert, and unit_assert_equal.

Referenced by runSpecialTest(), and test5peptide().

{
// recalculate
initialEstimate.mz = testInfo.mzInitialEstimate;
vector<PrecursorRecalculator::PrecursorInfo> result;
pr.recalculate(begin, end, initialEstimate, result);
// validate result
if (os_)
for (vector<PrecursorRecalculator::PrecursorInfo>::const_iterator it=result.begin(), end=result.end(); it!=end; ++it)
*os_ << " " << it->mz << " " << it->charge << endl;
unit_assert(result.size() >= 1);
unit_assert_equal(result[0].mz, testInfo.mzTrue, 1e-2);
unit_assert(result[0].charge == testInfo.chargeTrue);
}
void test5peptide ( const bfs::path &  datadir)

Definition at line 538 of file PrecursorRecalculatorDefaultTest.cpp.

References createPrecursorRecalculator_msprefix(), os_, readData(), unit_assert, and validateRecalculation().

Referenced by runTests().

{
if (os_) *os_ << "test5peptide()\n" << flush;
vector<MZIntensityPair> data = readData(datadir / "5peptide.b64");
unit_assert(data.size() == 19914);
shared_ptr<PrecursorRecalculatorDefault> pr = createPrecursorRecalculator_msprefix();
const MZIntensityPair* begin = &data[0];
const MZIntensityPair* end = begin + data.size();
validateRecalculation(begin, end, *pr, TestInfo(810.79, 810.42, 2));
validateRecalculation(begin, end, *pr, TestInfo(837.34, 836.96, 2));
validateRecalculation(begin, end, *pr, TestInfo(725.36, 724.91, 2));
validateRecalculation(begin, end, *pr, TestInfo(558.87, 558.31, 3));
validateRecalculation(begin, end, *pr, TestInfo(812.33, 810.42, 2));
validateRecalculation(begin, end, *pr, TestInfo(810.75, 810.42, 2));
validateRecalculation(begin, end, *pr, TestInfo(837.96, 836.96, 2));
validateRecalculation(begin, end, *pr, TestInfo(644.06, 643.37, 2));
validateRecalculation(begin, end, *pr, TestInfo(725.68, 724.91, 2));
validateRecalculation(begin, end, *pr, TestInfo(559.19, 558.31, 3));
validateRecalculation(begin, end, *pr, TestInfo(811.41, 810.42, 2));
validateRecalculation(begin, end, *pr, TestInfo(674.64, 674.37, 2));
validateRecalculation(begin, end, *pr, TestInfo(882.45, 882.47, 1));
}
void runSpecialTest ( const bfs::path &  filename,
size_t  pairCount,
const TestInfo testInfo 
)

Definition at line 566 of file PrecursorRecalculatorDefaultTest.cpp.

References TestInfo::chargeTrue, createPrecursorRecalculator_msprefix(), TestInfo::mzInitialEstimate, TestInfo::mzTrue, os_, readData(), testInfo(), unit_assert, and validateRecalculation().

Referenced by runTests().

{
if (os_) *os_ << "runSpecialTest: " << filename << " " << testInfo.mzInitialEstimate << " "
<< testInfo.mzTrue << " " << testInfo.chargeTrue << endl;
vector<MZIntensityPair> data = readData(filename);
unit_assert(data.size() == pairCount);
shared_ptr<PrecursorRecalculatorDefault> pr = createPrecursorRecalculator_msprefix();
validateRecalculation(&*data.begin(), &*data.begin()+data.size(), *pr, testInfo);
}
void runTests ( const bfs::path &  datadir)

Definition at line 578 of file PrecursorRecalculatorDefaultTest.cpp.

References runSpecialTest(), test(), test2(), and test5peptide().

Referenced by main().

{
test();
test2();
test5peptide(datadir);
runSpecialTest(datadir / "special_1a.b64", 12118, TestInfo(484.2727357, 484.28, 0));
runSpecialTest(datadir / "special_1b.b64", 17767, TestInfo(930.0000218, 929.99, 2));
// noise floor calculation issue (due to big neighbor)
runSpecialTest(datadir / "special_2a.b64", 4802, TestInfo(705.0000091, 704.32, 2));
// charge state determination (window must be > 1.5amu to the right)
runSpecialTest(datadir / "special_2b.b64", 8897, TestInfo(961.0000167, 960.9639, 2));
// monoisotopic peak threshold must be lenient
runSpecialTest(datadir / "special_2c.b64", 7006, TestInfo(731.090919, 730.36, 3));
runSpecialTest(datadir / "special_2d.b64", 12512, TestInfo(730.3599854,730.36, 3));
// charge state calculation issues due to small 1-neutron peak
runSpecialTest(datadir / "special_3a.b64", 5721, TestInfo(560.3636411, 560.28, 2));
runSpecialTest(datadir / "special_3b.b64", 5342, TestInfo(820.6363762, 820.47, 2));
// charge state calculation issues due to small 1-neutron peak
runSpecialTest(datadir / "special_4a.b64", 4142, TestInfo(791.5454722, 791.37, 2));
// charge state regression due to generous acceptance of charge 2 scores
runSpecialTest(datadir / "special_5a.b64", 12324, TestInfo(445.0000073, 445.12, 1));
runSpecialTest(datadir / "special_5a.b64", 12324, TestInfo(407.9090971, 408.31, 1));
runSpecialTest(datadir / "special_5a.b64", 12324, TestInfo(462.0000078, 462.14, 1));
runSpecialTest(datadir / "special_5a.b64", 12324, TestInfo(536.0909191, 536.16, 1));
runSpecialTest(datadir / "special_5a.b64", 12324, TestInfo(519.0909186, 519.14, 1));
// lonely peaks
runSpecialTest(datadir / "special_6a.b64", 12358, TestInfo(1682.636408, 1683.39, 0));
runSpecialTest(datadir / "special_6b.b64", 12280, TestInfo(1565.636404, 1563.74, 0));
runSpecialTest(datadir / "special_6c.b64", 12245, TestInfo(1668.545498, 1667.55, 0));
runSpecialTest(datadir / "special_6d.b64", 12386, TestInfo(1851.545504, 1849.69, 0));
runSpecialTest(datadir / "special_6e.b64", 12221, TestInfo(1444.636401, 1442.54, 0));
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 620 of file PrecursorRecalculatorDefaultTest.cpp.

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

{
TEST_PROLOG(argc, argv)
try
{
bfs::path datadir = ".";
for (int i=1; i<argc; i++)
{
if (!strcmp(argv[i],"-v"))
os_ = &cout;
else
// hack to allow running unit test from a different directory:
// Jamfile passes full path to specified input file.
// we want the path, so we can ignore filename
datadir = bfs::path(argv[i]).branch_path();
}
runTests(datadir);
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 39 of file PrecursorRecalculatorDefaultTest.cpp.

double testData_[]

Definition at line 42 of file PrecursorRecalculatorDefaultTest.cpp.

Referenced by initializeWithTestData(), and test().

const size_t testDataSize_ = sizeof(testData_)/sizeof(double)

Definition at line 384 of file PrecursorRecalculatorDefaultTest.cpp.

Referenced by initializeWithTestData(), and test().

const MZIntensityPair* testDataBegin_ = reinterpret_cast<MZIntensityPair*>(testData_)

Definition at line 385 of file PrecursorRecalculatorDefaultTest.cpp.

Referenced by test(), and test2().

const MZIntensityPair* testDataEnd_ = reinterpret_cast<MZIntensityPair*>(testData_+testDataSize_)

Definition at line 386 of file PrecursorRecalculatorDefaultTest.cpp.

Referenced by test(), and test2().