ProteoWizard
FeatureModelerTest.cpp
Go to the documentation of this file.
1//
2// $Id$
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"
26#include "boost/filesystem/path.hpp"
28#include <cstring>
29
30
31using namespace pwiz::util;
32using namespace pwiz::analysis;
33using namespace pwiz::data::peakdata;
34namespace bfs = boost::filesystem;
35
36
37ostream* os_ = 0;
38
39
40FeaturePtr getFeature(const string& filename)
41{
42 std::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
52void 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
60 Feature result;
61 fm.fitFeature(bombesin2, result);
62
63 if (os_) *os_ << "after:\n" << result << endl;
64}
65
66
67void 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
75 Feature result;
76 fm.fitFeature(bombesin3, result);
77
78 if (os_) *os_ << "after:\n" << result << endl;
79}
80
81
82void testMulti(const FeatureField& ff)
83{
84 if (os_) *os_ << "testMulti()\n";
85
86 FeatureField result;
87 unit_assert(result.empty());
88
90 fm.fitFeatures(ff, result);
91
92 if (os_) *os_ << result << endl;
93 unit_assert(result.size() == 2);
94}
95
96
97void 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
112int 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
143}
144
int main(int argc, char *argv[])
void testMulti(const FeatureField &ff)
void testGaussian_Bombesin2(const Feature &bombesin2)
FeaturePtr getFeature(const string &filename)
void testGaussian_Bombesin3(const Feature &bombesin3)
ostream * os_
virtual void fitFeature(const Feature &in, Feature &out) const
virtual void fitFeatures(const FeatureField &in, FeatureField &out) const
boost::shared_ptr< Feature > FeaturePtr
Definition PeakData.hpp:292
MZRTField is a std::set of boost::shared_ptrs, stored as a binary tree ordered by LessThan_MZRT.
Definition MZRTField.hpp:95
std::vector< PeakelPtr > peakels
Definition PeakData.hpp:274
#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