table_populator.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include <vector>
10 #include "interop/util/exception.h"
19 
20 namespace illumina { namespace interop { namespace logic { namespace table
21 {
25  {
26  enum VoidType
27  {
28  Void
29  };
30  typedef model::metrics::q_metric::uint_t uint_t;
31  public:
43  template<class Metric, typename OutputIterator>
44  static void populate_id(const Metric &metric,
46  const size_t q20_idx,
47  const size_t q30_idx,
48  const constants::tile_naming_method naming_method,
49  const std::vector <size_t> &columns,
50  OutputIterator data_it, OutputIterator data_end)
51  {
52  populate(static_cast<const model::metric_base::base_metric &>(metric),
53  read.number,
54  q20_idx,
55  q30_idx,
56  naming_method,
57  columns,
58  data_it,
59  data_end);
60  populate(static_cast<const model::metric_base::base_cycle_metric &>(metric),
61  read.number,
62  q20_idx,
63  q30_idx,
64  naming_method,
65  columns,
66  data_it,
67  data_end);
68  assign(data_it[columns[model::table::ReadColumn]], read.number);
69  assign(data_it[columns[model::table::CycleWithinReadColumn]], read.cycle_within_read);
70  (void) data_end;
71  }
72 
84  template<class Metric, typename OutputIterator>
85  static void populate(const Metric &metric,
86  const size_t read,
87  const size_t q20_idx,
88  const size_t q30_idx,
89  const constants::tile_naming_method naming_method,
90  const std::vector <size_t> &columns,
91  OutputIterator data_it, OutputIterator data_end)
92  {
93  /* For every entry in INTEROP_IMAGING_COLUMN_TYPES
94  * Add a method call to update each field with the given `metric`
95  *
96  * Example:
97  * INTEROP_TUPLE7(Lane, metric_base::base_metric, lane, Void, UInt, IdType) ->
98  *
99  * update_laneVoid(metric, q20_idx, q30_idx, naming_convention);
100  */
101 # define INTEROP_TUPLE7(Ignore1, Ignore2, Method, Param, Ignore4, Ignore5, Ignored6) \
102  populate_##Method##Param(metric, read, static_cast<uint_t>(q20_idx), static_cast<uint_t>(q30_idx), naming_method, columns, data_it, data_end);
104 # undef INTEROP_TUPLE7 // Reuse this for another conversion
105  }
106 
107  private:
108  /* For every entry in INTEROP_IMAGING_COLUMN_TYPES
109  * This macro creates two functions, one to populate a field/column with the data from the correspond metric
110  * and an empty method to ignore a group
111  *
112  * Example:
113  * INTEROP_TUPLE7(Lane, metric_base::base_metric, lane, Void, UInt, IdType) ->
114  *
115  * void update_laneVoid(const model::metric_base::base_metric& metric, const size_t Q20, const size_t Q30, const naming_method NamingConvention)
116  * void update_laneVoid(const model::metric_base::empty_metric&)
117  *
118  * @note Param can be can field in this class, e.g. Read, or the function parameters Q20, Q30 or NamingConvention
119  */
120 # define INTEROP_TUPLE7(Id, Metric, Method, Param, Type, Kind, Round) \
121  template<typename OutputIterator>\
122  static void populate_##Method##Param(const model:: Metric& metric,\
123  const size_t Read,\
124  const uint_t Q20,\
125  const uint_t Q30,\
126  const constants::tile_naming_method NamingConvention,\
127  const std::vector<size_t>& columns,\
128  OutputIterator data_it, OutputIterator data_end)\
129  {\
130  INTEROP_ASSERT( model::table:: Id##Column < columns.size() ); \
131  const size_t index = columns[model::table:: Id##Column];\
132  if(!is_valid(index)) return; /*Missing column */ \
133  copy_to(data_it+index, data_end, call_adapter(metric, Param, &model:: Metric::Method), Round);\
134  (void)Q20;(void)Q30;(void)NamingConvention;(void)Read;\
135  }\
136  template<class MetricType, typename OutputIterator>\
137  static void populate_##Method##Param(const MetricType&,\
138  const size_t,\
139  const uint_t,\
140  const uint_t,\
141  const constants::tile_naming_method,\
142  const std::vector<size_t>&,\
143  OutputIterator,OutputIterator){}
145 # undef INTEROP_TUPLE7 // Reuse this for another conversion
146 
147  private:
155  template<typename T, typename U>
156  static void assign(T &destination, const U source, const size_t num_digits = 0)
157  {
158  //INTEROP_ASSERTMSG(std::isnan(destination), destination);
159  if(is_valid(source))
160  destination = static_cast<T>(roundto(source, num_digits));
161  }
162 
163  private:
164  inline static float roundto(const float val, const size_t n)
165  {
166  if (n > 0)
167  {
168  double mult = 1.0;
169  for (size_t i = 0; i < n; ++i) mult *= 10;
170  return static_cast<float>(std::floor(val * mult + 0.5) / mult);
171  }
172  return val;
173  }
174 
175  template<typename T>
176  inline static T roundto(const T val, const size_t)
177  { return val; }
178 
186  template<typename OutputIterator, typename U>
187  static void copy_to(OutputIterator destination, OutputIterator end, const U source, const size_t num_digits)
188  {
189  INTEROP_ASSERT(destination < end);
190  (void) end;
191  assign(*destination, source, num_digits);
192  }
193 
201  template<typename OutputIterator, typename U>
202  static void
203  copy_to(OutputIterator destination, OutputIterator end, const std::vector <U> &source, const size_t num_digits)
204  {
205  (void) end;
206  for (typename std::vector<U>::const_iterator it = source.begin(); it != source.end(); ++it, ++destination)
207  {
208  INTEROP_ASSERT(destination < end);
209  assign(*destination, *it, num_digits);
210  }
211  }
212 
218  static bool is_valid(const float val)
219  {
220  return !std::isnan(val);
221  }
222 
228  template<typename T>
229  static bool is_valid(const T val)
230  {
231  return val < std::numeric_limits<T>::max();
232  }
233 
239  template<typename T>
240  static bool is_valid(const std::vector <T> &values)
241  {
242  return !values.empty();
243  }
244  };
245 }}}}
246 
Definition: enum_description.h:15
static void populate(const Metric &metric, const size_t read, const size_t q20_idx, const size_t q30_idx, const constants::tile_naming_method naming_method, const std::vector< size_t > &columns, OutputIterator data_it, OutputIterator data_end)
Definition: table_populator.h:85
size_t cycle_within_read
Definition: map_cycle_to_read.h:33
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
::uint32_t uint_t
Definition: base_metric.h:77
Definition: imaging_column.h:91
Definition: map_cycle_to_read.h:19
#define INTEROP_IMAGING_COLUMN_TYPES
Definition: imaging_column.h:48
def read(run, valid_to_load=None, requires=None, search_paths=None, extra)
Definition: core.py:752
Definition: enums.h:301
Definition: table_populator.h:24
size_t number
Definition: map_cycle_to_read.h:31
static void populate_id(const Metric &metric, const summary::read_cycle &read, const size_t q20_idx, const size_t q30_idx, const constants::tile_naming_method naming_method, const std::vector< size_t > &columns, OutputIterator data_it, OutputIterator data_end)
Definition: table_populator.h:44
tile_naming_method
Definition: enums.h:294