flowcell_data.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <cstring>
11 #include "interop/util/exception.h"
12 #include "interop/util/assert.h"
13 #include "interop/util/cstdint.h"
17 
18 namespace illumina { namespace interop { namespace model { namespace plot
19 {
20 
25  class flowcell_data : public heatmap_data
26  {
27  public:
29  flowcell_data() : m_data(0), m_swath_count(0), m_tile_count(0), m_free(false)
30  { }
31 
33  virtual ~flowcell_data()
34  {
35  clear();
36  }
37 
38  public:
52  ::uint32_t tile_at(const size_t index)const
53  {
54  INTEROP_ASSERTMSG(m_data != 0, "length: " << length());
55 
56  INTEROP_BOUNDS_CHECK(index, length(), "Tile Index out of bounds");
57  return m_data[index];
58  }
59 
66  ::uint32_t tile_id(const size_t lane_idx, const size_t loc) const INTEROP_THROW_SPEC((model::index_out_of_bounds_exception))
67  {
68  INTEROP_BOUNDS_CHECK(lane_idx, lane_count(), "Lane Index out of bounds");
69  INTEROP_BOUNDS_CHECK(loc, column_count(), "Location Index out of bounds");
70  INTEROP_ASSERT(index_of(lane_idx, loc) < length());
71  INTEROP_ASSERT(m_data != 0);
72  return m_data[index_of(lane_idx, loc)];
73  }
74 
79  const plot::axis &saxis() const
80  {
81  return y_axis();
82  }
83 
88  const std::string &subtitle() const
89  {
90  return m_subtitle;
91  }
92 
97  size_t lane_count() const
98  {
99  return row_count();
100  }
101 
106  size_t swath_count() const
107  {
108  return m_swath_count;
109  }
110 
115  size_t tile_count() const
116  {
117  return m_tile_count;
118  }
119 
124  size_t total_tile_count() const
125  {
126  return m_tile_count * m_swath_count;
127  }
130  public:
131 
139  void set_data(const size_t lane_idx, const size_t loc, const ::uint32_t tile_id, const float value)
141  {
142  INTEROP_BOUNDS_CHECK(lane_idx, lane_count(), "Lane Index out of bounds");
143  INTEROP_BOUNDS_CHECK(loc, column_count(), "Location Index out of bounds");
144  heatmap_data::operator()(lane_idx, loc) = value;
145  INTEROP_ASSERT(m_data != 0);
146  m_data[index_of(lane_idx, loc)] = tile_id;
147  }
154  ::uint32_t& tile_id(const size_t lane_idx, const size_t loc) INTEROP_THROW_SPEC((model::index_out_of_bounds_exception))
155  {
156  INTEROP_BOUNDS_CHECK(lane_idx, lane_count(), "Lane Index out of bounds");
157  INTEROP_BOUNDS_CHECK(loc, column_count(), "Location Index out of bounds");
158  INTEROP_ASSERT(index_of(lane_idx, loc) < length());
159  INTEROP_ASSERT(m_data != 0);
160  return m_data[index_of(lane_idx, loc)];
161  }
166  void set_saxis(const plot::axis &plot_axis)
167  {
168  set_yaxis(plot_axis);
169  }
170 
175  void set_label(const std::string &label)
176  {
177  set_ylabel(label);
178  }
183  void set_subtitle(const std::string &subtitle)
184  {
186  }
187 
193  void set_range(const float vmin, const float vmax)
194  {
195  set_yrange(vmin, vmax);
196  }
205  void set_buffer(float *data_buffer,
206  ::uint32_t *id_buffer,
207  const size_t lanes,
208  const size_t swaths,
209  const size_t tiles) INTEROP_THROW_SPEC((model::invalid_parameter))
210  {
211  heatmap_data::set_buffer(data_buffer, lanes, swaths * tiles);
212  set_buffer(id_buffer, swaths, tiles);
213  }
214 
221  void resize(const size_t lanes, const size_t swaths, const size_t tiles)
222  {
223  if (lanes != row_count() && swaths != m_swath_count && tiles != m_tile_count)
224  {
225  heatmap_data::resize(lanes, swaths * tiles);
226  resize(swaths, tiles);
227  }
228  }
229 
232  void clear()
233  {
235  if (m_free)
236  {
237  delete[] m_data;
238  m_data = 0;
239  m_free = false;
240  }
241  m_swath_count = 0;
242  m_tile_count = 0;
243  }
244 
245  protected:
250  void set_buffer(::uint32_t *id_buffer)
251  {
252  if (m_free) INTEROP_THROW(invalid_parameter, "Cannot use internal buffer map with external buffer");
253  if (empty()) INTEROP_THROW(invalid_parameter, "Cannot set external buffer to empty map");
254  m_data = id_buffer;
255  }
256 
263  void set_buffer(::uint32_t *id_buffer,
264  const size_t swaths,
265  const size_t tiles)
266  {
267  if (m_free) delete[] m_data;
268  m_data = id_buffer;
269  m_swath_count = swaths;
270  m_tile_count = tiles;
271  m_free = false;
272  std::fill(id_buffer, id_buffer+length(), 0);
273  }
274 
280  void resize(const size_t swaths,
281  const size_t tiles)
282  {
283  if (m_free) delete[] m_data;
284  m_swath_count = swaths;
285  m_tile_count = tiles;
286  m_data = new ::uint32_t[heatmap_data::length()];
287  std::memset(reinterpret_cast<char *>(m_data), 0, sizeof(::uint32_t) * heatmap_data::length());
288  m_free = true;
289  }
290  friend std::ostream& operator<<(std::ostream& out, const flowcell_data& data)
291  {
292  out << static_cast<const heatmap_data&>(data);
293  out << data.m_subtitle << ",";
294  out << data.m_swath_count << ",";
295  out << data.m_tile_count << ",";
296  for(size_t i=0, n=data.length();i<n;++i)
297  out << data.m_data[i] << ",";
298  return out;
299  }
300  friend std::istream& operator>>(std::istream& in, flowcell_data& data)
301  {
302  in >> static_cast<heatmap_data&>(data);
303  std::string tmp;
304  std::getline(in, data.m_subtitle, ',');
305  std::getline(in, tmp, ',');
306  const size_t swath_count = util::lexical_cast<size_t>(tmp);
307  std::getline(in, tmp, ',');
308  const size_t tile_count = util::lexical_cast<size_t>(tmp);
309  data.resize(swath_count, tile_count);
310  for(size_t i=0, n=data.length();i<n;++i)
311  {
312  std::getline(in, tmp, ',');
313  data.m_data[i] = util::lexical_cast< ::uint32_t >(tmp);
314  }
315  return in;
316  }
317 
318 protected:
320  ::uint32_t* m_data;
322  std::string m_subtitle;
326  size_t m_tile_count;
327 private:
328  bool m_free;
329 };
330 
331 }}}}
332 
#define INTEROP_ASSERTMSG(TST, MSG)
Definition: assert.h:32
float operator()(const size_t row, const size_t col) const INTEROP_THROW_SPEC((model
Definition: heatmap_data.h:96
void set_buffer(float *data) INTEROP_THROW_SPEC((model
Definition: heatmap_data.h:165
Definition: enum_description.h:15
void resize(const size_t swaths, const size_t tiles)
Definition: flowcell_data.h:280
size_t m_tile_count
Definition: flowcell_data.h:326
::uint32_t & tile_id(const size_t lane_idx, const size_t loc) INTEROP_THROW_SPEC((model
Definition: flowcell_data.h:154
size_t tile_count() const
Definition: flowcell_data.h:115
Definition: flowcell_data.h:25
#define INTEROP_THROW_SPEC(SPEC)
Definition: exception_specification.h:15
size_t column_count() const
Definition: heatmap_data.h:137
void set_buffer(float *data_buffer,::uint32_t *id_buffer, const size_t lanes, const size_t swaths, const size_t tiles) INTEROP_THROW_SPEC((model
Definition: flowcell_data.h:205
size_t total_tile_count() const
Definition: flowcell_data.h:124
flowcell_data()
Definition: flowcell_data.h:29
void resize(const size_t lanes, const size_t swaths, const size_t tiles)
Definition: flowcell_data.h:221
#define INTEROP_THROW(EXCEPTION, MESSAGE)
Definition: exception.h:18
void set_buffer(::uint32_t *id_buffer, const size_t swaths, const size_t tiles)
Definition: flowcell_data.h:263
::uint32_t * m_data
Definition: flowcell_data.h:320
size_t index_of(const size_t row, const size_t col) const
Definition: heatmap_data.h:230
void set_subtitle(const std::string &subtitle)
Definition: flowcell_data.h:183
void resize(const size_t rows, const size_t cols, const float default_val=std::numeric_limits< float >::quiet_NaN())
Definition: heatmap_data.h:196
const axis & y_axis() const
Definition: chart_data.h:138
void set_range(const float vmin, const float vmax)
Definition: flowcell_data.h:193
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
const plot::axis & saxis() const
Definition: flowcell_data.h:79
::uint32_t tile_id(const size_t lane_idx, const size_t loc) const INTEROP_THROW_SPEC((model
Definition: flowcell_data.h:66
size_t swath_count() const
Definition: flowcell_data.h:106
size_t m_swath_count
Definition: flowcell_data.h:324
void clear()
Definition: flowcell_data.h:232
void clear()
Definition: heatmap_data.h:212
bool empty() const
Definition: heatmap_data.h:154
size_t length() const
Definition: heatmap_data.h:146
Definition: model_exceptions.h:50
virtual ~flowcell_data()
Definition: flowcell_data.h:33
void set_yrange(const float vmin, const float vmax)
Definition: chart_data.h:95
const std::string & subtitle() const
Definition: flowcell_data.h:88
size_t lane_count() const
Definition: flowcell_data.h:97
::uint32_t tile_at(const size_t index) const
Definition: flowcell_data.h:52
void set_buffer(::uint32_t *id_buffer)
Definition: flowcell_data.h:250
#define INTEROP_BOUNDS_CHECK(VALUE, RANGE, MESSAGE)
Definition: exception.h:24
void set_label(const std::string &label)
Definition: flowcell_data.h:175
void set_saxis(const plot::axis &plot_axis)
Definition: flowcell_data.h:166
void set_ylabel(const std::string &label)
Definition: chart_data.h:62
friend std::istream & operator>>(std::istream &in, flowcell_data &data)
Definition: flowcell_data.h:300
void set_yaxis(const axis &yaxes)
Definition: chart_data.h:44
void set_data(const size_t lane_idx, const size_t loc, const ::uint32_t tile_id, const float value)
Definition: flowcell_data.h:139
size_t row_count() const
Definition: heatmap_data.h:128
Destination lexical_cast(const Source &src)
Definition: lexical_cast.h:264
friend std::ostream & operator<<(std::ostream &out, const flowcell_data &data)
Definition: flowcell_data.h:290
std::string m_subtitle
Definition: flowcell_data.h:322