4 #include <unordered_map> 7 #include <Sequence/VariantMatrix.hpp> 8 #include <Sequence/VariantMatrixViews.hpp> 14 std::vector<std::int32_t>
17 std::vector<std::int32_t> rv;
19 for (std::size_t i = 0; i < m.
nsam - 1; ++i)
22 for (std::size_t j = i + 1; j < m.
nsam; ++j)
25 std::int32_t ndiffs = 0;
26 auto cib = ci.begin(), cjb = cj.begin();
29 while (cib != ci.end())
31 if (*cib >= 0 && *cjb >= 0 && *cib != *cjb)
44 std::vector<std::int32_t>
47 std::vector<std::int32_t> rv;
49 for (std::size_t i = 0; i < m.
nsam - 1; ++i)
52 for (std::size_t j = i + 1; j < m.
nsam; ++j)
55 auto cib = ci.begin(), cjb = cj.begin();
56 std::int32_t different = 0;
59 while (cib != ci.end() && !different)
61 if (*cib >= 0 && *cjb >= 0 && *cib != *cjb)
68 rv.push_back(different);
74 std::vector<std::int32_t>
77 std::vector<std::int32_t> rv(m.
nsam, -1);
84 auto dmi = dm.cbegin();
90 for (std::size_t i = 0; i < m.
nsam; ++i)
97 for (std::size_t j = i + 1; j < m.
nsam;
125 std::remove_if(labels.begin(), labels.end(),
126 [](decltype(labels[0]) x) {
return x < 0; }),
128 std::sort(labels.begin(), labels.end());
129 auto u = std::unique(labels.begin(), labels.end());
130 return static_cast<std::int32_t
>(std::distance(labels.begin(), u));
138 return std::numeric_limits<double>::quiet_NaN();
142 = std::count_if(labels.begin(), labels.end(),
143 [](decltype(labels[0]) x) {
return x < 0; });
144 auto nsam_adjusted = m.
nsam -
static_cast<decltype(m.nsam)
>(nmissing);
146 std::remove_if(labels.begin(), labels.end(),
147 [](decltype(labels[0]) x) {
return x < 0; }),
149 std::unordered_map<std::int32_t, std::int32_t> label_counts;
150 for (
auto l : labels)
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.
std::int32_t number_of_haplotypes(const VariantMatrix &m)
Calculate the number of haplotypes in a sample.
bool all_missing(const T &t)
The namespace in which this library resides.
std::vector< std::int32_t > label_haplotypes(const VariantMatrix &m)
Assign a unique label to each haplotype.
Generic utilities for calculating summary statistics.
Helper functions for implementing summary statistics.
Matrix representation of variation data.
std::vector< std::int32_t > is_different_matrix(const VariantMatrix &m)
std::size_t nsam
Sample size of data set.
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...
std::vector< std::int8_t > data
Data stored in matrix form with rows as sites.
double haplotype_diversity(const VariantMatrix &m)
Calculate the haplotype diversity of a sample.
std::vector< std::int32_t > difference_matrix(const VariantMatrix &m)
Calculate number of differences between all samples.