Changeset 1020


Ignore:
Timestamp:
Apr 3, 2009, 11:53:27 AM (14 years ago)
Author:
Jari Häkkinen
Message:

Addresses #118 and fixes #187.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/c++/bin/qQN.cc

    r1014 r1020  
    3737#include <fstream>
    3838#include <iostream>
     39#include <stdexcept>
    3940
    40 using namespace theplu::yat;
     41using namespace theplu::yat::normalizer;
     42using namespace theplu::yat::utility;
     43
     44void create_target(std::vector<double>&, const Matrix&);
     45void create_target(std::vector<double>&, const Matrix&, const std::string&);
     46
    4147
    4248int main(int argc, char* argv[])
    43 
    44   using namespace normalizer;
    45   using namespace utility;
    46 
     49{
    4750  CommandLine cmd;
    48   OptionArg<std::string> dir(cmd, "assay-data", "assay annotation file");
     51  OptionArg<std::string> assay(cmd, "assay-data", "assay annotation file");
    4952  OptionHelp help(cmd);
    5053  help.synopsis()=(std::string("See ") +
     
    5356  OptionSwitch version(cmd, "version", "output version and exit");
    5457  std::stringstream copyright;
    55   copyright << cmd.program_name() << VERSION << '\n'
     58  copyright << PACKAGE_STRING << '\n'
    5659            << "Copyright (C) 2009 Jari Häkkinen\n\n"
    5760            << "This is free software see the source for copying "
     
    6871    std::cout << e.what() << std::endl;
    6972    return EXIT_FAILURE;
    70   } 
     73  }
    7174  if (version.present()) {
    7275    std::cout << copyright.str();
     
    7578
    7679  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);
    7785  Matrix result(m.rows(),m.columns());
    78   qQuantileNormalizer qqn(m.begin_column(0), m.end_column(0),100);
    79   ColumnNormalizer<qQuantileNormalizer> cn(qqn);
    8086  cn(m,result);
    8187  std::cout << result << std::endl;
     
    8389  return EXIT_SUCCESS;
    8490}
     91
     92
     93void 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
     120void 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.