5 #include <unordered_map> 8 #include <Sequence/VariantMatrix.hpp> 13 GarudStats::GarudStats()
14 : H1(1.), H12(
std::numeric_limits<double>::quiet_NaN()),
15 H2H1(
std::numeric_limits<double>::quiet_NaN())
19 GarudStats::GarudStats(
const double __h1,
const double __h12,
21 : H1(__h1), H12(__h12), H2H1(__h2h1)
36 std::unordered_map<std::int32_t, std::int32_t> counts;
37 std::size_t nmissing = 0;
49 if (counts.size() < 2)
54 std::vector<std::pair<std::int32_t, std::int32_t>> vcounts(
55 counts.begin(), counts.end());
56 std::sort(vcounts.begin(), vcounts.end(),
57 [](
const std::pair<std::int32_t, std::int32_t>& a,
58 const std::pair<std::int32_t, std::int32_t>& b) {
59 return a.second > b.second;
62 =
static_cast<double>(m.
nsam) - static_cast<double>(nmissing);
64 + 2. *
static_cast<double>(vcounts[0].second)
65 * static_cast<double>(vcounts[1].second)
66 / (nsam * (nsam - 1.0));
68 -
static_cast<double>(vcounts[0].second
69 * (vcounts[0].second - 1))
70 / (nsam * (nsam - 1)))
double diversity_from_counts(const std::unordered_map< std::int32_t, std::int32_t > &counts, const std::size_t nsam)
Calculate heterozygosity/diversity from count data.
GarudStats garud_statistics(const VariantMatrix &m)
Calculate H1, H12, and H2/H1.
The namespace in which this library resides.
H1, H12, and H2/H1 stats.
std::vector< std::int32_t > label_haplotypes(const VariantMatrix &m)
Assign a unique label to each haplotype.
Generic utilities for calculating summary statistics.
"Classic" summaries of variation data.
Matrix representation of variation data.
std::size_t nsam
Sample size of data set.
std::vector< std::int8_t > data
Data stored in matrix form with rows as sites.