7 #include <Sequence/AlleleCountMatrix.hpp> 13 const std::size_t refindex,
const double power)
15 std::int32_t nsam = 0;
16 std::int32_t nnonref = 0;
18 bool ref_seen =
false;
19 for (std::size_t j = i; j < i + ac.ncol; ++j)
24 if (j - i != refindex)
27 temp += std::pow(ac.counts[j], power);
37 throw std::runtime_error(
38 "site has more than one derived state");
44 auto x = (power == 1.0) ? 1./
static_cast<double>(nsam-1) :
45 2.0/static_cast<double>(nsam*(nsam-1));
53 const std::vector<std::int8_t>& refstates,
const double power)
56 if (ac.counts.empty())
60 if (refstates.size() != ac.counts.size() / ac.ncol)
62 throw std::invalid_argument(
63 "incorrect number of reference states");
65 if (std::all_of(refstates.begin(), refstates.end(),
66 [](
const std::int8_t i) {
return i < 0; }))
68 throw std::invalid_argument(
69 "all reference states encoded as missing");
71 std::size_t rstate = 0;
72 for (std::size_t i = 0; i < ac.counts.size();
73 i += ac.ncol, ++rstate)
75 if (refstates[rstate] >= 0)
78 =
static_cast<std::size_t
>(refstates[rstate]);
79 if (refindex >= ac.ncol)
81 throw std::invalid_argument(
82 "reference state greater than max allelic " 85 rv += process_row(ac, i, refindex, power);
93 const std::int8_t refstate,
const double power)
96 if (ac.counts.empty())
100 auto refindex =
static_cast<std::size_t
>(refstate);
101 if (refindex >= ac.ncol)
103 throw std::invalid_argument(
104 "reference state greater than max allelic state");
106 for (std::size_t i = 0; i < ac.counts.size(); i += ac.ncol)
108 rv += process_row(ac, i, refindex, power);
119 return calc_stat(ac, refstate, 2.0);
124 const std::vector<std::int8_t>& refstates)
126 return calc_stat(ac, refstates, 2.0);
132 return calc_stat(ac, refstate, 1.0);
137 const std::vector<std::int8_t>& refstates)
139 return calc_stat(ac, refstates, 1.0);
double thetal(const AlleleCountMatrix &ac, const std::int8_t refstate)
Zeng et al. .
double thetah(const AlleleCountMatrix &ac, const std::int8_t refstate)
Fay and Wu's .
The namespace in which this library resides.
Matrix representation of allele counts in a VariantMatrix To be constructed.