Changeset 1020
- Timestamp:
- Apr 3, 2009, 11:53:27 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizers/trunk/src/c++/bin/qQN.cc
r1014 r1020 37 37 #include <fstream> 38 38 #include <iostream> 39 #include <stdexcept> 39 40 40 using namespace theplu::yat; 41 using namespace theplu::yat::normalizer; 42 using namespace theplu::yat::utility; 43 44 void create_target(std::vector<double>&, const Matrix&); 45 void create_target(std::vector<double>&, const Matrix&, const std::string&); 46 41 47 42 48 int main(int argc, char* argv[]) 43 { 44 using namespace normalizer; 45 using namespace utility; 46 49 { 47 50 CommandLine cmd; 48 OptionArg<std::string> dir(cmd, "assay-data", "assay annotation file");51 OptionArg<std::string> assay(cmd, "assay-data", "assay annotation file"); 49 52 OptionHelp help(cmd); 50 53 help.synopsis()=(std::string("See ") + … … 53 56 OptionSwitch version(cmd, "version", "output version and exit"); 54 57 std::stringstream copyright; 55 copyright << cmd.program_name() << VERSION<< '\n'58 copyright << PACKAGE_STRING << '\n' 56 59 << "Copyright (C) 2009 Jari Häkkinen\n\n" 57 60 << "This is free software see the source for copying " … … 68 71 std::cout << e.what() << std::endl; 69 72 return EXIT_FAILURE; 70 } 73 } 71 74 if (version.present()) { 72 75 std::cout << copyright.str(); … … 75 78 76 79 Matrix m(std::cin,'\t'); 80 std::vector<double> target(m.rows(),0); 81 ( assay.present() ? create_target(target,m,assay.value()) : 82 create_target(target,m) ); 83 qQuantileNormalizer qqn(target.begin(), target.end(), 100); 84 ColumnNormalizer<qQuantileNormalizer> cn(qqn); 77 85 Matrix result(m.rows(),m.columns()); 78 qQuantileNormalizer qqn(m.begin_column(0), m.end_column(0),100);79 ColumnNormalizer<qQuantileNormalizer> cn(qqn);80 86 cn(m,result); 81 87 std::cout << result << std::endl; … … 83 89 return EXIT_SUCCESS; 84 90 } 91 92 93 void create_target(std::vector<double>& t, const Matrix& m, 94 const std::string& assay) 95 { 96 std::ifstream is(assay.c_str()); 97 std::string line; 98 size_t column=0; 99 size_t yes=0; 100 for (size_t row=0; row<m.rows(); ++row) 101 t[row]=0; 102 while (getline(is, line)) { 103 size_t found=line.find("yes"); 104 if (found!=std::string::npos) { 105 for (size_t row=0; row<m.rows(); ++row) 106 t[row]+=m(row,column); 107 ++yes; 108 } 109 ++column; 110 if (column>m.columns()) 111 throw std::runtime_error("Too many annotation columns wrt data matrix"); 112 } 113 if (!yes) 114 throw std::runtime_error("No columns marked as reference"); 115 for (size_t row=0; row<m.rows(); ++row) 116 t[row]/=yes; 117 } 118 119 120 void create_target(std::vector<double>& t, const Matrix& m) 121 { 122 for (size_t row=0; row<m.rows(); ++row) { 123 t[row]=0; 124 for (size_t column=0; column<m.columns(); ++column) 125 t[row]+=m(row,column); 126 t[row]/=m.columns(); 127 } 128 }
Note: See TracChangeset
for help on using the changeset viewer.