tile_metric.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include <cstring>
15 #include <fstream>
16 #include <map>
17 #include "interop/util/math.h"
22 
23 namespace illumina { namespace interop { namespace model { namespace metrics
24 {
28  {
29  public:
34  tile_metric_header(const float density) : m_density(density) {}
40  float density()const{return m_density;}
46  {
47  return tile_metric_header(std::numeric_limits<float>::quiet_NaN());
48  }
51  void clear()
52  {
53  m_density=0;
55  }
56  private:
57  float m_density;
58  template<class MetricType, int Version>
59  friend struct io::generic_layout;
60  };
64  {
65  public:
67  typedef ::uint32_t uint_t;
68  public:
76  read_metric(const uint_t read = 0,
77  const float percent_aligned = std::numeric_limits<float>::quiet_NaN(),
78  const float percent_phasing = std::numeric_limits<float>::quiet_NaN(),
79  const float percent_prephasing = std::numeric_limits<float>::quiet_NaN()) :
80  m_read(read),
81  m_percent_aligned(percent_aligned),
82  m_percent_phasing(percent_phasing),
83  m_percent_prephasing(percent_prephasing)
84  {
85  }
86 
87  public:
101  uint_t read() const
102  { return m_read; }
103 
110  float percent_aligned() const
111  { return m_percent_aligned; }
112 
118  float percent_phasing() const
119  { return (m_percent_phasing < 0) ? 0 : m_percent_phasing; /* Consistent with legacy */ }
120 
126  float percent_prephasing() const
127  { return (m_percent_prephasing < 0) ? 0 : m_percent_prephasing; /* Consistent with legacy */ }
133  void percent_aligned(const float val)
134  { m_percent_aligned = val; }
135 
141  void percent_phasing(const float val)
142  { m_percent_phasing = val; }
143 
149  void percent_prephasing(const float val)
150  { m_percent_prephasing = val; }
151 
152  private:
153  uint_t m_read;
154  float m_percent_aligned;
155  float m_percent_phasing;
156  float m_percent_prephasing;
157  template<class MetricType, int Version>
158  friend struct io::generic_layout;
159  };
160 
166  {
167  public:
168  enum
169  {
174  };
177  typedef std::vector<read_metric> read_metric_vector;
179  typedef read_metric_vector::const_iterator const_iterator;
184  private:
185  typedef read_metric_vector::iterator read_iterator;
186  public:
189  tile_metric() : metric_base::base_metric(0, 0),
190  m_cluster_density(std::numeric_limits<float>::quiet_NaN()),
191  m_cluster_density_pf(std::numeric_limits<float>::quiet_NaN()),
192  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
193  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN())
194  { }
197  tile_metric(const header_type&) : metric_base::base_metric(0, 0),
198  m_cluster_density(std::numeric_limits<float>::quiet_NaN()),
199  m_cluster_density_pf(std::numeric_limits<float>::quiet_NaN()),
200  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
201  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN())
202  { }
203 
215  tile_metric(const uint_t lane,
216  const uint_t tile,
217  const float cluster_density,
218  const float cluster_density_pf,
219  const float cluster_count,
220  const float cluster_count_pf,
221  const read_metric_vector &read_metrics = read_metric_vector()) :
222  metric_base::base_metric(lane, tile),
223  m_cluster_density(cluster_density),
224  m_cluster_density_pf(cluster_density_pf),
225  m_cluster_count(cluster_count),
226  m_cluster_count_pf(cluster_count_pf),
227  m_read_metrics(read_metrics)
228  { }
229 
237  tile_metric(const uint_t lane,
238  const uint_t tile,
239  const read_metric_vector &read_metrics = read_metric_vector()) :
240  metric_base::base_metric(lane, tile),
241  m_cluster_density(std::numeric_limits<float>::quiet_NaN()),
242  m_cluster_density_pf(std::numeric_limits<float>::quiet_NaN()),
243  m_cluster_count(std::numeric_limits<float>::quiet_NaN()),
244  m_cluster_count_pf(std::numeric_limits<float>::quiet_NaN()),
245  m_read_metrics(read_metrics)
246  { }
247 
253  tile_metric(const tile_metric &metric,
254  const read_metric_vector &read_metrics = read_metric_vector()) :
255  metric_base::base_metric(metric),
256  m_cluster_density(metric.m_cluster_density),
257  m_cluster_density_pf(metric.m_cluster_density_pf),
258  m_cluster_count(metric.m_cluster_count),
259  m_cluster_count_pf(metric.m_cluster_count_pf),
260  m_read_metrics(read_metrics.size() > 0 ? read_metrics : metric.read_metrics())
261  { }
271  tile_metric(const uint_t lane,
272  const uint_t tile,
273  const float cluster_count,
274  const float cluster_count_pf,
275  const read_metric_vector & read_metrics=read_metric_vector()) :
276  metric_base::base_metric(lane,tile),
277  m_cluster_density(std::numeric_limits<float>::quiet_NaN()),
278  m_cluster_density_pf(std::numeric_limits<float>::quiet_NaN()),
279  m_cluster_count(cluster_count),
280  m_cluster_count_pf(cluster_count_pf),
281  m_read_metrics(read_metrics)
282  {}
283 
284  public:
306  float cluster_density() const
307  { return m_cluster_density; }
308 
313  float cluster_density_k() const
314  { return m_cluster_density/1000.0f; }
315 
320  float cluster_density_pf() const
321  { return m_cluster_density_pf; }
322 
327  float cluster_density_pf_k() const
328  { return m_cluster_density_pf/1000.0f; }
329 
334  float cluster_count() const
335  { return m_cluster_count; }
336 
341  float cluster_count_k() const
342  { return m_cluster_count/1000.0f; }
343 
348  float cluster_count_m() const
349  { return m_cluster_count/1000000.0f; }
350 
355  float cluster_count_pf() const
356  { return m_cluster_count_pf; }
357 
362  float cluster_count_pf_k() const
363  { return m_cluster_count_pf/1000.0f; }
364 
369  float cluster_count_pf_m() const
370  { return m_cluster_count_pf/1000000.0f; }
371 
376  float percent_pf() const
377  {
378  return 100 * m_cluster_count_pf / m_cluster_count;
379  }
380 
385  const read_metric_vector &read_metrics() const
386  { return m_read_metrics; }
387 
395  float percent_aligned(const size_t n) const
396  {
397  if (n >= m_read_metrics.size())
398  return std::numeric_limits<float>::quiet_NaN();
399  return m_read_metrics[n].percent_aligned();
400  }
401 
408  float percent_phasing(const size_t n) const
409  {
410  if (n >= m_read_metrics.size())
411  return std::numeric_limits<float>::quiet_NaN();
412  return m_read_metrics[n].percent_phasing();
413  }
414 
421  float percent_prephasing(const size_t n) const
422  {
423  if (n >= m_read_metrics.size())
424  return std::numeric_limits<float>::quiet_NaN();
425  return m_read_metrics[n].percent_prephasing();
426  }
427 
435  float percent_aligned_at(const size_t number) const
436  {
437  for (const_iterator b = m_read_metrics.begin(), e = m_read_metrics.end(); b != e; ++b)
438  if (b->read() == number) return b->percent_aligned();
439  return std::numeric_limits<float>::quiet_NaN();
440  }
441 
448  float percent_phasing_at(const size_t number) const
449  {
450  for (const_iterator b = m_read_metrics.begin(), e = m_read_metrics.end(); b != e; ++b)
451  if (b->read() == number) return b->percent_phasing();
452  return std::numeric_limits<float>::quiet_NaN();
453  }
454 
461  float percent_prephasing_at(const size_t number) const
462  {
463  for (const_iterator b = m_read_metrics.begin(), e = m_read_metrics.end(); b != e; ++b)
464  if (b->read() == number) return b->percent_prephasing();
465  return std::numeric_limits<float>::quiet_NaN();
466  }
467 
472  size_t read_count() const
473  {
474  return m_read_metrics.size();
475  }
476 
481  bool is_dead_tile() const
482  {
483  return (cluster_count() == 0) || (cluster_count_pf() == 0);
484  }
485 
486  /* @} */
493  void update_phasing_if_missing(const size_t number, const float phasing, const float prephasing)
494  {
495  for (read_iterator b = m_read_metrics.begin(); b != m_read_metrics.end(); ++b)
496  {
497  if (b->read() == static_cast<uint_t>(number))
498  {
499  if(std::isnan(b->percent_phasing()))
500  {
501  b->percent_phasing(phasing);
502  }
503  if(std::isnan(b->percent_prephasing()))
504  {
505  b->percent_prephasing(prephasing);
506  }
507  return;
508  }
509  }
510  m_read_metrics.push_back(read_metric(static_cast<uint_t>(number),
511  std::numeric_limits<float>::quiet_NaN(),
512  phasing,
513  prephasing));
514  }
520  float clusterDensity() const
521  { return m_cluster_density; }
522 
528  float clusterDensityPf() const
529  { return m_cluster_density_pf; }
530 
536  float clusterCount() const
537  { return m_cluster_count; }
538 
544  float clusterCountPf() const
545  { return m_cluster_count_pf; }
546 
547  public:
552  static const char *prefix()
553  { return "Tile"; }
554 
555  private:
556  float m_cluster_density;
557  float m_cluster_density_pf;
558  float m_cluster_count;
559  float m_cluster_count_pf;
560  read_metric_vector m_read_metrics;
561 
562  template<class MetricType, int Version>
563  friend
564  struct io::generic_layout;
565  };
566 }}}}
567 
::uint32_t uint_t
Definition: tile_metric.h:67
static tile_metric_header default_header()
Definition: tile_metric.h:45
const read_metric_vector & read_metrics() const
Definition: tile_metric.h:385
float percent_phasing(const size_t n) const
Definition: tile_metric.h:408
float percent_prephasing_at(const size_t number) const
Definition: tile_metric.h:461
Definition: enum_description.h:15
float cluster_count() const
Definition: tile_metric.h:334
tile_metric(const uint_t lane, const uint_t tile, const float cluster_density, const float cluster_density_pf, const float cluster_count, const float cluster_count_pf, const read_metric_vector &read_metrics=read_metric_vector())
Definition: tile_metric.h:215
float clusterCountPf() const
Definition: tile_metric.h:544
uint_t tile() const
Definition: base_metric.h:284
bool is_dead_tile() const
Definition: tile_metric.h:481
float percent_prephasing() const
Definition: tile_metric.h:126
float cluster_count_m() const
Definition: tile_metric.h:348
std::vector< read_metric > read_metric_vector
Definition: tile_metric.h:177
float cluster_density() const
Definition: tile_metric.h:306
tile_metric(const uint_t lane, const uint_t tile, const float cluster_count, const float cluster_count_pf, const read_metric_vector &read_metrics=read_metric_vector())
Definition: tile_metric.h:271
float clusterDensity() const
Definition: tile_metric.h:520
uint_t number(const illumina::interop::constants::tile_naming_method) const
Definition: base_metric.h:293
float cluster_density_k() const
Definition: tile_metric.h:313
float percent_phasing() const
Definition: tile_metric.h:118
float cluster_count_pf_m() const
Definition: tile_metric.h:369
float density() const
Definition: tile_metric.h:40
float cluster_density_pf_k() const
Definition: tile_metric.h:327
static const char * prefix()
Definition: tile_metric.h:552
float cluster_count_pf() const
Definition: tile_metric.h:355
size_t read_count() const
Definition: tile_metric.h:472
read_metric_vector::const_iterator const_iterator
Definition: tile_metric.h:179
float clusterDensityPf() const
Definition: tile_metric.h:528
float cluster_count_pf_k() const
Definition: tile_metric.h:362
tile_metric_header header_type
Definition: tile_metric.h:183
tile_metric_header(const float density)
Definition: tile_metric.h:34
tile_metric(const tile_metric &metric, const read_metric_vector &read_metrics=read_metric_vector())
Definition: tile_metric.h:253
void clear()
Definition: tile_metric.h:51
read_metric read_metric_type
Definition: tile_metric.h:181
float percent_aligned_at(const size_t number) const
Definition: tile_metric.h:435
read_metric(const uint_t read=0, const float percent_aligned=std::numeric_limits< float >::quiet_NaN(), const float percent_phasing=std::numeric_limits< float >::quiet_NaN(), const float percent_prephasing=std::numeric_limits< float >::quiet_NaN())
Definition: tile_metric.h:76
float clusterCount() const
Definition: tile_metric.h:536
Definition: generic_layout.h:24
tile_metric(const header_type &)
Definition: tile_metric.h:197
uint_t lane() const
Definition: base_metric.h:269
float percent_pf() const
Definition: tile_metric.h:376
def read_metric
Definition: core.py:826
base_metric(const uint_t lane=0, const uint_t tile=0)
Definition: base_metric.h:178
uint_t read() const
Definition: tile_metric.h:101
float percent_phasing_at(const size_t number) const
Definition: tile_metric.h:448
void percent_phasing(const float val)
Definition: tile_metric.h:141
float cluster_density_pf() const
Definition: tile_metric.h:320
void update_phasing_if_missing(const size_t number, const float phasing, const float prephasing)
Definition: tile_metric.h:493
void percent_aligned(const float val)
Definition: tile_metric.h:133
Definition: enums.h:291
void percent_prephasing(const float val)
Definition: tile_metric.h:149
tile_metric()
Definition: tile_metric.h:189
tile_metric(const uint_t lane, const uint_t tile, const read_metric_vector &read_metrics=read_metric_vector())
Definition: tile_metric.h:237
float percent_aligned() const
Definition: tile_metric.h:110
float percent_prephasing(const size_t n) const
Definition: tile_metric.h:421
float percent_aligned(const size_t n) const
Definition: tile_metric.h:395
float cluster_count_k() const
Definition: tile_metric.h:341