source: trunk/se/lu/thep/wenni/base/base1/BaseFileConverter/BaseFileConverter.cc @ 594

Last change on this file since 594 was 594, checked in by Jari Häkkinen, 13 years ago

Improved memory usage of BaseFileConverter?. Previous implementation was not flattering.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: BaseFileConverter.cc 594 2008-02-26 14:24:46Z jari $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2008 Jari Häkkinen
6
7  This file is part of WeNNI,
8  http://lev.thep.lu.se/trac/baseplugins/wiki/WeNNI
9
10  WeNNI is free software; you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  WeNNI is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
18  License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "Clone.h"
27#include "Data.h"
28#include "Parameter.h"
29
30#include <basefile.h>
31
32#include <iostream>
33
34
35int main(const int argc,const char* argv[]) 
36{
37  theplu::wenni::Parameter option(argc,argv);
38  std::string s=option.input_file();
39  std::ifstream is(s.c_str());
40  BASE::BaseFileReader bfr(is);
41  BASE::BaseFileSection bfs;
42 
43  do {
44    if (!bfr.readSection(bfs)) {
45      if (bfr.getError())
46        std::cerr << "Error reading section in input: "  << bfr.errText()
47                  << std::endl;
48      exit(-1);
49    }
50  } while (bfs.type != "spots");
51
52  if (option.show()) {
53    std::cout << "Available types are:\n";
54    std::cout << "\t -assayFields -columns \n\n";
55    std::cout << "Available assayFields are:\n";
56
57    std::string af;
58    if (bfs.findStringOpt("assayFields",af)) {
59      std::vector<std::string> af_vec;
60      char delim = '\t';
61      BASE::split(af, af_vec, 100, delim);
62      for (size_t i=0; i<af_vec.size(); i++)
63        std::cout << "\t" << af_vec[i] << "\n";
64    }
65    else {
66      std::cerr << "Error: Cannot find assayFields" << std::endl;
67      exit(-1);
68    }
69    std::cout << std::endl;
70
71    std::cout << "Available columns are:\n";
72    std::string c;
73    if (bfs.findStringOpt("columns",c)) {
74      std::vector<std::string> c_vec;
75      char delim = '\t';
76      BASE::split(c, c_vec, 100, delim);
77      for (size_t i=0; i<c_vec.size()-1; i++)
78        std::cout << "\t" << c_vec[i] << "\n";
79    }
80    else {
81      std::cerr << "Error: Cannot find assayFields\n";
82      exit(-1);
83    }
84    std::cout << std::endl;
85  }
86
87  std::vector<theplu::wenni::Data*> data;
88  std::vector<theplu::wenni::Clone> clone;
89  for (int i=0; i<option.nof_property(); i++) {
90    if (option.type(i)=="-assayFields")
91      data.push_back(new theplu::wenni::Data(bfs,option.property(i),
92                                             option.output_file(i)));
93    else if (option.type(i)=="-columns")
94      clone.push_back(theplu::wenni::Clone(bfs,option.property(i),
95                                           option.output_file(i)));
96    else {
97      std::cerr << "Error: Unknown type" << option.type(i)
98                << " for " << option.property(i) << "\n";
99      exit(-1);
100    }
101  }
102
103  // Extract data
104  if (data.size()) {
105    std::vector<std::string> vals(data[0]->total_nof_columns());
106    while (bfr.readVec(vals))
107      for (size_t i=0; i<data.size(); i++) 
108        data[i]->write(vals);
109  }
110
111  // Extract columns
112  if (clone.size()) {
113    std::vector<std::string> vals(clone[0].total_nof_columns());
114    while (bfr.readVec(vals))
115      for (size_t i=0; i<clone.size(); i++) 
116        clone[i].push_back(vals);
117  }
118  for (size_t i=0; i<clone.size(); i++) 
119    clone[i].write();
120
121  // clean up
122  for (size_t i=0; i<data.size(); i++) 
123    delete data[i];
124
125  return 0;
126}
Note: See TracBrowser for help on using the repository browser.