-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathtabix.hpp
68 lines (58 loc) · 1.55 KB
/
tabix.hpp
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
#pragma once
#include <string>
#include <stdlib.h>
#include <sys/stat.h>
#include "htslib/bgzf.h"
#include "htslib/tbx.h"
#include "htslib/kseq.h"
#include "htslib/hfile.h"
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
class Tabix {
htsFile* fn;
tbx_t* tbx;
kstring_t str;
hts_itr_t* iter;
const tbx_conf_t *idxconf;
int tid, beg, end;
string firstline;
bool has_jumped;
vector<string>::iterator current_chrom;
/* uncompressed file pos
off_t hts_utell1(htsFile *fp)
{
if (fp->is_bgzf) {
return bgzf_htell(fp->fp.bgzf);
}
else
return htell(fp->fp.hfile);
}
*/
// Get file position in compressed file - really on disk
off_t bgzf_htell1(BGZF *fp) {
if (fp->mt) {
return -1; // skip if multithreading
//pthread_mutex_lock(&fp->mt->job_pool_m);
//off_t pos = fp->block_address + fp->block_clength;
//pthread_mutex_unlock(&fp->mt->job_pool_m);
//return pos;
} else {
return htell(fp->fp);
}
}
public:
string filename;
vector<string> chroms;
Tabix(void);
Tabix(string& file);
~Tabix(void);
const kstring_t * getKstringPtr();
void getHeader(string& header);
bool setRegion(string& region);
bool getNextLine(string& line);
bool getNextLineKS();
// Specialised function gets actual file position when using bgzf
long file_pos() { return bgzf_htell1(fn->fp.bgzf); };
};