24 static inline int get_tid(
tbx_t *tbx,
const char *ss,
int is_add)
32 k =
kh_put(s2i, d, ss, &absent);
37 }
else k =
kh_get(s2i, d, ss);
43 return get_tid(tbx, ss, 0);
48 int i, b = 0,
id = 1, ncols = 0;
50 intv->
ss = intv->
se = 0; intv->
beg = intv->
end = -1;
51 for (i = 0; i <= len; ++i) {
52 if (line[i] ==
'\t' || line[i] == 0) {
55 intv->
ss = line + b; intv->
se = line + i;
56 }
else if (
id == conf->
bc) {
58 intv->
beg = intv->
end = strtol(line + b, &s, 0);
59 if ( s==line+b )
return -1;
62 if (intv->
beg < 0) intv->
beg = 0;
63 if (intv->
end < 1) intv->
end = 1;
68 intv->
end = strtol(line + b, &s, 0);
69 if ( s==line+b )
return -1;
75 for (s = line + b; s < line + i;) {
76 long x = strtol(s, &t, 10);
78 if (op ==
'M' || op ==
'D' || op ==
'N') l += x;
86 if (b < i) intv->
end = intv->
beg + (i - b);
90 s = strstr(line + b,
"END=");
91 if (s == line + b) s += 4;
93 s = strstr(line + b,
";END=");
96 if (s) intv->
end = strtol(s, &s, 0);
105 if (intv->
ss == 0 || intv->
se == 0 || intv->
beg < 0 || intv->
end < 0)
return -1;
113 *intv->
se =
'\0'; intv->
tid = get_tid(tbx, intv->
ss, is_add); *intv->
se = c;
114 return (intv->
tid >= 0 && intv->
beg >= 0 && intv->
end >= 0)? 0 : -1;
119 case TBX_SAM: type =
"TBX_SAM";
break;
120 case TBX_VCF: type =
"TBX_VCF";
break;
121 case TBX_UCSC: type =
"TBX_UCSC";
break;
122 default: type =
"TBX_GENERIC";
break;
124 fprintf(stderr,
"[E::%s] failed to parse %s, was wrong -p [type] used?\nThe offending line was: \"%s\"\n", __func__, type, str->
s);
136 get_intv(tbx, s, &intv, 0);
137 *tid = intv.
tid; *beg = intv.
beg; *end = intv.
end;
151 memcpy(x, &tbx->
conf, 24);
152 name = (
char**)malloc(
sizeof(
char*) *
kh_size(d));
156 l += strlen(
kh_key(d, k)) + 1;
159 meta = (
uint8_t*)malloc(l_nm + 28);
161 for (i = 0; i < 7; ++i)
162 x[i] = ed_swap_4(x[i]);
164 for (l = 28, i = 0; i < (int)
kh_size(d); ++i) {
165 int x = strlen(name[i]) + 1;
166 memcpy(meta + l, name[i], x);
177 int ret, first = 0, n_lvls, fmt;
182 str.
s = 0; str.
l = str.
m = 0;
186 else min_shift = 14, n_lvls = 5, fmt =
HTS_FMT_TBI;
197 get_intv(tbx, &str, &intv, 1);
232 if (
bgzf_is_bgzf(fn)!=1 ) { fprintf(stderr,
"Not a BGZF file: %s\n", fn);
return -1; }
233 if ((fp =
bgzf_open(fn,
"r")) == 0)
return -1;
237 if ( !tbx )
return -1;
259 memcpy(&tbx->
conf, x, 24);
260 p = nm = (
char*)meta + 28;
262 for (; p - nm < l_nm; p += strlen(p) + 1) get_tid(tbx, p, 1);
275 const char **names = (
const char**) calloc(m,
sizeof(
const char*));
285 for (tid=0; tid<m; tid++)