Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Functions | Variables
hts.c File Reference
#include <zlib.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include "htslib/bgzf.h"
#include "htslib/hts.h"
#include "cram/cram.h"
#include "htslib/hfile.h"
#include "version.h"
#include "htslib/kseq.h"
#include "htslib/khash.h"
#include "htslib/ksort.h"

Classes

struct  bins_t
 
struct  __hts_idx_t
 

Macros

#define KS_BGZF   1
 
#define HTS_MIN_MARKER_DIST   0x10000
 
#define META_BIN(idx)   ((idx)->n_bins + 1)
 
#define pair64_lt(a, b)   ((a).u < (b).u)
 

Functions

const char * hts_version ()
 
int hts_detect_format (hFILE *hfile, htsFormat *fmt)
 
const char * hts_format_description (const htsFormat *format)
 
htsFilehts_open (const char *fn, const char *mode)
 
htsFilehts_hopen (struct hFILE *hfile, const char *fn, const char *mode)
 
int hts_close (htsFile *fp)
 
const htsFormathts_get_format (htsFile *fp)
 
int hts_set_opt (htsFile *fp, enum cram_option opt,...)
 
int hts_set_threads (htsFile *fp, int n)
 
int hts_set_fai_filename (htsFile *fp, const char *fn_aux)
 
BGZFhts_get_bgzfp (htsFile *fp)
 
int hts_useek (htsFile *fp, long uoffset, int where)
 
long hts_utell (htsFile *fp)
 
int hts_getline (htsFile *fp, int delimiter, kstring_t *str)
 
char ** hts_readlist (const char *string, int is_file, int *_n)
 
char ** hts_readlines (const char *fn, int *_n)
 
typedef khash_t (bin)
 
hts_idx_thts_idx_init (int n, int fmt, uint64_t offset0, int min_shift, int n_lvls)
 
void hts_idx_finish (hts_idx_t *idx, uint64_t final_offset)
 
int hts_idx_push (hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int is_mapped)
 
void hts_idx_destroy (hts_idx_t *idx)
 
void hts_idx_save (const hts_idx_t *idx, const char *fn, int fmt)
 
hts_idx_thts_idx_load_local (const char *fn, int fmt)
 
void hts_idx_set_meta (hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy)
 
uint8_t * hts_idx_get_meta (hts_idx_t *idx, int *l_meta)
 
const char ** hts_idx_seqnames (const hts_idx_t *idx, int *n, hts_id2name_f getid, void *hdr)
 
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)
 
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)
 
const char * hts_parse_reg (const char *s, int *beg, int *end)
 
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)
 
char * hts_idx_getfn (const char *fn, const char *ext)
 
hts_idx_thts_idx_load (const char *fn, int fmt)
 

Variables

int hts_verbose = 3
 
const unsigned char seq_nt16_table [256]
 
const char seq_nt16_str [] = "=ACMGRSVTWYHKDBN"
 
 lidx_t
 

Macro Definition Documentation

#define HTS_MIN_MARKER_DIST   0x10000
#define KS_BGZF   1
#define META_BIN (   idx)    ((idx)->n_bins + 1)
#define pair64_lt (   a,
 
)    ((a).u < (b).u)

Function Documentation

int hts_close ( htsFile fp)

Close a file handle, flushing buffered data for output streams

Parameters
fpThe file handle to be closed
Returns
0 for success, or negative if an error occurred.
int hts_detect_format ( struct hFILE fp,
htsFormat fmt 
)

Determine format by peeking at the start of a file

Parameters
fpFile opened for reading, positioned at the beginning
fmtFormat structure that will be filled out on return
Returns
0 for success, or negative if an error occurred.
const char* hts_format_description ( const htsFormat format)

Get a human-readable description of the file format

BGZF* hts_get_bgzfp ( htsFile fp)
const htsFormat* hts_get_format ( htsFile fp)

Returns the file's format information

Parameters
fpThe file handle
Returns
Read-only pointer to the file's htsFormat.
int hts_getline ( htsFile fp,
int  delimiter,
kstring_t str 
)
htsFile* hts_hopen ( struct hFILE fp,
const char *  fn,
const char *  mode 
)

Open an existing stream as a SAM/BAM/CRAM/VCF/BCF/etc file

Parameters
fnThe already-open file handle
modeOpen mode, as per hts_open()
void hts_idx_destroy ( hts_idx_t idx)
void hts_idx_finish ( hts_idx_t idx,
uint64_t  final_offset 
)
uint8_t* hts_idx_get_meta ( hts_idx_t idx,
int *  l_meta 
)
uint64_t hts_idx_get_n_no_coor ( const hts_idx_t idx)
int hts_idx_get_stat ( const hts_idx_t idx,
int  tid,
uint64_t *  mapped,
uint64_t *  unmapped 
)
char* hts_idx_getfn ( const char *  fn,
const char *  ext 
)
hts_idx_t* hts_idx_init ( int  n,
int  fmt,
uint64_t  offset0,
int  min_shift,
int  n_lvls 
)
hts_idx_t* hts_idx_load ( const char *  fn,
int  fmt 
)
hts_idx_t* hts_idx_load_local ( const char *  fn,
int  fmt 
)
int hts_idx_push ( hts_idx_t idx,
int  tid,
int  beg,
int  end,
uint64_t  offset,
int  is_mapped 
)
void hts_idx_save ( const hts_idx_t idx,
const char *  fn,
int  fmt 
)
const char** hts_idx_seqnames ( const hts_idx_t idx,
int *  n,
hts_id2name_f  getid,
void *  hdr 
)
void hts_idx_set_meta ( hts_idx_t idx,
int  l_meta,
uint8_t *  meta,
int  is_copy 
)
void hts_itr_destroy ( hts_itr_t iter)
int hts_itr_next ( BGZF fp,
hts_itr_t iter,
void *  r,
void *  data 
)
hts_itr_t* hts_itr_query ( const hts_idx_t idx,
int  tid,
int  beg,
int  end,
hts_readrec_func readrec 
)
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 
)
htsFile* hts_open ( const char *  fn,
const char *  mode 
)
const char* hts_parse_reg ( const char *  s,
int *  beg,
int *  end 
)
char** hts_readlines ( const char *  fn,
int *  _n 
)
char** hts_readlist ( const char *  fn,
int  is_file,
int *  _n 
)

Parse comma-separated list or read list from a file

Parameters
listFile name or comma-separated list
is_file
_nSize of the output array (number of items read)
Returns
NULL on failure or pointer to newly allocated array of strings
int hts_set_fai_filename ( htsFile fp,
const char *  fn_aux 
)

Set .fai filename for a file opened for reading

Returns
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.
int hts_set_opt ( htsFile fp,
enum cram_option  opt,
  ... 
)

Sets a specified CRAM option on the open file handle.

Parameters
fpThe file handle open the open file.
optThe CRAM_OPT_* option.
...Optional arguments, dependent on the option used.
Returns
0 for success, or negative if an error occurred.
int hts_set_threads ( htsFile fp,
int  n 
)

Create extra threads to aid compress/decompression for this file

Parameters
fpThe file handle
nThe number of worker threads to create
Returns
0 for success, or negative if an error occurred. THIS THREADING API IS LIKELY TO CHANGE IN FUTURE.
int hts_useek ( htsFile fp,
long  uoffset,
int  where 
)
long hts_utell ( htsFile fp)
const char* hts_version ( void  )

Get the htslib version number

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

Variable Documentation

int hts_verbose = 3
lidx_t
const char seq_nt16_str[] = "=ACMGRSVTWYHKDBN"

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

const unsigned char seq_nt16_table[256]
Initial value:
= {
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
1, 2, 4, 8, 15,15,15,15, 15,15,15,15, 15, 0 ,15,15,
15, 1,14, 2, 13,15,15, 4, 11,15,15,12, 15, 3,15,15,
15,15, 5, 6, 8,15, 7, 9, 15,10,15,15, 15,15,15,15,
15, 1,14, 2, 13,15,15, 4, 11,15,15,12, 15, 3,15,15,
15,15, 5, 6, 8,15, 7, 9, 15,10,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15
}

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