ProteoWizard
FrequencyEstimatorPhysicalModelTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2007 Spielberg Family Center for Appled Proteomics
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
27
28using namespace pwiz::util;
29using namespace pwiz::frequency;
30using namespace pwiz::data;
31using namespace pwiz::data::peakdata;
32
33
34ostream* os_ = 0;
35
36
37struct Datum
38{
39 double frequency;
40 complex<double> intensity;
41};
42
43
45{
46 {159442.7083, complex<double>(4877.101315, 44697.12422)},
47 {159444.0104, complex<double>(4080.603141, 50558.42071)},
48 {159445.3125, complex<double>(6577.789977, 58423.29765)},
49 {159446.6146, complex<double>(12831.99571, 62206.40467)},
50 {159447.9167, complex<double>(12432.57475, 78692.36757)},
51 {159449.2188, complex<double>(14863.21774, 97002.26961)},
52 {159450.5208, complex<double>(20799.47308, 118598.6778)},
53 {159451.8229, complex<double>(22593.31198, 165638.8917)},
54 {159453.125, complex<double>(47599.33584, 277486.3998)},
55 {159454.4271, complex<double>(286144.9904, 833086.4972)},
56 {159455.7292, complex<double>(185071.6796, -646557.3157)},
57 {159457.0312, complex<double>(-17704.58144, -233633.2989)},
58 {159458.3333, complex<double>(12582.54006, -142740.2498)},
59 {159459.6354, complex<double>(-4281.026921, -119490.1607)},
60 {159460.9375, complex<double>(-2407.375413, -104118.8209)},
61 {159462.2396, complex<double>(-6020.466709, -71343.6045)},
62 {159463.5417, complex<double>(-6861.637568, -64726.61834)},
63 {159464.8438, complex<double>(4448.264865, -50486.19487)},
64 {159466.1458, complex<double>(-2683.225884, -43254.46692)},
65 {159467.4479, complex<double>(-1409.582306, -46362.11256)},
66 {159468.75, complex<double>(-901.9171424, -39197.02914)},
67};
68
69
70const int dataSize_ = sizeof(data_)/sizeof(Datum);
71
72
73void test()
74{
75 if (os_) *os_ << setprecision(14);
76
77 // initialize frequency data
78
80 for (const Datum* p=data_; p!=data_+dataSize_; ++p)
81 fd.data().push_back(FrequencyDatum(p->frequency, p->intensity));
82 fd.observationDuration(.768);
83 fd.analyze();
84
85 // "peak detection"
86
87 Peak detected;
88 detected.attributes[Peak::Attribute_Frequency] = fd.max()->x;
89 if (os_) *os_ << "detected: " << detected << endl;
90
91 // create estimator
92
94 auto_ptr<FrequencyEstimatorPhysicalModel> fe(FrequencyEstimatorPhysicalModel::create(config));
95
96 // get estimate and check answer
97
98 Peak estimate = fe->estimate(fd, detected);
99 if (os_) *os_ << "estimate: " << estimate << endl;
100
101 unit_assert_equal(estimate.attributes[Peak::Attribute_Frequency], 159454.98465, 1e-4);
102}
103
104
105int main(int argc, char* argv[])
106{
107 TEST_PROLOG(argc, argv)
108
109 try
110 {
111 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
112 if (os_) *os_ << "FrequencyEstimatorPhysicalModelTest\n";
113 test();
114 }
115 catch (exception& e)
116 {
117 TEST_FAILED(e.what())
118 }
119 catch (...)
120 {
121 TEST_FAILED("Caught unknown exception.")
122 }
123
125}
126
int main(int argc, char *argv[])
Class for binary storage of complex frequency data.
double observationDuration() const
const_iterator max() const
returns an iterator to FrequencyDatum with highest magnitude
void analyze()
recache statistics calculations after any direct data changes via non-const data()
const container & data() const
const access to underlying data
static std::auto_ptr< FrequencyEstimatorPhysicalModel > create(const Config &config)
create an instance
SampleDatum< double, std::complex< double > > FrequencyDatum
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175