error_metric.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <cstring>
18 #include "interop/util/exception.h"
24 
25 namespace illumina { namespace interop { namespace model { namespace metrics
26 {
30  {
31  public:
34  error_metric_header(const std::vector<std::string>& adapters) :
35  m_number_adapters(static_cast<uint16_t>(adapters.size())),
36  m_adapter_length(0)
37  {
38  if(adapters.size()>0)
39  m_adapter_length = static_cast<uint16_t>(adapters[0].size());
40  for(size_t i = 0; i < adapters.size(); i++) {
41  INTEROP_ASSERTMSG(adapters[i].size() == m_adapter_length,
42  "Adapter Sequence (" << adapters[i] << ") length doesn't match expected adapter length");
43  m_adapter_sequences.push_back(adapters[i]);
44  }
45  }
46 
48  m_number_adapters(0),
49  m_adapter_length(0)
50  {}
51 
56  uint16_t number_adapters() const
57  {
58  return m_number_adapters;
59  }
60 
65  uint16_t adapter_length() const
66  {
67  return m_adapter_length;
68  }
69 
74  const std::vector<std::string>& adapter_sequences() const
75  {
76  return m_adapter_sequences;
77  }
78 
79  void clear()
80  {
81  m_number_adapters = 0;
82  m_adapter_length = 0;
83  m_adapter_sequences.clear();
85  }
91  {
92  return error_metric_header(std::vector<std::string>());
93  }
94 
95  private:
96  uint16_t m_number_adapters;
97  uint16_t m_adapter_length;
98  std::vector<std::string> m_adapter_sequences;
99 
100  template<class MetricType, int Version>
101  friend
102  struct io::generic_layout;
103  };
104 
113  {
114  public:
115  enum
116  {
124  };
127  typedef std::vector<uint_t> uint_array_t;
129  typedef std::vector<float> float_vector;
132  public:
136  metric_base::base_cycle_metric(0, 0, 0),
137  m_error_rate(std::numeric_limits<float>::quiet_NaN()),
138  m_phix_adapter_rate(std::numeric_limits<float>::quiet_NaN()),
139  m_mismatch_cluster_count(MAX_MISMATCH, 0)
140  {
141  }
144  error_metric(const header_type& header) :
145  metric_base::base_cycle_metric(0, 0, 0),
146  m_error_rate(std::numeric_limits<float>::quiet_NaN()),
147  m_phix_adapter_rate(std::numeric_limits<float>::quiet_NaN()),
148  m_phix_adapter_rates(header.number_adapters(), 0),
149  m_mismatch_cluster_count(MAX_MISMATCH, 0)
150  {
151  }
152 
161  const uint_t tile,
162  const uint_t cycle,
163  const float error,
164  const float phix_adapter_rate) :
165  metric_base::base_cycle_metric(lane, tile, cycle),
166  m_error_rate(error),
167  m_phix_adapter_rate(phix_adapter_rate),
168  m_mismatch_cluster_count(MAX_MISMATCH, 0)
169  {
170  }
171 
181  const uint_t tile,
182  const uint_t cycle,
183  const float error,
184  const float_vector &phix_adapter_rates) :
185  metric_base::base_cycle_metric(lane, tile, cycle),
186  m_error_rate(error),
187  m_phix_adapter_rates(phix_adapter_rates),
188  m_mismatch_cluster_count(MAX_MISMATCH, 0)
189  {
190  set_mean_adapter_rate();
191  }
192 
193  public:
208  float error_rate() const
209  {
210  return m_error_rate;
211  }
212 
218  float phix_adapter_rate() const
219  {
220  return m_phix_adapter_rate;
221  }
222  /* Calculated adapter trim rate per adapter of PhiX clusters
223  *
224  * @note Supported by v6
225  * @return vector of adapter rates per adapter
226  */
227  const float_vector& phix_adapter_rates() const
228  {
229  return m_phix_adapter_rates;
230  }
231  /* Calculated adapter trim rate per adapter of PhiX clusters
232  *
233  * @note Supported by v6
234  * @return adapter rate for given adapter index
235  */
237  {
238  INTEROP_BOUNDS_CHECK(n, m_phix_adapter_rates.size(), "Index out of bounds");
239  return m_phix_adapter_rates[n];
240  }
241  /* Number of adapters on PhiX
242  *
243  * @note Supported by v6
244  * @return number of adapters
245  */
246  size_t phix_adapter_count() const
247  {
248  return m_phix_adapter_rates.size();
249  }
250 
262  {
263  INTEROP_BOUNDS_CHECK(n, static_cast<size_t>(MAX_MISMATCH), "Index out of bounds");
264  return m_mismatch_cluster_count[n];
265  }
266 
273  {
274  return MAX_MISMATCH;
275  }
276 
286  const uint_array_t &mismatch_cluster_counts() const
287  {
288  return m_mismatch_cluster_count;
289  }
297  float errorRate() const
298  {
299  return m_error_rate;
300  }
301 
302  public:
307  static const char *prefix()
308  { return "Error"; }
309 
310  private:
311 
312  void set_mean_adapter_rate() {
313  const size_t size = m_phix_adapter_rates.size();
314  if(size == 0) return;
315  m_phix_adapter_rate = 0;
316  for(size_t i = 0; i < size; i++)
317  m_phix_adapter_rate += m_phix_adapter_rates[i];
318  m_phix_adapter_rate /= size;
319  }
320 
321  float m_error_rate;
322  float m_phix_adapter_rate;
323  float_vector m_phix_adapter_rates;
324  uint_array_t m_mismatch_cluster_count;
325  template<class MetricType, int Version>
326  friend
327  struct io::generic_layout;
328  };
329 }}}}
330 
#define INTEROP_ASSERTMSG(TST, MSG)
Definition: assert.h:32
float phix_adapter_rate() const
Definition: error_metric.h:218
Error rate for a spiked in PhiX control sample.
Definition: error_metric.h:112
Definition: enum_description.h:15
error_metric_header header_type
Definition: error_metric.h:131
uint_t tile() const
Definition: base_metric.h:284
uint16_t adapter_length() const
Definition: error_metric.h:65
error_metric_header(const std::vector< std::string > &adapters)
Definition: error_metric.h:34
std::vector< float > float_vector
Definition: error_metric.h:129
#define INTEROP_THROW_SPEC(SPEC)
Definition: exception_specification.h:15
std::vector< uint_t > uint_array_t
Definition: error_metric.h:127
size_t phix_adapter_count() const
Definition: error_metric.h:246
error_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const float error, const float_vector &phix_adapter_rates)
Definition: error_metric.h:180
base_cycle_metric(const uint_t lane=0, const uint_t tile=0, const uint_t cycle=0)
Definition: base_cycle_metric.h:90
uint_t cycle() const
Definition: base_cycle_metric.h:131
void clear()
Definition: error_metric.h:79
::uint32_t uint_t
Definition: base_metric.h:77
Definition: generic_layout.h:24
error_metric(const header_type &header)
Definition: error_metric.h:144
static const char * prefix()
Definition: error_metric.h:307
uint_t lane() const
Definition: base_metric.h:269
error_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const float error, const float phix_adapter_rate)
Definition: error_metric.h:160
static error_metric_header default_header()
Definition: error_metric.h:90
const uint_array_t & mismatch_cluster_counts() const
Definition: error_metric.h:286
uint_t mismatch_count() const
Definition: error_metric.h:272
#define INTEROP_BOUNDS_CHECK(VALUE, RANGE, MESSAGE)
Definition: exception.h:24
float phix_adapter_rate_at(const size_t n) const INTEROP_THROW_SPEC((model
Definition: error_metric.h:236
float error_rate() const
Definition: error_metric.h:208
uint16_t number_adapters() const
Definition: error_metric.h:56
error_metric()
Definition: error_metric.h:135
error_metric_header()
Definition: error_metric.h:47
const float_vector & phix_adapter_rates() const
Definition: error_metric.h:227
float errorRate() const
Definition: error_metric.h:297
uint_t mismatch_cluster_count(const size_t n) const INTEROP_THROW_SPEC((model
Definition: error_metric.h:261
const std::vector< std::string > & adapter_sequences() const
Definition: error_metric.h:74