-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDecycling.cpp
51 lines (38 loc) · 1.06 KB
/
Decycling.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
#include "Decycling.h"
DecyclingSet::DecyclingSet(uint k) : k(k), unit(2 * M_PI / k), coef(4 * k, 0) {
for (size_t i = 4; i < 4 * k; i += 4) {
coef[i + 1] = sin(unit * (i / 4));
coef[i + 2] = 2 * coef[i + 1];
coef[i + 3] = 3 * coef[i + 1];
}
}
double DecyclingSet::computeR(kmer seq) {
double R = 0;
for (size_t i = 4 * (k - 1); i > 0; i -= 4) {
R += coef[i + (seq & 0b11)];
seq >>= 2;
}
return R;
}
bool DecyclingSet::mem(kmer seq) {
if (computeR(seq) > eps) {
kmer rot = ((seq & 0b11) << (2 * (k - 1))) + (seq >> 2);
return computeR(rot) < eps;
}
return false;
}
uint DecyclingSet::memDouble(kmer seq) {
double Rseq = computeR(seq);
if (Rseq > eps) {
kmer rot = ((seq & 0b11) << (2 * (k - 1))) + (seq >> 2);
if (computeR(rot) < eps) {
return 2;
}
} else if (Rseq < -eps) {
kmer rot = ((seq & 0b11) << (2 * (k - 1))) + (seq >> 2);
if (computeR(rot) > -eps) {
return 1;
}
}
return 0;
}