-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGEMBamToMask.cpp
66 lines (57 loc) · 1.41 KB
/
GEMBamToMask.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
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include "htslib/sam.h"
#include <cmath>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "Usage: gemBamToMask input.bam" << endl;
exit(1);
}
string filename = argv[1];
htsFile *htsfp;
bam_hdr_t *samHeader;
htsfp = hts_open(filename.c_str(),"r");
const htsFormat *fmt = hts_get_format(htsfp);
samHeader = sam_hdr_read(htsfp);
cerr << "starting " << endl;
bam1_t *b = bam_init1();
int res=1;
res= sam_read1(htsfp, samHeader, b);
long readIndex=0;
long nCounted=0;
cerr << "res: "<< res<< endl;
while (res > 0) {
readIndex+=1;
long alnPos = b->core.pos;
int tid=b->core.tid;
if (alnPos >= 0) {
nCounted+=1;
uint8_t *xaData = bam_aux_get(b, "XA");
if (xaData != 0) {
char *xaString=bam_aux2Z(xaData);
stringstream auxStrm((char*)xaString);
string aln;
int index=0;
int nAux=0;
while(std::getline(auxStrm, aln, ';')) {
nAux+=1;
if (nAux > 10000) {
cerr <<"Woah nelly: " << readIndex << endl;
exit(0);
}
}
if (nAux>= 20) {
cout << samHeader->target_name[tid] << "\t" << alnPos << "\t" << alnPos + b->core.l_qseq << "\t" << nAux << endl;
}
}
}
res = sam_read1(htsfp, samHeader, b);
if (readIndex %100000 == 0) {
cerr << "proc " << readIndex /100000 << "M\t" << nCounted << endl;
}
}
}