9 #include <Sequence/VariantMatrix.hpp> 10 #include <Sequence/VariantMatrixViews.hpp> 13 #include "VariantMatrixFixture.hpp" 14 #include <boost/test/unit_test.hpp> 16 BOOST_FIXTURE_TEST_SUITE(test_garud_stats, dataset)
18 BOOST_AUTO_TEST_CASE(test_garud_stats)
30 BOOST_REQUIRE_EQUAL(1.0 - hdiv, G.H1);
33 std::vector<std::string> haps;
34 for (
auto i = 0; i < m.nsam; ++i)
40 h += (ci == 0) ?
'0' :
'1';
42 haps.push_back(std::move(h));
45 std::set<std::string> uhaps(haps.begin(), haps.end());
46 std::vector<int> hcounts;
49 hcounts.push_back(std::count(haps.begin(), haps.end(), u));
51 std::sort(hcounts.begin(), hcounts.end(), std::greater<int>());
53 double nsam =
static_cast<double>(m.nsam);
54 for (
auto hc : hcounts)
56 H1 +=
static_cast<double>(hc) * static_cast<double>(hc - 1);
58 H1 /= ((nsam) * (nsam - 1));
63 BOOST_CHECK_CLOSE(H1, G.H1, 1e-6);
66 decltype(hcounts) hcounts2(hcounts.begin() + 1, hcounts.end());
67 hcounts2[0] += hcounts[0];
69 for (
auto hc : hcounts2)
71 double x =
static_cast<double>(hc) * static_cast<double>(hc - 1);
72 x /= (nsam * (nsam - 1));
75 BOOST_CHECK_CLOSE(H12, G.H12, 1e-6);
77 double p1sq =
static_cast<double>(hcounts[0] * (hcounts[0] - 1))
78 / (nsam * (nsam - 1.0));
79 double H2 = H1 - p1sq;
80 BOOST_CHECK_CLOSE(H2 / H1, G.H2H1, 1e-6);
83 BOOST_AUTO_TEST_SUITE_END()
GarudStats garud_statistics(const VariantMatrix &m)
Calculate H1, H12, and H2/H1.
H1, H12, and H2/H1 stats.
"Classic" summaries of variation data.
ConstColView get_ConstColView(VariantMatrix &m, const std::size_t col)
Return a ConstColView from VariantMatrix m at col col. std::out_of_range is thcoln if col is out of r...
double haplotype_diversity(const VariantMatrix &m)
Calculate the haplotype diversity of a sample.