-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKmerCounter.hpp
More file actions
136 lines (101 loc) · 3.11 KB
/
Copy pathKmerCounter.hpp
File metadata and controls
136 lines (101 loc) · 3.11 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// Created by Walfred (Wangfei) MA at the University of Southern California,
// Mark Chaisson Lab on 2/13/23.
//
// Licensed under the MIT License.
// If you use this code, please cite our work.
//
#ifndef KmerCounter_hpp
#define KmerCounter_hpp
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <iostream>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <algorithm>
#include <atomic>
#include <mutex>
#include <thread>
#include <atomic>
#include <unordered_map>
#include <tuple>
#include <filesystem>
#if defined(__APPLE__) && defined(__clang__)
// Apple Clang uses __fs::filesystem instead of std::filesystem
namespace std {
namespace filesystem = __fs::filesystem;
}
#endif
#include "FastaReader.hpp"
#include "FastqReader.hpp"
#include "CramReader.hpp"
#include "KtableReader.hpp"
#include "KmerHash.hpp"
struct Hash10M {
std::size_t operator()(ull key) const {
return static_cast<std::size_t>(key % prime10M);
}
};
template <typename T1>
string int_to_kmer(T1 value, int size = 31)
{
string kmer (31,' ');
for (int i = 0; i<31 ; ++i)
{
kmer[30-i] = "ACGT"[value % 4];
value /= 4;
}
return kmer;
}
static inline bool base_to_int(const char base, int &converted)
{
switch (base)
{
case 'A' :
converted=0b00;
break;
case 'C' :
converted=0b01;
break;
case 'G' :
converted=0b10;
break;
case 'T' :
converted=0b11;
break;
default:
return 0;
}
return 1;
}
class KmerCounter
{
public:
KmerCounter()
{};
~KmerCounter()
{};
ull read_target(KtableReader &fastafile);
ull read_target(FastaReader &fastafile);
ull read_target(const char* infile);
void load_backgrounds(const char * backfile);
void count_kmer(CramReader &file, counterint* samplevecs, Excess_hash &exbucks , ull_atom &nBases, ull_atom &nReads ,ull_atom &nBg);
void count_kmer(FastaReader &file, counterint* samplevecs, Excess_hash &exbucks, ull_atom &nBases, ull_atom &nReads, ull_atom &nBg);
void count_kmer(FastqReader &file, counterint* samplevecs, Excess_hash &exbucks , ull_atom &nBases, ull_atom &nReads ,ull_atom &nBg);
void read_files(std::vector<std::string>& inputfiles, std::vector<std::string>& outputfiles, std::vector<std::string>& prefixes,std::vector<float>& deps,int numthread);
void Call(const char* infile, counterint* samplevecs, Excess_hash &exbucks, ull_atom &nBases, ull_atom &nReads, ull_atom &nBg, const int nthreads, std::string reference="");
std::vector<ull> backgrounds;
ull totalbks = 0;
uint totalkmers = 0;
std::vector<char *> regions;
const int klen = 31;
Kmer_hash kmer_hash;
std::mutex counting_lock;
template <class typefile>
void count_kmer_(typefile &file, counterint* samplevecs, Excess_hash &exbucks, ull_atom &nBases, ull_atom &nReads, ull_atom &nBg, int nthreads);
};
#endif /* KmerCounter_hpp */