-
Notifications
You must be signed in to change notification settings - Fork 118
/
buildReadIndex.cpp
86 lines (68 loc) · 1.75 KB
/
buildReadIndex.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
85
86
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<fstream>
#include<iostream>
#include "utils.h"
using namespace std;
bool verbose = true;
int gap;
bool hasQ;
void buildIndex(char* readF, int gap, bool hasQ) {
int nPos;
READ_INT_TYPE nReads;
bool success;
string line;
char idxF[STRLEN];
char buf[sizeof(nReads) + sizeof(gap) + sizeof(nPos)];
streampos startPos;
sprintf(idxF, "%s.ridx", readF);
ifstream fin(readF);
if (!fin.is_open()) { fprintf(stderr, "Cannot open %s! It may not exist.\n", readF); exit(-1); }
ofstream fout(idxF, ios::binary);
startPos = fout.tellp();
memset(buf, 0, sizeof(buf));
fout.write((char*)buf, sizeof(buf));
nReads = 0; nPos = 0;
do {
streampos pos = fin.tellg();
success = true;
success = (getline(fin, line));
if (!success) continue;
success = (getline(fin, line));
if (!success) continue;
if (hasQ) {
success = (getline(fin, line));
if (!success) continue;
success = (getline(fin, line));
if (!success) continue;
}
if (nReads % gap == 0) {
++nPos;
fout.write((char*)&pos, sizeof(pos));
}
++nReads;
if (verbose && nReads % 1000000 == 0) { cout<< "FIN "<< nReads<< endl; }
} while (success);
fout.seekp(startPos);
fout.write((char*)&nReads, sizeof(nReads));
fout.write((char*)&gap, sizeof(gap));
fout.write((char*)&nPos, sizeof(nPos));
fin.close();
fout.close();
if (verbose) { cout<< "Build Index "<< readF<< " is Done!"<< endl; }
}
int main(int argc, char* argv[]) {
if (argc < 5) {
printf("Usage : rsem-build-read-index gap hasQ quiet readFile1, readFile2, ...\n");
exit(-1);
}
gap = atoi(argv[1]);
hasQ = atoi(argv[2]);
verbose = !atoi(argv[3]);
for (int i = 4; i < argc; i++) {
buildIndex(argv[i], gap, hasQ);
}
return 0;
}