Ignore:
Timestamp:
Sep 23, 2009, 11:08:19 AM (14 years ago)
Author:
Jari Häkkinen
Message:

Fixes #247. A work around for the erroneous export from exportPlainMatrix.

File:
1 edited

Legend:

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

    r1073 r1164  
    5959
    6060
     61void create_matrix_until_183_fixed(MatrixWeighted**, const MatrixWeighted&,
     62                                   const std::string&);
    6163void create_target(std::vector<double>&, const MatrixWeighted&, bool use_median);
    6264void create_target(std::vector<double>&, const MatrixWeighted&,
     
    111113    std::cin.rdbuf(infile->rdbuf());
    112114  }
    113   MatrixWeighted m(std::cin,'\t');
     115
     116  // The BASE core API deprecated exportPlainMatrix method of the
     117  // deprecated BioAssaySetExporter does not behave well when
     118  // exporting bioassaysets where assays have been filtered out in
     119  // some filter step. Variables and functions with 183 in their name
     120  // should be removed when http://baseplugins.thep.lu.se/ticket/183
     121  // is fixed.
     122
     123  // m is a pointer below, should be changed to a normal variable when
     124  // http://baseplugins.thep.lu.se/ticket/183 is fixed.
     125
     126  // Change to m when http://baseplugins.thep.lu.se/ticket/183 fixed.
     127  MatrixWeighted m_tmp_until_183_fixed(std::cin,'\t');
    114128  if (indata.present()) {
    115129    std::cin.rdbuf(cin_buffer); // restore old input buffer
     
    117131    delete infile;
    118132  }
    119 
    120   std::transform(m.begin(), m.end(), m.begin(), CleanUpMatrix());
     133  // Remove until HERE below when
     134  // http://baseplugins.thep.lu.se/ticket/183 fixed.
     135  MatrixWeighted* m=NULL;
     136  if (assay.present())
     137    create_matrix_until_183_fixed(&m, m_tmp_until_183_fixed, assay.value());
     138  else
     139    m = &m_tmp_until_183_fixed;
     140  // HERE remove until here.
     141
     142  std::transform(m->begin(), m->end(), m->begin(), CleanUpMatrix());
    121143  std::vector<double> target;
    122144  ( assay.present() ?
    123     create_target(target, m, assay.value(), target_median.value()) :
    124     create_target(target, m, target_median.value()) );
     145    create_target(target, *m, assay.value(), target_median.value()) :
     146    create_target(target, *m, target_median.value()) );
    125147  std::transform(target.begin(), target.end(),
    126148                 target.begin(), theplu::yat::utility::Log<double>());
    127   std::transform(data_iterator(m.begin()), data_iterator(m.end()),
    128                  data_iterator(m.begin()), theplu::yat::utility::Log<double>());
     149  std::transform(data_iterator(m->begin()), data_iterator(m->end()),
     150                 data_iterator(m->begin()), theplu::yat::utility::Log<double>());
    129151  // q = min(100,target_size/10) but no smaller than 10
    130152  unsigned int q=target.size()/10;
     
    132154  qQuantileNormalizer qqn(target.begin(), target.end(), q);
    133155  ColumnNormalizer<qQuantileNormalizer> cn(qqn);
    134   MatrixWeighted result(m.rows(),m.columns());
    135   cn(m,result);
     156  MatrixWeighted result(m->rows(),m->columns());
     157  cn(*m,result);
    136158  std::transform(data_iterator(result.begin()), data_iterator(result.end()),
    137159                 data_iterator(result.begin()), theplu::yat::utility::Exp<double>());
     
    151173  }
    152174
     175  // clean up until http://baseplugins.thep.lu.se/ticket/183 fixed.
     176  if (assay.present())
     177    delete m;
     178
    153179  return EXIT_SUCCESS;
     180}
     181
     182
     183void create_matrix_until_183_fixed(MatrixWeighted** m,
     184                                   const MatrixWeighted& m_tmp_183,
     185                                   const std::string& assay)
     186{
     187  std::ifstream is(assay.c_str());
     188  std::vector<size_t> idx;
     189  while (is.good()) {
     190    size_t i;
     191    is >> i;
     192    if (is.good()) idx.push_back(i);
     193    std::string line;
     194    getline(is, line);
     195    if (idx.size()>m_tmp_183.columns())
     196      throw std::runtime_error(std::string("183_tmp: Too many annotation ") +
     197                               "columns wrt data matrix");
     198  }
     199
     200  if (*m) delete *m;
     201  size_t rows=m_tmp_183.rows();
     202  size_t cols=idx.size();
     203  *m=new MatrixWeighted(rows,cols);
     204  for (size_t i=0; i<rows; ++i)
     205    for (size_t j=0; j<cols; ++j)
     206      (**m)(i,j)=m_tmp_183(i,idx[j]-1);
    154207}
    155208
Note: See TracChangeset for help on using the changeset viewer.