21 #define BCF_HL_FLT 0 // header line
25 #define BCF_HL_STR 4 // structured header line TAG=<A=..,B=..>
26 #define BCF_HL_GEN 5 // generic header line
28 #define BCF_HT_FLAG 0 // header type
33 #define BCF_VL_FIXED 0 // variable length
51 #define BCF_DT_ID 0 // dictionary type
53 #define BCF_DT_SAMPLE 2
82 int ntransl, *transl[2];
96 #define BCF_BT_INT16 2
97 #define BCF_BT_INT32 3
98 #define BCF_BT_FLOAT 5
134 #define BCF1_DIRTY_ID 1
135 #define BCF1_DIRTY_ALS 2
136 #define BCF1_DIRTY_FLT 4
137 #define BCF1_DIRTY_INF 8
140 int m_fmt,
m_info, m_id, m_als, m_allele, m_flt;
154 #define BCF_ERR_CTG_UNDEF 1
155 #define BCF_ERR_TAG_UNDEF 2
156 #define BCF_ERR_NCOLS 4
205 #define bcf_init1() bcf_init()
206 #define bcf_read1(fp,h,v) bcf_read((fp),(h),(v))
207 #define vcf_read1(fp,h,v) vcf_read((fp),(h),(v))
208 #define bcf_write1(fp,h,v) bcf_write((fp),(h),(v))
209 #define vcf_write1(fp,h,v) vcf_write((fp),(h),(v))
210 #define bcf_destroy1(v) bcf_destroy(v)
211 #define vcf_parse1(s,h,v) vcf_parse((s),(h),(v))
212 #define bcf_clear1(v) bcf_clear(v)
213 #define vcf_format1(h,v,s) vcf_format((h),(v),(s))
249 #define bcf_open(fn, mode) hts_open((fn), (mode))
250 #define vcf_open(fn, mode) hts_open((fn), (mode))
251 #define bcf_close(fp) hts_close(fp)
252 #define vcf_close(fp) hts_close(fp)
309 #define BCF_UN_STR 1 // up to ALT inclusive
310 #define BCF_UN_FLT 2 // up to FILTER
311 #define BCF_UN_INFO 4 // up to INFO
312 #define BCF_UN_SHR (BCF_UN_STR|BCF_UN_FLT|BCF_UN_INFO) // all shared information
313 #define BCF_UN_FMT 8 // unpack format and each sample
314 #define BCF_UN_IND BCF_UN_FMT // a synonymo of BCF_UN_FMT
315 #define BCF_UN_ALL (BCF_UN_SHR|BCF_UN_FMT) // everything
343 int bcf_readrec(
BGZF *fp,
void *null,
void *v,
int *tid,
int *beg,
int *end);
403 #define bcf_hdr_nsamples(hdr) (hdr)->n[BCF_DT_SAMPLE]
493 #define bcf_update_info_int32(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_INT)
494 #define bcf_update_info_float(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL)
495 #define bcf_update_info_flag(hdr,line,key,string,n) bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG)
496 #define bcf_update_info_string(hdr,line,key,string) bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR)
515 #define bcf_update_format_int32(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_INT)
516 #define bcf_update_format_float(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_REAL)
517 #define bcf_update_format_char(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_STR)
518 #define bcf_update_genotypes(hdr,line,gts,n) bcf_update_format((hdr),(line),"GT",(gts),(n),BCF_HT_INT) // See bcf_gt_ macros below
525 #define bcf_gt_phased(idx) ((idx+1)<<1|1)
526 #define bcf_gt_unphased(idx) ((idx+1)<<1)
527 #define bcf_gt_missing 0
528 #define bcf_gt_is_phased(idx) ((idx)&1)
529 #define bcf_gt_allele(val) (((val)>>1)-1)
532 #define bcf_alleles2gt(a,b) ((a)>(b)?((a)*((a)+1)/2+(b)):((b)*((b)+1)/2+(a)))
533 static inline void bcf_gt2alleles(
int igt,
int *a,
int *b)
536 while ( k<igt ) { dk++; k += dk; }
537 *b = dk - 1; *a = igt - k + *b;
570 #define bcf_get_info_int32(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
571 #define bcf_get_info_float(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
572 #define bcf_get_info_string(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
573 #define bcf_get_info_flag(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_FLAG)
597 #define bcf_get_format_int32(hdr,line,tag,dst,ndst) bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
598 #define bcf_get_format_float(hdr,line,tag,dst,ndst) bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
599 #define bcf_get_format_char(hdr,line,tag,dst,ndst) bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
600 #define bcf_get_genotypes(hdr,line,dst,ndst) bcf_get_format_values(hdr,line,"GT",(void**)(dst),ndst,BCF_HT_INT)
620 #define bcf_hdr_int2id(hdr,type,int_id) ((hdr)->id[type][int_id].key)
644 #define bcf_hdr_id2length(hdr,type,int_id) ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>8 & 0xf)
645 #define bcf_hdr_id2number(hdr,type,int_id) ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>12)
646 #define bcf_hdr_id2type(hdr,type,int_id) ((hdr)->id[BCF_DT_ID][int_id].val->info[type]>>4 & 0xf)
647 #define bcf_hdr_id2coltype(hdr,type,int_id) ((hdr)->id[BCF_DT_ID][int_id].val->info[type] & 0xf)
648 #define bcf_hdr_idinfo_exists(hdr,type,int_id) ((int_id<0 || bcf_hdr_id2coltype(hdr,type,int_id)==0xf) ? 0 : 1)
649 #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)])
667 #define bcf_itr_destroy(iter) hts_itr_destroy(iter)
668 #define bcf_itr_queryi(idx, tid, beg, end) hts_itr_query((idx), (tid), (beg), (end), bcf_readrec)
669 #define bcf_itr_querys(idx, hdr, s) hts_itr_querys((idx), (s), (hts_name2id_f)(bcf_hdr_name2id), (hdr), hts_itr_query, bcf_readrec)
670 #define bcf_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), 0)
671 #define bcf_index_load(fn) hts_idx_load(fn, HTS_FMT_CSI)
672 #define bcf_index_seqnames(idx, hdr, nptr) hts_idx_seqnames((idx),(nptr),(hts_id2name_f)(bcf_hdr_id2name),(hdr))
697 #define bcf_int8_vector_end (INT8_MIN+1)
698 #define bcf_int16_vector_end (INT16_MIN+1)
699 #define bcf_int32_vector_end (INT32_MIN+1)
700 #define bcf_str_vector_end 0
701 #define bcf_int8_missing INT8_MIN
702 #define bcf_int16_missing INT16_MIN
703 #define bcf_int32_missing INT32_MIN
704 #define bcf_str_missing 0x07
707 static inline void bcf_float_set(
float *ptr,
uint32_t value)
713 #define bcf_float_set_vector_end(x) bcf_float_set(&(x),bcf_float_vector_end)
714 #define bcf_float_set_missing(x) bcf_float_set(&(x),bcf_float_missing)
715 static inline int bcf_float_is_missing(
float f)
721 static inline int bcf_float_is_vector_end(
float f)
730 #define BRANCH(type_t, missing, vector_end) { \
731 type_t *ptr = (type_t*) (fmt->p + isample*fmt->size); \
733 for (i=0; i<fmt->n && ptr[i]!=vector_end; i++) \
735 if ( i ) kputc("/|"[ptr[i]&1], str); \
736 if ( !(ptr[i]>>1) ) kputc('.', str); \
737 else kputw((ptr[i]>>1) - 1, str); \
739 if (i == 0) kputc('.', str); \
745 default: fprintf(stderr,
"FIXME: type %d in bcf_format_gt?\n", fmt->
type); abort();
break;
750 static inline void bcf_enc_size(
kstring_t *s,
int size,
int type)
753 kputc(15<<4|type, s);
758 kputsn((
char*)&x, 4, s);
762 kputsn((
char*)&x, 2, s);
768 }
else kputc(size<<4|type, s);
771 static inline int bcf_enc_inttype(
long x)
785 kputc(bcf_int8_missing, s);
786 }
else if (x <= INT8_MAX && x > bcf_int8_missing) {
792 kputsn((
char*)&z, 2, s);
796 kputsn((
char*)&z, 4, s);
816 return bcf_dec_int1(p + 1, *p&0xf, q);
825 }
else return bcf_dec_typed_int1(p + 1, q);