metric_value.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include <vector>
10 #include <set>
11 #include "interop/util/exception.h"
21 
22 
23 namespace illumina { namespace interop { namespace logic { namespace metric
24 {
25 
31  template<class M>
32  class metric_value;
33 
38  template<>
39  class metric_value<model::metrics::extraction_metric>
40  {
41  public:
46  metric_value(const size_t _channel) : channel(_channel){}
54  {
55  switch(type)
56  {
58  return metric.max_intensity(channel);
59  case constants::FWHM:
60  return metric.focus_score(channel);
61  default:
62  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
63  }
64  }
65  private:
66  const size_t channel;
67  };
68 
69 
74  template<>
75  class metric_value<model::metrics::q_by_lane_metric>
76  {
78  public:
84  metric_value(const size_t _index_for_qvalue,
86  index_for_qvalue(static_cast<uint_t>(_index_for_qvalue)), bins(_bins){}
94  {
95  switch(type)
96  {
99  return metric.percent_over_qscore(index_for_qvalue);
102  return metric.percent_over_qscore_cumulative(index_for_qvalue);
103  case constants::QScore:
104  {
105  const uint_t median = metric.median(bins);
106  if (median == std::numeric_limits<uint_t>::max() || median == 0)
107  return std::numeric_limits<float>::quiet_NaN();
108  return static_cast<float>(median);
109  }
110  default:
111  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
112  }
113  }
114  private:
115  const uint_t index_for_qvalue;
117  };
118 
123  template<>
124  class metric_value<model::metrics::q_collapsed_metric>
125  {
127  public:
135  {
136  switch(type)
137  {
139  return metric.percent_over_q20();
141  return metric.percent_over_q30();
143  return metric.cumulative_percent_over_q20();
145  return metric.cumulative_percent_over_q30();
146  case constants::QScore:
147  {
148  const uint_t median = metric.median_qscore();
149  if (median == std::numeric_limits<uint_t>::max() || median == 0)
150  return std::numeric_limits<float>::quiet_NaN();
151  return static_cast<float>(median);
152  }
153  default:
154  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
155  }
156  }
157  };
158 
163  template<>
164  class metric_value<model::metrics::error_metric>
165  {
166  public:
173  float operator()(const model::metrics::error_metric& metric, const constants::metric_type type)const
174  {
175  switch(type)
176  {
178  return metric.error_rate();
179  default:
180  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
181  }
182  }
183  };
184 
189  template<>
190  class metric_value<model::metrics::corrected_intensity_metric>
191  {
192  public:
197  metric_value(const constants::dna_bases _base) : base(_base){}
205  const constants::metric_type type)const
206  {
207  switch(type)
208  {
210  return metric.percent_base(base);
212  {
213  const ::uint16_t corrected_int_all = metric.corrected_int_all(base);
214  if (corrected_int_all == std::numeric_limits< ::uint16_t>::max())
215  return std::numeric_limits<float>::quiet_NaN();
216  return static_cast<float>(corrected_int_all);
217  }
219  {
220  const float corrected_int_called = metric.corrected_int_called(base);
221  if (corrected_int_called == std::numeric_limits< ::uint16_t>::max() ||
222  std::isnan(corrected_int_called))
223  return std::numeric_limits<float>::quiet_NaN();
224  return corrected_int_called;
225  }
227  return metric.signal_to_noise();
229  return metric.percent_nocall();
230  default:
231  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
232  }
233  }
234  private:
235  const constants::dna_bases base;
236  };
237 
238 
239 
245  template<>
246  class metric_value<model::metrics::tile_metric>
247  {
248  public:
253  metric_value(const size_t read) : m_read(read == 0 ? 1 : read){}
260  float operator()(const model::metrics::tile_metric& metric, const constants::metric_type type)const
261  {
262  const float density_scale = 1000;
263  const float count_scale = 1000000;
264  const float NaN = std::numeric_limits<float>::quiet_NaN();
265  switch(type)
266  {
267  case constants::ClustersPF://constants::DensityPF:
268  {
269  return metric.cluster_density_pf() / density_scale;
270  }
271  case constants::Clusters://Density:
272  {
273  return metric.cluster_density() / density_scale;
274  }
276  {
277  return metric.cluster_count() / count_scale;
278  }
280  {
281  return metric.cluster_count_pf() / count_scale;
282  }
284  {
285  for(size_t i=0;i<metric.read_metrics().size();++i)
286  {
287  if (m_read == metric.read_metrics()[i].read())
288  {
289  return metric.read_metrics()[i].percent_aligned();
290  }
291  }
292  return NaN;
293  }
295  {
296  for(size_t i=0;i<metric.read_metrics().size();++i)
297  {
298  if (m_read == metric.read_metrics()[i].read())
299  {
300  return metric.read_metrics()[i].percent_phasing();
301  }
302  }
303  return NaN;
304  }
306  {
307  for(size_t i=0;i<metric.read_metrics().size();++i)
308  {
309  if (m_read == metric.read_metrics()[i].read())
310  {
311  return metric.read_metrics()[i].percent_prephasing();
312  }
313  }
314  return NaN;
315  }
316  default:
317  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
318  }
319  }
320  private:
321  const size_t m_read;
322  };
323 
324 
329  template<>
330  class metric_value<model::metrics::phasing_metric>
331  {
332  public:
340  const constants::metric_type type)const
341  {
342  switch(type)
343  {
344  case constants::Phasing:
345  return metric.phasing_weight();
347  return metric.prephasing_weight();
348  default:
349  INTEROP_THROW(model::invalid_metric_type, "Unknown metric type " << constants::to_string(type));
350  }
351  }
352  };
353 }}}}
354 
355 
const read_metric_vector & read_metrics() const
Definition: tile_metric.h:385
float operator()(const model::metrics::error_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:173
float focus_score(const size_t channel) const INTEROP_THROW_SPEC((model
Definition: extraction_metric.h:395
Error rate for a spiked in PhiX control sample.
Definition: error_metric.h:112
metric_value(const size_t _index_for_qvalue, const model::metrics::q_by_lane_metric::qscore_bin_vector_type &_bins)
Definition: metric_value.h:84
uint_t median_qscore() const
Definition: q_collapsed_metric.h:162
metric_type
Definition: enums.h:284
Definition: enum_description.h:15
float cluster_count() const
Definition: tile_metric.h:334
float signal_to_noise() const
Definition: corrected_intensity_metric.h:391
float operator()(const model::metrics::q_collapsed_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:134
float percent_base(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:435
float cluster_density() const
Definition: tile_metric.h:306
float percent_over_qscore(const size_t qscore_index) const
Definition: q_metric.h:481
#define INTEROP_THROW(EXCEPTION, MESSAGE)
Definition: exception.h:18
float percent_over_q20() const
Definition: q_collapsed_metric.h:204
float operator()(const model::metrics::extraction_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:53
Definition: model_exceptions.h:38
float percent_over_q30() const
Definition: q_collapsed_metric.h:212
float cumulative_percent_over_q20() const
Definition: q_collapsed_metric.h:220
float corrected_int_called(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:330
float cluster_count_pf() const
Definition: tile_metric.h:355
metric_value(const constants::dna_bases _base)
Definition: metric_value.h:197
float prephasing_weight() const
Definition: phasing_metric.h:93
header_type::qscore_bin_vector_type qscore_bin_vector_type
Definition: q_metric.h:266
::uint32_t uint_t
Definition: base_metric.h:77
float cumulative_percent_over_q30() const
Definition: q_collapsed_metric.h:228
I median(I beg, I end)
Definition: statistics.h:493
def read(run, valid_to_load=None, requires=None, search_paths=None, extra)
Definition: core.py:752
float cluster_density_pf() const
Definition: tile_metric.h:320
float percent_over_qscore_cumulative(const size_t qscore_index) const
Definition: q_metric.h:498
Definition: enums.h:286
float operator()(const model::metrics::corrected_intensity_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:204
float percent_nocall() const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:466
float operator()(const model::metrics::phasing_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:339
ushort_t max_intensity(const size_t channel) const INTEROP_THROW_SPEC((model
Definition: extraction_metric.h:384
metric_value(const size_t read)
Definition: metric_value.h:253
float operator()(const model::metrics::tile_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:260
float error_rate() const
Definition: error_metric.h:208
Intensity and count metrics for each base.
Definition: corrected_intensity_metric.h:50
float phasing_weight() const
Definition: phasing_metric.h:83
dna_bases
Definition: enums.h:299
uint_t median(const qscore_bin_vector_type &bins=qscore_bin_vector_type()) const
Definition: q_metric.h:587
std::string to_string(Enum value)
Definition: enums.h:43
ushort_t corrected_int_all(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:306
float operator()(const model::metrics::q_by_lane_metric &metric, const constants::metric_type type) const
Definition: metric_value.h:93