File: GroupInfo.h

package info (click to toggle)
rsem 1.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 37,664 kB
  • sloc: cpp: 19,230; perl: 1,326; python: 1,245; ansic: 547; makefile: 186; sh: 154
file content (55 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download | duplicates (5)
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
#ifndef GROUPINFO_H_
#define GROUPINFO_H_

#include<cstdio>
#include<cassert>
#include<vector>

class GroupInfo {
public:
	GroupInfo() { m = 0; starts.clear(); gids = NULL; }
	~GroupInfo() { m = 0; starts.clear(); if (gids != NULL) delete[] gids; }

	void load(const char*);

	int getm() const { return m; }

	int gidAt(int sid) const {
		assert(sid > 0 && sid < starts.back());
		return gids[sid];
	}

	// sp : start position
	int spAt(int gid) const {
		assert(gid >= 0 && gid <= m);
		return starts[gid];
	}

private:
	int m; // m genes
	std::vector<int> starts; // genes' start positions
	int *gids; // hash
};

void GroupInfo::load(const char* groupF) {
	FILE *fi = fopen(groupF, "r");
	int pos;

	if (fi == NULL) { fprintf(stderr, "Cannot open %s! It may not exist.\n", groupF); exit(-1); }

	starts.clear();
	while(fscanf(fi, "%d", &pos) == 1) {
		starts.push_back(pos);
	}
	fclose(fi);

	m = starts.size() - 1;
	gids = new int[starts.back()];
	for (int i = 0; i < m; i++) {
		for (int j = starts[i]; j < starts[i + 1]; j++) {
			gids[j] = i;
		}
	}
}

#endif /* GROUPINFO_H_ */