libsequence  1.9.5
algorithm.hpp
Go to the documentation of this file.
1 
4 #ifndef SEQUENCE_SUMMSTATS_ALGORITHM_HPP
5 #define SEQUENCE_SUMMSTATS_ALGORITHM_HPP
6 
7 #include <cstdint>
8 #include <Sequence/VariantMatrix.hpp>
9 #include <Sequence/StateCounts.hpp>
10 #include <Sequence/VariantMatrixViews.hpp>
11 
12 namespace Sequence
13 {
14  namespace sstats_algo
15  {
16  template <typename F>
17  inline void
18  aggregate_sites(const VariantMatrix& m, const F& f,
19  const std::int8_t refstate)
44  {
45  StateCounts c(refstate);
46  for (std::size_t i = 0; i < m.nsites; ++i)
47  {
48  auto r = get_ConstRowView(m, i);
49  c(r);
50  f(c);
51  }
52  }
53 
54  template <typename F>
55  inline void
56  aggregate_sites(const VariantMatrix& m, const F& f,
57  const std::vector<std::int8_t>& refstates)
82  {
83  if (refstates.size() != m.nsites)
84  {
85  throw std::invalid_argument(
86  "number of reference states must equal number of "
87  "sites in VariantMatrix");
88  }
89  StateCounts c;
90  for (std::size_t i = 0; i < m.nsites; ++i)
91  {
92  c.refstate = refstates[i];
93  auto r = get_ConstRowView(m, i);
94  c(r);
95  f(c);
96  }
97  }
98  } // namespace sstats_algo
99 } // namespace Sequence
100 
101 #endif
Track character state occurrence at a site in a VariantMatrix.
Definition: StateCounts.hpp:11
The namespace in which this library resides.
std::size_t nsites
Number of sites in data set.
ConstRowView get_ConstRowView(const VariantMatrix &m, const std::size_t row)
Return a ConstRowView from VariantMatrix m at row row. std::out_of_range is thrown if row is out of r...
Matrix representation of variation data.
void aggregate_sites(const VariantMatrix &m, const F &f, const std::vector< std::int8_t > &refstates)
Definition: algorithm.hpp:56