2 #include <Sequence/SummStats/nSL.hpp> 8 #include <unordered_map> 18 maxabs(
double score,
double mean,
double sd,
double rv)
22 double zscore = (score -
mean) / sd;
23 if (!isfinite(rv) || fabs(zscore) > fabs(rv))
30 update_s2(std::string::const_iterator start,
31 std::string::const_iterator left,
33 const std::unordered_map<double, double> &gmap)
36 std::vector<double>::size_type(distance(start, right)) - 1);
38 std::vector<double>::size_type(distance(start, left)));
46 auto fp1 = gmap.find(p1);
47 auto fp2 = gmap.find(p2);
48 if (fp1 == gmap.end() || fp2 == gmap.end())
50 throw std::runtime_error(
51 "position could not be found in genetic map, " 52 + std::string(__FILE__) +
" line " 53 + std::to_string(__LINE__));
55 return fabs(fp1->second - fp2->second);
65 const std::unordered_map<double, double> &gmap)
67 auto csize = d.size();
70 std::array<double, 4> rv = { 0., 0., 0., 0. };
73 std::array<unsigned, 2> nc = { 0u, 0u };
74 for (
size_t i = 0; i < csize; ++i)
76 auto start = d[i].cbegin();
79 +
static_cast<decltype(start)::difference_type
>(core);
80 size_t iIsDer = (*bi ==
'1');
81 for (
size_t j = i + 1; j < csize; ++j)
85 +
static_cast<decltype(start)::difference_type
>(
87 size_t jIsDer = (*bj ==
'1');
90 auto eri = d[i].crend();
91 auto ei = d[i].cend();
92 auto right = mismatch(bi, ei, bj);
93 string::const_reverse_iterator ri1(bi),
95 auto left = mismatch(ri1, eri, ri2);
96 if (left.first != eri && right.first != ei)
98 rv[2 * iIsDer] +=
static_cast<double>(
99 distance(left.first.base(),
102 rv[2 * iIsDer + 1] += update_s2(
103 start, left.first.base(),
104 right.first, d, gmap);
110 rv[0] /=
static_cast<double>(nc[0]);
111 rv[1] /=
static_cast<double>(nc[0]);
112 rv[2] /=
static_cast<double>(nc[1]);
113 rv[3] /=
static_cast<double>(nc[1]);
125 const std::unordered_map<double, double> &gmap)
127 auto nsl = __nSLdetails(core, d, gmap);
128 return make_pair(log(
nsl[0]) - log(
nsl[2]), log(
nsl[1]) - log(
nsl[3]));
std::pair< double, double > nSL(const std::size_t &core, const SimData &d, const std::unordered_map< double, double > &gmap=std::unordered_map< double, double >()) __attribute__((deprecated))
The namespace in which this library resides.
double mean(iterator beg, iterator end)
nSLiHS nsl(const VariantMatrix &m, const std::size_t core, const std::int8_t refstate)
nSL and iHS statistics
Declaration of Sequence::SimData, a class representing polymorphism data from coalescent simulations ...
Data from coalescent simulations.