index_metric.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <string>
17 #include <map>
18 #include <vector>
19 #include "interop/util/exception.h"
20 #include "interop/util/assert.h"
24 
25 namespace illumina { namespace interop { namespace model { namespace metrics
26 {
27 
34  class index_info
35  {
36  public:
41  m_index_seq(""),
42  m_sample_id(""),
43  m_sample_proj(""),
44  m_cluster_count(0)
45  {
46  }
47 
55  index_info(const std::string &index_seq,
56  const std::string &sample_id,
57  const std::string &sample_proj,
58  const ::uint64_t cluster_count) :
59  m_index_seq(index_seq),
60  m_sample_id(sample_id),
61  m_sample_proj(sample_proj),
62  m_cluster_count(cluster_count)
63  {
64  }
65 
66  public:
79  const std::string &index_seq() const
80  { return m_index_seq; }
81 
86  const std::string &sample_id() const
87  { return m_sample_id; }
88 
93  const std::string &sample_proj() const
94  { return m_sample_proj; }
95 
100  ::uint64_t cluster_count() const
101  { return m_cluster_count; }
102 
109  bool is_dual() const
110  {
111  return index_of_separator() != std::string::npos;
112  }
113 
118  std::string index1() const
119  {
120  const std::string::size_type pos = index_of_separator();
121  if (pos != std::string::npos) return m_index_seq.substr(0, pos);
122  return m_index_seq;
123  }
124 
129  std::string index2() const
130  {
131  const std::string::size_type pos = index_of_separator();
132  if (pos != std::string::npos) return m_index_seq.substr(pos + 1);
133  return "";
134  }
139  std::string unique_id()const
140  {
141  return m_index_seq+m_sample_id;
142  }
144  private:
145  std::string::size_type index_of_separator() const
146  {
147  const std::string::size_type pos = m_index_seq.find('-');
148  if (pos != std::string::npos) return pos;
149  return m_index_seq.find('+');
150  }
151 
152  private:
153  std::string m_index_seq;
154  std::string m_sample_id;
155  std::string m_sample_proj;
156  ::uint64_t m_cluster_count;
157  template<class MetricType, int Version>
158  friend
159  struct io::generic_layout;
160  };
161 
162 
166  {
167  public:
170  typedef ::uint16_t ushort_t;
171  public:
176 
181  const std::vector<std::string>& index_order() const
182  { return m_index_order; }
187  void index_order(const std::vector<std::string>& order)
188  {
189  m_index_order = order;
190  }
191 
197  {
198  return index_metric_header();
199  }
202  void clear()
203  {
204  m_index_order.clear();
206  }
207 
208  private:
209  std::vector<std::string> m_index_order;
210  template<class MetricType, int Version>
211  friend
212  struct io::generic_layout;
213  };
214 
222  {
223  public:
224  enum
225  {
230  };
234  typedef std::vector<index_info> index_array_t;
238  typedef index_array_t::const_iterator const_iterator;
239  public:
243  metric_base::base_read_metric(0, 0, 0),
244  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
245  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN())
246  {
247  }
250  index_metric(const header_type&) :
251  metric_base::base_read_metric(0, 0, 0),
252  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
253  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN())
254  {
255  }
256 
265  uint_t tile,
266  uint_t read,
267  const index_array_t &indices) :
268  metric_base::base_read_metric(lane, tile, read),
269  m_indices(indices),
270  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
271  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN())
272  {
273  }
274 
275  public:
286  size_t size() const
287  {
288  return m_indices.size();
289  }
290 
297  {
298  INTEROP_BOUNDS_CHECK(n, m_indices.size(), "Index out of bounds");
299  return m_indices[n];
300  }
301 
306  const index_array_t &indices() const
307  {
308  return m_indices;
309  }
315  const_iterator begin()const
316  {
317  return m_indices.begin();
318  }
323  const_iterator end()const
324  {
325  return m_indices.end();
326  }
332  float cluster_count() const
333  { return m_cluster_count; }
334 
340  float cluster_count_pf() const
341  { return m_cluster_count_pf; }
342 
343  public:
349  void set_cluster_counts(const float cluster_count, const float cluster_count_pf)
350  {
351  m_cluster_count = cluster_count;
352  m_cluster_count_pf = cluster_count_pf;
353  }
358  static const char *prefix()
359  { return "Index"; }
360 
367  float percent_demultiplexed(const std::string& sample_id) const
368  {
369  uint64_t total_demultiplexed_clusters = 0;
370  if (sample_id.empty())
371  {
372  for (size_t index_array_counter = 0; index_array_counter < m_indices.size(); ++index_array_counter)
373  {
374  total_demultiplexed_clusters += m_indices[index_array_counter].cluster_count();
375  }
376  }
377  else
378  {
379  for (size_t index_array_counter = 0; index_array_counter < m_indices.size(); ++index_array_counter)
380  {
381  if(m_indices[index_array_counter].sample_id() == sample_id)
382  {
383  total_demultiplexed_clusters = m_indices[index_array_counter].cluster_count();
384  break;
385  }
386  }
387  }
388  return static_cast<float>(total_demultiplexed_clusters)/m_cluster_count_pf * 100;
389  }
390 
391  private:
392  index_array_t m_indices;
393  float m_cluster_count; // Derived from tile metric
394  float m_cluster_count_pf; // Derived from tile metric
395  template<class MetricType, int Version>
396  friend
397  struct io::generic_layout;
398  };
399 }}}}
400 
::uint16_t ushort_t
Definition: index_metric.h:170
Definition: enum_description.h:15
uint_t tile() const
Definition: base_metric.h:284
index_info()
Definition: index_metric.h:40
void index_order(const std::vector< std::string > &order)
Definition: index_metric.h:187
static const char * prefix()
Definition: index_metric.h:358
const std::vector< std::string > & index_order() const
Definition: index_metric.h:181
size_t size() const
Definition: index_metric.h:286
#define INTEROP_THROW_SPEC(SPEC)
Definition: exception_specification.h:15
const index_info & indices(const size_t n) const INTEROP_THROW_SPEC((model
Definition: index_metric.h:296
index_metric_header()
Definition: index_metric.h:175
void clear()
Definition: index_metric.h:202
std::vector< index_info > index_array_t
Definition: index_metric.h:234
::uint32_t uint_t
Definition: base_metric.h:77
float cluster_count() const
Definition: index_metric.h:332
void set_cluster_counts(const float cluster_count, const float cluster_count_pf)
Definition: index_metric.h:349
Definition: generic_layout.h:24
const std::string & index_seq() const
Definition: index_metric.h:79
const_iterator end() const
Definition: index_metric.h:323
index_metric(const header_type &)
Definition: index_metric.h:250
const std::string & sample_id() const
Definition: index_metric.h:86
uint_t lane() const
Definition: base_metric.h:269
index_metric(uint_t lane, uint_t tile, uint_t read, const index_array_t &indices)
Definition: index_metric.h:264
std::string index2() const
Definition: index_metric.h:129
static index_metric_header default_header()
Definition: index_metric.h:196
index_info index_info_t
Definition: index_metric.h:236
index_array_t::const_iterator const_iterator
Definition: index_metric.h:238
const index_array_t & indices() const
Definition: index_metric.h:306
std::string index1() const
Definition: index_metric.h:118
std::string unique_id() const
Definition: index_metric.h:139
float percent_demultiplexed(const std::string &sample_id) const
Definition: index_metric.h:367
bool is_dual() const
Definition: index_metric.h:109
index_metric_header header_type
Definition: index_metric.h:232
#define INTEROP_BOUNDS_CHECK(VALUE, RANGE, MESSAGE)
Definition: exception.h:24
index_info(const std::string &index_seq, const std::string &sample_id, const std::string &sample_proj, const ::uint64_t cluster_count)
Definition: index_metric.h:55
index_metric()
Definition: index_metric.h:242
const std::string & sample_proj() const
Definition: index_metric.h:93
::uint64_t cluster_count() const
Definition: index_metric.h:100
float cluster_count_pf() const
Definition: index_metric.h:340
const_iterator begin() const
Definition: index_metric.h:315
uint_t read() const
Definition: base_read_metric.h:118
base_read_metric(const uint_t lane, const uint_t tile, const uint_t read)
Definition: base_read_metric.h:77