-
Notifications
You must be signed in to change notification settings - Fork 1
/
bam_pool.h
52 lines (43 loc) · 1.02 KB
/
bam_pool.h
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
#include "Error.h"
#include "PhredHelper.h"
extern "C" {
#include "htslib/sam.h"
}
class bamPool {
public:
samFile* fp;
bam_hdr_t* hdr;
std::vector<bam1_t*> readPools;
bam1_t* head;
int32_t cursor;
bamPool(samFile* _fp, bam_hdr_t* _hdr) : fp(_fp), hdr(_hdr), head(NULL), cursor(-1) {
}
int32_t init() {
head = bam_init1();
bam1_t* tmp = bam_init1();
int32_t ret = sam_read1(fp, hdr, tmp);
readPools.push(tmp);
cursor = 0;
return ret;
}
int32_t pushPool() {
int32_t ret = sam_read1(fp, hdr, head);
if ( ret < 0 ) return ret;
while( hasSameReadName(head, readPools[cursor]) ) {
if ( cursor + 1 == (int32_t)readPools.size() ) {
readPools.push_back(bam_init1());
}
bam1_t* tmp = readPools[cursor+1];
readPools[cursor+1] = head;
head = tmp;
ret = am_read1(fp, hdr, head);
}
return ret
}
int32_t read() {
return sam_read1(fp, hdr, head);
}
bool isSamePair() {
if ( readPools.empty() ) return false;
}
};