libsequence  1.9.5
lHaf.cc
1 #include <Sequence/SummStats/lHaf.hpp>
2 #include <algorithm>
3 #include <numeric>
4 #include <cmath>
5 
6 namespace Sequence
7 {
8  std::vector<double>
9  lHaf(const SimData &data, const double l)
10  {
11  //using range_type = tbb::blocked_range<SimData::const_site_iterator>;
12  //using data_range_type
13  // = tbb::blocked_range<std::vector<std::string>::const_iterator>;
14  // Get derived mutation frequency counts per site
15  std::vector<unsigned> dcounts;
16  dcounts.reserve(data.numsites());
17  for (auto i = data.sbegin(); i < data.send(); ++i)
18  {
19  dcounts.push_back(static_cast<unsigned>(
20  std::count(i->second.begin(), i->second.end(), '1')));
21  }
22  // Get the values for each element in the data
23  std::vector<double> rv;
24  rv.reserve(data.size());
25  for (auto &i : data)
26  {
27  auto j
28  = std::find_if(i.cbegin(), i.cend(),
29  [](const char &ch) { return ch == '1'; });
30  double score = 0.0;
31  while (j != i.cend())
32  {
33  size_t d2 = size_t(j - i.cbegin());
34  score += std::pow(static_cast<double>(dcounts[d2]), l);
35  j = std::find(j + 1, i.cend(), '1');
36  }
37  rv.push_back(score);
38  }
39  return rv;
40  }
41 } // namespace Sequence
The namespace in which this library resides.