ProteoWizard
Functions | Variables
RegionAnalyzerTest.cpp File Reference
#include "RegionAnalyzer.hpp"
#include "pwiz/data/msdata/TextWriter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>
#include <boost/algorithm/string/split.hpp>

Go to the source code of this file.

Functions

void initialize (MSData &msd)
ostream & operator<< (ostream &os, const RegionAnalyzer::SpectrumStats &ss)
ostream & operator<< (ostream &os, const RegionAnalyzer::Stats &stats)
void testConfig (const RegionAnalyzer::Config &config)
void test ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0
double data_ [5][14]
const double epsilon_ = 1e-14

Function Documentation

void initialize ( MSData msd)

Definition at line 57 of file RegionAnalyzerTest.cpp.

References data_, boost::lexical_cast(), MS_number_of_counts, MS_scan_start_time, pwiz::msdata::MSData::run, pwiz::msdata::Run::spectrumListPtr, and UO_second.

Referenced by testConfig().

{
msd.run.spectrumListPtr = sl;
for (size_t i=0; i<5; i++)
{
SpectrumPtr spectrum(new Spectrum);
sl->spectra.push_back(spectrum);
spectrum->index = i;
spectrum->id = "scan=" + lexical_cast<string>(18+(int)i);
spectrum->scanList.scans.push_back(Scan());
spectrum->scanList.scans.back().cvParams.push_back(CVParam(MS_scan_start_time, 420+int(i), UO_second));
spectrum->setMZIntensityPairs((MZIntensityPair*)data_[i], 7, MS_number_of_counts);
}
}
ostream& operator<< ( ostream &  os,
const RegionAnalyzer::SpectrumStats ss 
)
ostream& operator<< ( ostream &  os,
const RegionAnalyzer::Stats stats 
)

Definition at line 87 of file RegionAnalyzerTest.cpp.

References pwiz::analysis::RegionAnalyzer::Stats::indexApex, pwiz::analysis::RegionAnalyzer::Stats::mean_peak_mz, pwiz::analysis::RegionAnalyzer::Stats::nonzeroCount, pwiz::analysis::RegionAnalyzer::Stats::sd_peak_mz, pwiz::analysis::RegionAnalyzer::Stats::sum_peak_intensity, pwiz::analysis::RegionAnalyzer::Stats::sum_sumIntensity, and pwiz::analysis::RegionAnalyzer::Stats::variance_peak_mz.

{
os << "nonzeroCount: " << stats.nonzeroCount << endl
<< "sum_sumIntensity: " << stats.sum_sumIntensity << endl
<< "sum_peak_intensity: " << stats.sum_peak_intensity << endl
<< "mean_peak_mz: " << stats.mean_peak_mz << endl
<< "variance_peak_mz: " << stats.variance_peak_mz << endl
<< "sd_peak_mz: " << stats.sd_peak_mz << endl
<< "indexApex: " << stats.indexApex << endl;
return os;
}
void testConfig ( const RegionAnalyzer::Config config)

Definition at line 100 of file RegionAnalyzerTest.cpp.

References pwiz::analysis::MSDataAnalyzerDriver::analyze(), epsilon_, pwiz::analysis::RegionAnalyzer::Stats::indexApex, initialize(), pwiz::analysis::RegionAnalyzer::Stats::mean_peak_mz, pwiz::analysis::RegionAnalyzer::Stats::nonzeroCount, os_, pwiz::analysis::RegionAnalyzer::Stats::sd_peak_mz, pwiz::analysis::RegionAnalyzer::Stats::sum_peak_intensity, pwiz::analysis::RegionAnalyzer::Stats::sum_sumIntensity, unit_assert, unit_assert_equal, and pwiz::analysis::RegionAnalyzer::Stats::variance_peak_mz.

Referenced by test().

{
MSData msd;
initialize(msd);
shared_ptr<MSDataCache> cache(new MSDataCache);
shared_ptr<RegionAnalyzer> regionAnalyzer(new RegionAnalyzer(config, *cache));
analyzers.push_back(cache);
analyzers.push_back(regionAnalyzer);
MSDataAnalyzerDriver driver(analyzers);
driver.analyze(msd);
unit_assert(regionAnalyzer->spectrumStats().size() == 5);
if (os_) *os_ << "sumIntensity (max) (peak):\n";
vector<RegionAnalyzer::SpectrumStats>::const_iterator it =
regionAnalyzer->spectrumStats().begin();
if (os_) *os_ << *it << endl;
unit_assert(it->sumIntensity == 0);
unit_assert_equal(it->max.mz, 0, epsilon_);
unit_assert_equal(it->max.intensity, 0, epsilon_);
unit_assert_equal(it->peak.mz, 0, epsilon_);
unit_assert_equal(it->peak.intensity, 0, epsilon_);
++it;
if (os_) *os_ << *it << endl;
unit_assert(it->sumIntensity == 5);
unit_assert_equal(it->max.mz, 3.1, epsilon_);
unit_assert_equal(it->max.intensity, 2, epsilon_);
unit_assert_equal(it->peak.mz, 3.1, epsilon_);
unit_assert_equal(it->peak.intensity, 2, epsilon_);
++it;
if (os_) *os_ << *it << endl;
unit_assert(it->sumIntensity == 6); // with omitted sample intensity 4
unit_assert_equal(it->max.mz, 1.9, epsilon_);
unit_assert_equal(it->max.intensity, 3, epsilon_);
unit_assert_equal(it->peak.mz, 2.9, epsilon_); // found the peak by interpolation
unit_assert_equal(it->peak.intensity, 4, epsilon_);
++it;
if (os_) *os_ << *it << endl;
unit_assert(it->sumIntensity == 5);
unit_assert_equal(it->max.mz, 3.1, epsilon_);
unit_assert_equal(it->max.intensity, 2, epsilon_);
unit_assert_equal(it->peak.mz, 3.1, epsilon_);
unit_assert_equal(it->peak.intensity, 2, epsilon_);
++it;
if (os_) *os_ << *it << endl;
unit_assert(it->sumIntensity == 0);
unit_assert_equal(it->max.mz, 0, epsilon_);
unit_assert_equal(it->max.intensity, 0, epsilon_);
unit_assert_equal(it->peak.mz, 0, epsilon_);
unit_assert_equal(it->peak.intensity, 0, epsilon_);
// Stats
const RegionAnalyzer::Stats& stats = regionAnalyzer->stats();
if (os_) *os_ << stats << endl;
unit_assert(stats.indexApex == 2);
}
void test ( )

Definition at line 174 of file RegionAnalyzerTest.cpp.

References pwiz::analysis::TabularConfig::checkDelimiter(), pwiz::analysis::RegionAnalyzer::Config::dumpRegionData, pwiz::analysis::RegionAnalyzer::Config::indexRange, pwiz::analysis::RegionAnalyzer::Config::mzRange, os_, pwiz::analysis::RegionAnalyzer::Config::osDump, pwiz::analysis::RegionAnalyzer::Config::rtRange, pwiz::analysis::RegionAnalyzer::Config::scanNumberRange, TABULARCONFIG_DELIMITER_OPTIONS_STR, testConfig(), and unit_assert.

{
// test for each output delimiter type
std::vector<std::string> options;
std::vector<std::string> outputs;
std::string delimiter_help(TABULARCONFIG_DELIMITER_OPTIONS_STR);
boost::algorithm::split(options, delimiter_help, boost::algorithm::is_any_of("=|") );
for (int n=1; n<(int)options.size(); n++)
{
std::ostringstream txtstream;
std::string delim = options[0] + "=" + options[n];
if (os_) *os_ << "test with delimiter style " << delim <<":\n";
if (os_) *os_ << "test index:\n";
unit_assert(config.checkDelimiter(delim)); // set output delimiter type
config.dumpRegionData = true;
config.osDump = &txtstream; // dump to this stream
config.mzRange = make_pair(.5, 5.5);
config.indexRange = make_pair(1,3);
testConfig(config);
if (os_) *os_ << "test scanNumber:\n";
unit_assert(config.checkDelimiter(delim)); // set output delimiter type
config.dumpRegionData = true;
config.osDump = &txtstream; // dump to this stream
config.mzRange = make_pair(.5, 5.5);
config.scanNumberRange = make_pair(19,21);
testConfig(config);
if (os_) *os_ << "test retentionTime:\n";
unit_assert(config.checkDelimiter(delim)); // set output delimiter type
config.dumpRegionData = true;
config.osDump = &txtstream; // dump to this stream
config.mzRange = make_pair(.5, 5.5);
config.rtRange = make_pair(420.5, 423.5);
testConfig(config);
// save each output style
outputs.push_back(txtstream.str());
}
// all the outputs should be different
for (int m=(int)outputs.size();m-->1;)
{
unit_assert(outputs[m]!=outputs[m-1]);
}
// now convert all delimiters back to a single space
for (int mm=(int)outputs.size();mm--;)
{
// reduce double spaces to single
// no, replace_all(outputs[mm],std::string(" "),std::string(" ")); doesn't do it
for (int n=outputs[mm].size();n-->1;)
{
if ((outputs[mm][n]==' ') && (outputs[mm][n-1]==' '))
{
outputs[mm] = outputs[mm].substr(0,n-1)+outputs[mm].substr(n);
}
if ((outputs[mm][n]==' ') && (outputs[mm][n-1]=='\n'))
{
// watch for lines with leading spaces
outputs[mm] = outputs[mm].substr(0,n-1)+outputs[mm].substr(n);
outputs[mm][n-1]='\n';
}
}
// and replace single character delimiters
boost::algorithm::replace_all(outputs[mm],std::string("\t"),std::string(" "));
boost::algorithm::replace_all(outputs[mm],std::string(","),std::string(" "));
}
// all the outputs should now be identical
for (int delimtype=(int)outputs.size();delimtype-->1;)
{
unit_assert(outputs[delimtype]==outputs[delimtype-1]);
}
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 254 of file RegionAnalyzerTest.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 37 of file RegionAnalyzerTest.cpp.

double data_[5][14]
Initial value:
{
{0,9, 1,9, 2,9, 3,9, 4,9, 5,9, 6,9},
{0.1,9, 1.1,0, 2.1,1.5, 3.1,2, 4.1,1.5, 5.1,0, 6.1,9},
{-.1,9, .9,0, 1.9,3, 3.9,3, 4.9,0, 5.9,9, 6,0},
{0.1,9, 1.1,0, 2.1,1.5, 3.1,2, 4.1,1.5, 5.1,0, 6.1,9},
{0,9, 1,9, 2,9, 3,9, 4,9, 5,9, 6,9}
}

Definition at line 47 of file RegionAnalyzerTest.cpp.

const double epsilon_ = 1e-14

Definition at line 75 of file RegionAnalyzerTest.cpp.