libsequence  1.9.5
nvariablesites.cc
1 #include <cstdint>
2 #include <algorithm>
3 #include <Sequence/AlleleCountMatrix.hpp>
4 
5 namespace Sequence
6 {
7  std::uint32_t
9  {
10  std::uint32_t nv = 0;
11  for (std::size_t site = 0; site < m.nrow; ++site)
12  {
13  auto r = m.row(site);
14  auto nstates
15  = std::count_if(r.first, r.second,
16  [](const AlleleCountMatrix::value_type c) {
17  return c > 0;
18  });
19  if (nstates > 1)
20  {
21  ++nv;
22  }
23  }
24  return nv;
25  }
26 
27  std::uint32_t
29  {
30  std::uint32_t nv = 0;
31  for (std::size_t site = 0; site < m.nrow; ++site)
32  {
33  auto r = m.row(site);
34  auto nstates
35  = std::count_if(r.first, r.second,
36  [](const AlleleCountMatrix::value_type c) {
37  return c > 0;
38  });
39  if (nstates == 2)
40  {
41  ++nv;
42  }
43  }
44  return nv;
45  }
46 
47  std::uint32_t
49  {
50  std::uint32_t nv = 0;
51  for (std::size_t site = 0; site < m.nrow; ++site)
52  {
53  auto r = m.row(site);
54  auto nstates
55  = std::count_if(r.first, r.second,
56  [](const AlleleCountMatrix::value_type c) {
57  return c > 0;
58  });
59  if (nstates > 1)
60  {
61  nv += static_cast<decltype(nv)>(nstates) - 1;
62  }
63  }
64  return nv;
65  }
66 } // namespace Sequence
std::uint32_t total_number_of_mutations(const AlleleCountMatrix &m)
Total number of mutations in the sample.
The namespace in which this library resides.
std::uint32_t nvariable_sites(const AlleleCountMatrix &m)
Number of polymorphic sites.
std::uint32_t nbiallelic_sites(const AlleleCountMatrix &m)
Number of bi-allelic sites.
Matrix representation of allele counts in a VariantMatrix To be constructed.