File: buildReadIndex.cpp

package info (click to toggle)
rsem 1.3.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 37,700 kB
  • sloc: cpp: 19,230; perl: 1,326; python: 1,245; ansic: 547; makefile: 186; sh: 154
file content (86 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download
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 = ((bool)getline(fin, line));
		if (!success) continue;
		success = ((bool)getline(fin, line));
		if (!success) continue;

		if (hasQ) {
			success = ((bool)getline(fin, line));
			if (!success) continue;
			success = ((bool)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;
}