ProteoWizard
Functions | Variables
PeakFitterTest.cpp File Reference
#include "PeakFitter.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 testParabola ()
 
void testMultiplePeaks ()
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ testParabola()

void testParabola ( )

Definition at line 39 of file PeakFitterTest.cpp.

References pwiz::analysis::Peak::area, epsilon, pwiz::analysis::PeakFitter_Parabola::fitPeak(), os_, unit_assert, unit_assert_equal, and pwiz::analysis::PeakFitter_Parabola::Config::windowRadius.

Referenced by test().

40 {
41  if (os_) *os_ << "testParabola()\n";
42 
43  const double center = 2.1;
44  const double height = 5;
45 
46  vector<OrderedPair> pairs;
47  for (double i=0; i<5; i++)
48  pairs.push_back(OrderedPair(i, height-(i-center)*(i-center))); // sampled parabola
49 
51  config.windowRadius = 1;
52 
53  PeakFitter_Parabola fitter(config);
54  Peak peak;
55 
56  fitter.fitPeak(pairs, 2, peak);
57 
58  if (os_)
59  {
60  *os_ << peak;
61  copy(peak.data.begin(), peak.data.end(), ostream_iterator<OrderedPair>(*os_, " "));
62  *os_ << endl;
63  }
64 
65  const double epsilon = 1e-6;
66  unit_assert_equal(peak.mz, center, epsilon);
67  unit_assert_equal(peak.intensity, 5, epsilon);
68  unit_assert_equal(peak.area, 12.97, epsilon);
69  unit_assert_equal(peak.error, 0, epsilon);
70  unit_assert_equal(peak.intensity, 5, epsilon);
71  unit_assert(!peak.data.empty());
72 }
const double epsilon
Definition: DiffTest.cpp:41
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
PeakFitter implementation based on fitting a parabola.
Definition: PeakFitter.hpp:61
represents some generic metadata about a peak detected in a signal
ostream * os_
#define unit_assert(x)
Definition: unit.hpp:85

§ testMultiplePeaks()

void testMultiplePeaks ( )

Definition at line 75 of file PeakFitterTest.cpp.

References epsilon, pwiz::analysis::PeakFitter::fitPeaks(), pwiz::chemistry::Ion::mz(), os_, unit_assert, and unit_assert_equal.

Referenced by test().

76 {
77  if (os_) *os_ << "testMultiplePeaks()\n";
78 
79  const double center = 2.1;
80  const double height = 5;
81 
82  vector<OrderedPair> pairs;
83  for (double i=0; i<5; i++)
84  pairs.push_back(OrderedPair(i, height-(i-center)*(i-center))); // sampled parabola
85  for (double i=0; i<5; i++)
86  pairs.push_back(OrderedPair(i+5, height-(i-center)*(i-center))); // sampled parabola
87  for (double i=0; i<5; i++)
88  pairs.push_back(OrderedPair(i+10, height-(i-center)*(i-center))); // sampled parabola
89 
90  vector<size_t> indices;
91  indices.push_back(2);
92  indices.push_back(7);
93  indices.push_back(12);
94 
95  PeakFitter_Parabola fitter;
96  vector<Peak> peaks;
97 
98  fitter.fitPeaks(pairs, indices, peaks);
99 
100  if (os_)
101  {
102  for (vector<Peak>::const_iterator it=peaks.begin(); it!=peaks.end(); ++it)
103  {
104  *os_ << *it;
105  copy(it->data.begin(), it->data.end(), ostream_iterator<OrderedPair>(*os_, " "));
106  *os_ << endl;
107  }
108  }
109 
110  const double epsilon = 1e-6;
111  unit_assert(peaks.size() == 3);
112  unit_assert_equal(peaks[0].mz, center, epsilon);
113  unit_assert_equal(peaks[1].mz, center+5, epsilon);
114  unit_assert_equal(peaks[2].mz, center+10, epsilon);
115 }
const double epsilon
Definition: DiffTest.cpp:41
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
PeakFitter implementation based on fitting a parabola.
Definition: PeakFitter.hpp:61
void fitPeaks(const math::OrderedPairContainerRef &pairs, std::vector< size_t > &indices, std::vector< Peak > &result) const
double mz(double neutralMass, int protonDelta, int electronDelta=0, int neutronDelta=0)
Definition: Ion.hpp:78
ostream * os_
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 118 of file PeakFitterTest.cpp.

References testMultiplePeaks(), and testParabola().

Referenced by main().

119 {
120  testParabola();
122 }
void testParabola()
void testMultiplePeaks()

§ main()

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

Definition at line 125 of file PeakFitterTest.cpp.

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

126 {
127  TEST_PROLOG(argc, argv)
128 
129  try
130  {
131  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
132  test();
133  }
134  catch (exception& e)
135  {
136  TEST_FAILED(e.what())
137  }
138  catch (...)
139  {
140  TEST_FAILED("Caught unknown exception.")
141  }
142 
144 }
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_FAILED(x)
Definition: unit.hpp:176
ostream * os_
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
void test()

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 36 of file PeakFitterTest.cpp.

Referenced by main(), testMultiplePeaks(), and testParabola().