-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathihsfinder.hpp
100 lines (91 loc) · 3.73 KB
/
ihsfinder.hpp
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
89
90
91
92
93
94
95
96
97
98
99
100
/*
* 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/>.
*
*/
#ifndef IHSFINDER_H
#define IHSFINDER_H
#include "ehhfinder.hpp"
#include <map>
#include <mutex>
#ifdef __MINGW32__
//from https://github.com/meganz/mingw-std-threads
#include <windows.h>
#include "mingw.mutex.h"
#endif
#include <functional>
#include <thread>
#include <atomic>
class IHSFinder
{
public:
using IndexMap = std::map<std::size_t, double>;
using IhsInfoMap = std::map<std::size_t, IhsScore>;
using XIhsInfoMap = std::map<std::size_t, XPEHH>;
using FreqVecMap = std::map<double, std::vector<double>>;
using StatsMap = std::map<double, Stats>;
IHSFinder(std::size_t snpLength, double cutoff, double minMAF, double scale, unsigned long long maxExtend, int bins);
FreqVecMap unStdIHSByFreq() const { return m_unStdIHSByFreq; }
FreqVecMap unStdNSLByFreq() const { return m_unStdNSLByFreq; }
IhsInfoMap unStdByIndex() const { return m_unStdByIndex; }
XIhsInfoMap unStdXIHSByIndex() const { return m_unStdXIHSByIndex; }
IndexMap freqsByIndex() const { return m_freqsByIndex; }
IhsInfoMap std() const { return m_std; }
unsigned long long numCompleted() const { return m_counter; }
unsigned long long numReachedEnd() const { return m_reachedEnd; }
unsigned long long numOutsideMaf() const { return m_outsideMaf; }
unsigned long long numNanResults() const { return m_nanResults; }
template <bool Binom>
void run(const HapMap* map, std::size_t start, std::size_t end);
template <bool Binom>
void runXpehh(const HapMap* mA, const HapMap* mB, std::size_t start, std::size_t end);
void addData(const IHSFinder::IndexMap& freqsByIndex,
const IHSFinder::IhsInfoMap& unStandIHSByIndex,
const IHSFinder::FreqVecMap& unStdIHSByFreq,
const IHSFinder::FreqVecMap& unStdNSLByFreq,
long long unsigned int reachedEnd,
long long unsigned int outsideMaf,
long long unsigned int nanResults);
void addXData(const IndexMap& freqsBySite,
const XIhsInfoMap& unStandXIHSByIndex,
const FreqVecMap& unStandIHSByFreq,
unsigned long long reachedEnd,
unsigned long long outsideMaf,
unsigned long long nanResults);
void normalize();
protected:
void processEHH(const EHH& ehh, std::size_t index);
void processXPEHH(XPEHH& e, size_t index);
std::size_t m_snpLength;
double m_cutoff;
double m_minMAF;
double m_scale;
unsigned long long m_maxExtend;
int m_bins;
std::mutex m_mutex;
IndexMap m_freqsByIndex;
IhsInfoMap m_unStdByIndex;
XIhsInfoMap m_unStdXIHSByIndex;
FreqVecMap m_unStdIHSByFreq;
FreqVecMap m_unStdNSLByFreq;
IhsInfoMap m_std;
std::atomic<unsigned long long> m_counter;
std::atomic<unsigned long long> m_reachedEnd;
std::atomic<unsigned long long> m_outsideMaf;
std::atomic<unsigned long long> m_nanResults;
};
#include "ihsfinder-impl.hpp"
#endif // IHSFINDER_H