All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions | Variables
hts.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.


struct  __kstring_t
struct  htsFile
struct  hts_pair64_t
struct  hts_itr_t


#define KSTRING_T   kstring_t
#define kroundup32(x)   (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#define hts_expand(type_t, n, m, ptr)
#define hts_expand0(type_t, n, m, ptr)
#define HTS_IDX_NOCOOR   (-2)
#define HTS_IDX_START   (-3)
#define HTS_IDX_REST   (-4)
#define HTS_IDX_NONE   (-5)
#define HTS_FMT_CSI   0
#define HTS_FMT_BAI   1
#define HTS_FMT_TBI   2
#define HTS_FMT_CRAI   3
#define hts_bin_first(l)   (((1<<(((l)<<1) + (l))) - 1) / 7)
#define hts_bin_parent(l)   (((l) - 1) >> 3)
#define FT_UNKN   0
#define FT_GZ   1
#define FT_VCF   2
#define FT_VCF_GZ   (FT_GZ|FT_VCF)
#define FT_BCF   (1<<2)
#define FT_BCF_GZ   (FT_GZ|FT_BCF)
#define FT_STDIN   (1<<3)


typedef struct BGZF BGZF
typedef struct __kstring_t kstring_t
typedef struct __hts_idx_t hts_idx_t
typedef int hts_readrec_func (BGZF *fp, void *data, void *r, int *tid, int *beg, int *end)
typedef int(* hts_name2id_f )(void *, const char *)
typedef const char *(* hts_id2name_f )(void *, int)
typedef hts_itr_thts_itr_query_func (const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)


const char * hts_version (void)
htsFilehts_open (const char *fn, const char *mode)
int hts_close (htsFile *fp)
int hts_getline (htsFile *fp, int delimiter, kstring_t *str)
char ** hts_readlines (const char *fn, int *_n)
char ** hts_readlist (const char *fn, int is_file, int *_n)
int hts_set_threads (htsFile *fp, int n)
int hts_set_fai_filename (htsFile *fp, const char *fn_aux)
hts_idx_thts_idx_init (int n, int fmt, uint64_t offset0, int min_shift, int n_lvls)
void hts_idx_destroy (hts_idx_t *idx)
int hts_idx_push (hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int is_mapped)
void hts_idx_finish (hts_idx_t *idx, uint64_t final_offset)
void hts_idx_save (const hts_idx_t *idx, const char *fn, int fmt)
hts_idx_thts_idx_load (const char *fn, int fmt)
uint8_thts_idx_get_meta (hts_idx_t *idx, int *l_meta)
void hts_idx_set_meta (hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy)
int hts_idx_get_stat (const hts_idx_t *idx, int tid, uint64_t *mapped, uint64_t *unmapped)
uint64_t hts_idx_get_n_no_coor (const hts_idx_t *idx)
const char * hts_parse_reg (const char *s, int *beg, int *end)
hts_itr_thts_itr_query (const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)
void hts_itr_destroy (hts_itr_t *iter)
hts_itr_thts_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)
int hts_itr_next (BGZF *fp, hts_itr_t *iter, void *r, void *data)
const char ** hts_idx_seqnames (const hts_idx_t *idx, int *n, hts_id2name_f getid, void *hdr)
int hts_file_type (const char *fname)


int hts_verbose
const unsigned char seq_nt16_table [256]
const char seq_nt16_str []

Macro Definition Documentation

#define FT_BCF   (1<<2)

Definition at line 240 of file hts.h.

#define FT_BCF_GZ   (FT_GZ|FT_BCF)

Definition at line 241 of file hts.h.

#define FT_GZ   1

Definition at line 237 of file hts.h.

#define FT_STDIN   (1<<3)

Definition at line 242 of file hts.h.

#define FT_UNKN   0

hts_file_type() - Convenience function to determine file type : the file name

Returns one of the FT_* defines.

This function was added in order to avoid the need for excessive command line switches.

Definition at line 236 of file hts.h.

#define FT_VCF   2

Definition at line 238 of file hts.h.

#define FT_VCF_GZ   (FT_GZ|FT_VCF)

Definition at line 239 of file hts.h.


Definition at line 9 of file hts.h.

#define hts_bin_first (   l)    (((1<<(((l)<<1) + (l))) - 1) / 7)

Definition at line 198 of file hts.h.

#define hts_bin_parent (   l)    (((l) - 1) >> 3)

Definition at line 199 of file hts.h.

#define hts_expand (   type_t,
if ((n) > (m)) { \
(m) = (n); kroundup32(m); \
(ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \

hts_expand() - expands memory block pointed to by $ptr; hts_expand0() the latter sets the newly allocated part to 0.

nrequested number of elements of type type_t
msize of memory allocated

Definition at line 33 of file hts.h.

#define hts_expand0 (   type_t,
if ((n) > (m)) { \
int t = (m); (m) = (n); kroundup32(m); \
(ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \
memset(((type_t*)ptr)+t,0,sizeof(type_t)*((m)-t)); \

Definition at line 37 of file hts.h.

#define HTS_FMT_BAI   1

Definition at line 169 of file hts.h.

#define HTS_FMT_CRAI   3

Definition at line 171 of file hts.h.

#define HTS_FMT_CSI   0

Definition at line 168 of file hts.h.

#define HTS_FMT_TBI   2

Definition at line 170 of file hts.h.

#define HTS_IDX_NOCOOR   (-2)

These HTS_IDX_* macros are used as special tid values for hts_itr_query()/etc, producing iterators operating as follows:

  • HTS_IDX_NOCOOR iterates over unmapped reads sorted at the end of the file
  • HTS_IDX_START iterates over the entire file
  • HTS_IDX_REST iterates from the current position to the end of the file
  • HTS_IDX_NONE always returns "no more alignment records" When one of these special tid values is used, beg and end are ignored. When REST or NONE is used, idx is also ignored and may be NULL.

Definition at line 163 of file hts.h.

#define HTS_IDX_NONE   (-5)

Definition at line 166 of file hts.h.

#define HTS_IDX_REST   (-4)

Definition at line 165 of file hts.h.

#define HTS_IDX_START   (-3)

Definition at line 164 of file hts.h.

#define kroundup32 (   x)    (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))

Definition at line 23 of file hts.h.

#define KSTRING_T   kstring_t

Definition at line 15 of file hts.h.

Typedef Documentation

typedef struct BGZF BGZF

Definition at line 8 of file hts.h.

typedef const char*(* hts_id2name_f)(void *, int)

Definition at line 220 of file hts.h.

typedef struct __hts_idx_t hts_idx_t

Definition at line 174 of file hts.h.

typedef hts_itr_t* hts_itr_query_func(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)

Definition at line 221 of file hts.h.

typedef int(* hts_name2id_f)(void *, const char *)

Definition at line 219 of file hts.h.

typedef int hts_readrec_func(BGZF *fp, void *data, void *r, int *tid, int *beg, int *end)

Definition at line 180 of file hts.h.

typedef struct __kstring_t kstring_t

Function Documentation

int hts_close ( htsFile fp)

Close a file handle, flushing buffered data for output streams

fpThe file handle to be closed
0 for success, or negative if an error occurred.

Definition at line 194 of file hts.c.

int hts_file_type ( const char *  fname)

Definition at line 396 of file hts.c.

int hts_getline ( htsFile fp,
int  delimiter,
kstring_t str 

Definition at line 285 of file hts.c.

void hts_idx_destroy ( hts_idx_t idx)

Definition at line 698 of file hts.c.

void hts_idx_finish ( hts_idx_t idx,
uint64_t  final_offset 

Definition at line 619 of file hts.c.

uint8_t* hts_idx_get_meta ( hts_idx_t idx,
int *  l_meta 

Definition at line 981 of file hts.c.

uint64_t hts_idx_get_n_no_coor ( const hts_idx_t idx)

Definition at line 1026 of file hts.c.

int hts_idx_get_stat ( const hts_idx_t idx,
int  tid,
uint64_t mapped,
uint64_t unmapped 

Definition at line 1007 of file hts.c.

hts_idx_t* hts_idx_init ( int  n,
int  fmt,
uint64_t  offset0,
int  min_shift,
int  n_lvls 

Definition at line 513 of file hts.c.

hts_idx_t* hts_idx_load ( const char *  fn,
int  fmt 

Definition at line 1316 of file hts.c.

int hts_idx_push ( hts_idx_t idx,
int  tid,
int  beg,
int  end,
uint64_t  offset,
int  is_mapped 

Definition at line 635 of file hts.c.

void hts_idx_save ( const hts_idx_t idx,
const char *  fn,
int  fmt 

Definition at line 804 of file hts.c.

const char** hts_idx_seqnames ( const hts_idx_t idx,
int *  n,
hts_id2name_f  getid,
void *  hdr 

Definition at line 987 of file hts.c.

void hts_idx_set_meta ( hts_idx_t idx,
int  l_meta,
uint8_t meta,
int  is_copy 

Definition at line 971 of file hts.c.

void hts_itr_destroy ( hts_itr_t iter)

Definition at line 1166 of file hts.c.

int hts_itr_next ( BGZF fp,
hts_itr_t iter,
void *  r,
void *  data 

Definition at line 1220 of file hts.c.

hts_itr_t* hts_itr_query ( const hts_idx_t idx,
int  tid,
int  beg,
int  end,
hts_readrec_func readrec 

Definition at line 1053 of file hts.c.

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 at line 1202 of file hts.c.

htsFile* hts_open ( const char *  fn,
const char *  mode 

Definition at line 100 of file hts.c.

const char* hts_parse_reg ( const char *  s,
int *  beg,
int *  end 

Definition at line 1171 of file hts.c.

char** hts_readlines ( const char *  fn,
int *  _n 

Definition at line 347 of file hts.c.

char** hts_readlist ( const char *  fn,
int  is_file,
int *  _n 

Parse comma-separated list or read list from a file

listFile name or comma-separated list
_nSize of the output array (number of items read)
NULL on failure or pointer to newly allocated array of strings

Definition at line 293 of file hts.c.

int hts_set_fai_filename ( htsFile fp,
const char *  fn_aux 

Set .fai filename for a file opened for reading

0 for success, negative on failure Called before *_hdr_read(), this provides the name of a .fai file used to provide a reference list if the htsFile contains no headers.

Definition at line 245 of file hts.c.

int hts_set_threads ( htsFile fp,
int  n 

Create extra threads to aid compress/decompression for this file

fpThe file handle
nThe number of worker threads to create
0 for success, or negative if an error occurred. THIS THREADING API IS LIKELY TO CHANGE IN FUTURE.

Definition at line 236 of file hts.c.

const char* hts_version ( void  )

Get the htslib version number

For released versions, a string like "N.N[.N]"; or git describe output if using a library built within a Git repository.

Definition at line 29 of file hts.c.

Variable Documentation

int hts_verbose

Definition at line 27 of file hts.c.

const char seq_nt16_str[]

Table for converting a 4-bit encoded nucleotide to a letter.

Definition at line 54 of file hts.c.

const unsigned char seq_nt16_table[256]

Table for converting a nucleotide character to the 4-bit encoding.

Definition at line 34 of file hts.c.