libsequence  1.9.5
testLD.cc
Go to the documentation of this file.
1 
3 #include <cmath>
4 #include <algorithm>
5 #include <vector>
6 #include <iostream>
7 #include <Sequence/VariantMatrix.hpp>
8 #include <Sequence/VariantMatrixViews.hpp>
9 #include <Sequence/summstats/ld.hpp>
10 #include "VariantMatrixFixture.hpp"
11 #include <boost/test/unit_test.hpp>
12 
13 BOOST_FIXTURE_TEST_SUITE(test_LD, dataset)
14 
15 BOOST_AUTO_TEST_CASE(test_two_locus_haplotype_counts)
16 {
17  std::vector<int> results;
18  for (std::size_t i = 0; i < m.nsites - 1; ++i)
19  {
20  for (std::size_t j = i + 1; j < m.nsites; ++j)
21  {
22  std::vector<std::pair<std::int8_t, std::int8_t>> haps;
23  auto hc
24  = Sequence::two_locus_haplotype_counts(m, i, j, true);
25  auto ri = Sequence::get_ConstRowView(m, i);
26  auto rj = Sequence::get_ConstRowView(m, j);
27  for (std::size_t k = 0; k < ri.size(); ++k)
28  {
29  haps.emplace_back(ri[k], rj[k]);
30  }
31  std::sort(haps.begin(), haps.end());
32  auto end_of_unique_haps
33  = std::unique(haps.begin(), haps.end());
34  BOOST_REQUIRE_EQUAL(
35  hc.size(), static_cast<std::size_t>(std::distance(
36  haps.begin(), end_of_unique_haps)));
37  }
38  }
39 }
40 
41 BOOST_AUTO_TEST_SUITE_END()
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...