corrected_intensity_metric.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include <limits>
23 #include <numeric>
24 #include <cstring>
25 #include <fstream>
26 #include "interop/util/math.h"
27 #include "interop/util/exception.h"
34 
35 namespace illumina { namespace interop { namespace model { namespace metrics
36 {
51  {
52  public:
53  enum
54  {
59  };
65  typedef std::vector<ushort_t> ushort_array_t;
68  typedef std::vector<uint_t> uint_array_t;
71  typedef std::vector<float> float_array_t;
74  typedef ::uint16_t *ushort_pointer_t;
77  typedef ::uint32_t *uint_pointer_t;
80  typedef float* float_pointer_t;
81  public:
85  metric_base::base_cycle_metric(0, 0, 0),
86  m_average_cycle_intensity(0),
87  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
88  m_corrected_int_called(constants::NUM_OF_BASES, std::numeric_limits<float>::quiet_NaN()),
89  m_called_counts(constants::NUM_OF_BASES_AND_NC, 0),
90  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
91  { }
95  metric_base::base_cycle_metric(0, 0, 0),
96  m_average_cycle_intensity(0),
97  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
98  m_corrected_int_called(constants::NUM_OF_BASES, std::numeric_limits<float>::quiet_NaN()),
99  m_called_counts(constants::NUM_OF_BASES_AND_NC, 0),
100  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
101  { }
102 
116  const uint_t tile,
117  const uint_t cycle,
119  const float signal_to_noise,
120  const float_array_t &corrected_int_called,
121  const ushort_array_t &corrected_int_all,
122  const uint_array_t &called_counts) :
123  metric_base::base_cycle_metric(lane, tile, cycle),
124  m_average_cycle_intensity(average_cycle_intensity),
125  m_corrected_int_all(corrected_int_all),
126  m_corrected_int_called(corrected_int_called),
127  m_called_counts(called_counts),
128  m_signal_to_noise(signal_to_noise)
129  {
130  INTEROP_ASSERT(m_corrected_int_all.size() == constants::NUM_OF_BASES);
131  INTEROP_ASSERT(m_corrected_int_called.size() == constants::NUM_OF_BASES);
132  INTEROP_ASSERT(m_called_counts.size() == constants::NUM_OF_BASES_AND_NC);
133  }
134 
148  const uint_t tile,
149  const uint_t cycle,
151  const float signal_to_noise,
152  const float_pointer_t corrected_int_called,
153  const ushort_pointer_t corrected_int_all,
154  const uint_pointer_t called_counts) :
155  metric_base::base_cycle_metric(lane, tile, cycle),
156  m_average_cycle_intensity(average_cycle_intensity),
157  m_corrected_int_all(corrected_int_all, corrected_int_all + constants::NUM_OF_BASES),
158  m_corrected_int_called(corrected_int_called, corrected_int_called + constants::NUM_OF_BASES),
159  m_called_counts(called_counts, called_counts + constants::NUM_OF_BASES_AND_NC),
160  m_signal_to_noise(signal_to_noise)
161  {
162  INTEROP_ASSERT(m_corrected_int_all.size() == constants::NUM_OF_BASES);
163  INTEROP_ASSERT(m_corrected_int_called.size() == constants::NUM_OF_BASES);
164  INTEROP_ASSERT(m_called_counts.size() == constants::NUM_OF_BASES_AND_NC);
165  }
166 
177  const uint_t tile,
178  const uint_t cycle,
179  const float_array_t &corrected_int_called,
180  const uint_array_t &called_counts) :
181  metric_base::base_cycle_metric(lane, tile, cycle),
182  m_average_cycle_intensity(std::numeric_limits<ushort_t>::max()),
183  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
184  m_corrected_int_called(corrected_int_called),
185  m_called_counts(called_counts),
186  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
187  {
188  INTEROP_ASSERT(m_corrected_int_all.size() == constants::NUM_OF_BASES);
189  INTEROP_ASSERT(m_called_counts.size() == constants::NUM_OF_BASES_AND_NC);
190  }
191 
202  const uint_t tile,
203  const uint_t cycle,
204  const ushort_pointer_t corrected_int_called,
205  const uint_pointer_t called_counts) :
206  metric_base::base_cycle_metric(lane, tile, cycle),
207  m_average_cycle_intensity(std::numeric_limits<ushort_t>::max()),
208  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
209  m_corrected_int_called(corrected_int_called, corrected_int_called + constants::NUM_OF_BASES),
210  m_called_counts(called_counts, called_counts + constants::NUM_OF_BASES_AND_NC),
211  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
212  {// TODO: Add array safety to this constructor
213  INTEROP_ASSERT(m_corrected_int_called.size() == constants::NUM_OF_BASES);
214  INTEROP_ASSERT(m_called_counts.size() == constants::NUM_OF_BASES_AND_NC);
215  }
216 
226  const uint_t tile,
227  const uint_t cycle,
228  const uint_array_t& called_count) :
229  metric_base::base_cycle_metric(lane, tile, cycle),
230  m_average_cycle_intensity(std::numeric_limits<ushort_t>::max()),
231  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
232  m_corrected_int_called(constants::NUM_OF_BASES, std::numeric_limits<float>::quiet_NaN()),
233  m_called_counts(called_count),
234  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
235  {
236  INTEROP_ASSERT(called_count.size() == static_cast<size_t>(constants::NUM_OF_BASES_AND_NC));
237  }
248  const uint_t tile,
249  const uint_t cycle,
250  const ::uint32_t* called_counts,
251  const size_t num_of_counts,
252  const size_t /*dummy*/, /* dummy parameters work around swig bug */
253  const size_t /*dummy*/) :
254  metric_base::base_cycle_metric(lane, tile, cycle),
255  m_average_cycle_intensity(std::numeric_limits<ushort_t>::max()),
256  m_corrected_int_all(constants::NUM_OF_BASES, std::numeric_limits<ushort_t>::max()),
257  m_corrected_int_called(constants::NUM_OF_BASES, std::numeric_limits<float>::quiet_NaN()),
258  m_called_counts(called_counts, called_counts + std::min(num_of_counts, static_cast<size_t>(constants::NUM_OF_BASES_AND_NC))),
259  m_signal_to_noise(std::numeric_limits<float>::quiet_NaN())
260  {
261  INTEROP_ASSERT(num_of_counts== static_cast<size_t>(constants::NUM_OF_BASES_AND_NC));
262  }
263 
264  public:
272  void set(const uint_t lane,
273  const uint_t tile,
274  const uint_t cycle,
275  const uint_array_t& called_counts)
276  {
277  metric_base::base_cycle_metric::set_base(lane, tile, cycle);
278  m_called_counts = called_counts;
279  }
280 
281  public:
296  {
297  return m_average_cycle_intensity;
298  }
299 
307  {
308  INTEROP_BOUNDS_CHECK(static_cast<size_t>(index), m_corrected_int_all.size(), "Base out of bounds");
309  return m_corrected_int_all[index];
310  }
311 
319  {
320  INTEROP_BOUNDS_CHECK(static_cast<size_t>(index), m_corrected_int_all.size(), "Base out of bounds");
321  return util::float_cast(m_corrected_int_all[index]);
322  }
323 
331  {
332  INTEROP_BOUNDS_CHECK(static_cast<size_t>(index), m_corrected_int_all.size(), "Base out of bounds");
333  return m_corrected_int_called[index];
334  }
335 
340  const uint_array_t &called_counts_array() const
341  { return m_called_counts; }
342 
348  const float_array_t &corrected_int_called_array() const
349  { return m_corrected_int_called; }
350 
356  const ushort_array_t &corrected_int_all_array() const
357  { return m_corrected_int_all; }
358 
369  {
370  INTEROP_BOUNDS_CHECK(static_cast<size_t>(index + 1), m_called_counts.size(), "Base out of bounds");
371  return m_called_counts[static_cast<uint_t>(index + 1)];
372  }
373 
379  uint_t no_calls() const
380  {
381  if(m_called_counts.empty()) return 0;
382  return m_called_counts[0];
383  }
384 
391  float signal_to_noise() const
392  {
393  return m_signal_to_noise;
394  }
395 
402  uint_t total_calls(const bool nocalls = false) const
403  {
404  if (nocalls)
405  return std::accumulate(m_called_counts.begin(), m_called_counts.end(), 0);
406  return std::accumulate(m_called_counts.begin() + 1, m_called_counts.end(), 0);
407  }
408 
415  {
416  return std::accumulate(m_corrected_int_all.begin(), m_corrected_int_all.end(), 0);
417  }
418 
425  {
426  return std::accumulate(m_corrected_int_called.begin(), m_corrected_int_called.end(), 0.0f);
427  }
428 
436  {
437  const uint_t total = total_calls(index == constants::NC );
438  if (total == 0)
439  return std::numeric_limits<float>::quiet_NaN();
440  return called_counts(index) / static_cast<float>(total) * 100.0f;
441  }
442 
448  float_array_t percent_bases() const
449  {
450  if(m_called_counts.empty())
451  {
452  return float_array_t();
453  }
454  const uint_t total = total_calls();
455  float_array_t percent_bases(constants::NUM_OF_BASES);
456  for (size_t i = 0; i < percent_bases.size(); ++i)
457  percent_bases[i] = static_cast<float>(m_called_counts[i + 1]) / static_cast<float>(total) * 100.0f;
458  return percent_bases;
459  }
460 
467  {
468  return percent_base(constants::NC);
469  }
475  void corrected_int_called_array(const float_array_t & vals)
476  {
477  m_corrected_int_called.assign(vals.begin(), vals.end());
478  }
479 
480  //--------------------------------------------------------------------------------------------------------------
486  {
487  for(size_t i=0;i<m_corrected_int_called.size();++i)
488  if(!std::isnan(static_cast<float>(m_corrected_int_called[i]))) return true;
489  return false;
490  }
498  {
499  return m_average_cycle_intensity;
500  }
501 
509  ushort_t correctedIntAll(size_t index) const
510  {
511  INTEROP_ASSERT(index < static_cast<size_t>(constants::NUM_OF_BASES));
512  return m_corrected_int_all[index];
513  }
514 
522  float correctedIntCalled(size_t index) const
523  {
524  INTEROP_ASSERT(index < static_cast<size_t>(constants::NUM_OF_BASES));
525  return m_corrected_int_called[index];
526  }
527 
533  const float_array_t &correctedIntCalled() const
534  { return m_corrected_int_called; }
535 
542  const ushort_array_t &correctedIntAll() const
543  { return m_corrected_int_all; }
544 
550  const uint_array_t &calledCounts() const
551  { return m_called_counts; }
552 
559  uint_t noCalls() const
560  {
561  return m_called_counts[0];
562  }
563 
571  float percentBase(difference_type index) const
572  {
573  uint_t total = totalCalls(static_cast<constants::dna_bases>(index) == constants::NC);
574  if (total == 0) return std::numeric_limits<float>::quiet_NaN();
575  return calledCounts(index) / static_cast<float>(total) * 100;
576  }
577 
588  uint_t calledCounts(difference_type index) const
589  {
590  INTEROP_ASSERT((index + 1) < static_cast<difference_type>(constants::NUM_OF_BASES_AND_NC));
591  return m_called_counts[static_cast<uint_t>(index + 1)];
592  }
593 
601  float signalToNoise() const
602  {
603  return m_signal_to_noise;
604  }
605 
612  uint_t totalCalls(const bool nocalls = false) const
613  {
614  if (nocalls)
615  return std::accumulate(m_called_counts.begin(), m_called_counts.end(), 0);
616  return std::accumulate(m_called_counts.begin() + 1, m_called_counts.end(), 0);
617  }
618 
626  {
627  return std::accumulate(m_corrected_int_all.begin(), m_corrected_int_all.end(), 0u);
628  }
629 
636  float totalCalledIntensity() const
637  {
638  return std::accumulate(m_corrected_int_called.begin(), m_corrected_int_called.end(), 0.0f);
639  }
640 
648  float percentIntensity(size_t index) const
649  {
650  uint_t total = totalIntensity();
651  if (total == 0) return std::numeric_limits<float>::quiet_NaN();
652  return correctedIntAll(index) / static_cast<float>(total) * 100;
653  }
654 
662  float percentCalledIntensity(const size_t index) const
663  {
664  float total = totalCalledIntensity();
665  if (total == 0) return std::numeric_limits<float>::quiet_NaN();
666  return correctedIntCalled(index) / total * 100;
667  }
668 
669  public:
674  static const char *prefix()
675  { return "CorrectedInt"; }
676 
677  private:
678  ushort_t m_average_cycle_intensity; // Version 1 & 2
679  ushort_array_t m_corrected_int_all; // Version 1 & 2
680  float_array_t m_corrected_int_called;
681  // All
682  uint_array_t m_called_counts; // All
683  float m_signal_to_noise; // Version 2
684 
685  template<class MetricType, int Version>
686  friend
687  struct io::generic_layout;
688  };
689 }}}}
690 
691 
692 
693 
694 
695 
bool any_valid_called_int() const
Definition: corrected_intensity_metric.h:485
void corrected_int_called_array(const float_array_t &vals)
Definition: corrected_intensity_metric.h:475
ushort_t correctedIntAll(size_t index) const
Definition: corrected_intensity_metric.h:509
uint_t total_intensity() const
Definition: corrected_intensity_metric.h:414
Definition: enum_description.h:15
const ushort_array_t & corrected_int_all_array() const
Definition: corrected_intensity_metric.h:356
float signal_to_noise() const
Definition: corrected_intensity_metric.h:391
void set(const uint_t lane, const uint_t tile, const uint_t cycle, const uint_array_t &called_counts)
Definition: corrected_intensity_metric.h:272
uint_t tile() const
Definition: base_metric.h:284
corrected_intensity_metric(const header_type &)
Definition: corrected_intensity_metric.h:94
#define INTEROP_THROW_SPEC(SPEC)
Definition: exception_specification.h:15
float percent_base(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:435
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const float_array_t &corrected_int_called, const uint_array_t &called_counts)
Definition: corrected_intensity_metric.h:176
::uint16_t ushort_t
Definition: base_metric.h:141
std::vector< ushort_t > ushort_array_t
Definition: corrected_intensity_metric.h:65
ushort_t averageCycleIntensity() const
Definition: corrected_intensity_metric.h:497
ptrdiff_t intptr_t
Definition: pstdint.h:729
::intptr_t difference_type
Definition: corrected_intensity_metric.h:62
float corrected_int_called(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:330
uint_t totalCalls(const bool nocalls=false) const
Definition: corrected_intensity_metric.h:612
uint_t called_counts(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:368
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
const uint_array_t & calledCounts() const
Definition: corrected_intensity_metric.h:550
::uint16_t * ushort_pointer_t
Definition: corrected_intensity_metric.h:74
const float_array_t & corrected_int_called_array() const
Definition: corrected_intensity_metric.h:348
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
float percentBase(difference_type index) const
Definition: corrected_intensity_metric.h:571
::uint32_t uint_t
Definition: base_metric.h:77
Definition: generic_layout.h:24
::uint32_t * uint_pointer_t
Definition: corrected_intensity_metric.h:77
uint_t lane() const
Definition: base_metric.h:269
corrected_intensity_metric()
Definition: corrected_intensity_metric.h:84
const ushort_array_t & correctedIntAll() const
Definition: corrected_intensity_metric.h:542
void set_base(const uint_t lane, const uint_t tile)
Definition: base_cycle_metric.h:101
float percentIntensity(size_t index) const
Definition: corrected_intensity_metric.h:648
float signalToNoise() const
Definition: corrected_intensity_metric.h:601
Definition: enums.h:301
uint_t calledCounts(difference_type index) const
Definition: corrected_intensity_metric.h:588
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const ushort_t average_cycle_intensity, const float signal_to_noise, const float_pointer_t corrected_int_called, const ushort_pointer_t corrected_int_all, const uint_pointer_t called_counts)
Definition: corrected_intensity_metric.h:147
float_array_t percent_bases() const
Definition: corrected_intensity_metric.h:448
uint_t total_calls(const bool nocalls=false) const
Definition: corrected_intensity_metric.h:402
const uint_array_t & called_counts_array() const
Definition: corrected_intensity_metric.h:340
float totalCalledIntensity() const
Definition: corrected_intensity_metric.h:636
float float_cast(const T val, const T sentinel=std::numeric_limits< T >::max())
Definition: math.h:77
std::vector< uint_t > uint_array_t
Definition: corrected_intensity_metric.h:68
uint_t noCalls() const
Definition: corrected_intensity_metric.h:559
static const char * prefix()
Definition: corrected_intensity_metric.h:674
float percent_nocall() const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:466
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const uint_array_t &called_count)
Definition: corrected_intensity_metric.h:225
#define INTEROP_BOUNDS_CHECK(VALUE, RANGE, MESSAGE)
Definition: exception.h:24
float * float_pointer_t
Definition: corrected_intensity_metric.h:80
float corrected_int_all_float(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:318
ushort_t average_cycle_intensity() const
Definition: corrected_intensity_metric.h:295
const float_array_t & correctedIntCalled() const
Definition: corrected_intensity_metric.h:533
float percentCalledIntensity(const size_t index) const
Definition: corrected_intensity_metric.h:662
uint_t no_calls() const
Definition: corrected_intensity_metric.h:379
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const ushort_pointer_t corrected_int_called, const uint_pointer_t called_counts)
Definition: corrected_intensity_metric.h:201
std::vector< float > float_array_t
Definition: corrected_intensity_metric.h:71
Intensity and count metrics for each base.
Definition: corrected_intensity_metric.h:50
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const ::uint32_t *called_counts, const size_t num_of_counts, const size_t, const size_t)
Definition: corrected_intensity_metric.h:247
dna_bases
Definition: enums.h:299
float correctedIntCalled(size_t index) const
Definition: corrected_intensity_metric.h:522
corrected_intensity_metric(const uint_t lane, const uint_t tile, const uint_t cycle, const ushort_t average_cycle_intensity, const float signal_to_noise, const float_array_t &corrected_int_called, const ushort_array_t &corrected_int_all, const uint_array_t &called_counts)
Definition: corrected_intensity_metric.h:115
ushort_t corrected_int_all(const constants::dna_bases index) const INTEROP_THROW_SPEC((model
Definition: corrected_intensity_metric.h:306
float total_called_intensity() const
Definition: corrected_intensity_metric.h:424
uint_t totalIntensity() const
Definition: corrected_intensity_metric.h:625