]> git.donarmstrong.com Git - samtools.git/blob - bcftools/bcf.h
* put n_smpl to "bcf1_t" to simplify API a little
[samtools.git] / bcftools / bcf.h
1 #ifndef BCF_H
2 #define BCF_H
3
4 #include <stdint.h>
5 #include <zlib.h>
6 #include "bgzf.h"
7
8 typedef struct {
9         uint32_t fmt;
10         int len; // len is the unit length
11         void *data;
12         // derived info: fmt, len
13 } bcf_ginfo_t;
14
15 typedef struct {
16         int32_t tid, pos;
17         int32_t l_str, m_str;
18         float qual;
19         char *str, *ref, *alt, *flt, *info, *fmt; // fmt, ref, alt and info point to str
20         int n_gi, m_gi;
21         bcf_ginfo_t *gi;
22         int n_alleles, n_smpl;
23         // derived info: ref, alt, flt, info, fmt, n_gi, n_alleles
24 } bcf1_t;
25
26 typedef struct {
27         int32_t n_ref, n_smpl;
28         int32_t l_nm;
29         int32_t l_smpl;
30         int32_t l_txt;
31         char *name, *sname, *txt;
32         char **ns, **sns;
33         // derived info: n_ref, n_smpl, ns, sns
34 } bcf_hdr_t;
35
36 typedef struct {
37         int is_vcf;
38         void *v;
39         BGZF *fp;
40 } bcf_t;
41
42 struct __bcf_idx_t;
43 typedef struct __bcf_idx_t bcf_idx_t;
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49         bcf_t *bcf_open(const char *fn, const char *mode);
50         int bcf_close(bcf_t *b);
51         int bcf_read(bcf_t *bp, const bcf_hdr_t *h, bcf1_t *b);
52         int bcf_sync(bcf1_t *b);
53         int bcf_write(bcf_t *bp, const bcf_hdr_t *h, const bcf1_t *b);
54         bcf_hdr_t *bcf_hdr_read(bcf_t *b);
55         int bcf_hdr_write(bcf_t *b, const bcf_hdr_t *h);
56         int bcf_hdr_sync(bcf_hdr_t *b);
57         void bcf_hdr_destroy(bcf_hdr_t *h);
58         int bcf_destroy(bcf1_t *b);
59         char *bcf_fmt(const bcf_hdr_t *h, bcf1_t *b);
60
61         bcf_t *vcf_open(const char *fn, const char *mode);
62         int vcf_close(bcf_t *bp);
63         bcf_hdr_t *vcf_hdr_read(bcf_t *bp);
64         int vcf_hdr_write(bcf_t *bp, const bcf_hdr_t *h);
65         int vcf_write(bcf_t *bp, bcf_hdr_t *h, bcf1_t *b);
66         int vcf_read(bcf_t *bp, bcf_hdr_t *h, bcf1_t *b);
67
68         int bcf_shrink_alt(bcf1_t *b, int n);
69         int bcf_gl2pl(bcf1_t *b);
70
71         void *bcf_build_refhash(bcf_hdr_t *h);
72         void bcf_str2id_destroy(void *_hash);
73         int bcf_str2id_add(void *_hash, const char *str);
74         int bcf_str2id(void *_hash, const char *str);
75         void *bcf_str2id_init();
76
77         int bcf_idx_build(const char *fn);
78         uint64_t bcf_idx_query(const bcf_idx_t *idx, int tid, int beg);
79         int bcf_parse_region(void *str2id, const char *str, int *tid, int *begin, int *end);
80         bcf_idx_t *bcf_idx_load(const char *fn);
81         void bcf_idx_destroy(bcf_idx_t *idx);
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 static inline uint32_t bcf_str2int(const char *str, int l)
88 {
89         int i;
90         uint32_t x = 0;
91         for (i = 0; i < l && i < 4; ++i) {
92                 if (str[i] == 0) return x;
93                 x = x<<8 | str[i];
94         }
95         return x;
96 }
97
98 #endif