32 #ifndef HTS_BGZF_TYPEDEF
34 #define HTS_BGZF_TYPEDEF
40 #define KSTRING_T kstring_t
48 #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
58 #define hts_expand(type_t, n, m, ptr) if ((n) > (m)) { \
59 (m) = (n); kroundup32(m); \
60 (ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \
62 #define hts_expand0(type_t, n, m, ptr) if ((n) > (m)) { \
63 int t = (m); (m) = (n); kroundup32(m); \
64 (ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \
65 memset(((type_t*)ptr)+t,0,sizeof(type_t)*((m)-t)); \
87 sam,
bam,
bai,
cram,
crai,
vcf,
bcfv1,
bcf,
csi,
gzi,
tbi,
bed,
110 uint32_t is_bin:1, is_write:1, is_be:1, is_cram:1, dummy:28;
302 #define HTS_IDX_NOCOOR (-2)
303 #define HTS_IDX_START (-3)
304 #define HTS_IDX_REST (-4)
305 #define HTS_IDX_NONE (-5)
307 #define HTS_FMT_CSI 0
308 #define HTS_FMT_BAI 1
309 #define HTS_FMT_TBI 2
310 #define HTS_FMT_CRAI 3
322 uint32_t read_rest:1, finished:1, dummy:29;
323 int tid, beg, end, n_off, i;
337 #define hts_bin_first(l) (((1<<(((l)<<1) + (l))) - 1) / 7)
338 #define hts_bin_parent(l) (((l) - 1) >> 3)
354 const char *
hts_parse_reg(
const char *s,
int *beg,
int *end);
359 typedef const char *(*hts_id2name_f)(
void*, int);
370 static inline int hts_reg2bin(int64_t beg, int64_t end,
int min_shift,
int n_lvls)
372 int l, s = min_shift, t = ((1<<((n_lvls<<1) + n_lvls)) - 1) / 7;
373 for (--end, l = n_lvls; l > 0; --l, s += 3, t -= 1<<((l<<1)+l))
374 if (beg>>s == end>>s)
return t + (beg>>s);
378 static inline int hts_bin_bot(
int bin,
int n_lvls)
389 static inline int ed_is_big(
void)
392 return !(*((
char *)(&one)));
394 static inline uint16_t ed_swap_2(uint16_t v)
396 return (uint16_t)(((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8));
398 static inline void *ed_swap_2p(
void *x)
400 *(uint16_t*)x = ed_swap_2(*(uint16_t*)x);
403 static inline uint32_t ed_swap_4(uint32_t v)
405 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
406 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
408 static inline void *ed_swap_4p(
void *x)
410 *(uint32_t*)x = ed_swap_4(*(uint32_t*)x);
413 static inline uint64_t ed_swap_8(uint64_t v)
415 v = ((v & 0x00000000FFFFFFFFLLU) << 32) | (v >> 32);
416 v = ((v & 0x0000FFFF0000FFFFLLU) << 16) | ((v & 0xFFFF0000FFFF0000LLU) >> 16);
417 return ((v & 0x00FF00FF00FF00FFLLU) << 8) | ((v & 0xFF00FF00FF00FF00LLU) >> 8);
419 static inline void *ed_swap_8p(
void *x)
421 *(uint64_t*)x = ed_swap_8(*(uint64_t*)x);
#define hts_bin_first(l)
Definition: hts.h:337
uint8_t * hts_idx_get_meta(hts_idx_t *idx, int *l_meta)
Definition: hts.c:1161
char * fn_aux
Definition: hts.h:113
int is_file(char *fn)
Definition: files.c:57
void hts_idx_finish(hts_idx_t *idx, uint64_t final_offset)
Definition: hts.c:803
char ** hts_readlist(const char *fn, int is_file, int *_n)
Definition: hts.c:507
int * a
Definition: hts.h:329
const char seq_nt16_str[]
Definition: hts.c:79
char ** hts_readlines(const char *fn, int *_n)
Definition: hts.c:561
int hts_close(htsFile *fp)
Definition: hts.c:367
int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data)
Definition: hts.c:1400
const char * hts_parse_reg(const char *s, int *beg, int *end)
Definition: hts.c:1351
struct cram_fd * cram
Definition: hts.h:116
struct htsFormat htsFormat
struct hFILE * hfile
Definition: hts.h:117
void * voidp
Definition: hts.h:118
void hts_idx_destroy(hts_idx_t *idx)
Definition: hts.c:878
const char * hts_format_description(const htsFormat *format)
Definition: hts.c:235
size_t l
Definition: bgzf.h:70
int hts_verbose
Definition: hts.c:52
int hts_set_opt(htsFile *fp, enum cram_option opt,...)
Definition: hts.c:432
struct __kstring_t kstring_t
hts_pair64_t * off
Definition: hts.h:325
htsCompression
Definition: hts.h:91
htsFormat format
Definition: hts.h:120
int hts_set_threads(htsFile *fp, int n)
Definition: hts.c:446
void hts_idx_set_meta(hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy)
Definition: hts.c:1151
const char * hts_version(void)
Definition: hts.c:54
BGZF * bgzf
Definition: hts.h:115
kstring_t line
Definition: hts.h:112
int hts_set_fai_filename(htsFile *fp, const char *fn_aux)
Definition: hts.c:456
void hts_idx_save(const hts_idx_t *idx, const char *fn, int fmt)
Definition: hts.c:984
const char *(* hts_id2name_f)(void *, int)
Definition: hts.h:359
uint64_t hts_idx_get_n_no_coor(const hts_idx_t *idx)
Definition: hts.c:1206
int hts_readrec_func(BGZF *fp, void *data, void *r, int *tid, int *beg, int *end)
Definition: hts.h:319
const char ** hts_idx_seqnames(const hts_idx_t *idx, int *n, hts_id2name_f getid, void *hdr)
Definition: hts.c:1167
void hts_itr_destroy(hts_itr_t *iter)
Definition: hts.c:1346
htsFile * hts_hopen(struct hFILE *fp, const char *fn, const char *mode)
Definition: hts.c:273
size_t m
Definition: bgzf.h:70
int(* hts_name2id_f)(void *, const char *)
Definition: hts.h:358
int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int is_mapped)
Definition: hts.c:819
#define str(x)
Definition: sam.c:66
hts_itr_t * hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)
Definition: hts.c:1233
int n
Definition: hts.h:328
int hts_idx_get_stat(const hts_idx_t *idx, int tid, uint64_t *mapped, uint64_t *unmapped)
Definition: hts.c:1187
hts_readrec_func * readrec
Definition: hts.h:326
char * s
Definition: bgzf.h:71
hts_itr_t * hts_itr_query_func(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)
Definition: hts.h:360
htsExactFormat
Definition: hts.h:84
uint64_t curr_off
Definition: hts.h:324
cram_option
Definition: hts.h:140
int tid
Definition: hts.h:323
const htsFormat * hts_get_format(htsFile *fp)
Definition: hts.c:427
htsFile * hts_open(const char *fn, const char *mode)
Definition: hts.c:252
int hts_getline(htsFile *fp, int delimiter, kstring_t *str)
Definition: hts.c:499
hts_idx_t * hts_idx_init(int n, int fmt, uint64_t offset0, int min_shift, int n_lvls)
Definition: hts.c:697
#define hts_bin_parent(l)
Definition: hts.h:338
hts_itr_t * hts_itr_querys(const hts_idx_t *idx, const char *reg, hts_name2id_f getid, void *hdr, hts_itr_query_func *itr_query, hts_readrec_func *readrec)
Definition: hts.c:1382
const unsigned char seq_nt16_table[256]
Definition: hts.c:59
htsFormatCategory
Definition: hts.h:75
int64_t lineno
Definition: hts.h:111
sam_fields
Definition: hts.h:124
Definition: cram_structs.h:655
uint64_t v
Definition: hts.h:316
hts_idx_t * hts_idx_load(const char *fn, int fmt)
Definition: hts.c:1500
int hts_detect_format(struct hFILE *fp, htsFormat *fmt)
Definition: hts.c:148