source: trunk/se/lu/thep/wenni/bin/BaseFileConverter/BaseFileConverter.cc @ 95

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

Added copyright statement to files.

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