71 |
14 Feb 06 |
jari |
// $Id$ |
71 |
14 Feb 06 |
jari |
2 |
|
95 |
05 Apr 06 |
jari |
3 |
/* |
95 |
05 Apr 06 |
jari |
Copyright (C) 2005, 2006 Jari Häkkinen |
836 |
28 Nov 08 |
peter |
Copyright (C) 2007 2008 Peter Johansson |
95 |
05 Apr 06 |
jari |
6 |
|
95 |
05 Apr 06 |
jari |
This file is part of WeNNI, |
825 |
26 Nov 08 |
jari |
http://baseplugins.thep.lu.se/wiki/se.lu.thep.WeNNI |
95 |
05 Apr 06 |
jari |
9 |
|
95 |
05 Apr 06 |
jari |
WeNNI is free software; you can redistribute it and/or modify it |
95 |
05 Apr 06 |
jari |
under the terms of the GNU General Public License as published by |
824 |
26 Nov 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
95 |
05 Apr 06 |
jari |
(at your option) any later version. |
95 |
05 Apr 06 |
jari |
14 |
|
95 |
05 Apr 06 |
jari |
WeNNI is distributed in the hope that it will be useful, but WITHOUT |
95 |
05 Apr 06 |
jari |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
95 |
05 Apr 06 |
jari |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
95 |
05 Apr 06 |
jari |
License for more details. |
95 |
05 Apr 06 |
jari |
19 |
|
95 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
824 |
26 Nov 08 |
jari |
along with WeNNI. If not, see <http://www.gnu.org/licenses/>. |
95 |
05 Apr 06 |
jari |
22 |
*/ |
95 |
05 Apr 06 |
jari |
23 |
|
849 |
01 Dec 08 |
peter |
24 |
#include <config.h> |
849 |
01 Dec 08 |
peter |
25 |
|
75 |
15 Feb 06 |
jari |
26 |
#include "c++_tools/gslapi/matrix.h" |
75 |
15 Feb 06 |
jari |
27 |
|
836 |
28 Nov 08 |
peter |
28 |
#include <cassert> |
75 |
15 Feb 06 |
jari |
29 |
#include <cmath> |
71 |
14 Feb 06 |
jari |
30 |
#include <cstdlib> |
71 |
14 Feb 06 |
jari |
31 |
#include <iostream> |
75 |
15 Feb 06 |
jari |
32 |
#include <fstream> |
836 |
28 Nov 08 |
peter |
33 |
#include <sstream> |
71 |
14 Feb 06 |
jari |
34 |
#include <string> |
71 |
14 Feb 06 |
jari |
35 |
#include <unistd.h> |
71 |
14 Feb 06 |
jari |
36 |
|
72 |
14 Feb 06 |
jari |
37 |
bool check_default_results(void); |
74 |
15 Feb 06 |
jari |
38 |
bool check_knni_results(void); |
72 |
14 Feb 06 |
jari |
39 |
bool check_raw_results(void); |
74 |
15 Feb 06 |
jari |
40 |
bool check_wenni_snr_results(void); |
71 |
14 Feb 06 |
jari |
41 |
bool cleanup(void); |
86 |
04 Apr 06 |
jari |
42 |
bool compare(const std::string&, const std::string&, double error_bound=1e-20); |
86 |
04 Apr 06 |
jari |
43 |
bool diff(const std::string&, const std::string&); |
846 |
01 Dec 08 |
peter |
44 |
std::string get_srcdir(void); |
72 |
14 Feb 06 |
jari |
45 |
bool rm(const std::string& filename); |
71 |
14 Feb 06 |
jari |
46 |
|
71 |
14 Feb 06 |
jari |
47 |
int main(const int argc,const char* argv[]) |
71 |
14 Feb 06 |
jari |
48 |
{ |
71 |
14 Feb 06 |
jari |
49 |
bool teststatus=false; |
71 |
14 Feb 06 |
jari |
50 |
|
849 |
01 Dec 08 |
peter |
51 |
if (WeNNI_STATE == "base1") { |
849 |
01 Dec 08 |
peter |
52 |
teststatus|=check_raw_results(); |
849 |
01 Dec 08 |
peter |
53 |
teststatus|=check_default_results(); |
849 |
01 Dec 08 |
peter |
54 |
} |
72 |
14 Feb 06 |
jari |
55 |
|
846 |
01 Dec 08 |
peter |
56 |
std::string srcdir=get_srcdir(); |
836 |
28 Nov 08 |
peter |
57 |
std::stringstream system_call; |
849 |
01 Dec 08 |
peter |
58 |
system_call << "./nni -data " << srcdir << "/../data/wenni_logratio.data" |
836 |
28 Nov 08 |
peter |
59 |
<< " -neighbours 10 -weight " << srcdir |
836 |
28 Nov 08 |
peter |
60 |
<< "/../data/wenni_snr.data -weight_is_snr" |
836 |
28 Nov 08 |
peter |
61 |
<< " > wenni_imputed.data"; |
836 |
28 Nov 08 |
peter |
62 |
if (system(system_call.str().c_str())) { |
74 |
15 Feb 06 |
jari |
63 |
teststatus|=true; |
74 |
15 Feb 06 |
jari |
64 |
std::cerr << "ERROR: system call failed:\n\t" << system_call << std::endl; |
74 |
15 Feb 06 |
jari |
65 |
} |
74 |
15 Feb 06 |
jari |
66 |
teststatus|=check_wenni_snr_results(); |
74 |
15 Feb 06 |
jari |
67 |
|
836 |
28 Nov 08 |
peter |
68 |
system_call.str(""); |
849 |
01 Dec 08 |
peter |
69 |
system_call << "./nni -data " << srcdir |
849 |
01 Dec 08 |
peter |
70 |
<< "/../data/wenni_logratio.data -neighbours 10" |
849 |
01 Dec 08 |
peter |
71 |
<< " -nni_algorithm kNNI -weight " << srcdir |
849 |
01 Dec 08 |
peter |
72 |
<< "/../data/wenni_weight.data" |
836 |
28 Nov 08 |
peter |
73 |
<< " -weight_cutoff 0.5 > knni_imputed.data"; |
836 |
28 Nov 08 |
peter |
74 |
if (system(system_call.str().c_str())) { |
74 |
15 Feb 06 |
jari |
75 |
teststatus|=true; |
74 |
15 Feb 06 |
jari |
76 |
std::cerr << "ERROR: system call failed:\n\t" << system_call << std::endl; |
74 |
15 Feb 06 |
jari |
77 |
} |
74 |
15 Feb 06 |
jari |
78 |
teststatus|=check_knni_results(); |
74 |
15 Feb 06 |
jari |
79 |
|
325 |
01 Jun 07 |
peter |
//teststatus|=cleanup(); |
71 |
14 Feb 06 |
jari |
81 |
|
71 |
14 Feb 06 |
jari |
82 |
return (teststatus ? -1 : 0); |
71 |
14 Feb 06 |
jari |
83 |
} |
71 |
14 Feb 06 |
jari |
84 |
|
71 |
14 Feb 06 |
jari |
85 |
|
72 |
14 Feb 06 |
jari |
86 |
bool check_default_results(void) |
72 |
14 Feb 06 |
jari |
87 |
{ |
846 |
01 Dec 08 |
peter |
88 |
std::string srcdir=get_srcdir(); |
836 |
28 Nov 08 |
peter |
89 |
|
72 |
14 Feb 06 |
jari |
90 |
bool teststatus=false; |
836 |
28 Nov 08 |
peter |
91 |
teststatus|=diff("default_results/BASEfile.data", |
836 |
28 Nov 08 |
peter |
92 |
srcdir+"/../data/basefile_in.data"); |
325 |
01 Jun 07 |
peter |
93 |
teststatus|=diff("default_results/basefile_out.data", |
836 |
28 Nov 08 |
peter |
94 |
srcdir+"/../data/basefile_out.data"); |
325 |
01 Jun 07 |
peter |
95 |
teststatus|=compare("default_results/wenni_BCh1SD.data", |
836 |
28 Nov 08 |
peter |
96 |
srcdir+"/../data/wenni_BCh1SD.data"); |
325 |
01 Jun 07 |
peter |
97 |
teststatus|=compare("default_results/wenni_BCh2SD.data", |
836 |
28 Nov 08 |
peter |
98 |
srcdir+"/../data/wenni_BCh2SD.data"); |
325 |
01 Jun 07 |
peter |
99 |
teststatus|=compare("default_results/wenni_imputed.data", |
836 |
28 Nov 08 |
peter |
100 |
srcdir+"/../data/wenni_imputed.data"); |
325 |
01 Jun 07 |
peter |
101 |
teststatus|=compare("default_results/wenni_intensity1.data", |
836 |
28 Nov 08 |
peter |
102 |
srcdir+"/../data/wenni_intensity1.data"); |
325 |
01 Jun 07 |
peter |
103 |
teststatus|=compare("default_results/wenni_intensity2.data", |
836 |
28 Nov 08 |
peter |
104 |
srcdir+"/../data/wenni_intensity2.data"); |
325 |
01 Jun 07 |
peter |
105 |
teststatus|=compare("default_results/wenni_logratio.data", |
836 |
28 Nov 08 |
peter |
106 |
srcdir+"/../data/wenni_logratio.data"); |
325 |
01 Jun 07 |
peter |
107 |
teststatus|=compare("default_results/wenni_weight.data", |
836 |
28 Nov 08 |
peter |
108 |
srcdir+"/../data/wenni_weight.data"); |
72 |
14 Feb 06 |
jari |
109 |
if (teststatus) |
74 |
15 Feb 06 |
jari |
110 |
std::cerr << "ERROR: check_default_results failed." << std::endl; |
72 |
14 Feb 06 |
jari |
111 |
return teststatus; |
72 |
14 Feb 06 |
jari |
112 |
} |
71 |
14 Feb 06 |
jari |
113 |
|
72 |
14 Feb 06 |
jari |
114 |
|
74 |
15 Feb 06 |
jari |
115 |
bool check_knni_results(void) |
74 |
15 Feb 06 |
jari |
116 |
{ |
846 |
01 Dec 08 |
peter |
117 |
std::string srcdir=get_srcdir(); |
74 |
15 Feb 06 |
jari |
118 |
bool teststatus=false; |
836 |
28 Nov 08 |
peter |
119 |
teststatus|=diff("knni_imputed.data",srcdir+"/../data/knni_imputed.data"); |
74 |
15 Feb 06 |
jari |
120 |
if (teststatus) |
74 |
15 Feb 06 |
jari |
121 |
std::cerr << "ERROR: check_knni_results failed." << std::endl; |
74 |
15 Feb 06 |
jari |
122 |
return teststatus; |
74 |
15 Feb 06 |
jari |
123 |
} |
74 |
15 Feb 06 |
jari |
124 |
|
74 |
15 Feb 06 |
jari |
125 |
|
72 |
14 Feb 06 |
jari |
126 |
bool check_raw_results(void) |
72 |
14 Feb 06 |
jari |
127 |
{ |
846 |
01 Dec 08 |
peter |
128 |
std::string srcdir=get_srcdir(); |
836 |
28 Nov 08 |
peter |
129 |
|
72 |
14 Feb 06 |
jari |
130 |
bool teststatus=false; |
836 |
28 Nov 08 |
peter |
131 |
teststatus|=diff("raw_results/BASEfile.data", |
836 |
28 Nov 08 |
peter |
132 |
srcdir+"/../data/basefile_in.data"); |
325 |
01 Jun 07 |
peter |
133 |
teststatus|=diff("raw_results/basefile_out.data","../data/basefile_out.data"); |
325 |
01 Jun 07 |
peter |
134 |
teststatus|=compare("raw_results/wenni_BCh1Mean.data", |
836 |
28 Nov 08 |
peter |
135 |
srcdir+"/../data/wenni_BCh1Mean.data"); |
325 |
01 Jun 07 |
peter |
136 |
teststatus|=compare("raw_results/wenni_BCh1SD.data", |
836 |
28 Nov 08 |
peter |
137 |
srcdir+"/../data/wenni_BCh1SD.data"); |
325 |
01 Jun 07 |
peter |
138 |
teststatus|=compare("raw_results/wenni_BCh2Mean.data", |
836 |
28 Nov 08 |
peter |
139 |
srcdir+"/../data/wenni_BCh2Mean.data"); |
325 |
01 Jun 07 |
peter |
140 |
teststatus|=compare("raw_results/wenni_BCh2SD.data", |
836 |
28 Nov 08 |
peter |
141 |
srcdir+"/../data/wenni_BCh2SD.data"); |
325 |
01 Jun 07 |
peter |
142 |
teststatus|=compare("raw_results/wenni_FCh1Mean.data", |
836 |
28 Nov 08 |
peter |
143 |
srcdir+"/../data/wenni_FCh1Mean.data"); |
325 |
01 Jun 07 |
peter |
144 |
teststatus|=compare("raw_results/wenni_FCh2Mean.data", |
836 |
28 Nov 08 |
peter |
145 |
srcdir+"/../data/wenni_FCh2Mean.data"); |
325 |
01 Jun 07 |
peter |
146 |
teststatus|=compare("raw_results/wenni_imputed.data", |
836 |
28 Nov 08 |
peter |
147 |
srcdir+"/../data/wenni_imputed.data"); |
325 |
01 Jun 07 |
peter |
148 |
teststatus|=compare("raw_results/wenni_logratio.data", |
836 |
28 Nov 08 |
peter |
149 |
srcdir+"/../data/wenni_logratio.data"); |
325 |
01 Jun 07 |
peter |
150 |
teststatus|=compare("raw_results/wenni_weight.data", |
836 |
28 Nov 08 |
peter |
151 |
srcdir+"/../data/wenni_weight.data"); |
72 |
14 Feb 06 |
jari |
152 |
if (teststatus) |
72 |
14 Feb 06 |
jari |
153 |
std::cerr << "ERROR: check_raw_results failed." << std::endl; |
72 |
14 Feb 06 |
jari |
154 |
return teststatus; |
71 |
14 Feb 06 |
jari |
155 |
} |
71 |
14 Feb 06 |
jari |
156 |
|
72 |
14 Feb 06 |
jari |
157 |
|
74 |
15 Feb 06 |
jari |
158 |
bool check_wenni_snr_results(void) |
74 |
15 Feb 06 |
jari |
159 |
{ |
74 |
15 Feb 06 |
jari |
160 |
bool teststatus=false; |
846 |
01 Dec 08 |
peter |
161 |
std::string srcdir=get_srcdir(); |
836 |
28 Nov 08 |
peter |
162 |
teststatus|=compare("wenni_imputed.data",srcdir+"/../data/wenni_imputed.data", |
86 |
04 Apr 06 |
jari |
163 |
1.1e-11); |
74 |
15 Feb 06 |
jari |
164 |
if (teststatus) |
74 |
15 Feb 06 |
jari |
165 |
std::cerr << "ERROR: check_wenni_results failed." << std::endl; |
74 |
15 Feb 06 |
jari |
166 |
return teststatus; |
74 |
15 Feb 06 |
jari |
167 |
} |
74 |
15 Feb 06 |
jari |
168 |
|
74 |
15 Feb 06 |
jari |
169 |
|
71 |
14 Feb 06 |
jari |
170 |
bool cleanup(void) |
71 |
14 Feb 06 |
jari |
171 |
{ |
71 |
14 Feb 06 |
jari |
172 |
bool teststatus=false; |
71 |
14 Feb 06 |
jari |
173 |
teststatus|=rm("BASEfile.data"); |
74 |
15 Feb 06 |
jari |
174 |
teststatus|=rm("basefile_out.data"); |
74 |
15 Feb 06 |
jari |
175 |
teststatus|=rm("knni_imputed.data"); |
71 |
14 Feb 06 |
jari |
176 |
teststatus|=rm("wenni_BCh1Mean.data"); |
71 |
14 Feb 06 |
jari |
177 |
teststatus|=rm("wenni_BCh1SD.data"); |
71 |
14 Feb 06 |
jari |
178 |
teststatus|=rm("wenni_BCh2Mean.data"); |
71 |
14 Feb 06 |
jari |
179 |
teststatus|=rm("wenni_BCh2SD.data"); |
71 |
14 Feb 06 |
jari |
180 |
teststatus|=rm("wenni_FCh1Mean.data"); |
71 |
14 Feb 06 |
jari |
181 |
teststatus|=rm("wenni_FCh2Mean.data"); |
71 |
14 Feb 06 |
jari |
182 |
teststatus|=rm("wenni_imputed.data"); |
72 |
14 Feb 06 |
jari |
183 |
teststatus|=rm("wenni_intensity1.data"); |
72 |
14 Feb 06 |
jari |
184 |
teststatus|=rm("wenni_intensity2.data"); |
71 |
14 Feb 06 |
jari |
185 |
teststatus|=rm("wenni_logratio.data"); |
71 |
14 Feb 06 |
jari |
186 |
teststatus|=rm("wenni_weight.data"); |
71 |
14 Feb 06 |
jari |
187 |
return teststatus; |
71 |
14 Feb 06 |
jari |
188 |
} |
72 |
14 Feb 06 |
jari |
189 |
|
72 |
14 Feb 06 |
jari |
190 |
|
86 |
04 Apr 06 |
jari |
191 |
bool compare(const std::string& a,const std::string& b, double error_bound) |
75 |
15 Feb 06 |
jari |
192 |
{ |
75 |
15 Feb 06 |
jari |
193 |
bool teststatus=false; |
75 |
15 Feb 06 |
jari |
194 |
std::ifstream astream(a.c_str()); |
836 |
28 Nov 08 |
peter |
195 |
assert(astream.good()); |
75 |
15 Feb 06 |
jari |
196 |
std::ifstream bstream(b.c_str()); |
836 |
28 Nov 08 |
peter |
197 |
assert(bstream.good()); |
75 |
15 Feb 06 |
jari |
198 |
theplu::gslapi::matrix adata(astream); |
75 |
15 Feb 06 |
jari |
199 |
theplu::gslapi::matrix bdata(bstream); |
75 |
15 Feb 06 |
jari |
200 |
adata-=bdata; |
75 |
15 Feb 06 |
jari |
201 |
for (size_t i=0; i<adata.rows(); i++) |
75 |
15 Feb 06 |
jari |
202 |
for (size_t j=0; j<adata.columns(); j++) |
75 |
15 Feb 06 |
jari |
203 |
if ((fabs(adata(i,j))>error_bound) || // result outside acceptable bounds |
75 |
15 Feb 06 |
jari |
204 |
(!((adata(i,j)==adata(i,j))))) // calucaltion error detected |
75 |
15 Feb 06 |
jari |
205 |
teststatus=true; |
75 |
15 Feb 06 |
jari |
206 |
astream.close(); |
75 |
15 Feb 06 |
jari |
207 |
bstream.close(); |
325 |
01 Jun 07 |
peter |
208 |
if (teststatus) |
325 |
01 Jun 07 |
peter |
209 |
std::cerr << "ERROR: compare " << a << " " << b << std::endl; |
75 |
15 Feb 06 |
jari |
210 |
return teststatus; |
75 |
15 Feb 06 |
jari |
211 |
} |
75 |
15 Feb 06 |
jari |
212 |
|
75 |
15 Feb 06 |
jari |
213 |
|
72 |
14 Feb 06 |
jari |
214 |
bool diff(const std::string& a,const std::string& b) |
72 |
14 Feb 06 |
jari |
215 |
{ |
325 |
01 Jun 07 |
peter |
216 |
std::ifstream is1(a.c_str()); |
836 |
28 Nov 08 |
peter |
217 |
assert(is1.good()); |
325 |
01 Jun 07 |
peter |
218 |
std::ifstream is2(a.c_str()); |
836 |
28 Nov 08 |
peter |
219 |
assert(is2.good()); |
325 |
01 Jun 07 |
peter |
220 |
std::string str1; |
325 |
01 Jun 07 |
peter |
221 |
std::string str2; |
325 |
01 Jun 07 |
peter |
222 |
while (getline(is1,str1)){ |
325 |
01 Jun 07 |
peter |
223 |
getline(is2,str2); |
325 |
01 Jun 07 |
peter |
224 |
if (str1!=str2) { |
325 |
01 Jun 07 |
peter |
225 |
std::cerr << "ERROR: diff " << a << " " << b << std::endl; |
325 |
01 Jun 07 |
peter |
226 |
return true; |
325 |
01 Jun 07 |
peter |
227 |
} |
72 |
14 Feb 06 |
jari |
228 |
} |
325 |
01 Jun 07 |
peter |
229 |
return false; |
72 |
14 Feb 06 |
jari |
230 |
} |
72 |
14 Feb 06 |
jari |
231 |
|
72 |
14 Feb 06 |
jari |
232 |
|
846 |
01 Dec 08 |
peter |
233 |
std::string get_srcdir(void) |
846 |
01 Dec 08 |
peter |
234 |
{ |
846 |
01 Dec 08 |
peter |
235 |
char* buf=std::getenv("srcdir"); |
846 |
01 Dec 08 |
peter |
236 |
if (buf) |
846 |
01 Dec 08 |
peter |
237 |
return buf; |
846 |
01 Dec 08 |
peter |
238 |
return "."; |
846 |
01 Dec 08 |
peter |
239 |
|
846 |
01 Dec 08 |
peter |
240 |
} |
846 |
01 Dec 08 |
peter |
241 |
|
846 |
01 Dec 08 |
peter |
242 |
|
72 |
14 Feb 06 |
jari |
243 |
bool rm(const std::string& filename) { |
72 |
14 Feb 06 |
jari |
244 |
if (unlink(filename.c_str())) { |
72 |
14 Feb 06 |
jari |
245 |
std::cerr << "ERROR: unlink call failed for: " << filename << std::endl; |
72 |
14 Feb 06 |
jari |
246 |
return true; |
72 |
14 Feb 06 |
jari |
247 |
} |
72 |
14 Feb 06 |
jari |
248 |
return false; |
72 |
14 Feb 06 |
jari |
249 |
} |