-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhapbin.cpp
89 lines (77 loc) · 2.21 KB
/
hapbin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Hapbin: A fast binary implementation EHH, iHS, and XPEHH
* Copyright (C) 2014-2017 Colin MacLean <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hapbin.hpp"
#include <vector>
#include <sstream>
#include <unistd.h>
double binom_2(double n)
{
return n*(n-1.0)*0.5;
}
double nearest(double target, double number)
{
if (target == 0)
return number;
return std::round(number/target)*target;
}
Stats stats(const std::vector<double>& list)
{
Stats s;
if (list.size() == 0)
return s;
double total = 0.0;
for (double v : list)
{
total += v;
}
s.mean = total/(double)list.size();
double sqtotal = 0.0;
for (double v : list)
{
sqtotal += std::pow(v - s.mean, 2);
}
s.stddev = std::sqrt(sqtotal/(double)list.size());
return s;
}
std::vector<std::string> splitString(const std::string input, char delim)
{
std::stringstream ss(input);
std::vector<std::string> split;
std::string part;
while (std::getline(ss,part,delim))
split.push_back(part);
return split;
}
void filter(unsigned long long* in, unsigned long long* out, std::size_t inlen, std::size_t outlen, const PopKey& pk)
{
assert(outlen <= inlen);
assert(out[0] == 0ULL);
std::size_t outpos = 0ULL;
constexpr std::size_t bits = sizeof(unsigned long long)*8;
for(size_t i = 0; i < inlen; ++i)
{
bool state = (in[i/bits] & (1ULL << (i % bits))) > 0;
if (pk[i])
{
if (state)
out[outpos/bits] |= (1ULL << (outpos % bits));
++outpos;
}
}
}