imaging_table_csv.h
Go to the documentation of this file.
1 
12 
13 namespace illumina { namespace interop { namespace model { namespace table
14 {
15 
16 
23  inline std::istream& operator>>(std::istream& in, imaging_column& column)
24  {
25  std::getline(in, column.m_name, ',');
26  std::string::size_type n;
27  if((n=column.m_name.find("<")) != std::string::npos)
28  {
29  column.m_subcolumn_names.clear();
30  std::istringstream iss(column.m_name.substr(n+1, column.m_name.length()-1-n-1));
31  std::string tmp;
32  while(iss.good())
33  {
34  std::getline(iss, tmp, ';');
35  if(!tmp.empty()) column.m_subcolumn_names.push_back(tmp);
36  else break;
37  }
38  column.m_name = column.m_name.substr(0, n);
39  }
40  return in;
41  }
42 
49  inline std::ostream& operator<<(std::ostream& out, const imaging_column& column)
50  {
51  if(column.has_children())
52  {
53  out << column.name() << "<" << column.subcolumns()[0];
54  for(size_t i=1;i<column.subcolumns().size();++i)
55  out << ";" << column.subcolumns()[i];
56  out << ">";
57  }
58  else out << column.name();
59  return out;
60  }
61 
68  inline std::istream &operator>>(std::istream &in, imaging_table &table)
69  {
71  io::table::read_csv_line(in, cols);
72  if (!in.good()) return in;
74 
75  const size_t column_count = logic::table::count_table_columns(cols);
76  size_t row_count = 0;
79  values.reserve(column_count);
80  while (!in.eof())
81  {
82  io::table::read_csv_line(in, values, std::numeric_limits<float>::quiet_NaN());
83  if (values.empty()) continue;
84  INTEROP_RANGE_CHECK_NE(column_count, values.size(), io::bad_format_exception,
85  "Number of values does not match number of columns");
86  data.resize(data.size()+column_count);
87  std::copy(values.begin(), values.end(), data.begin()+data.size()-column_count);
88  ++row_count;
89  }
90  table.set_data(row_count, cols, data);
91  return in;
92  }
99  inline std::ostream &operator<<(std::ostream &out, const imaging_table &table)
100  {
101  if (!out.good()) return out;
102  io::table::write_csv_line(out, table.m_columns);
103  if (!out.good()) return out;
104  for (size_t row=0,offset=0;row<table.m_row_count;++row)
105  {
106  io::table::write_csv_line(out, table.m_data, offset, offset+table.m_col_count);
107  offset += table.m_col_count;
108  if (!out.good())return out;
109  }
110  return out;
111  }
112 }}}}
113 
void set_data(const size_t rows, column_vector_t &cols, data_vector_t &data)
Definition: imaging_table.h:40
Definition: enum_description.h:15
const string_vector & subcolumns() const
Definition: imaging_column.h:168
void read_csv_line(std::istream &in, std::vector< T > &values, const T missing=T())
Definition: csv_format.h:22
void write_csv_line(std::ostream &out, const std::vector< T > &values, const size_t beg=0, size_t last=0)
Definition: csv_format.h:141
std::ostream & operator<<(std::ostream &out, const imaging_column &column)
Definition: imaging_table_csv.h:49
std::vector< imaging_column > column_vector_t
Definition: imaging_table.h:21
std::vector< float > data_vector_t
Definition: imaging_table.h:23
size_t count_table_columns(const std::vector< model::table::imaging_column > &columns)
Definition: create_imaging_table.cpp:332
std::istream & operator>>(std::istream &in, imaging_column &column)
Definition: imaging_table_csv.h:23
bool has_children() const
Definition: imaging_column.h:152
#define INTEROP_RANGE_CHECK_NE(VALUE, RANGE, EXCEPTION, MESSAGE)
Definition: exception.h:46
Definition: stream_exceptions.h:59
const std::string & name() const
Definition: imaging_column.h:144
void populate_column_offsets(std::vector< model::table::imaging_column > &columns)
Definition: create_imaging_table_columns.cpp:186