69 |
11 Feb 06 |
jari |
// $Id$ |
69 |
11 Feb 06 |
jari |
2 |
|
95 |
05 Apr 06 |
jari |
3 |
/* |
597 |
27 Feb 08 |
jari |
Copyright (C) 2005, 2006, 2008 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" |
69 |
11 Feb 06 |
jari |
24 |
#include "weight.h" |
69 |
11 Feb 06 |
jari |
25 |
|
69 |
11 Feb 06 |
jari |
26 |
#include <cmath> |
69 |
11 Feb 06 |
jari |
27 |
#include <fstream> |
597 |
27 Feb 08 |
jari |
28 |
#include <string> |
69 |
11 Feb 06 |
jari |
29 |
|
69 |
11 Feb 06 |
jari |
30 |
#include <c++_tools/gslapi/matrix.h> |
69 |
11 Feb 06 |
jari |
31 |
|
69 |
11 Feb 06 |
jari |
32 |
|
69 |
11 Feb 06 |
jari |
33 |
int main(const int argc,const char* argv[]) |
69 |
11 Feb 06 |
jari |
34 |
{ |
69 |
11 Feb 06 |
jari |
35 |
theplu::wenni::nnifileconverter::Parameter option(argc,argv); |
597 |
27 Feb 08 |
jari |
36 |
std::ifstream is_f1(option.fg1().c_str()); |
597 |
27 Feb 08 |
jari |
37 |
std::ifstream is_f2(option.fg2().c_str()); |
597 |
27 Feb 08 |
jari |
38 |
std::ifstream is_s1(option.bgstd1().c_str()); |
597 |
27 Feb 08 |
jari |
39 |
std::ifstream is_s2(option.bgstd2().c_str()); |
597 |
27 Feb 08 |
jari |
40 |
std::ifstream* is_b1=NULL; |
597 |
27 Feb 08 |
jari |
41 |
std::ifstream* is_b2=NULL; |
69 |
11 Feb 06 |
jari |
42 |
if (option.datatype()==std::string("raw")) { |
597 |
27 Feb 08 |
jari |
43 |
is_b1=new std::ifstream(option.bg1().c_str()); |
597 |
27 Feb 08 |
jari |
44 |
is_b2=new std::ifstream(option.bg2().c_str()); |
69 |
11 Feb 06 |
jari |
45 |
} |
69 |
11 Feb 06 |
jari |
46 |
|
597 |
27 Feb 08 |
jari |
47 |
std::ofstream os_r(option.logratio().c_str()); |
597 |
27 Feb 08 |
jari |
48 |
std::ofstream os_w(option.weight().c_str()); |
597 |
27 Feb 08 |
jari |
49 |
std::string f1str; |
597 |
27 Feb 08 |
jari |
50 |
while (std::getline(is_f1,f1str)) { |
597 |
27 Feb 08 |
jari |
51 |
std::string f2str; |
597 |
27 Feb 08 |
jari |
52 |
std::string s1str; |
597 |
27 Feb 08 |
jari |
53 |
std::string s2str; |
597 |
27 Feb 08 |
jari |
54 |
std::getline(is_f2,f2str); |
597 |
27 Feb 08 |
jari |
55 |
std::getline(is_s1,s1str); |
597 |
27 Feb 08 |
jari |
56 |
std::getline(is_s2,s2str); |
597 |
27 Feb 08 |
jari |
57 |
if (is_f1.fail() || is_f2.fail() ||is_s1.fail() ||is_s2.fail()) { |
597 |
27 Feb 08 |
jari |
58 |
std::cerr << "Failed to read at least one file. Length problem?\n" |
597 |
27 Feb 08 |
jari |
59 |
<< " (fg1, fg2, bgstd1, or bgstd2)" << std::endl; |
597 |
27 Feb 08 |
jari |
60 |
exit(-1); |
597 |
27 Feb 08 |
jari |
61 |
} |
597 |
27 Feb 08 |
jari |
62 |
theplu::gslapi::vector f1(f1str); |
597 |
27 Feb 08 |
jari |
63 |
theplu::gslapi::vector f2(f2str); |
597 |
27 Feb 08 |
jari |
64 |
theplu::gslapi::vector s1(s1str); |
597 |
27 Feb 08 |
jari |
65 |
theplu::gslapi::vector s2(s2str); |
597 |
27 Feb 08 |
jari |
66 |
theplu::gslapi::vector b1(f1.size(),0.0); |
597 |
27 Feb 08 |
jari |
67 |
theplu::gslapi::vector b2(f2.size(),0.0); |
597 |
27 Feb 08 |
jari |
68 |
if (is_b1) { |
597 |
27 Feb 08 |
jari |
69 |
std::string b1str; |
597 |
27 Feb 08 |
jari |
70 |
std::getline(*is_b1,b1str); |
597 |
27 Feb 08 |
jari |
71 |
if (is_b1->fail()) { |
597 |
27 Feb 08 |
jari |
72 |
std::cerr << "Failed to read at bg1 file. Length problem?" |
597 |
27 Feb 08 |
jari |
73 |
<< std::endl; |
597 |
27 Feb 08 |
jari |
74 |
exit(-1); |
597 |
27 Feb 08 |
jari |
75 |
} |
597 |
27 Feb 08 |
jari |
76 |
b1=theplu::gslapi::vector(b1str); |
597 |
27 Feb 08 |
jari |
77 |
} |
597 |
27 Feb 08 |
jari |
78 |
if (is_b2) { |
597 |
27 Feb 08 |
jari |
79 |
std::string b2str; |
597 |
27 Feb 08 |
jari |
80 |
std::getline(*is_b2,b2str); |
597 |
27 Feb 08 |
jari |
81 |
if (is_b2->fail()) { |
597 |
27 Feb 08 |
jari |
82 |
std::cerr << "Failed to read at bg2 file. Length problem?" |
597 |
27 Feb 08 |
jari |
83 |
<< std::endl; |
597 |
27 Feb 08 |
jari |
84 |
exit(-1); |
597 |
27 Feb 08 |
jari |
85 |
} |
597 |
27 Feb 08 |
jari |
86 |
b2=theplu::gslapi::vector(b2str); |
597 |
27 Feb 08 |
jari |
87 |
} |
69 |
11 Feb 06 |
jari |
88 |
|
597 |
27 Feb 08 |
jari |
// Calculating log2ratio |
597 |
27 Feb 08 |
jari |
90 |
theplu::gslapi::vector log2ratio(f1.size()); |
597 |
27 Feb 08 |
jari |
91 |
double log2=log(2); |
597 |
27 Feb 08 |
jari |
92 |
for (size_t i=0; i<log2ratio.size(); i++) |
597 |
27 Feb 08 |
jari |
93 |
if (f1(i)>b1(i) && f2(i)>b2(i)) |
597 |
27 Feb 08 |
jari |
94 |
log2ratio(i)=log( (f1(i)-b1(i)) / (f2(i)-b2(i)) ) / log2; |
597 |
27 Feb 08 |
jari |
95 |
|
597 |
27 Feb 08 |
jari |
// calculating weights |
597 |
27 Feb 08 |
jari |
97 |
theplu::gslapi::vector weight(f1.size()); |
597 |
27 Feb 08 |
jari |
98 |
for (size_t i=0; i<weight.size(); i++) { |
69 |
11 Feb 06 |
jari |
99 |
using namespace theplu::wenni::weight; |
597 |
27 Feb 08 |
jari |
100 |
weight(i)=weight_SNR2(get_snr(f1(i),b1(i),s1(i)), |
597 |
27 Feb 08 |
jari |
101 |
get_snr(f2(i),b2(i),s2(i)),option.beta()); |
69 |
11 Feb 06 |
jari |
102 |
} |
69 |
11 Feb 06 |
jari |
103 |
|
597 |
27 Feb 08 |
jari |
104 |
os_r << log2ratio << '\n'; |
597 |
27 Feb 08 |
jari |
105 |
os_w << weight << '\n'; |
597 |
27 Feb 08 |
jari |
106 |
} |
69 |
11 Feb 06 |
jari |
107 |
|
597 |
27 Feb 08 |
jari |
108 |
is_f1.close(); |
597 |
27 Feb 08 |
jari |
109 |
is_s1.close(); |
597 |
27 Feb 08 |
jari |
110 |
is_f2.close(); |
597 |
27 Feb 08 |
jari |
111 |
is_s2.close(); |
597 |
27 Feb 08 |
jari |
112 |
if (is_b1) { |
597 |
27 Feb 08 |
jari |
113 |
is_b1->close(); |
597 |
27 Feb 08 |
jari |
114 |
delete is_b1; |
597 |
27 Feb 08 |
jari |
115 |
} |
597 |
27 Feb 08 |
jari |
116 |
if (is_b2) { |
597 |
27 Feb 08 |
jari |
117 |
is_b2->close(); |
597 |
27 Feb 08 |
jari |
118 |
delete is_b2; |
597 |
27 Feb 08 |
jari |
119 |
} |
597 |
27 Feb 08 |
jari |
120 |
os_r.close(); |
597 |
27 Feb 08 |
jari |
121 |
os_w.close(); |
597 |
27 Feb 08 |
jari |
122 |
|
69 |
11 Feb 06 |
jari |
123 |
return 0; |
69 |
11 Feb 06 |
jari |
124 |
} |