-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnthash_simple.hpp
62 lines (52 loc) · 1.4 KB
/
nthash_simple.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
#include <string>
using namespace std;
namespace nthash {
uint64_t h(char i) {
switch (i) {
case 'A': return 0x3c8bfbb395c60474;
case 'C': return 0x3193c18562a02b4c;
case 'G': return 0x20323ed082572324;
case 'T': return 0x295549f54be24456;
case 'N': return 0x0000000000000000;
default: break;
}
return 0;
}
uint64_t rc(char i) {
switch (i) {
case 'A': return 0x295549f54be24456;
case 'C': return 0x20323ed082572324;
case 'G': return 0x3193c18562a02b4c;
case 'T': return 0x3c8bfbb395c60474;
case 'N': return 0x0000000000000000;
default: break;
}
return 0;
}
uint64_t rol(uint64_t v, unsigned k) {
return (v << k) | (v >> (64 - k));
}
inline uint64_t NT64(const char * kmerSeq, const unsigned k) {
uint64_t hVal = 0;
for(unsigned i=0; i < k; i++)
hVal ^= rol(h(kmerSeq[i]), k-1-i);
return hVal;
}
inline uint64_t NTF64(const char * kmerSeq, const unsigned k) {
uint64_t hVal = 0;
for(unsigned i=0; i < k; i++)
hVal ^= rol(h(kmerSeq[i]), k-1-i);
return hVal;
}
inline uint64_t NTR64(const char * kmerSeq, const unsigned k) {
uint64_t hVal = 0;
for(unsigned i=0; i < k; i++)
hVal ^= rol(rc(kmerSeq[k-i-1]), k-1-i);
return hVal;
}
inline uint64_t NTC64(const char * kmerSeq, const unsigned k, uint64_t& fhVal, uint64_t& rhVal) {
fhVal=NTF64(kmerSeq, k);
rhVal=NTR64(kmerSeq, k);
return (rhVal<fhVal)? rhVal : fhVal;
}
}