Changeset 1043
- Timestamp:
- Apr 23, 2009, 6:55:02 PM (14 years ago)
- Location:
- plugins/base2/net.sf.basedb.normalizers/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizers/trunk/src/c++/bin/qQN.cc
r1037 r1043 29 29 30 30 #include <yat/utility/CommandLine.h> 31 #include <yat/utility/Matrix .h>31 #include <yat/utility/MatrixWeighted.h> 32 32 #include <yat/utility/OptionHelp.h> 33 33 #include <yat/utility/OptionInFile.h> … … 43 43 using namespace theplu::yat::utility; 44 44 45 void create_target(std::vector<double>&, const Matrix&); 46 void create_target(std::vector<double>&, const Matrix&, const std::string&); 45 void create_target(std::vector<double>&, const MatrixWeighted&); 46 void create_target(std::vector<double>&, const MatrixWeighted&, 47 const std::string&); 48 /** 49 writes the data values in the matrix ignoring the weights, i.e., 50 produces the same output as the Matrix output operator does. 51 */ 52 std::ostream& operator<< (std::ostream&, const MatrixWeighted&); 47 53 48 54 … … 79 85 return EXIT_SUCCESS; 80 86 } 81 82 87 std::ifstream* infile=NULL; 83 88 std::streambuf* cin_buffer=NULL; … … 87 92 std::cin.rdbuf(infile->rdbuf()); 88 93 } 89 Matrix m(std::cin,'\t');94 MatrixWeighted m(std::cin,'\t'); 90 95 if (indata.present()) { 91 96 std::cin.rdbuf(cin_buffer); // restore old input buffer … … 94 99 } 95 100 96 std::vector<double> target(m.rows() ,0);101 std::vector<double> target(m.rows()); 97 102 ( assay.present() ? create_target(target,m,assay.value()) : 98 103 create_target(target,m) ); 99 104 qQuantileNormalizer qqn(target.begin(), target.end(), 100); 100 105 ColumnNormalizer<qQuantileNormalizer> cn(qqn); 101 Matrix result(m.rows(),m.columns());106 MatrixWeighted result(m.rows(),m.columns()); 102 107 cn(m,result); 103 108 … … 120 125 121 126 122 void create_target(std::vector<double>& t, const Matrix & m,127 void create_target(std::vector<double>& t, const MatrixWeighted& m, 123 128 const std::string& assay) 124 129 { … … 126 131 std::string line; 127 132 size_t column=0; 128 s ize_t yes=0;133 std::vector<size_t> yes(m.rows(),0); 129 134 for (size_t row=0; row<m.rows(); ++row) 130 135 t[row]=0; … … 133 138 if (found!=std::string::npos) { 134 139 for (size_t row=0; row<m.rows(); ++row) 135 t[row]+=m(row,column); 136 ++yes; 140 if (m(row,column).weight()) { // weight either 0 or 1 141 t[row]+=m(row,column).data(); 142 ++yes[row]; 143 } 137 144 } 138 145 ++column; … … 140 147 throw std::runtime_error("Too many annotation columns wrt data matrix"); 141 148 } 142 if (!yes) 143 throw std::runtime_error("No columns marked as reference"); 144 for (size_t row=0; row<m.rows(); ++row) 145 t[row]/=yes; 149 for (size_t row=0; row<m.rows(); ++row) { 150 if (!yes[row]) 151 throw std::runtime_error("At least one row with no valid reference"); 152 t[row]/=yes[row]; 153 } 146 154 } 147 155 148 156 149 void create_target(std::vector<double>& t, const Matrix & m)157 void create_target(std::vector<double>& t, const MatrixWeighted& m) 150 158 { 151 159 for (size_t row=0; row<m.rows(); ++row) { 152 160 t[row]=0; 153 161 for (size_t column=0; column<m.columns(); ++column) 154 t[row]+=m(row,column) ;162 t[row]+=m(row,column).data(); 155 163 t[row]/=m.columns(); 156 164 } 157 165 } 166 167 168 std::ostream& operator<< (std::ostream& s, const MatrixWeighted& m) 169 { 170 s.setf(std::ios::dec); 171 s.precision(12); 172 for(size_t i=0, j=0; i<m.rows(); i++) 173 for (j=0; j<m.columns(); j++) { 174 s << m(i,j).data(); 175 if (j<m.columns()-1) 176 s << s.fill(); 177 else if (i<m.rows()-1) 178 s << "\n"; 179 } 180 return s; 181 } -
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/qQuantileNormalization.java
r1036 r1043 263 263 // C/C++ style string nan's (Java expects NaN) will cause a 264 264 // NumberFormatException which also an emtpy string 265 // does. However, we do not expect missing values in the 266 // resulting matrix. Postponing exception catching until 267 // they start occuring. 268 batcher.insert(column.get(i), position, 269 Float.parseFloat(lineSplit[i])); 265 // does. 266 try 267 { 268 float value=Float.parseFloat(lineSplit[i]); 269 if (value!=Float.NaN) batcher.insert(column.get(i), position, value); 270 } 271 catch (NumberFormatException e) 272 { 273 // Assume all NumberFormatExceptions are triggered by 274 // nan's in the result file. Nan's in the result file 275 // represents a missing value and should not be stored in 276 // BASE since BASE missing values are really missing in 277 // BASE. 278 } 270 279 } 271 280 }
Note: See TracChangeset
for help on using the changeset viewer.