q_metric.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include <vector>
15 
16 
17 namespace illumina { namespace interop { namespace logic { namespace metric
18 {
19 
26  template<typename I>
27  size_t count_q_metric_bins(I beg, I end)
28  {
29  return (beg==end) ? 0 : beg->size();
30  }
37  {
38  return count_q_metric_bins(metric_set.begin(), metric_set.end());
39  }
46  {
47  return count_q_metric_bins(metric_set.begin(), metric_set.end());
48  }
55  {
56  return 0;
57  }
86  template<class QMetric>
88  {
89  // 0 is a sentinel that indicates legacy binning is not required
90  if (q_metric_set.version() > 4) return 0; // Version 5 and later do not require legacy binning
91  if (!q_metric_set.get_bins().empty()) return 0; // If the metrics already have a header they do not require binning
92 
93  const size_t max_bin_count = 7;
95  end = q_metric_set.end();
96  if (beg == end) return 0;
97  typedef model::metrics::q_metric::uint_t uint_t;
98  std::set<uint_t> bins_found;
99  for (; beg != end; ++beg) {
100  for (uint_t i = 0; i < static_cast<uint_t>(beg->qscore_hist().size()); ++i)
101  if (beg->qscore_hist()[i] > 0) bins_found.insert(i);
102  if (bins_found.size() > max_bin_count) break; // Number of bins greater than 7 indicates this is unbinned
103  }
104  return bins_found.size();
105  }
111  inline bool requires_legacy_bins(const size_t count)
112  {
113  return count <= 7 && count > 0;
114  }
124  void populate_legacy_q_score_bins(std::vector<model::metrics::q_score_bin>& q_score_bins,
125  const constants::instrument_type instrument,
126  const size_t count);
147  std::vector<model::metrics::q_score_bin>& q_score_bins,
148  const constants::instrument_type instrument)
149  {
150  const size_t count = count_legacy_q_score_bins(q_metric_set);
151  populate_legacy_q_score_bins(q_score_bins, instrument, count);
152  }
163  std::vector<model::metrics::q_score_bin>& q_score_bins,
164  const constants::instrument_type instrument)
165  {
166  const size_t count = count_legacy_q_score_bins(q_metric_set);
167  populate_legacy_q_score_bins(q_score_bins, instrument, count);
168  }
175  {
176  return q_metric_set.size() > 0 ? q_metric_set[0].size() : 0;
177  }
184  {
185  return q_metric_set.size() > 0 ? q_metric_set[0].size() : 0;
186  }
193  {
194  return 0;
195  }
202  {
203  const size_t q_val_count = count_qvals(q_metric_set);
204  return q_val_count > 0 && q_val_count != model::metrics::q_metric::MAX_Q_BINS;
205  }
212  {
213  const size_t q_val_count = count_qvals(q_metric_set);
214  return q_val_count > 0 && q_val_count != model::metrics::q_metric::MAX_Q_BINS;
215  }
222  {
223  const size_t q_val_count = count_qvals(q_metric_set);
224  return q_val_count > 0 && q_val_count != model::metrics::q_metric::MAX_Q_BINS;
225  }
231  inline size_t max_qval(
233  {
234  return is_compressed(q_metric_set) ? q_metric_set.get_bins().back().upper() : count_qvals(q_metric_set);
235  }
242  {
243  return is_compressed(q_metric_set) ? q_metric_set.get_bins().back().upper() : count_qvals(q_metric_set);
244  }
251  {
252  return is_compressed(q_metric_set) ?
253  static_cast<size_t>(q_metric_set.get_bins().back().upper()) : count_qvals(q_metric_set);
254  }
261  inline size_t index_for_q_value(
263  const size_t qval)
264  {
265  if(!is_compressed(q_metric_set)) return qval-1;
266  return q_metric_set.index_for_q_value(qval);
267  }
274  inline size_t index_for_q_value(
276  const size_t qval)
277  {
278  if(!is_compressed(q_metric_set)) return qval-1;
279  return q_metric_set.index_for_q_value(qval);
280  }
297  const constants::instrument_type instrument)
299 }}}}
300 
size_t count_q_metric_bins(I beg, I end)
Definition: q_metric.h:27
size_t index_for_q_value(const model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set, const size_t qval)
Definition: q_metric.h:261
::int16_t version() const
Definition: metric_set.h:535
Definition: enum_description.h:15
void populate_legacy_q_score_bins(std::vector< model::metrics::q_score_bin > &q_score_bins, const constants::instrument_type instrument, const size_t count)
Definition: q_metric.cpp:117
#define INTEROP_THROW_SPEC(SPEC)
Definition: exception_specification.h:15
bool empty() const
Definition: metric_set.h:525
void populate_cumulative_distribution(model::metric_base::metric_set< model::metrics::q_by_lane_metric > &q_metric_set)
Definition: q_metric.cpp:83
size_t size() const
Definition: metric_set.h:519
void compress_q_metrics(model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set)
Definition: q_metric.cpp:292
metric_set< q_metric > q_metric_set
Definition: q_metrics_test.cpp:25
bool is_compressed(const model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set)
Definition: q_metric.h:201
::uint32_t uint_t
Definition: base_metric.h:77
size_t count_qvals(const model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set)
Definition: q_metric.h:174
bool requires_legacy_bins(const size_t count)
Definition: q_metric.h:111
const_iterator begin() const
Definition: metric_set.h:166
size_t max_qval(const model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set)
Definition: q_metric.h:231
const_iterator end() const
Definition: metric_set.h:175
void create_collapse_q_metrics(const model::metric_base::metric_set< model::metrics::q_metric > &metric_set, model::metric_base::metric_set< model::metrics::q_collapsed_metric > &collapsed)
Definition: q_metric.cpp:189
instrument_type
Definition: enums.h:309
void create_q_metrics_by_lane(const model::metric_base::metric_set< model::metrics::q_metric > &metric_set, model::metric_base::metric_set< model::metrics::q_by_lane_metric > &bylane, const constants::instrument_type instrument)
Definition: q_metric.cpp:257
void populate_cumulative_distribution(model::metric_base::metric_set< model::metrics::q_by_lane_metric > &q_metric_set) INTEROP_THROW_SPEC((model void populate_cumulative_distribution(model::metric_base::metric_set< model::metrics::q_metric > &q_metric_set) INTEROP_THROW_SPEC((model void populate_cumulative_distribution(model::metric_base::metric_set< model::metrics::q_collapsed_metric > &q_metric_set) INTEROP_THROW_SPEC((model size_t count_legacy_q_score_bins(const model::metric_base::metric_set< QMetric > &q_metric_set)
Definition: q_metric.h:87
metric_array_t::const_iterator const_iterator
Definition: metric_set.h:77