69 |
11 Feb 06 |
jari |
// $Id$ |
69 |
11 Feb 06 |
jari |
2 |
|
95 |
05 Apr 06 |
jari |
3 |
/* |
95 |
05 Apr 06 |
jari |
Copyright (C) 2005, 2006 Jari Häkkinen |
95 |
05 Apr 06 |
jari |
5 |
|
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 |
8 |
|
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 |
13 |
|
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 |
18 |
|
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 |
21 |
*/ |
95 |
05 Apr 06 |
jari |
22 |
|
69 |
11 Feb 06 |
jari |
23 |
#include "Parameter.h" |
88 |
04 Apr 06 |
jari |
24 |
#include <config.h> // this header file is created by configure |
69 |
11 Feb 06 |
jari |
25 |
|
69 |
11 Feb 06 |
jari |
26 |
#include <cstdlib> |
69 |
11 Feb 06 |
jari |
27 |
#include <iostream> |
69 |
11 Feb 06 |
jari |
28 |
#include <string> |
69 |
11 Feb 06 |
jari |
29 |
|
69 |
11 Feb 06 |
jari |
30 |
#include <c++_tools/utility/FileIO.h> |
69 |
11 Feb 06 |
jari |
31 |
|
69 |
11 Feb 06 |
jari |
32 |
|
69 |
11 Feb 06 |
jari |
33 |
namespace theplu { |
69 |
11 Feb 06 |
jari |
34 |
namespace wenni { |
69 |
11 Feb 06 |
jari |
35 |
namespace nnifileconverter { |
69 |
11 Feb 06 |
jari |
36 |
|
69 |
11 Feb 06 |
jari |
37 |
Parameter::Parameter(const int argc,const char *argv[]) |
69 |
11 Feb 06 |
jari |
38 |
{ |
69 |
11 Feb 06 |
jari |
39 |
using namespace std; |
69 |
11 Feb 06 |
jari |
40 |
|
69 |
11 Feb 06 |
jari |
41 |
defaults(); |
69 |
11 Feb 06 |
jari |
42 |
|
69 |
11 Feb 06 |
jari |
43 |
for (int i=1; i<argc; i++) { |
69 |
11 Feb 06 |
jari |
44 |
bool ok=false; |
69 |
11 Feb 06 |
jari |
45 |
string myargv(argv[i]); |
69 |
11 Feb 06 |
jari |
46 |
if (myargv==string("-help") || myargv==string("-h")) { |
69 |
11 Feb 06 |
jari |
47 |
help(); |
69 |
11 Feb 06 |
jari |
48 |
exit(0); // always exit after printing help |
69 |
11 Feb 06 |
jari |
49 |
} |
69 |
11 Feb 06 |
jari |
50 |
if (myargv==string("-beta")) |
69 |
11 Feb 06 |
jari |
51 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
52 |
beta_=atof(argv[++i]); |
69 |
11 Feb 06 |
jari |
53 |
ok=true; |
69 |
11 Feb 06 |
jari |
54 |
} |
69 |
11 Feb 06 |
jari |
55 |
if (myargv==string("-bg1")) |
69 |
11 Feb 06 |
jari |
56 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
57 |
bg1_=argv[++i]; |
69 |
11 Feb 06 |
jari |
58 |
ok=true; |
69 |
11 Feb 06 |
jari |
59 |
} |
69 |
11 Feb 06 |
jari |
60 |
if (myargv==string("-bg2")) |
69 |
11 Feb 06 |
jari |
61 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
62 |
bg2_=argv[++i]; |
69 |
11 Feb 06 |
jari |
63 |
ok=true; |
69 |
11 Feb 06 |
jari |
64 |
} |
69 |
11 Feb 06 |
jari |
65 |
if (myargv==string("-bgstd1")) |
69 |
11 Feb 06 |
jari |
66 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
67 |
bgstd1_=argv[++i]; |
69 |
11 Feb 06 |
jari |
68 |
ok=true; |
69 |
11 Feb 06 |
jari |
69 |
} |
69 |
11 Feb 06 |
jari |
70 |
if (myargv==string("-bgstd2")) |
69 |
11 Feb 06 |
jari |
71 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
72 |
bgstd2_=argv[++i]; |
69 |
11 Feb 06 |
jari |
73 |
ok=true; |
69 |
11 Feb 06 |
jari |
74 |
} |
69 |
11 Feb 06 |
jari |
75 |
if (myargv==string("-datatype")) |
69 |
11 Feb 06 |
jari |
76 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
77 |
datatype_=argv[++i]; |
69 |
11 Feb 06 |
jari |
78 |
ok=true; |
69 |
11 Feb 06 |
jari |
79 |
} |
69 |
11 Feb 06 |
jari |
80 |
if (myargv==string("-fg1")) |
69 |
11 Feb 06 |
jari |
81 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
82 |
fg1_=argv[++i]; |
69 |
11 Feb 06 |
jari |
83 |
ok=true; |
69 |
11 Feb 06 |
jari |
84 |
} |
69 |
11 Feb 06 |
jari |
85 |
if (myargv==string("-fg2")) |
69 |
11 Feb 06 |
jari |
86 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
87 |
fg2_=argv[++i]; |
69 |
11 Feb 06 |
jari |
88 |
ok=true; |
69 |
11 Feb 06 |
jari |
89 |
} |
69 |
11 Feb 06 |
jari |
90 |
if (myargv==string("-logratio")) |
69 |
11 Feb 06 |
jari |
91 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
92 |
logratio_=argv[++i]; |
69 |
11 Feb 06 |
jari |
93 |
ok=true; |
69 |
11 Feb 06 |
jari |
94 |
} |
88 |
04 Apr 06 |
jari |
95 |
if (myargv=="--version") { |
88 |
04 Apr 06 |
jari |
96 |
version(); |
88 |
04 Apr 06 |
jari |
97 |
exit(0); |
88 |
04 Apr 06 |
jari |
98 |
} |
69 |
11 Feb 06 |
jari |
99 |
if (myargv==string("-weight")) |
69 |
11 Feb 06 |
jari |
100 |
if ((i+1)<argc) { |
69 |
11 Feb 06 |
jari |
101 |
weight_=argv[++i]; |
69 |
11 Feb 06 |
jari |
102 |
ok=true; |
69 |
11 Feb 06 |
jari |
103 |
} |
69 |
11 Feb 06 |
jari |
104 |
if (!ok) |
69 |
11 Feb 06 |
jari |
105 |
std::cerr << "# Parameter::Parameter Invalid option: " |
69 |
11 Feb 06 |
jari |
106 |
<< argv[i] << '\n'; |
69 |
11 Feb 06 |
jari |
107 |
} |
69 |
11 Feb 06 |
jari |
108 |
|
69 |
11 Feb 06 |
jari |
109 |
analyse(); |
69 |
11 Feb 06 |
jari |
110 |
} |
69 |
11 Feb 06 |
jari |
111 |
|
69 |
11 Feb 06 |
jari |
112 |
void Parameter::analyse(void) |
69 |
11 Feb 06 |
jari |
113 |
{ |
69 |
11 Feb 06 |
jari |
114 |
using namespace theplu::utility; |
69 |
11 Feb 06 |
jari |
115 |
bool allok=true; |
69 |
11 Feb 06 |
jari |
116 |
|
69 |
11 Feb 06 |
jari |
117 |
if (beta_<0) { |
69 |
11 Feb 06 |
jari |
118 |
std::cerr << "Negativ beta is not allowed " << beta_ << std::endl; |
69 |
11 Feb 06 |
jari |
119 |
allok=false; |
69 |
11 Feb 06 |
jari |
120 |
} |
69 |
11 Feb 06 |
jari |
121 |
|
69 |
11 Feb 06 |
jari |
122 |
if (datatype_==std::string("raw")) { |
69 |
11 Feb 06 |
jari |
123 |
if (bg1_.empty()) { |
69 |
11 Feb 06 |
jari |
124 |
std::cerr << "No file for bg1 given" << std::endl; |
69 |
11 Feb 06 |
jari |
125 |
allok=false; |
69 |
11 Feb 06 |
jari |
126 |
} |
69 |
11 Feb 06 |
jari |
127 |
else if (FileIO().access_rights(bg1_,"r")) { |
69 |
11 Feb 06 |
jari |
128 |
std::cerr << "Cannot access channel 1 background input file " << bg1_ |
69 |
11 Feb 06 |
jari |
129 |
<< std::endl; |
69 |
11 Feb 06 |
jari |
130 |
allok=false; |
69 |
11 Feb 06 |
jari |
131 |
} |
69 |
11 Feb 06 |
jari |
132 |
|
69 |
11 Feb 06 |
jari |
133 |
if (bg2_.empty()) { |
69 |
11 Feb 06 |
jari |
134 |
std::cerr << "No file for bg2 given" << std::endl; |
69 |
11 Feb 06 |
jari |
135 |
allok=false; |
69 |
11 Feb 06 |
jari |
136 |
} |
69 |
11 Feb 06 |
jari |
137 |
else if (FileIO().access_rights(bg2_,"r")) { |
69 |
11 Feb 06 |
jari |
138 |
std::cerr << "Cannot access channel 2 background input file " << bg2_ |
69 |
11 Feb 06 |
jari |
139 |
<< std::endl; |
69 |
11 Feb 06 |
jari |
140 |
allok=false; |
69 |
11 Feb 06 |
jari |
141 |
} |
69 |
11 Feb 06 |
jari |
142 |
} |
69 |
11 Feb 06 |
jari |
143 |
|
69 |
11 Feb 06 |
jari |
144 |
if (bgstd1_.empty()) { |
69 |
11 Feb 06 |
jari |
145 |
std::cerr << "No file for bgstd1 given" << std::endl; |
69 |
11 Feb 06 |
jari |
146 |
allok=false; |
69 |
11 Feb 06 |
jari |
147 |
} |
69 |
11 Feb 06 |
jari |
148 |
else if (FileIO().access_rights(bgstd1_,"r")) { |
69 |
11 Feb 06 |
jari |
149 |
std::cerr << "Cannot access channel 1 background std input file " |
69 |
11 Feb 06 |
jari |
150 |
<< bgstd1_ << std::endl; |
69 |
11 Feb 06 |
jari |
151 |
allok=false; |
69 |
11 Feb 06 |
jari |
152 |
} |
69 |
11 Feb 06 |
jari |
153 |
|
69 |
11 Feb 06 |
jari |
154 |
if (bgstd2_.empty()) { |
69 |
11 Feb 06 |
jari |
155 |
std::cerr << "No file for bgstd2 given" << std::endl; |
69 |
11 Feb 06 |
jari |
156 |
allok=false; |
69 |
11 Feb 06 |
jari |
157 |
} |
69 |
11 Feb 06 |
jari |
158 |
else if (FileIO().access_rights(bgstd2_,"r")) { |
69 |
11 Feb 06 |
jari |
159 |
std::cerr << "Cannot access channel 2 background std input file " |
69 |
11 Feb 06 |
jari |
160 |
<< bgstd2_ << std::endl; |
69 |
11 Feb 06 |
jari |
161 |
allok=false; |
69 |
11 Feb 06 |
jari |
162 |
} |
69 |
11 Feb 06 |
jari |
163 |
|
69 |
11 Feb 06 |
jari |
164 |
if (datatype_!=std::string("derived") && datatype_!=std::string("raw")) { |
69 |
11 Feb 06 |
jari |
165 |
std::cerr << "Illegal datatype value: " << datatype_ << std::endl; |
69 |
11 Feb 06 |
jari |
166 |
allok=false; |
69 |
11 Feb 06 |
jari |
167 |
} |
69 |
11 Feb 06 |
jari |
168 |
|
69 |
11 Feb 06 |
jari |
169 |
if (fg1_.empty()) { |
69 |
11 Feb 06 |
jari |
170 |
std::cerr << "No file for fg1 given" << std::endl; |
69 |
11 Feb 06 |
jari |
171 |
allok=false; |
69 |
11 Feb 06 |
jari |
172 |
} |
69 |
11 Feb 06 |
jari |
173 |
else if (FileIO().access_rights(fg1_,"r")) { |
69 |
11 Feb 06 |
jari |
174 |
std::cerr << "Cannot access channel 1 foreground input file " << fg1_ |
69 |
11 Feb 06 |
jari |
175 |
<< std::endl; |
69 |
11 Feb 06 |
jari |
176 |
allok=false; |
69 |
11 Feb 06 |
jari |
177 |
} |
69 |
11 Feb 06 |
jari |
178 |
|
69 |
11 Feb 06 |
jari |
179 |
if (fg2_.empty()) { |
69 |
11 Feb 06 |
jari |
180 |
std::cerr << "No file for fg2 given" << std::endl; |
69 |
11 Feb 06 |
jari |
181 |
allok=false; |
69 |
11 Feb 06 |
jari |
182 |
} |
69 |
11 Feb 06 |
jari |
183 |
else if (FileIO().access_rights(fg2_,"r")) { |
69 |
11 Feb 06 |
jari |
184 |
std::cerr << "Cannot access channel 2 foreground input file " << fg2_ |
69 |
11 Feb 06 |
jari |
185 |
<< std::endl; |
69 |
11 Feb 06 |
jari |
186 |
allok=false; |
69 |
11 Feb 06 |
jari |
187 |
} |
69 |
11 Feb 06 |
jari |
188 |
|
69 |
11 Feb 06 |
jari |
189 |
if (logratio_.empty()) { |
69 |
11 Feb 06 |
jari |
190 |
std::cerr << "No file for logratio given" << std::endl; |
69 |
11 Feb 06 |
jari |
191 |
allok=false; |
69 |
11 Feb 06 |
jari |
192 |
} |
69 |
11 Feb 06 |
jari |
193 |
/* |
69 |
11 Feb 06 |
jari |
else if (FileIO().access_rights(logratio_,"w")) { |
69 |
11 Feb 06 |
jari |
std::cerr << "No write rights for output file " << logratio_ << std::endl; |
69 |
11 Feb 06 |
jari |
allok=false; |
69 |
11 Feb 06 |
jari |
197 |
} |
69 |
11 Feb 06 |
jari |
198 |
*/ |
69 |
11 Feb 06 |
jari |
199 |
|
69 |
11 Feb 06 |
jari |
200 |
if (weight_.empty()) { |
69 |
11 Feb 06 |
jari |
201 |
std::cerr << "No file for weight given" << std::endl; |
69 |
11 Feb 06 |
jari |
202 |
allok=false; |
69 |
11 Feb 06 |
jari |
203 |
} |
69 |
11 Feb 06 |
jari |
204 |
/* |
69 |
11 Feb 06 |
jari |
else if (FileIO().access_rights(weight_,"w")) { |
69 |
11 Feb 06 |
jari |
std::cerr << "No write rights for output file " << weight_ << std::endl; |
69 |
11 Feb 06 |
jari |
allok=false; |
69 |
11 Feb 06 |
jari |
208 |
} |
69 |
11 Feb 06 |
jari |
209 |
*/ |
69 |
11 Feb 06 |
jari |
210 |
|
69 |
11 Feb 06 |
jari |
211 |
if (!allok) |
69 |
11 Feb 06 |
jari |
212 |
std::exit(-1); |
69 |
11 Feb 06 |
jari |
213 |
} |
69 |
11 Feb 06 |
jari |
214 |
|
69 |
11 Feb 06 |
jari |
215 |
|
69 |
11 Feb 06 |
jari |
216 |
|
69 |
11 Feb 06 |
jari |
217 |
void Parameter::defaults(void) |
69 |
11 Feb 06 |
jari |
218 |
{ |
73 |
14 Feb 06 |
jari |
219 |
beta_=0.6; |
69 |
11 Feb 06 |
jari |
220 |
datatype_=std::string("raw"); |
69 |
11 Feb 06 |
jari |
221 |
logratio_=std::string("logratio.data"); |
69 |
11 Feb 06 |
jari |
222 |
weight_=std::string("weight.data"); |
69 |
11 Feb 06 |
jari |
223 |
} |
69 |
11 Feb 06 |
jari |
224 |
|
69 |
11 Feb 06 |
jari |
225 |
|
69 |
11 Feb 06 |
jari |
226 |
|
69 |
11 Feb 06 |
jari |
227 |
void Parameter::help(void) const |
69 |
11 Feb 06 |
jari |
228 |
{ |
69 |
11 Feb 06 |
jari |
229 |
std::cout << "Convert files created by BaseFileConverter to logratios\n" |
69 |
11 Feb 06 |
jari |
230 |
<< "and weights\n" |
69 |
11 Feb 06 |
jari |
231 |
<< "Usage: filter -option option\n" |
69 |
11 Feb 06 |
jari |
232 |
<< "\nInputs:\n" |
69 |
11 Feb 06 |
jari |
233 |
<< "\t-beta beta value of the snr to weight calculation\n" |
73 |
14 Feb 06 |
jari |
234 |
<< "\t [default: " << beta_ << "]\n" |
69 |
11 Feb 06 |
jari |
235 |
<< "\t-datatype Values 'raw' or 'derived' . When 'derived' is\n" |
69 |
11 Feb 06 |
jari |
236 |
<< "\t given, only foreground files are expected, and\n" |
69 |
11 Feb 06 |
jari |
237 |
<< "\t background files ignored (cf. options -fg1,\n" |
69 |
11 Feb 06 |
jari |
238 |
<< "\t -fg2, -bg1, and -bg2.\n" |
73 |
14 Feb 06 |
jari |
239 |
<< "\t [" << datatype_ << "]\n" |
69 |
11 Feb 06 |
jari |
240 |
<< "\t-fg1 input file first foreground\n" |
69 |
11 Feb 06 |
jari |
241 |
<< "\t-bg1 input file first background\n" |
69 |
11 Feb 06 |
jari |
242 |
<< "\t-bgstd1 input file first background standard deviation\n" |
69 |
11 Feb 06 |
jari |
243 |
<< "\t-fg2 input file second foreground\n" |
69 |
11 Feb 06 |
jari |
244 |
<< "\t-bg2 input file second background\n" |
69 |
11 Feb 06 |
jari |
245 |
<< "\t-bgstd2 input file second background standard deviation\n" |
69 |
11 Feb 06 |
jari |
246 |
<< "\t-logratio output file logratio (first/second)\n" |
73 |
14 Feb 06 |
jari |
247 |
<< "\t [" << logratio_ << "\n" |
88 |
04 Apr 06 |
jari |
248 |
<< "\t--version print version information and exit\n" |
73 |
14 Feb 06 |
jari |
249 |
<< "\t-weight output file weight\n" |
73 |
14 Feb 06 |
jari |
250 |
<< "\t [" << weight_ << "]\n"; |
69 |
11 Feb 06 |
jari |
251 |
} |
69 |
11 Feb 06 |
jari |
252 |
|
88 |
04 Apr 06 |
jari |
253 |
|
88 |
04 Apr 06 |
jari |
254 |
void Parameter::version(void) const |
88 |
04 Apr 06 |
jari |
255 |
{ |
88 |
04 Apr 06 |
jari |
256 |
using namespace std; |
88 |
04 Apr 06 |
jari |
257 |
cout << PACKAGE_STRING |
111 |
14 Jun 06 |
jari |
258 |
<< "\nCopyright (C) 2005-2006 Jari Häkkinen and Peter Johansson.\n\n" |
88 |
04 Apr 06 |
jari |
259 |
<< "This is free software; see the source for copying conditions.\n" |
88 |
04 Apr 06 |
jari |
260 |
<< "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR\n" |
88 |
04 Apr 06 |
jari |
261 |
<< "A PARTICULAR PURPOSE." << endl; |
88 |
04 Apr 06 |
jari |
262 |
} |
88 |
04 Apr 06 |
jari |
263 |
|
69 |
11 Feb 06 |
jari |
264 |
}}} // of namespace nnifileconverter, wenni and namespace theplu |