summary_statistics.h
Go to the documentation of this file.
1 
8 #pragma once
9 
13 
14 
15 namespace illumina { namespace interop { namespace logic { namespace summary
16 {
23  template<typename I>
24  void reserve(I beg, I end, const ptrdiff_t n)
25  {
26  for (; beg != end; ++beg) beg->reserve(n);
27  }
28 
31  template<typename T>
33  {
34  public:
36  typedef std::vector<T> vector_t; // TODO: Speed up with 2d vector?
38  typedef std::vector<vector_t> vector2d_t;
40  typedef std::vector<vector2d_t> vector3d_t;
42  typedef typename vector_t::const_iterator const_iterator;
44  typedef typename vector3d_t::iterator read_iterator;
46  typedef typename vector_t::const_reference const_reference;
47 
48 
49  public:
56  summary_by_lane_read(const model::summary::run_summary &run, const ptrdiff_t n, const size_t surface_count=1) :
57  m_summary_by_lane_read(run.size(), vector2d_t(run.lane_count()*std::max(static_cast<size_t>(1),surface_count))),
58  m_lane_count(run.lane_count()),
59  m_surface_count(std::max(static_cast<size_t>(1),surface_count))
60  {
61  for (read_iterator beg = m_summary_by_lane_read.begin(), end = m_summary_by_lane_read.end();
62  beg != end; ++beg)
63  reserve(beg->begin(), beg->end(), n);
64  }
65 
66  public:
74  vector_t &operator()(const size_t read, const size_t lane, const size_t surface=0)
75  {
76  INTEROP_ASSERTMSG(surface < m_surface_count, surface << " < " << m_surface_count);
77  INTEROP_ASSERTMSG(read < m_summary_by_lane_read.size(), read << " < " << m_summary_by_lane_read.size());
78  const size_t offset = lane*m_surface_count+surface;
79  INTEROP_ASSERTMSG(offset < m_summary_by_lane_read[read].size(),
80  offset << " < " << m_summary_by_lane_read[read].size());
81  return m_summary_by_lane_read[read][offset];
82  }
83 
86  void clear()
87  {
88  for (read_iterator beg = m_summary_by_lane_read.begin(), end = m_summary_by_lane_read.end();
89  beg != end; ++beg)
90  clear(beg->begin(), beg->end());
91  }
92 
97  size_t size() const
98  {
99  return m_summary_by_lane_read.size();
100  }
101 
106  size_t read_count() const
107  {
108  return m_summary_by_lane_read.size();
109  }
110 
115  size_t lane_count() const
116  {
117  return m_lane_count;
118  }
123  size_t surface_count() const
124  {
125  return m_surface_count;
126  }
127 
128  private:
129  template<typename I>
130  static void clear(I beg, I end)
131  {
132  for (; beg != end; ++beg) beg->clear();
133  }
134 
135  private:
136  vector3d_t m_summary_by_lane_read;
137  size_t m_lane_count;
138  size_t m_surface_count;
139  };
140 
148  template<typename I, typename S>
149  void summarize(I beg, I end, S &stat, const bool skip_median)
150  {
151  stat.clear();
152  if (beg == end) return;
153  stat.mean(util::mean<float>(beg, end));
154  stat.stddev(std::sqrt(util::variance_with_mean<float>(beg, end, stat.mean())));
155  if(!skip_median) stat.median(util::median_interpolated<float>(beg, end));
156  }
157 
167  template<typename I, typename S, typename BinaryOp, typename Compare>
168  void summarize(I beg, I end, S &stat, BinaryOp op, Compare comp, const bool skip_median)
169  {
170  if (beg == end) return;
171  stat.mean(util::mean<float>(beg, end, op));
172  stat.stddev(std::sqrt(util::variance_with_mean<float>(beg, end, stat.mean(), op)));
173  if(!skip_median) stat.median(util::median_interpolated<float>(beg, end, comp, op));
174  }
175 
186  template<typename I, typename S, typename BinaryOp, typename Compare>
187  size_t nan_summarize(I beg, I end, S &stat, BinaryOp op, Compare comp, const bool skip_median)
188  {
189  stat.clear();
190  if (beg == end) return 0;
191  end = util::remove_nan(beg, end, op);
192  if (beg == end) return 0;
193  stat.mean(util::mean<float>(beg, end, op));
194  INTEROP_ASSERT(!std::isnan(stat.mean()));
195  stat.stddev(std::sqrt(util::variance_with_mean<float>(beg, end, stat.mean(), op)));
196  if(!skip_median) stat.median(util::median_interpolated<float>(beg, end, comp, op));
197  return size_t(std::distance(beg, end));
198  }
199 
208  template<typename I, typename S, typename Op>
209  S nan_accumulate(I beg, I end, const S init, Op op)
210  {
211  S return_value = init;
212  if (beg == end) return init;
213  const float temp_value = 0;
214  for (; beg != end; ++beg)
215  {
216  const float current_value = op(temp_value, *beg);
217  if(!std::isnan(current_value))
218  {
219  return_value += static_cast<S>(current_value);
220  }
221  }
222  return return_value;
223  }
224 
231  inline float divide(const float num, const float div)
232  {
233  static const float eps = 1e-9f;
234  return (div < eps) ? 0 : num / div;
235  }
242  inline double divide(const double num, const double div)
243  {
244  static const double eps = 1e-9;
245  return (div < eps) ? 0 : num / div;
246  }
247 
248  namespace op
249  {
253  template<typename UnaryOp>
255  {
260  total_cycle_sum(const UnaryOp &op) : m_op(op)
261  { }
262 
269  template<class T>
270  size_t operator()(const size_t last, const T &obj) const
271  {
272  return last + m_op(obj).total_cycles();
273  }
274 
275  private:
276  UnaryOp m_op;
277  };
278 
283  {
290  {
291  return summary.read();
292  }
293 
300  {
301  return read;
302  }
303 
310  {
311  return summary.read();
312  }
313 
320  {
321  return read;
322  }
323  };
324  }
325 
326 }}}}
327 
#define INTEROP_ASSERTMSG(TST, MSG)
Definition: assert.h:32
model::run::read_info & operator()(model::run::read_info &read) const
Definition: summary_statistics.h:299
vector_t & operator()(const size_t read, const size_t lane, const size_t surface=0)
Definition: summary_statistics.h:74
Definition: enum_description.h:15
const model::run::read_info & operator()(const model::summary::read_summary &summary) const
Definition: summary_statistics.h:309
summary_by_lane_read(const model::summary::run_summary &run, const ptrdiff_t n, const size_t surface_count=1)
Definition: summary_statistics.h:56
model::run::read_info & operator()(model::summary::read_summary &summary) const
Definition: summary_statistics.h:289
S nan_accumulate(I beg, I end, const S init, Op op)
Definition: summary_statistics.h:209
inline::uint32_t surface(const ::uint32_t tile_id, const constants::tile_naming_method method)
Definition: tile_metric.h:93
total_cycle_sum(const UnaryOp &op)
Definition: summary_statistics.h:260
vector_t::const_reference const_reference
Definition: summary_statistics.h:46
size_t read_count() const
Definition: summary_statistics.h:106
vector_t::const_iterator const_iterator
Definition: summary_statistics.h:42
const model::run::read_info & operator()(const model::run::read_info &read) const
Definition: summary_statistics.h:319
std::vector< vector2d_t > vector3d_t
Definition: summary_statistics.h:40
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
size_t nan_summarize(I beg, I end, S &stat, BinaryOp op, Compare comp, const bool skip_median)
Definition: summary_statistics.h:187
size_t lane_count() const
Definition: summary_statistics.h:115
def summary(run_metrics, level='Total', columns=None, dtype='f4', ignore_missing_columns=True, extra)
Definition: core.py:217
void reserve(I beg, I end, const ptrdiff_t n)
Definition: summary_statistics.h:24
void clear()
Definition: summary_statistics.h:86
void summarize(I beg, I end, S &stat, const bool skip_median)
Definition: summary_statistics.h:149
vector3d_t::iterator read_iterator
Definition: summary_statistics.h:44
Definition: summary_statistics.h:254
def read(run, valid_to_load=None, requires=None, search_paths=None, extra)
Definition: core.py:752
Definition: enums.h:301
size_t operator()(const size_t last, const T &obj) const
Definition: summary_statistics.h:270
I remove_nan(I beg, I end, UnaryOp op)
Definition: statistics.h:479
run::read_info & read()
Definition: read_summary.h:106
std::vector< T > vector_t
Definition: summary_statistics.h:36
std::vector< vector_t > vector2d_t
Definition: summary_statistics.h:38
size_t size() const
Definition: summary_statistics.h:97
size_t surface_count() const
Definition: summary_statistics.h:123
float divide(const float num, const float div)
Definition: summary_statistics.h:231