ProteoWizard
Functions | Variables
FrequencyDataTest.cpp File Reference
#include "FrequencyData.hpp"
#include "FrequencyDataTestData.hpp"
#include "pwiz/data/misc/CalibrationParameters.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <boost/filesystem/operations.hpp>

Go to the source code of this file.

Functions

void diff (const string &filename1, const string &filename2)
void test ()
void testFind ()
void testAddition ()
void testNoiseFloor ()
void cleanTests ()
void testNoiseFloorVarianceCalculation ()
int main (int argc, char *argv[])

Variables

ostream * os_
string filename1 = "FrequencyDataTest.output1.txt"

Function Documentation

void diff ( const string &  filename1,
const string &  filename2 
)

Definition at line 40 of file FrequencyDataTest.cpp.

References os_, and unit_assert.

Referenced by pwiz::data::Diff< object_type, config_type, object_result_type >::Diff(), pwiz::data::Diff< object_type, config_type, object_result_type >::operator()(), pwiz::data::operator<<(), test(), testAmbiguousResidue(), testAnalysisData(), testAnalysisSoftware(), testBinaryDataArray(), testChromatogram(), testChromatogramList(), testComponent(), testComponentList(), testCompound(), testConfiguration(), testContact(), testContactRole(), testCV(), testCVParam(), testDatabaseTranslation(), testDataCollection(), testDataProcessing(), testEnzyme(), testEnzymes(), testEvidence(), testFileContent(), testFileDescription(), testFilter(), testFragmentArray(), testIdentData(), testIdentifiable(), testInputs(), testInstrument(), testInstrumentConfiguration(), testIonType(), testMassTable(), testMaxPrecisionDiff(), testMeasure(), testModification(), testMSData(), testObject(), testObject_ChromatogramList(), testObject_SpectrumList(), testObjectWithMSData(), testParamContainer(), testParamGroup(), testPeptide(), testPeptideEvidence(), testPeptideHypothesis(), testPerson(), testPrecursor(), testPrediction(), testProcessingMethod(), testProduct(), testProtein(), testProteinAmbiguityGroup(), testProteinDetectionHypothesis(), testProteinDetectionList(), testProteinDetectionProtocol(), testProteinList(), testProteomeData(), testQR(), testRectangularQR(), testResidue(), testRetentionTime(), testRun(), testSample(), testScan(), testScanList(), testScanSettings(), testSearchDatabase(), testSearchModification(), testSerialize(), testSerializeReally(), testSnapModifications(), testSoftware(), testSource(), testSourceFile(), testSpectraData(), testSpectrum(), testSpectrumIdentificationList(), testSpectrumIdentificationProtocol(), testSpectrumList(), testTarget(), testTraData(), testTransition(), testUserParam(), testValidation(), testWriteRead(), testWriteReadBMS1(), testWriteReadBMS2(), testWriteReadCMS1(), testWriteReadCMS2(), testWriteReadMS1(), testWriteReadMS2(), and validateWriteRead().

{
ifstream file1(filename1.c_str()), file2(filename2.c_str());
string line1, line2;
while (getline(file1, line1) && getline(file2, line2))
unit_assert(line1 == line2);
if (os_) *os_ << "diff " << filename1 << " " << filename2 << ": success\n";
}
void test ( )

Definition at line 53 of file FrequencyDataTest.cpp.

References pwiz::data::CalibrationParameters::A, pwiz::data::FrequencyData::analyze(), pwiz::data::CalibrationParameters::B, pwiz::data::FrequencyData::calibrationParameters(), pwiz::data::FrequencyData::data(), diff(), e(), filename1, pwiz::data::FrequencyData::max(), max(), pwiz::data::FrequencyData::mean(), pwiz::data::FrequencyData::meanSquare(), pwiz::data::FrequencyData::noiseFloor(), pwiz::data::FrequencyData::normalize(), pwiz::data::FrequencyData::observationDuration(), pwiz::data::FrequencyData::observationDurationEstimatedFromData(), os_, pwiz::data::FrequencyData::retentionTime(), pwiz::data::FrequencyData::scale(), pwiz::data::FrequencyData::scanNumber(), pwiz::data::FrequencyData::shift(), pwiz::data::FrequencyData::sumSquares(), Text, pwiz::data::FrequencyData::transform(), unit_assert, unit_assert_equal, pwiz::data::FrequencyData::variance(), and pwiz::data::FrequencyData::write().

{
// create some data, f(x) = abs(5-(x-2))
for (int i=-5; i<=5; i++)
data.push_back(FrequencyDatum(i+2, 5-abs(i)));
fd.analyze(); // recache after changing data
// verify peak()
unit_assert(max->x == 2);
unit_assert(max->y == 5.);
// verify stats
unit_assert(fd.mean() == 25./11);
unit_assert(fd.meanSquare() == 85./11);
unit_assert(fd.sumSquares() == 85.);
unit_assert_equal(fd.variance(), 85./11 - 25.*25/11/11, 1e-12);
// write out data
if (os_) *os_ << "Writing " << filename1 << endl;
// read into const FrequencyData
string filename2 = "FrequencyDataTest.output2.txt";
// verify normalize()
fd2.normalize();
unit_assert(fd2.shift() == -2);
unit_assert(fd2.scale() == 1./5);
max = fd2.max();
unit_assert(max->x == 0);
unit_assert(max->y == 1.);
// verify transform(shift, scale)
fd2.transform(-fd2.shift(), 1./fd2.scale());
// verify read/write
if (os_) *os_ << "Writing " << filename2 << endl;
fd2.write(filename2, FrequencyData::Text);
diff(filename1, filename2);
// test subrange
string filename3 = "FrequencyDataTest.output3.txt";
FrequencyData fd3(fd2, fd2.data().begin(), fd2.max()); // copy first half
if (os_) *os_ << "Writing " << filename3 << endl;
fd3.write(filename3, FrequencyData::Text);
FrequencyData fd4(fd2, fd2.max(), fd2.data().end()); // copy second half
ofstream os(filename3.c_str(), ios::app);
os.close();
diff(filename1, filename3);
// read/write binary, and metadata
fd.scanNumber(555);
fd.retentionTime(444);
fd.noiseFloor(777);
string filename4a = "FrequencyDataTest.output4a.txt";
if (os_) *os_ << "Writing " << filename4a << endl;
fd.write(filename4a, FrequencyData::Text);
string filenameBinary1 = "FrequencyDataTest.output1.cfd";
if (os_) *os_ << "Writing " << filenameBinary1 << endl;
fd.write(filenameBinary1);
FrequencyData fd5(filenameBinary1);
unit_assert(fd5.observationDuration() == 666);
fd5.observationDuration(fd.observationDurationEstimatedFromData());
unit_assert(fd5.scanNumber() == 555);
unit_assert(fd5.retentionTime() == 444);
unit_assert(fd5.observationDuration() == 1);
unit_assert(fd5.noiseFloor() == 777);
if (os_) *os_ << "Calibration: " << fd5.calibrationParameters().A << " " << fd5.calibrationParameters().B << endl;
string filename4b = "FrequencyDataTest.output4b.txt";
if (os_) *os_ << "Writing " << filename4b << endl;
fd5.write(filename4b, FrequencyData::Text);
diff(filename4a, filename4b);
// test window
FrequencyData window1(fd, data.begin()+1, 2);
FrequencyData window2(fd, fd.max(), 1);
FrequencyData window3(fd, data.end()-2, 2);
string filename5 = "FrequencyDataTest.output5.txt";
if (os_) *os_ << "Writing " << filename5 << endl;
ofstream os5(filename5.c_str());
window1.write(os5, FrequencyData::Text);
window2.write(os5, FrequencyData::Text);
window3.write(os5, FrequencyData::Text);
os5.close();
diff(filename1, filename5);
}
void testFind ( )

Definition at line 151 of file FrequencyDataTest.cpp.

References pwiz::data::FrequencyData::data(), filename1, pwiz::data::FrequencyData::findNearest(), and unit_assert.

{
FrequencyData::const_iterator it = fd.findNearest(-.2);
unit_assert(it!=fd.data().end() && it->x==0);
it = fd.findNearest(.2);
unit_assert(it!=fd.data().end() && it->x==0);
it = fd.findNearest(6.1);
unit_assert(it!=fd.data().end() && it->x==6);
it = fd.findNearest(7.1);
unit_assert(it!=fd.data().end() && it->x==7);
it = fd.findNearest(666);
unit_assert(it!=fd.data().end() && it->x==7);
it = fd.findNearest(-666);
unit_assert(it==fd.data().begin());
}
void testAddition ( )

Definition at line 175 of file FrequencyDataTest.cpp.

References pwiz::data::FrequencyData::data(), filename1, pwiz::data::FrequencyData::transform(), and unit_assert.

Referenced by main().

{
fd += fd;
for (FrequencyData::const_iterator it=fd.data().begin(), jt=fd2.data().begin();
it!=fd.data().end();
++it, ++jt)
unit_assert(it->y == 2.*jt->y);
fd2.transform(0, -2.);
fd += fd2;
for (FrequencyData::const_iterator it=fd.data().begin(); it!=fd.data().end(); ++it)
unit_assert(it->y == 0.);
}
void testNoiseFloor ( )

Definition at line 195 of file FrequencyDataTest.cpp.

References filename1, pwiz::data::FrequencyData::noiseFloor(), os_, and pwiz::data::FrequencyData::variance().

Referenced by main().

{
if (os_) *os_ << "variance: " << fd.variance() << endl;
if (os_) *os_ << "noiseFloor: " << fd.noiseFloor() << endl;
}
void cleanTests ( )

Definition at line 203 of file FrequencyDataTest.cpp.

References pwiz::util::expand_pathmask(), and os_.

Referenced by main().

{
if (os_) *os_ << "Deleting FrequencyDataTest.output*.txt\n";
vector<bfs::path> filepaths;
expand_pathmask("FrequencyDataTest.output*.*", filepaths);
for (size_t i=0; i < filepaths.size(); ++i)
boost::filesystem::remove(filepaths[i]);
}
void testNoiseFloorVarianceCalculation ( )

Definition at line 213 of file FrequencyDataTest.cpp.

References pwiz::data::FrequencyData::analyze(), pwiz::data::FrequencyData::cutoffNoiseFloor(), pwiz::data::FrequencyData::data(), pwiz::data::CalibrationParameters::frequency(), os_, sampleFrequencyData_, sampleMassData_, sampleMassDataSize_, and unit_assert_equal.

Referenced by main().

{
if (os_) *os_ << "testNoiseFloorVarianceCalculation()\n";
if (os_) *os_ << setprecision(10);
// test noise floor calculation on sample frequency data
string filename = "FrequencyDataTest.cfd.temp.txt";
ofstream temp(filename.c_str());
temp.close();
FrequencyData fd(filename);
boost::filesystem::remove(filename);
double result = fd.cutoffNoiseFloor();
if (os_) *os_ << "result: " << result << endl;
unit_assert_equal(result, 29000, 1000);
// test noise floor calculation on sample mass data
FrequencyData fdMasses;
CalibrationParameters cp = CalibrationParameters::thermo_FT();
for (RawMassDatum* p=sampleMassData_; p!=sampleMassData_+sampleMassDataSize_; ++p)
fdMasses.data().push_back(FrequencyDatum(cp.frequency(p->mz), p->intensity));
fdMasses.analyze();
double result2 = fdMasses.cutoffNoiseFloor();
if (os_) *os_ << "result2: " << result2 << endl;
unit_assert_equal(result2, 6000, 1000);
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 247 of file FrequencyDataTest.cpp.

References cleanTests(), e(), os_, test(), TEST_EPILOG, TEST_FAILED, TEST_PROLOG, testAddition(), testFind(), testNoiseFloor(), and testNoiseFloorVarianceCalculation().

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

Variable Documentation

ostream* os_

Definition at line 37 of file FrequencyDataTest.cpp.

string filename1 = "FrequencyDataTest.output1.txt"

Definition at line 50 of file FrequencyDataTest.cpp.

Referenced by test(), testAddition(), testFind(), testNoiseFloor(), and validateWriteRead().