NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions | Variables
vcf.h File Reference
#include <stdint.h>
#include <limits.h>
#include <assert.h>
#include "hts.h"
#include "kstring.h"

Go to the source code of this file.

Classes

struct  bcf_hrec_t
 
struct  bcf_idinfo_t
 
struct  bcf_idpair_t
 
struct  bcf_hdr_t
 
struct  variant_t
 
struct  bcf_fmt_t
 
struct  bcf_info_t
 
struct  bcf_dec_t
 
struct  bcf1_t
 

Macros

#define BCF_HL_FLT   0
 
#define BCF_HL_INFO   1
 
#define BCF_HL_FMT   2
 
#define BCF_HL_CTG   3
 
#define BCF_HL_STR   4
 
#define BCF_HL_GEN   5
 
#define BCF_HT_FLAG   0
 
#define BCF_HT_INT   1
 
#define BCF_HT_REAL   2
 
#define BCF_HT_STR   3
 
#define BCF_VL_FIXED   0
 
#define BCF_VL_VAR   1
 
#define BCF_VL_A   2
 
#define BCF_VL_G   3
 
#define BCF_VL_R   4
 
#define BCF_DT_ID   0
 
#define BCF_DT_CTG   1
 
#define BCF_DT_SAMPLE   2
 
#define BCF_BT_NULL   0
 
#define BCF_BT_INT8   1
 
#define BCF_BT_INT16   2
 
#define BCF_BT_INT32   3
 
#define BCF_BT_FLOAT   5
 
#define BCF_BT_CHAR   7
 
#define VCF_REF   0
 
#define VCF_SNP   1
 
#define VCF_MNP   2
 
#define VCF_INDEL   4
 
#define VCF_OTHER   8
 
#define BCF1_DIRTY_ID   1
 
#define BCF1_DIRTY_ALS   2
 
#define BCF1_DIRTY_FLT   4
 
#define BCF1_DIRTY_INF   8
 
#define BCF_ERR_CTG_UNDEF   1
 
#define BCF_ERR_TAG_UNDEF   2
 
#define BCF_ERR_NCOLS   4
 
#define bcf_init1()   bcf_init()
 
#define bcf_read1(fp, h, v)   bcf_read((fp),(h),(v))
 
#define vcf_read1(fp, h, v)   vcf_read((fp),(h),(v))
 
#define bcf_write1(fp, h, v)   bcf_write((fp),(h),(v))
 
#define vcf_write1(fp, h, v)   vcf_write((fp),(h),(v))
 
#define bcf_destroy1(v)   bcf_destroy(v)
 
#define vcf_parse1(s, h, v)   vcf_parse((s),(h),(v))
 
#define bcf_clear1(v)   bcf_clear(v)
 
#define vcf_format1(h, v, s)   vcf_format((h),(v),(s))
 
#define bcf_open(fn, mode)   hts_open((fn), (mode))
 
#define vcf_open(fn, mode)   hts_open((fn), (mode))
 
#define bcf_close(fp)   hts_close(fp)
 
#define vcf_close(fp)   hts_close(fp)
 
#define BCF_UN_STR   1
 
#define BCF_UN_FLT   2
 
#define BCF_UN_INFO   4
 
#define BCF_UN_SHR   (BCF_UN_STR|BCF_UN_FLT|BCF_UN_INFO)
 
#define BCF_UN_FMT   8
 
#define BCF_UN_IND   BCF_UN_FMT
 
#define BCF_UN_ALL   (BCF_UN_SHR|BCF_UN_FMT)
 
#define bcf_hdr_nsamples(hdr)   (hdr)->n[BCF_DT_SAMPLE]
 
#define bcf_update_info_int32(hdr, line, key, values, n)   bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_INT)
 
#define bcf_update_info_float(hdr, line, key, values, n)   bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL)
 
#define bcf_update_info_flag(hdr, line, key, string, n)   bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG)
 
#define bcf_update_info_string(hdr, line, key, string)   bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR)
 
#define bcf_update_format_int32(hdr, line, key, values, n)   bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_INT)
 
#define bcf_update_format_float(hdr, line, key, values, n)   bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_REAL)
 
#define bcf_update_format_char(hdr, line, key, values, n)   bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_STR)
 
#define bcf_update_genotypes(hdr, line, gts, n)   bcf_update_format((hdr),(line),"GT",(gts),(n),BCF_HT_INT)
 
#define bcf_gt_phased(idx)   ((idx+1)<<1|1)
 
#define bcf_gt_unphased(idx)   ((idx+1)<<1)
 
#define bcf_gt_missing   0
 
#define bcf_gt_is_phased(idx)   ((idx)&1)
 
#define bcf_gt_allele(val)   (((val)>>1)-1)
 
#define bcf_alleles2gt(a, b)   ((a)>(b)?((a)*((a)+1)/2+(b)):((b)*((b)+1)/2+(a)))
 
#define bcf_get_info_int32(hdr, line, tag, dst, ndst)   bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
 
#define bcf_get_info_float(hdr, line, tag, dst, ndst)   bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
 
#define bcf_get_info_string(hdr, line, tag, dst, ndst)   bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
 
#define bcf_get_info_flag(hdr, line, tag, dst, ndst)   bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_FLAG)
 
#define bcf_get_format_int32(hdr, line, tag, dst, ndst)   bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
 
#define bcf_get_format_float(hdr, line, tag, dst, ndst)   bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
 
#define bcf_get_format_char(hdr, line, tag, dst, ndst)   bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
 
#define bcf_get_genotypes(hdr, line, dst, ndst)   bcf_get_format_values(hdr,line,"GT",(void**)(dst),ndst,BCF_HT_INT)
 
#define bcf_hdr_int2id(hdr, type, int_id)   ((hdr)->id[type][int_id].key)
 
#define bcf_hdr_id2length(hdr, type, int_id)   ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>8 & 0xf)
 
#define bcf_hdr_id2number(hdr, type, int_id)   ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>12)
 
#define bcf_hdr_id2type(hdr, type, int_id)   ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>4 & 0xf)
 
#define bcf_hdr_id2coltype(hdr, type, int_id)   ((hdr)->id[BCF_DT_ID][int_id].val->info[type] & 0xf)
 
#define bcf_hdr_idinfo_exists(hdr, type, int_id)   ((int_id<0 || bcf_hdr_id2coltype(hdr,type,int_id)==0xf) ? 0 : 1)
 
#define bcf_hdr_id2hrec(hdr, dict_type, col_type, int_id)   ((hdr)->id[(dict_type)==BCF_DT_CTG?BCF_DT_CTG:BCF_DT_ID][int_id].val->hrec[(dict_type)==BCF_DT_CTG?0:(col_type)])
 
#define bcf_itr_destroy(iter)   hts_itr_destroy(iter)
 
#define bcf_itr_queryi(idx, tid, beg, end)   hts_itr_query((idx), (tid), (beg), (end), bcf_readrec)
 
#define bcf_itr_querys(idx, hdr, s)   hts_itr_querys((idx), (s), (hts_name2id_f)(bcf_hdr_name2id), (hdr), hts_itr_query, bcf_readrec)
 
#define bcf_itr_next(htsfp, itr, r)   hts_itr_next((htsfp)->fp.bgzf, (itr), (r), 0)
 
#define bcf_index_load(fn)   hts_idx_load(fn, HTS_FMT_CSI)
 
#define bcf_index_seqnames(idx, hdr, nptr)   hts_idx_seqnames((idx),(nptr),(hts_id2name_f)(bcf_hdr_id2name),(hdr))
 
#define bcf_int8_vector_end   (INT8_MIN+1)
 
#define bcf_int16_vector_end   (INT16_MIN+1)
 
#define bcf_int32_vector_end   (INT32_MIN+1)
 
#define bcf_str_vector_end   0
 
#define bcf_int8_missing   INT8_MIN
 
#define bcf_int16_missing   INT16_MIN
 
#define bcf_int32_missing   INT32_MIN
 
#define bcf_str_missing   0x07
 
#define bcf_float_set_vector_end(x)   bcf_float_set(&(x),bcf_float_vector_end)
 
#define bcf_float_set_missing(x)   bcf_float_set(&(x),bcf_float_missing)
 
#define BRANCH(type_t, missing, vector_end)
 

Typedefs

typedef htsFile vcfFile
 

Functions

bcf_hdr_tbcf_hdr_init (const char *mode)
 
void bcf_hdr_destroy (bcf_hdr_t *h)
 
bcf1_tbcf_init (void)
 
void bcf_destroy (bcf1_t *v)
 
void bcf_empty (bcf1_t *v)
 
void bcf_clear (bcf1_t *v)
 
bcf_hdr_tbcf_hdr_read (htsFile *fp)
 
int bcf_hdr_set_samples (bcf_hdr_t *hdr, const char *samples, int is_file)
 
int bcf_subset_format (const bcf_hdr_t *hdr, bcf1_t *rec)
 
int bcf_hdr_write (htsFile *fp, const bcf_hdr_t *h)
 
int vcf_parse (kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
 
int vcf_format (const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s)
 
int bcf_read (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
 
int bcf_unpack (bcf1_t *b, int which)
 
bcf1_tbcf_dup (bcf1_t *src)
 
int bcf_write (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
 
bcf_hdr_tvcf_hdr_read (htsFile *fp)
 
int vcf_hdr_write (htsFile *fp, const bcf_hdr_t *h)
 
int vcf_read (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
 
int vcf_write (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
 
int bcf_readrec (BGZF *fp, void *null, void *v, int *tid, int *beg, int *end)
 
bcf_hdr_tbcf_hdr_dup (const bcf_hdr_t *hdr)
 
void bcf_hdr_combine (bcf_hdr_t *dst, const bcf_hdr_t *src)
 
int bcf_hdr_add_sample (bcf_hdr_t *hdr, const char *sample)
 
int bcf_hdr_set (bcf_hdr_t *hdr, const char *fname)
 
char * bcf_hdr_fmt_text (const bcf_hdr_t *hdr, int is_bcf, int *len)
 
int bcf_hdr_append (bcf_hdr_t *h, const char *line)
 
int bcf_hdr_printf (bcf_hdr_t *h, const char *format,...)
 
const char * bcf_hdr_get_version (const bcf_hdr_t *hdr)
 
void bcf_hdr_set_version (bcf_hdr_t *hdr, const char *version)
 
void bcf_hdr_remove (bcf_hdr_t *h, int type, const char *key)
 
bcf_hdr_tbcf_hdr_subset (const bcf_hdr_t *h0, int n, char *const *samples, int *imap)
 
const char ** bcf_hdr_seqnames (const bcf_hdr_t *h, int *nseqs)
 
bcf_hrec_tbcf_hdr_parse_line (const bcf_hdr_t *h, const char *line, int *len)
 
void bcf_hrec_format (const bcf_hrec_t *hrec, kstring_t *str)
 
int bcf_hdr_add_hrec (bcf_hdr_t *hdr, bcf_hrec_t *hrec)
 
bcf_hrec_tbcf_hdr_get_hrec (const bcf_hdr_t *hdr, int type, const char *id)
 
bcf_hrec_tbcf_hrec_dup (bcf_hrec_t *hrec)
 
void bcf_hrec_add_key (bcf_hrec_t *hrec, const char *str, int len)
 
void bcf_hrec_set_val (bcf_hrec_t *hrec, int i, const char *str, int len, int is_quoted)
 
int bcf_hrec_find_key (bcf_hrec_t *hrec, const char *key)
 
void bcf_hrec_destroy (bcf_hrec_t *hrec)
 
int bcf_subset (const bcf_hdr_t *h, bcf1_t *v, int n, int *imap)
 
int bcf_translate (const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *src_line)
 
int bcf_get_variant_types (bcf1_t *rec)
 
int bcf_get_variant_type (bcf1_t *rec, int ith_allele)
 
int bcf_is_snp (bcf1_t *v)
 
int bcf_update_filter (const bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n)
 
int bcf_add_filter (const bcf_hdr_t *hdr, bcf1_t *line, int flt_id)
 
int bcf_remove_filter (const bcf_hdr_t *hdr, bcf1_t *line, int flt_id, int pass)
 
int bcf_has_filter (const bcf_hdr_t *hdr, bcf1_t *line, char *filter)
 
int bcf_update_alleles (const bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals)
 
int bcf_update_alleles_str (const bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_string)
 
int bcf_update_id (const bcf_hdr_t *hdr, bcf1_t *line, const char *id)
 
int bcf_update_info (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type)
 
int bcf_update_format_string (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const char **values, int n)
 
int bcf_update_format (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type)
 
bcf_fmt_tbcf_get_fmt (const bcf_hdr_t *hdr, bcf1_t *line, const char *key)
 
bcf_info_tbcf_get_info (const bcf_hdr_t *hdr, bcf1_t *line, const char *key)
 
int bcf_get_info_values (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type)
 
int bcf_get_format_string (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, char ***dst, int *ndst)
 
int bcf_get_format_values (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type)
 
int bcf_hdr_id2int (const bcf_hdr_t *hdr, int type, const char *id)
 
void bcf_fmt_array (kstring_t *s, int n, int type, void *data)
 
uint8_tbcf_fmt_sized_array (kstring_t *s, uint8_t *ptr)
 
void bcf_enc_vchar (kstring_t *s, int l, const char *a)
 
void bcf_enc_vint (kstring_t *s, int n, int32_t *a, int wsize)
 
void bcf_enc_vfloat (kstring_t *s, int n, float *a)
 
int bcf_index_build (const char *fn, int min_shift)
 

Variables

uint8_t bcf_type_shift []
 
uint32_t bcf_float_vector_end
 
uint32_t bcf_float_missing
 

Macro Definition Documentation

#define BCF1_DIRTY_ALS   2

Definition at line 135 of file vcf.h.

#define BCF1_DIRTY_FLT   4

Definition at line 136 of file vcf.h.

#define BCF1_DIRTY_ID   1

Definition at line 134 of file vcf.h.

#define BCF1_DIRTY_INF   8

Definition at line 137 of file vcf.h.

#define bcf_alleles2gt (   a,
 
)    ((a)>(b)?((a)*((a)+1)/2+(b)):((b)*((b)+1)/2+(a)))

Conversion between alleles indexes to Number=G genotype index (assuming diploid, all 0-based)

Definition at line 532 of file vcf.h.

#define BCF_BT_CHAR   7

Definition at line 99 of file vcf.h.

#define BCF_BT_FLOAT   5

Definition at line 98 of file vcf.h.

#define BCF_BT_INT16   2

Definition at line 96 of file vcf.h.

#define BCF_BT_INT32   3

Definition at line 97 of file vcf.h.

#define BCF_BT_INT8   1

Definition at line 95 of file vcf.h.

#define BCF_BT_NULL   0

Definition at line 94 of file vcf.h.

#define bcf_clear1 (   v)    bcf_clear(v)

Definition at line 212 of file vcf.h.

#define bcf_close (   fp)    hts_close(fp)

Definition at line 251 of file vcf.h.

#define bcf_destroy1 (   v)    bcf_destroy(v)

Definition at line 210 of file vcf.h.

#define BCF_DT_CTG   1

Definition at line 52 of file vcf.h.

#define BCF_DT_ID   0

Definition at line 51 of file vcf.h.

#define BCF_DT_SAMPLE   2

Definition at line 53 of file vcf.h.

#define BCF_ERR_CTG_UNDEF   1

Definition at line 154 of file vcf.h.

#define BCF_ERR_NCOLS   4

Definition at line 156 of file vcf.h.

#define BCF_ERR_TAG_UNDEF   2

Definition at line 155 of file vcf.h.

#define bcf_float_set_missing (   x)    bcf_float_set(&(x),bcf_float_missing)

Definition at line 714 of file vcf.h.

#define bcf_float_set_vector_end (   x)    bcf_float_set(&(x),bcf_float_vector_end)

Definition at line 713 of file vcf.h.

#define bcf_get_format_char (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)

Definition at line 599 of file vcf.h.

#define bcf_get_format_float (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)

Definition at line 598 of file vcf.h.

#define bcf_get_format_int32 (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)

bcf_get_format_*() - same as bcf_get_info*() above

The function bcf_get_format_string() is a higher-level (slower) variant of bcf_get_format_char(). see the description of bcf_update_format_string() and bcf_update_format_char() above. Unlike other bcf_get_format__*() functions, bcf_get_format_string() allocates two arrays: a single block of \0-terminated strings collapsed into a single array and an array of pointers to these strings. Both arrays must be cleaned by the user.

Returns negative value on error or the number of written values on success.

Example: int ndst = 0; char **dst = NULL; if ( bcf_get_format_string(hdr, line, "XX", &dst, &ndst) > 0 ) for (i=0; i<bcf_hdr_nsamples(hdr); i++) printf("%s\n", dst[i]); free(dst[0]); free(dst);

Example: int ngt, *gt_arr = NULL, ngt_arr = 0; ngt = bcf_get_genotypes(hdr, line, &gt_arr, &ngt_arr);

Definition at line 597 of file vcf.h.

#define bcf_get_genotypes (   hdr,
  line,
  dst,
  ndst 
)    bcf_get_format_values(hdr,line,"GT",(void**)(dst),ndst,BCF_HT_INT)

Definition at line 600 of file vcf.h.

#define bcf_get_info_flag (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_FLAG)

Definition at line 573 of file vcf.h.

#define bcf_get_info_float (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)

Definition at line 571 of file vcf.h.

#define bcf_get_info_int32 (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)

bcf_get_info_*() - get INFO values, integers or floats : BCF header BCF record : INFO tag to retrieve : *dst is pointer to a memory location, can point to NULL : pointer to the size of allocated memory

Returns negative value on error or the number of written values on success. bcf_get_info_string() returns on success the number of characters written excluding the null-terminating byte. bcf_get_info_flag() returns 1 when flag is set or 0 if not.

List of return codes: -1 .. no such INFO tag defined in the header -2 .. clash between types defined in the header and encountered in the VCF record -3 .. tag is not present in the VCF record

Definition at line 570 of file vcf.h.

#define bcf_get_info_string (   hdr,
  line,
  tag,
  dst,
  ndst 
)    bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)

Definition at line 572 of file vcf.h.

#define bcf_gt_allele (   val)    (((val)>>1)-1)

Definition at line 529 of file vcf.h.

#define bcf_gt_is_phased (   idx)    ((idx)&1)

Definition at line 528 of file vcf.h.

#define bcf_gt_missing   0

Definition at line 527 of file vcf.h.

#define bcf_gt_phased (   idx)    ((idx+1)<<1|1)

Definition at line 525 of file vcf.h.

#define bcf_gt_unphased (   idx)    ((idx+1)<<1)

Definition at line 526 of file vcf.h.

#define bcf_hdr_id2coltype (   hdr,
  type,
  int_id 
)    ((hdr)->id[BCF_DT_ID][int_id].val->info[type] & 0xf)

Definition at line 647 of file vcf.h.

#define bcf_hdr_id2hrec (   hdr,
  dict_type,
  col_type,
  int_id 
)    ((hdr)->id[(dict_type)==BCF_DT_CTG?BCF_DT_CTG:BCF_DT_ID][int_id].val->hrec[(dict_type)==BCF_DT_CTG?0:(col_type)])

Definition at line 649 of file vcf.h.

#define bcf_hdr_id2length (   hdr,
  type,
  int_id 
)    ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>8 & 0xf)

bcf_hdr_id2*() - Macros for accessing bcf_idinfo_t : one of BCF_HL_FLT, BCF_HL_INFO, BCF_HL_FMT : return value of bcf_id2int, must be >=0

The returned values are: bcf_hdr_id2length .. whether the number of values is fixed or variable, one of BCF_VL_* bcf_hdr_id2number .. the number of values, 0xfffff for variable length fields bcf_hdr_id2type .. the field type, one of BCF_HT_* bcf_hdr_id2coltype .. the column type, one of BCF_HL_*

Notes: Prior to using the macros, the presence of the info should be tested with bcf_hdr_idinfo_exists().

Definition at line 644 of file vcf.h.

#define bcf_hdr_id2number (   hdr,
  type,
  int_id 
)    ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>12)

Definition at line 645 of file vcf.h.

#define bcf_hdr_id2type (   hdr,
  type,
  int_id 
)    ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>4 & 0xf)

Definition at line 646 of file vcf.h.

#define bcf_hdr_idinfo_exists (   hdr,
  type,
  int_id 
)    ((int_id<0 || bcf_hdr_id2coltype(hdr,type,int_id)==0xf) ? 0 : 1)

Definition at line 648 of file vcf.h.

#define bcf_hdr_int2id (   hdr,
  type,
  int_id 
)    ((hdr)->id[type][int_id].key)

Definition at line 620 of file vcf.h.

#define bcf_hdr_nsamples (   hdr)    (hdr)->n[BCF_DT_SAMPLE]

Get number of samples

Definition at line 403 of file vcf.h.

#define BCF_HL_CTG   3

Definition at line 24 of file vcf.h.

#define BCF_HL_FLT   0

Definition at line 21 of file vcf.h.

#define BCF_HL_FMT   2

Definition at line 23 of file vcf.h.

#define BCF_HL_GEN   5

Definition at line 26 of file vcf.h.

#define BCF_HL_INFO   1

Definition at line 22 of file vcf.h.

#define BCF_HL_STR   4

Definition at line 25 of file vcf.h.

#define BCF_HT_FLAG   0

Definition at line 28 of file vcf.h.

#define BCF_HT_INT   1

Definition at line 29 of file vcf.h.

#define BCF_HT_REAL   2

Definition at line 30 of file vcf.h.

#define BCF_HT_STR   3

Definition at line 31 of file vcf.h.

#define bcf_index_load (   fn)    hts_idx_load(fn, HTS_FMT_CSI)

Definition at line 671 of file vcf.h.

#define bcf_index_seqnames (   idx,
  hdr,
  nptr 
)    hts_idx_seqnames((idx),(nptr),(hts_id2name_f)(bcf_hdr_id2name),(hdr))

Definition at line 672 of file vcf.h.

#define bcf_init1 ( )    bcf_init()

These macros are defined only for consistency with other parts of htslib

Definition at line 205 of file vcf.h.

#define bcf_int16_missing   INT16_MIN

Definition at line 702 of file vcf.h.

#define bcf_int16_vector_end   (INT16_MIN+1)

Definition at line 698 of file vcf.h.

#define bcf_int32_missing   INT32_MIN

Definition at line 703 of file vcf.h.

#define bcf_int32_vector_end   (INT32_MIN+1)

Definition at line 699 of file vcf.h.

#define bcf_int8_missing   INT8_MIN

Definition at line 701 of file vcf.h.

#define bcf_int8_vector_end   (INT8_MIN+1)

Definition at line 697 of file vcf.h.

#define bcf_itr_destroy (   iter)    hts_itr_destroy(iter)

Definition at line 667 of file vcf.h.

#define bcf_itr_next (   htsfp,
  itr,
 
)    hts_itr_next((htsfp)->fp.bgzf, (itr), (r), 0)

Definition at line 670 of file vcf.h.

#define bcf_itr_queryi (   idx,
  tid,
  beg,
  end 
)    hts_itr_query((idx), (tid), (beg), (end), bcf_readrec)

Definition at line 668 of file vcf.h.

#define bcf_itr_querys (   idx,
  hdr,
 
)    hts_itr_querys((idx), (s), (hts_name2id_f)(bcf_hdr_name2id), (hdr), hts_itr_query, bcf_readrec)

Definition at line 669 of file vcf.h.

#define bcf_open (   fn,
  mode 
)    hts_open((fn), (mode))

Definition at line 249 of file vcf.h.

#define bcf_read1 (   fp,
  h,
 
)    bcf_read((fp),(h),(v))

Definition at line 206 of file vcf.h.

#define bcf_str_missing   0x07

Definition at line 704 of file vcf.h.

#define bcf_str_vector_end   0

Definition at line 700 of file vcf.h.

#define BCF_UN_ALL   (BCF_UN_SHR|BCF_UN_FMT)

Definition at line 315 of file vcf.h.

#define BCF_UN_FLT   2

Definition at line 310 of file vcf.h.

#define BCF_UN_FMT   8

Definition at line 313 of file vcf.h.

#define BCF_UN_IND   BCF_UN_FMT

Definition at line 314 of file vcf.h.

#define BCF_UN_INFO   4

Definition at line 311 of file vcf.h.

#define BCF_UN_SHR   (BCF_UN_STR|BCF_UN_FLT|BCF_UN_INFO)

Definition at line 312 of file vcf.h.

#define BCF_UN_STR   1
bcf_unpack() - unpack/decode a BCF record (fills the bcf1_t::d field)

Note that bcf_unpack() must be called even when reading VCF. It is safe to call the function repeatedly, it will not unpack the same field twice.

Definition at line 309 of file vcf.h.

#define bcf_update_format_char (   hdr,
  line,
  key,
  values,
 
)    bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_STR)

Definition at line 517 of file vcf.h.

#define bcf_update_format_float (   hdr,
  line,
  key,
  values,
 
)    bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_REAL)

Definition at line 516 of file vcf.h.

#define bcf_update_format_int32 (   hdr,
  line,
  key,
  values,
 
)    bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_INT)

Definition at line 515 of file vcf.h.

#define bcf_update_genotypes (   hdr,
  line,
  gts,
 
)    bcf_update_format((hdr),(line),"GT",(gts),(n),BCF_HT_INT)

Definition at line 518 of file vcf.h.

#define bcf_update_info_flag (   hdr,
  line,
  key,
  string,
 
)    bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG)

Definition at line 495 of file vcf.h.

#define bcf_update_info_float (   hdr,
  line,
  key,
  values,
 
)    bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL)

Definition at line 494 of file vcf.h.

#define bcf_update_info_int32 (   hdr,
  line,
  key,
  values,
 
)    bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_INT)

Definition at line 493 of file vcf.h.

#define bcf_update_info_string (   hdr,
  line,
  key,
  string 
)    bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR)

Definition at line 496 of file vcf.h.

#define BCF_VL_A   2

Definition at line 35 of file vcf.h.

#define BCF_VL_FIXED   0

Definition at line 33 of file vcf.h.

#define BCF_VL_G   3

Definition at line 36 of file vcf.h.

#define BCF_VL_R   4

Definition at line 37 of file vcf.h.

#define BCF_VL_VAR   1

Definition at line 34 of file vcf.h.

#define bcf_write1 (   fp,
  h,
 
)    bcf_write((fp),(h),(v))

Definition at line 208 of file vcf.h.

#define BRANCH (   type_t,
  missing,
  vector_end 
)
Value:
{ \
type_t *ptr = (type_t*) (fmt->p + isample*fmt->size); \
int i; \
for (i=0; i<fmt->n && ptr[i]!=vector_end; i++) \
{ \
if ( i ) kputc("/|"[ptr[i]&1], str); \
if ( !(ptr[i]>>1) ) kputc('.', str); \
else kputw((ptr[i]>>1) - 1, str); \
} \
if (i == 0) kputc('.', str); \
}
#define vcf_close (   fp)    hts_close(fp)

Definition at line 252 of file vcf.h.

#define vcf_format1 (   h,
  v,
 
)    vcf_format((h),(v),(s))

Definition at line 213 of file vcf.h.

#define VCF_INDEL   4

Definition at line 104 of file vcf.h.

#define VCF_MNP   2

Definition at line 103 of file vcf.h.

#define vcf_open (   fn,
  mode 
)    hts_open((fn), (mode))

Definition at line 250 of file vcf.h.

#define VCF_OTHER   8

Definition at line 105 of file vcf.h.

#define vcf_parse1 (   s,
  h,
 
)    vcf_parse((s),(h),(v))

Definition at line 211 of file vcf.h.

#define vcf_read1 (   fp,
  h,
 
)    vcf_read((fp),(h),(v))

Definition at line 207 of file vcf.h.

#define VCF_REF   0

Definition at line 101 of file vcf.h.

#define VCF_SNP   1

Definition at line 102 of file vcf.h.

#define vcf_write1 (   fp,
  h,
 
)    vcf_write((fp),(h),(v))

Definition at line 209 of file vcf.h.

Typedef Documentation

typedef htsFile vcfFile

bcf_open and vcf_open mode: please see hts_open() in hts.h

Definition at line 248 of file vcf.h.

Function Documentation

int bcf_add_filter ( const bcf_hdr_t hdr,
bcf1_t line,
int  flt_id 
)

bcf_add_filter() - adds to the FILTER column : filter ID to add, numeric ID returned by bcf_id2int(hdr, BCF_DT_ID, "PASS")

If flt_id is PASS, all existing filters are removed first. If other than PASS, existing PASS is removed.

Definition at line 2707 of file vcf.c.

void bcf_clear ( bcf1_t v)

Make the bcf1_t object ready for next read. Intended mostly for internal use, the user should rarely need to call this function directly.

Definition at line 733 of file vcf.c.

void bcf_destroy ( bcf1_t v)

Deallocate a bcf1_t object

bcf1_t* bcf_dup ( bcf1_t src)

Definition at line 1055 of file vcf.c.

void bcf_empty ( bcf1_t v)

Same as bcf_destroy() but frees only the memory allocated by bcf1_t, not the bcf1_t object itself.

void bcf_enc_vchar ( kstring_t s,
int  l,
const char *  a 
)

Definition at line 1339 of file vcf.c.

void bcf_enc_vfloat ( kstring_t s,
int  n,
float *  a 
)

Definition at line 1333 of file vcf.c.

void bcf_enc_vint ( kstring_t s,
int  n,
int32_t a,
int  wsize 
)

Definition at line 1294 of file vcf.c.

void bcf_fmt_array ( kstring_t s,
int  n,
int  type,
void *  data 
)

Definition at line 1345 of file vcf.c.

uint8_t* bcf_fmt_sized_array ( kstring_t s,
uint8_t ptr 
)

Definition at line 1384 of file vcf.c.

bcf_fmt_t* bcf_get_fmt ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  key 
)

bcf_get_fmt() - returns pointer to FORMAT's field data : for access to BCF_DT_ID dictionary VCF line obtained from vcf_parse1 : one of GT,PL,...

Returns bcf_fmt_t* if the call succeeded, or returns NULL when the field is not available.

Definition at line 2829 of file vcf.c.

int bcf_get_format_string ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  tag,
char ***  dst,
int *  ndst 
)

Definition at line 2917 of file vcf.c.

int bcf_get_format_values ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  tag,
void **  dst,
int *  ndst,
int  type 
)

Definition at line 2955 of file vcf.c.

bcf_info_t* bcf_get_info ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  key 
)

Definition at line 2841 of file vcf.c.

int bcf_get_info_values ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  tag,
void **  dst,
int *  ndst,
int  type 
)

Definition at line 2853 of file vcf.c.

int bcf_get_variant_type ( bcf1_t rec,
int  ith_allele 
)

Definition at line 2476 of file vcf.c.

int bcf_get_variant_types ( bcf1_t rec)

bcf_get_variant_type[s]() - returns one of VCF_REF, VCF_SNP, etc

Definition at line 2471 of file vcf.c.

int bcf_has_filter ( const bcf_hdr_t hdr,
bcf1_t line,
char *  filter 
)

Returns 1 if present, 0 if absent, or -1 if filter does not exist. "PASS" and "." can be used interchangeably.

Definition at line 2739 of file vcf.c.

int bcf_hdr_add_hrec ( bcf_hdr_t hdr,
bcf_hrec_t hrec 
)

Definition at line 428 of file vcf.c.

int bcf_hdr_add_sample ( bcf_hdr_t hdr,
const char *  sample 
)

bcf_hdr_add_sample() - add a new sample.

Parameters
sample,:Sample name to be added. After all samples have been added, NULL must be passed to update internal header structures.

Definition at line 32 of file vcf.c.

int bcf_hdr_append ( bcf_hdr_t h,
const char *  line 
)

Append new VCF header line, returns 0 on success

Definition at line 532 of file vcf.c.

void bcf_hdr_combine ( bcf_hdr_t dst,
const bcf_hdr_t src 
)

Copy header lines from src to dst if not already present in dst. See also bcf_translate().

Definition at line 2112 of file vcf.c.

void bcf_hdr_destroy ( bcf_hdr_t h)

Destroy a BCF header struct

Definition at line 650 of file vcf.c.

bcf_hdr_t* bcf_hdr_dup ( const bcf_hdr_t hdr)

Create a new header using the supplied template

Definition at line 2251 of file vcf.c.

char* bcf_hdr_fmt_text ( const bcf_hdr_t hdr,
int  is_bcf,
int *  len 
)

Returns formatted header (newly allocated string) and its length, excluding the terminating \0. If is_bcf parameter is unset, IDX fields are discarded.

Definition at line 1236 of file vcf.c.

bcf_hrec_t* bcf_hdr_get_hrec ( const bcf_hdr_t hdr,
int  type,
const char *  id 
)

Definition at line 463 of file vcf.c.

const char* bcf_hdr_get_version ( const bcf_hdr_t hdr)

Definition at line 604 of file vcf.c.

int bcf_hdr_id2int ( const bcf_hdr_t hdr,
int  type,
const char *  id 
)

bcf_hdr_id2int() - Translates string into numeric ID bcf_hdr_int2id() - Translates numeric ID into string : one of BCF_DT_ID, BCF_DT_CTG, BCF_DT_SAMPLE : tag name, such as: PL, DP, GT, etc.

Returns -1 if string is not in dictionary, otherwise numeric ID which identifies fields in BCF records.

Definition at line 2044 of file vcf.c.

bcf_hdr_t* bcf_hdr_init ( const char *  mode)

bcf_hdr_init() - create an empty BCF header.

Parameters
mode"r" or "w"

When opened for writing, the mandatory fileFormat and FILTER=PASS lines are added automatically.

Definition at line 634 of file vcf.c.

bcf_hrec_t* bcf_hdr_parse_line ( const bcf_hdr_t h,
const char *  line,
int *  len 
)

The following functions are for internal use and should rarely be called directly

Definition at line 244 of file vcf.c.

int bcf_hdr_printf ( bcf_hdr_t h,
const char *  format,
  ... 
)

Definition at line 581 of file vcf.c.

bcf_hdr_t* bcf_hdr_read ( htsFile fp)

Reads VCF or BCF header

Definition at line 672 of file vcf.c.

void bcf_hdr_remove ( bcf_hdr_t h,
int  type,
const char *  key 
)

bcf_hdr_remove() - remove VCF header tag

Parameters
type,:one of BCF_HL_*
key,:tag name

Definition at line 542 of file vcf.c.

const char** bcf_hdr_seqnames ( const bcf_hdr_t h,
int *  nseqs 
)

Creates a list of sequence names. It is up to the caller to free the list (but not the sequence names)

Definition at line 1256 of file vcf.c.

int bcf_hdr_set ( bcf_hdr_t hdr,
const char *  fname 
)

Read VCF header from a file and update the header

Definition at line 1193 of file vcf.c.

int bcf_hdr_set_samples ( bcf_hdr_t hdr,
const char *  samples,
int  is_file 
)

bcf_hdr_set_samples() - for more efficient VCF parsing when only one/few samples are needed : samples to include or exclude from file or as a comma-separated string. LIST|FILE .. select samples in list/file ^LIST|FILE .. exclude samples from list/file

  • .. include all samples NULL .. exclude all samples : is a file (1) or a comma-separated list (1)

The bottleneck of VCF reading is parsing of genotype fields. If the reader knows in advance that only subset of samples is needed (possibly no samples at all), the performance of bcf_read() can be significantly improved by calling bcf_hdr_set_samples after bcf_hdr_read(). The function bcf_read() will subset the VCF/BCF records automatically with the notable exception when reading records via bcf_itr_next(). In this case, bcf_subset_format() must be called explicitly, because bcf_readrec() does not see the header.

Returns 0 on success, -1 on error or a positive integer if the list contains samples not present in the VCF header. In such a case, the return value is the index of the offending sample.

Definition at line 2297 of file vcf.c.

void bcf_hdr_set_version ( bcf_hdr_t hdr,
const char *  version 
)

Definition at line 615 of file vcf.c.

bcf_hdr_t* bcf_hdr_subset ( const bcf_hdr_t h0,
int  n,
char *const samples,
int *  imap 
)

bcf_hdr_subset() - creates a new copy of the header removing unwanted samples

Parameters
n,:number of samples to keep
samples,:names of the samples to keep
imap,:mapping from index in to the sample index in the original file

Sample names not present in h0 are ignored. The number of unmatched samples can be checked by comparing n and bcf_hdr_nsamples(out_hdr). This function can be used to reorder samples. See also bcf_subset() which subsets individual records.

Definition at line 2260 of file vcf.c.

int bcf_hdr_write ( htsFile fp,
const bcf_hdr_t h 
)

Writes VCF or BCF header

Definition at line 705 of file vcf.c.

void bcf_hrec_add_key ( bcf_hrec_t hrec,
const char *  str,
int  len 
)

Definition at line 186 of file vcf.c.

void bcf_hrec_destroy ( bcf_hrec_t hrec)

Definition at line 122 of file vcf.c.

bcf_hrec_t* bcf_hrec_dup ( bcf_hrec_t hrec)

Definition at line 138 of file vcf.c.

int bcf_hrec_find_key ( bcf_hrec_t hrec,
const char *  key 
)

Definition at line 229 of file vcf.c.

void bcf_hrec_format ( const bcf_hrec_t hrec,
kstring_t str 
)

Definition at line 1232 of file vcf.c.

void bcf_hrec_set_val ( bcf_hrec_t hrec,
int  i,
const char *  str,
int  len,
int  is_quoted 
)

Definition at line 198 of file vcf.c.

int bcf_index_build ( const char *  fn,
int  min_shift 
)

Definition at line 2094 of file vcf.c.

bcf1_t* bcf_init ( void  )

Initialize a bcf1_t object; equivalent to calloc(1, sizeof(bcf1_t))

int bcf_is_snp ( bcf1_t v)

Definition at line 2391 of file vcf.c.

int bcf_read ( htsFile fp,
const bcf_hdr_t h,
bcf1_t v 
)

bcf_read() - read next VCF or BCF record

Returns -1 on critical errors, 0 otherwise. On errors which are not critical for reading, such as missing header definitions, v->errcode is set to one of BCF_ERR* code and must be checked before calling vcf_write().

Definition at line 853 of file vcf.c.

int bcf_readrec ( BGZF fp,
void *  null,
void *  v,
int *  tid,
int *  beg,
int *  end 
)

Helper function for the bcf_itr_next() macro; internal use, ignore it

Definition at line 861 of file vcf.c.

int bcf_remove_filter ( const bcf_hdr_t hdr,
bcf1_t line,
int  flt_id,
int  pass 
)

bcf_remove_filter() - removes from the FILTER column : filter ID to remove, numeric ID returned by bcf_id2int(hdr, BCF_DT_ID, "PASS") : when set to 1 and no filters are present, set to PASS

Definition at line 2725 of file vcf.c.

int bcf_subset ( const bcf_hdr_t h,
bcf1_t v,
int  n,
int *  imap 
)

See the description of bcf_hdr_subset()

Definition at line 2363 of file vcf.c.

int bcf_subset_format ( const bcf_hdr_t hdr,
bcf1_t rec 
)

Definition at line 812 of file vcf.c.

int bcf_translate ( const bcf_hdr_t dst_hdr,
bcf_hdr_t src_hdr,
bcf1_t src_line 
)

bcf_translate() - translate tags ids to be consistent with different header. This function is useful when lines from multiple VCF need to be combined. : the destination header, to be used in bcf_write(), see also bcf_hdr_combine() : the source header, used in bcf_read() : line obtained by bcf_read()

Definition at line 2137 of file vcf.c.

int bcf_unpack ( bcf1_t b,
int  which 
)

Definition at line 1859 of file vcf.c.

int bcf_update_alleles ( const bcf_hdr_t hdr,
bcf1_t line,
const char **  alleles,
int  nals 
)

bcf_update_alleles() and bcf_update_alleles_str() - update REF and ALLT column : Array of alleles : Number of alleles : Comma-separated alleles, starting with the REF allele

Not that in order for indexing to work correctly in presence of INFO/END tag, the length of reference allele (line->rlen) must be set explicitly by the caller, or otherwise, if rlen is zero, strlen(line->d.allele[0]) is used to set the length on bcf_write().

Definition at line 2772 of file vcf.c.

int bcf_update_alleles_str ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  alleles_string 
)

Definition at line 2799 of file vcf.c.

int bcf_update_filter ( const bcf_hdr_t hdr,
bcf1_t line,
int *  flt_ids,
int  n 
)

bcf_update_filter() - sets the FILTER column : The filter IDs to set, numeric IDs returned by bcf_id2int(hdr, BCF_DT_ID, "PASS")
: Number of filters. If n==0, all filters are removed

Definition at line 2694 of file vcf.c.

int bcf_update_format ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  key,
const void *  values,
int  n,
int  type 
)

Definition at line 2591 of file vcf.c.

int bcf_update_format_string ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  key,
const char **  values,
int  n 
)

Definition at line 2565 of file vcf.c.

int bcf_update_id ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  id 
)

Definition at line 2816 of file vcf.c.

int bcf_update_info ( const bcf_hdr_t hdr,
bcf1_t line,
const char *  key,
const void *  values,
int  n,
int  type 
)

Definition at line 2482 of file vcf.c.

int bcf_write ( htsFile fp,
const bcf_hdr_t h,
bcf1_t v 
)

bcf_write() - write one VCF or BCF record. The type is determined at the open() call.

Definition at line 1079 of file vcf.c.

int vcf_format ( const bcf_hdr_t h,
const bcf1_t v,
kstring_t s 
)

The opposite of vcf_parse. It should rarely be called directly, see vcf_write

bcf_hdr_idinfo_exists(h,BCF_HL_FMT,fmt[i].id) )

Definition at line 1928 of file vcf.c.

bcf_hdr_t* vcf_hdr_read ( htsFile fp)

The following functions work only with VCFs and should rarely be called directly. Usually one wants to use their bcf_* alternatives, which work transparently with both VCFs and BCFs.

Definition at line 1118 of file vcf.c.

int vcf_hdr_write ( htsFile fp,
const bcf_hdr_t h 
)

Definition at line 1276 of file vcf.c.

int vcf_parse ( kstring_t s,
const bcf_hdr_t h,
bcf1_t v 
)

Parse VCF line contained in kstring and populate the bcf1_t struct

Definition at line 1642 of file vcf.c.

int vcf_read ( htsFile fp,
const bcf_hdr_t h,
bcf1_t v 
)

Definition at line 1817 of file vcf.c.

int vcf_write ( htsFile fp,
const bcf_hdr_t h,
bcf1_t v 
)

Definition at line 2028 of file vcf.c.

Variable Documentation

uint32_t bcf_float_missing
uint32_t bcf_float_vector_end
uint8_t bcf_type_shift[]