ProteoWizard
PeakDetectorNaiveTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2006 Louis Warschaw Prostate Cancer Center
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
24#include "PeakDetectorNaive.hpp"
29
30using namespace pwiz::util;
31using namespace pwiz::frequency;
32using namespace pwiz::data;
33using namespace pwiz::data::peakdata;
34
35
36ostream* os_ = 0;
37
38
40{
41 const double noiseFactor = 666;
42 const unsigned int detectionRadius = 13;
43 auto_ptr<PeakDetectorNaive> pd = PeakDetectorNaive::create(noiseFactor, detectionRadius);
44 unit_assert(pd->noiseFactor() == noiseFactor);
45 unit_assert(pd->detectionRadius() == detectionRadius);
46}
47
48
50{
51 FrequencyDatum(0, 0),
52 FrequencyDatum(1, 1), // peak radius 1
53 FrequencyDatum(2, 0),
54 FrequencyDatum(3, 1),
55 FrequencyDatum(4, 2), // peak radius 2
56 FrequencyDatum(5, 1),
57 FrequencyDatum(6, 0),
58 FrequencyDatum(7, 1),
59 FrequencyDatum(8, 2),
60 FrequencyDatum(9, 3), // peak radius 3
61 FrequencyDatum(10, 2),
62 FrequencyDatum(11, 1),
63 FrequencyDatum(12, 0)
64};
65
66
67const unsigned int dataSize_ = sizeof(data_)/sizeof(FrequencyDatum);
68
69
71{
73 copy(data_, data_+dataSize_, back_inserter(fd.data()));
74 if (os_) copy(fd.data().begin(), fd.data().end(), ostream_iterator<FrequencyDatum>(*os_, "\n"));
75 fd.analyze();
76
77 PeakData pd;
78 pd.scans.resize(3);
79
80 const double noiseFactor = 1;
81
82 auto_ptr<PeakDetectorNaive> pdn1 = PeakDetectorNaive::create(noiseFactor, 1);
83 pdn1->findPeaks(fd, pd.scans[0]);
84 unit_assert(pd.scans[0].peakFamilies.size() == 3);
85
86 auto_ptr<PeakDetectorNaive> pdn2 = PeakDetectorNaive::create(noiseFactor, 2);
87 pdn2->findPeaks(fd, pd.scans[1]);
88 unit_assert(pd.scans[1].peakFamilies.size() == 2);
89
90 auto_ptr<PeakDetectorNaive> pdn3 = PeakDetectorNaive::create(noiseFactor, 3);
91 pdn3->findPeaks(fd, pd.scans[2]);
92 unit_assert(pd.scans[2].peakFamilies.size() == 1);
93
94 if (os_)
95 {
96 *os_ << "pd:\n" << pd << endl;
97
98 for (unsigned int i=0; i<pd.scans.size(); i++)
99 {
100 *os_ << "scan " << i << ":\n";
101 *os_ << pd.scans[i] << endl;
102 }
103 }
104}
105
106
107void test()
108{
109 testCreation();
110 testFind();
111}
112
113
114int main(int argc, char* argv[])
115{
116 TEST_PROLOG(argc, argv)
117
118 try
119 {
120 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
121 if (os_) *os_ << "PeakDetectorNaiveTest\n";
122 test();
123 }
124 catch (exception& e)
125 {
126 TEST_FAILED(e.what())
127 }
128 catch (...)
129 {
130 TEST_FAILED("Caught unknown exception.")
131 }
132
134}
135
int main(int argc, char *argv[])
void testCreation()
void testFind()
FrequencyDatum data_[]
const unsigned int dataSize_
ostream * os_
void test()
Class for binary storage of complex frequency data.
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< PeakDetectorNaive > create(double noiseFactor=5, unsigned int detectionRadius=2)
create an instance.
SampleDatum< double, std::complex< double > > FrequencyDatum
std::vector< Scan > scans
Definition PeakData.hpp:194
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175