ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
analysis
peakdetect
FeatureModelerTest.cpp
Go to the documentation of this file.
1
//
2
// $Id: FeatureModelerTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3
//
4
//
5
// Original author: Darren Kessner <darren@proteowizard.org>
6
//
7
// Copyright 2009 Center for Applied Molecular Medicine
8
// University of Southern California, Los Angeles, CA
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 "
FeatureModeler.hpp
"
25
#include "
pwiz/utility/misc/unit.hpp
"
26
#include "boost/filesystem/path.hpp"
27
#include "
pwiz/utility/misc/Std.hpp
"
28
#include <cstring>
29
30
31
using namespace
pwiz::util;
32
using namespace
pwiz::analysis;
33
using namespace
pwiz::data::peakdata;
34
namespace
bfs = boost::filesystem;
35
36
37
ostream*
os_
= 0;
38
39
40
FeaturePtr
getFeature
(
const
string
& filename)
41
{
42
ifstream is(filename.c_str());
43
if
(!is)
throw
runtime_error((
"Unable to open file "
+ filename).c_str());
44
45
FeaturePtr
feature(
new
Feature
);
46
is >> *feature;
47
48
return
feature;
49
}
50
51
52
void
testGaussian_Bombesin2
(
const
Feature
& bombesin2)
53
{
54
if
(
os_
) *
os_
<<
"testGaussian_Bombesin2()\n"
;
55
unit_assert
(bombesin2.
peakels
.size() == 5);
56
57
if
(
os_
) *
os_
<<
"before:\n"
<< bombesin2;
58
59
FeatureModeler_Gaussian
fm;
60
Feature
result;
61
fm.
fitFeature
(bombesin2, result);
62
63
if
(
os_
) *
os_
<<
"after:\n"
<< result << endl;
64
}
65
66
67
void
testGaussian_Bombesin3
(
const
Feature
& bombesin3)
68
{
69
if
(
os_
) *
os_
<<
"testGaussian_Bombesin3()\n"
;
70
unit_assert
(bombesin3.
peakels
.size() == 3);
71
72
if
(
os_
) *
os_
<<
"before:\n"
<< bombesin3;
73
74
FeatureModeler_Gaussian
fm;
75
Feature
result;
76
fm.
fitFeature
(bombesin3, result);
77
78
if
(
os_
) *
os_
<<
"after:\n"
<< result << endl;
79
}
80
81
82
void
testMulti
(
const
FeatureField
& ff)
83
{
84
if
(
os_
) *
os_
<<
"testMulti()\n"
;
85
86
FeatureField
result;
87
unit_assert
(result.empty());
88
89
FeatureModeler_Gaussian
fm;
90
fm.
fitFeatures
(ff, result);
91
92
if
(
os_
) *
os_
<< result << endl;
93
unit_assert
(result.size() == 2);
94
}
95
96
97
void
test
(
const
bfs::path& datadir)
98
{
99
FeaturePtr
bombesin2 =
getFeature
((datadir /
"Bombesin2.feature"
).
string
());
100
FeaturePtr
bombesin3 =
getFeature
((datadir /
"Bombesin3.feature"
).
string
());
101
102
testGaussian_Bombesin2
(*bombesin2);
103
testGaussian_Bombesin3
(*bombesin3);
104
105
FeatureField
ff;
106
ff.insert(bombesin2);
107
ff.insert(bombesin3);
108
testMulti
(ff);
109
}
110
111
112
int
main
(
int
argc,
char
* argv[])
113
{
114
TEST_PROLOG
(argc, argv)
115
116
try
117
{
118
bfs::path datadir =
"."
;
119
120
for
(
int
i=1; i<argc; i++)
121
{
122
if
(!strcmp(argv[i],
"-v"
))
123
os_
= &cout;
124
else
125
// hack to allow running unit test from a different directory:
126
// Jamfile passes full path to specified input file.
127
// we want the path, so we can ignore filename
128
datadir = bfs::path(argv[i]).branch_path();
129
}
130
131
test
(datadir);
132
}
133
catch
(exception&
e
)
134
{
135
TEST_FAILED
(e.what())
136
}
137
catch
(...)
138
{
139
TEST_FAILED
(
"Caught unknown exception."
)
140
}
141
142
TEST_EPILOG
143
}
144
Generated on Mon Nov 26 2012 18:05:47 for ProteoWizard by
1.8.1.1