-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbvtest.cpp
84 lines (74 loc) · 2.25 KB
/
bvtest.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
/**
* Used to test FastBit implementation of WAH by Kesheng Wu.
* http://crd-legacy.lbl.gov/~kewu/ps/PUB-3161.pdf
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <string.h>
#include <sys/times.h>
#include <unistd.h>
#include "bitvector.h"
using namespace FastBit;
using namespace std;
enum DiffType { SNP = 0, DEL = 1, INS = 2 };
enum Base { B_A = 0, B_C = 1, B_T = 2, B_G = 3 };
struct GenDiff {
DiffType difftype;
string tag;
size_t pos;
string ref_alt;
};
void encode(vector<GenDiff>::iterator itstart, vector<GenDiff>::iterator itend) {
bitvector bv;
vector<GenDiff>::iterator it = itstart;
for (; itstart != itend; itstart++) {
bv.setBit(itstart->pos, 1);
}
bv.compress();
cout << it->difftype << "," << it->tag << ", size: " << bv.bytes() << endl;
}
int main() {
/*
cout << "Loading gwah shared library" << endl;
void *hdl = dlopen(GWAHFILE, RTLD_LAZY | RTLD_GLOBAL);
if (!hdl) {
cerr << "Load failed" << endl;
return 1;
}
dlerror();
cout << "Loading symbols" << endl;
*/
cout << (sizeof(bitvector::word_t) * 8) << endl;
vector<GenDiff> diffs;
while (cin.good()) {
string line;
getline(cin, line);
if (line.empty())
break;
char *cline = (char *) line.c_str();
GenDiff cdiff;
cdiff.difftype = (DiffType) atoi(strtok(cline, ","));
cdiff.tag = strtok(NULL, ",");
cdiff.pos = atoi(strtok(NULL, ","));
cdiff.ref_alt = strtok(NULL, ",");
diffs.push_back(cdiff);
}
clock_t TMS_CLK_TCK = sysconf(_SC_CLK_TCK);
struct tms tmsstart, tmsend;
string prevtag = diffs.begin()->tag;
DiffType prevdiff = diffs.begin()->difftype;
vector<GenDiff>::iterator chrstart = diffs.begin();
times(&tmsstart);
for (vector<GenDiff>::iterator it = diffs.begin(); it != diffs.end(); it++) {
if (it->difftype != prevdiff || it->tag != prevtag || (it + 1) == diffs.end()) {
encode(chrstart, it);
chrstart = it;
prevtag = it->tag;
prevdiff = it->difftype;
}
}
times(&tmsend);
cout << "TIME: " << ((tmsend.tms_utime - tmsstart.tms_utime) / (double) TMS_CLK_TCK) << endl;
}