2 #include <Sequence/AlleleCountMatrix.hpp> 3 #include "hprime_faywuh_aggregator.hpp" 10 if (ac.counts.empty())
12 return std::numeric_limits<double>::quiet_NaN();
14 auto refindex =
static_cast<std::size_t
>(refstate);
15 if (refindex >= ac.ncol)
17 throw std::invalid_argument(
18 "reference state greater than max allelic state");
20 detail::hprime_faywuh_row_processor rp;
21 for (std::size_t i = 0; i < ac.counts.size(); i += ac.ncol)
23 rp(ac, i, refindex, detail::stat_is_faywuh());
27 return std::numeric_limits<double>::quiet_NaN();
29 return rp.pi - rp.theta;
34 const std::vector<std::int8_t>& refstates)
36 if (ac.counts.empty())
38 return std::numeric_limits<double>::quiet_NaN();
40 if (refstates.size() != ac.counts.size() / ac.ncol)
42 throw std::invalid_argument(
43 "incorrect number of reference states");
45 if (std::all_of(refstates.begin(), refstates.end(),
46 [](
const std::int8_t i) {
return i < 0; }))
48 throw std::invalid_argument(
49 "all reference states encoded as missing");
52 detail::hprime_faywuh_row_processor rp;
53 std::size_t rstate = 0;
54 for (std::size_t i = 0; i < ac.counts.size(); i += ac.ncol, ++rstate)
56 if (refstates[rstate] >= 0)
59 =
static_cast<std::size_t
>(refstates[rstate]);
60 if (refindex >= ac.ncol)
62 throw std::invalid_argument(
63 "reference state greater than max allelic " 66 rp(ac, i, refindex, detail::stat_is_faywuh());
71 return std::numeric_limits<double>::quiet_NaN();
73 return rp.pi - rp.theta;
The namespace in which this library resides.
double faywuh(const AlleleCountMatrix &ac, const std::int8_t refstate)
Fay and Wu's H.
Matrix representation of allele counts in a VariantMatrix To be constructed.