3 #include <Sequence/AlleleCountMatrix.hpp> 4 #include <Sequence/summstats/auxillary.hpp> 13 std::int32_t max_nsam = 0;
14 for (std::size_t i = 0; i < ac.counts.size(); i += ac.ncol)
16 std::int32_t nsam = 0;
17 double homozygosity = 0.0;
19 for (std::size_t j = i; j < i + ac.ncol; ++j)
25 homozygosity +=
static_cast<double>(
26 ac.counts[j] * (ac.counts[j] - 1));
32 max_nsam = std::max(max_nsam, nsam);
36 /
static_cast<double>(nsam * (nsam - 1));
41 return std::numeric_limits<double>::quiet_NaN();
43 auto a1 = summstats_aux::a_sub_n(static_cast<std::uint32_t>(max_nsam));
44 double w =
static_cast<double>(S) / a1;
45 auto a2 = summstats_aux::b_sub_n(static_cast<std::uint32_t>(max_nsam));
46 auto dn =
static_cast<double>(max_nsam);
47 double b1 = (dn + 1.0) / (3.0 * (dn - 1.0));
49 = (2.0 * (std::pow(dn, 2.0) + dn + 3.0)) / (9.0 * dn * (dn - 1.0));
50 double c1 = b1 - 1.0 / a1;
51 double c2 = b2 - (dn + 2.0) / (a1 * dn) + a2 / std::pow(a1, 2.0);
53 double e2 = c2 / (std::pow(a1, 2.0) + a2);
54 double denominator = std::pow((e1 * S + e2 * S * (S - 1.0)), 0.5);
55 return (pi - w) / denominator;
double tajd(const AlleleCountMatrix &ac)
Tajima's D.
The namespace in which this library resides.
Matrix representation of allele counts in a VariantMatrix To be constructed.