ProteoWizard
Functions | Variables
PeakDetectorMatchedFilterTest.cpp File Reference
#include "PeakDetectorMatchedFilter.hpp"
#include "PeakDetectorMatchedFilterTestData.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void initializeWithTestData (FrequencyData &fd)
 
void testCreation (const IsotopeEnvelopeEstimator &isotopeEnvelopeEstimator)
 
void testFind (FrequencyData &fd, const IsotopeEnvelopeEstimator &isotopeEnvelopeEstimator)
 
auto_ptr< IsotopeEnvelopeEstimatorcreateIsotopeEnvelopeEstimator ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ initializeWithTestData()

void initializeWithTestData ( FrequencyData fd)

Definition at line 41 of file PeakDetectorMatchedFilterTest.cpp.

References pwiz::data::FrequencyData::analyze(), pwiz::data::FrequencyData::calibrationParameters(), pwiz::data::FrequencyData::data(), pwiz::data::FrequencyData::observationDuration(), testData_, testDataCalibrationA_, testDataCalibrationB_, testDataObservationDuration_, and testDataSize_.

Referenced by test().

42 {
43  for (TestDatum* datum=testData_; datum<testData_+testDataSize_; datum++)
44  fd.data().push_back(FrequencyDatum(datum->frequency,
45  complex<double>(datum->real, datum->imaginary)));
46 
49  fd.analyze();
50 }
TestDatum testData_[]
void analyze()
recache statistics calculations after any direct data changes via non-const data() ...
const double testDataCalibrationB_
const container & data() const
const access to underlying data
const double testDataCalibrationA_
double observationDuration() const
SampleDatum< double, std::complex< double > > FrequencyDatum
const CalibrationParameters & calibrationParameters() const
const double testDataObservationDuration_
const unsigned int testDataSize_

§ testCreation()

void testCreation ( const IsotopeEnvelopeEstimator isotopeEnvelopeEstimator)

Definition at line 53 of file PeakDetectorMatchedFilterTest.cpp.

References pwiz::frequency::PeakDetectorMatchedFilter::config(), pwiz::frequency::PeakDetectorMatchedFilter::Config::filterMatchRate, pwiz::frequency::PeakDetectorMatchedFilter::Config::filterSampleRadius, pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeEnvelopeEstimator, pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeThresholdFactor, pwiz::frequency::PeakDetectorMatchedFilter::Config::monoisotopicPeakThresholdFactor, os_, pwiz::frequency::PeakDetectorMatchedFilter::Config::peakMaxCorrelationAngle, pwiz::frequency::PeakDetectorMatchedFilter::Config::peakThresholdFactor, and unit_assert.

Referenced by test().

54 {
55  if (os_) *os_ << "testCreation()\n";
56  const int filterMatchRate = 4;
57  const int filterSampleRadius = 2;
58  const double peakThresholdFactor = 0;
59  const double peakMaxCorrelationAngle = 5;
60  const double isotopeThresholdFactor = 666;
61  const double monoisotopicPeakThresholdFactor = 777;
62 
64  config.isotopeEnvelopeEstimator = &isotopeEnvelopeEstimator;
65  config.filterMatchRate = filterMatchRate;
66  config.filterSampleRadius = filterSampleRadius;
67  config.peakThresholdFactor = peakThresholdFactor;
68  config.peakMaxCorrelationAngle = peakMaxCorrelationAngle;
69  config.isotopeThresholdFactor = isotopeThresholdFactor;
70  config.monoisotopicPeakThresholdFactor = monoisotopicPeakThresholdFactor;
71 
72  auto_ptr<PeakDetectorMatchedFilter> pd = PeakDetectorMatchedFilter::create(config);
73 
74  unit_assert(pd->config().filterMatchRate == filterMatchRate);
75  unit_assert(pd->config().filterSampleRadius == filterSampleRadius);
76  unit_assert(pd->config().peakThresholdFactor == peakThresholdFactor);
77  unit_assert(pd->config().peakMaxCorrelationAngle == peakMaxCorrelationAngle);
78  unit_assert(pd->config().isotopeThresholdFactor == isotopeThresholdFactor);
79  unit_assert(pd->config().monoisotopicPeakThresholdFactor == monoisotopicPeakThresholdFactor);
80 }
int filterSampleRadius
number of filter samples taken on either side of 0
const chemistry::IsotopeEnvelopeEstimator * isotopeEnvelopeEstimator
IsotopeEnvelopeEstimator pointer, must be valid for PeakDetector lifetime.
virtual const Config & config() const =0
access to the configuration
double monoisotopicPeakThresholdFactor
noise floor multiple for monoisotopic peak threshold
double peakThresholdFactor
noise floor multiple for initial peak reporting threshold
int filterMatchRate
number of filter correlations computed per frequency step
double peakMaxCorrelationAngle
maximum correlation angle (degrees) for initial peak reporting
double isotopeThresholdFactor
noise floor multiple for isotope filter threshold
#define unit_assert(x)
Definition: unit.hpp:85

§ testFind()

void testFind ( FrequencyData fd,
const IsotopeEnvelopeEstimator isotopeEnvelopeEstimator 
)

Definition at line 83 of file PeakDetectorMatchedFilterTest.cpp.

References pwiz::frequency::PeakDetectorMatchedFilter::Config::collapseRadius, pwiz::frequency::PeakDetectorMatchedFilter::Config::filterMatchRate, pwiz::frequency::PeakDetectorMatchedFilter::Config::filterSampleRadius, pwiz::frequency::PeakDetectorMatchedFilter::findPeaks(), pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeEnvelopeEstimator, pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeMaxChargeState, pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeMaxNeutronCount, pwiz::frequency::PeakDetectorMatchedFilter::Config::isotopeThresholdFactor, pwiz::frequency::PeakDetectorMatchedFilter::Config::log, pwiz::frequency::PeakDetectorMatchedFilter::Config::logDetailLevel, pwiz::frequency::PeakDetectorMatchedFilter::Config::monoisotopicPeakThresholdFactor, pwiz::math::MatchedFilter::details::norm(), os_, pwiz::frequency::PeakDetectorMatchedFilter::Config::peakMaxCorrelationAngle, pwiz::frequency::PeakDetectorMatchedFilter::Config::peakThresholdFactor, pwiz::data::peakdata::PeakData::scans, unit_assert, unit_assert_equal, and pwiz::frequency::PeakDetectorMatchedFilter::Config::useMagnitudeFilter.

Referenced by test().

84 {
85  if (os_) *os_ << "testFind()\n";
86 
87  // fill in config structure
89  config.isotopeEnvelopeEstimator = &isotopeEnvelopeEstimator;
90  config.filterMatchRate = 4;
91  config.filterSampleRadius = 2;
92  config.peakThresholdFactor = 2;
93  config.peakMaxCorrelationAngle = 30;
94  config.isotopeThresholdFactor = 2;
96  config.isotopeMaxChargeState = 6;
97  config.isotopeMaxNeutronCount = 4;
98  config.collapseRadius = 15;
99  config.useMagnitudeFilter = false;
100  config.logDetailLevel = 1;
101  config.log = os_;
102 
103  // instantiate
104  auto_ptr<PeakDetectorMatchedFilter> pd = PeakDetectorMatchedFilter::create(config);
105 
106  // find peaks
107  PeakData data;
108  data.scans.push_back(Scan());
109  vector<PeakDetectorMatchedFilter::Score> scores;
110  pd->findPeaks(fd, data.scans[0], scores);
111 
112  // report results
113  if (os_)
114  {
115  *os_ << "peaks found: " << data.scans[0].peakFamilies.size() << endl;
116  *os_ << data.scans[0];
117  *os_ << "scores: " << scores.size() << endl;
118  copy(scores.begin(), scores.end(),
119  ostream_iterator<PeakDetectorMatchedFilter::Score>(*os_, "\n"));
120  }
121 
122  // assertions
123  unit_assert(data.scans[0].peakFamilies.size() == 1);
124  const PeakFamily& peakFamily = data.scans[0].peakFamilies.back();
125 
126  if (os_) *os_ << "peakFamily: " << peakFamily << endl;
127  unit_assert(peakFamily.peaks.size() > 1);
128  const Peak& peak = peakFamily.peaks[0];
129  unit_assert_equal(peak.getAttribute(Peak::Attribute_Frequency), 159455, 1);
130  unit_assert(peakFamily.charge == 2);
131 
132  unit_assert(scores.size() == 1);
133  const PeakDetectorMatchedFilter::Score& score = scores.back();
134  unit_assert(score.charge == peakFamily.charge);
135  unit_assert(score.monoisotopicFrequency == peak.getAttribute(Peak::Attribute_Frequency));
136  unit_assert_equal(norm(score.monoisotopicIntensity -
137  polar(peak.intensity, peak.getAttribute(Peak::Attribute_Phase))),
138  0, 1e-14);
139 }
double collapseRadius
multiple peaks within this radius (Hz) are reported as single peak
int filterSampleRadius
number of filter samples taken on either side of 0
int isotopeMaxNeutronCount
isotope filter maximum number of neutrons to score
int logDetailLevel
log detail level (0 == normal, 1 == extra)
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
const chemistry::IsotopeEnvelopeEstimator * isotopeEnvelopeEstimator
IsotopeEnvelopeEstimator pointer, must be valid for PeakDetector lifetime.
double monoisotopicPeakThresholdFactor
noise floor multiple for monoisotopic peak threshold
std::vector< Scan > scans
Definition: PeakData.hpp:194
std::ostream * log
log stream (0 == no logging)
double peakThresholdFactor
noise floor multiple for initial peak reporting threshold
int filterMatchRate
number of filter correlations computed per frequency step
double peakMaxCorrelationAngle
maximum correlation angle (degrees) for initial peak reporting
int isotopeMaxChargeState
isotope filter maximum charge state to score
virtual void findPeaks(const pwiz::data::FrequencyData &fd, pwiz::data::peakdata::Scan &result) const =0
Find the peaks in the frequency data, filling in Scan structure.
double isotopeThresholdFactor
noise floor multiple for isotope filter threshold
bool useMagnitudeFilter
use the magnitude of the peak shape filter kernel for finding peaks
structure for holding the matched filter calculation results
#define unit_assert(x)
Definition: unit.hpp:85

§ createIsotopeEnvelopeEstimator()

auto_ptr<IsotopeEnvelopeEstimator> createIsotopeEnvelopeEstimator ( )

Definition at line 142 of file PeakDetectorMatchedFilterTest.cpp.

References pwiz::chemistry::IsotopeEnvelopeEstimator::Config::isotopeCalculator.

Referenced by test().

143 {
144  const double abundanceCutoff = .01;
145  const double massPrecision = .1;
146  IsotopeCalculator isotopeCalculator(abundanceCutoff, massPrecision);
147 
149  config.isotopeCalculator = &isotopeCalculator;
150 
151  return auto_ptr<IsotopeEnvelopeEstimator>(new IsotopeEnvelopeEstimator(config));
152 }
Class used for calculating a theoretical isotope envelope for a given mass, based on an estimate of t...

§ test()

void test ( )

Definition at line 155 of file PeakDetectorMatchedFilterTest.cpp.

References createIsotopeEnvelopeEstimator(), initializeWithTestData(), os_, testCreation(), and testFind().

Referenced by main().

156 {
157  if (os_) *os_ << setprecision(12);
158 
159  auto_ptr<IsotopeEnvelopeEstimator> isotopeEnvelopeEstimator = createIsotopeEnvelopeEstimator();
160 
161  testCreation(*isotopeEnvelopeEstimator);
162 
163  FrequencyData fd;
165 
166  testFind(fd, *isotopeEnvelopeEstimator);
167 }
Class for binary storage of complex frequency data.
void testFind(FrequencyData &fd, const IsotopeEnvelopeEstimator &isotopeEnvelopeEstimator)
void initializeWithTestData(FrequencyData &fd)
void testCreation(const IsotopeEnvelopeEstimator &isotopeEnvelopeEstimator)
auto_ptr< IsotopeEnvelopeEstimator > createIsotopeEnvelopeEstimator()

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 170 of file PeakDetectorMatchedFilterTest.cpp.

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

171 {
172  TEST_PROLOG(argc, argv)
173 
174  try
175  {
176  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
177  if (os_) *os_ << "PeakDetectorMatchedFilterTest\n";
178  test();
179  }
180  catch (exception& e)
181  {
182  TEST_FAILED(e.what())
183  }
184  catch (...)
185  {
186  TEST_FAILED("Caught unknown exception.")
187  }
188 
190 }
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 38 of file PeakDetectorMatchedFilterTest.cpp.

Referenced by main(), test(), testCreation(), and testFind().