libsequence  1.9.5
ld.cc
1 #include <cstdint>
2 #include <vector>
3 #include <algorithm>
4 #include <Sequence/summstats/ld.hpp>
5 #include <Sequence/VariantMatrix.hpp>
6 #include <Sequence/VariantMatrixViews.hpp>
7 
8 namespace Sequence
9 {
10  TwoLocusCounts::TwoLocusCounts(std::int8_t i_, std::int8_t j_, int n_)
11  : i{ i_ }, j{ j_ }, n{ n_ }
12  {
13  }
14 
15  std::vector<TwoLocusCounts>
16  two_locus_haplotype_counts(const VariantMatrix& m, std::size_t sitei,
17  const std::size_t sitej,
18  const bool skip_missing)
19  {
20  auto ri = get_ConstRowView(m, sitei);
21  auto rj = get_ConstRowView(m, sitej);
22  std::vector<TwoLocusCounts> rv;
23  for (auto i = ri.begin(), j = rj.begin(); i < ri.end(); ++i, ++j)
24  {
25  if (!skip_missing || ((*i >= 0 || *j >= 0) && skip_missing))
26  {
27  auto exists
28  = std::find_if(rv.begin(), rv.end(),
29  [i, j](const TwoLocusCounts& t) {
30  return t.i == *i && t.j == *j;
31  });
32  if (exists == rv.end())
33  {
34  rv.emplace_back(*i, *j, 1);
35  }
36  else
37  {
38  exists->n++;
39  }
40  }
41  }
42  return rv;
43  }
44 } // namespace Sequence
The namespace in which this library resides.
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...