-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmhap.cpp
More file actions
executable file
·97 lines (76 loc) · 2.05 KB
/
Copy pathmhap.cpp
File metadata and controls
executable file
·97 lines (76 loc) · 2.05 KB
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
87
88
89
90
91
92
93
94
95
96
#include <unordered_map>
#include <cstring>
#include "mhap.h"
namespace std {
mHapFile* mhap_open(const char *filename, const char *mode) {
return fopen(filename, mode);
}
void parse_mhap_line(char *line, int buf_len, mhap_t *h_line_t) {
char *p, *q;
char end_char;
p = q = line;
while(*q != MHAP_LINE_DELIM_TAB && *q !='\n' && (q - line) < buf_len) {q++;}
(*q) = '\0';
h_line_t->chr = string(p);
(*q) = MHAP_LINE_DELIM_TAB;
q = p = q + 1;
while(*q != MHAP_LINE_DELIM_TAB && *q !='\n' && (q - line) < buf_len) {q++;}
(*q) = '\0';
h_line_t->chr_beg = atoll(p);
(*q) = MHAP_LINE_DELIM_TAB;
q = p = q + 1;
while(*q != MHAP_LINE_DELIM_TAB && *q !='\n' && (q - line) < buf_len) {q++;}
(*q) = '\0';
h_line_t->chr_end = atoll(p);
(*q) = MHAP_LINE_DELIM_TAB;
q = p = q + 1;
while(*q != MHAP_LINE_DELIM_TAB && *q !='\n' && (q - line) < buf_len) {q++;}
(*q) = '\0';
h_line_t->mhap_str = string(p);
(*q) = MHAP_LINE_DELIM_TAB;
q = p = q + 1;
while(*q != MHAP_LINE_DELIM_TAB && *q !='\n' && (q - line) < buf_len) {q++;}
end_char = *q;
(*q) = '\0';
h_line_t->mhap_count = atoi(p);
(*q) = end_char;
p = q + 1;
h_line_t->mhap_direction = *p;
};
int mhap_read(mHapFile *const fp, mhap_t *h_line_t) {
// Returns 0 on success,
// -1 on EOF,
static char buf [MHAP_BUF_SIZE];
fgets(buf, MHAP_BUF_SIZE, fp);
if (feof(fp)) {
return -1;
}
int buf_len = strlen(buf);
if (buf_len == 1) {
return -1;
}
parse_mhap_line(buf, buf_len, h_line_t);
return 0;
}
int mhap_close(mHapFile *fp) {
if (fp) {
fclose(fp);
}
return 0;
}
mhap_idx_t *mhap_index_load(const char *fn) {
return tbx_index_load(fn);
}
int mhap_name2id(mhap_idx_t *mhap_idx_t, const char *ss) {
return tbx_name2id(mhap_idx_t, ss);
}
int mhap_index_build(const char *hap_fn) {
/*
* return: 0 (success), -1 (general failure) or -2 (compression not BGZF)
*/
tbx_conf_t conf = tbx_conf_t{TBX_GENERIC, 1, 2 ,3};
const tbx_conf_t* conf_p = &conf;
int ret = tbx_index_build(hap_fn, 0, conf_p);
return ret;
}
}// namespace std