]> git.donarmstrong.com Git - samtools.git/blob - bcftools/bcf.h
* added prelimiary VCF parser (not finished)
[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         int fmt, len; // len is the unit length
10         void *data;
11         // derived info: fmt, len
12 } bcf_ginfo_t;
13
14 typedef struct {
15         int32_t tid, pos;
16         uint32_t qual:8, l_str:24;
17         int m_str;
18         char *str, *ref, *alt, *flt, *info, *fmt; // fmt, ref, alt and info point to str
19         int n_gi, m_gi;
20         bcf_ginfo_t *gi;
21         int n_alleles;
22         // derived info: ref, alt, flt, info, fmt, n_gi, n_alleles
23 } bcf1_t;
24
25 typedef struct {
26         int32_t n_ref, n_smpl;
27         int32_t l_nm;
28         int32_t l_smpl;
29         int32_t l_txt;
30         char *name, *sname, *txt;
31         char **ns, **sns;
32         // derived info: n_ref, n_smpl, ns, sns
33 } bcf_hdr_t;
34
35 typedef struct {
36         int is_vcf;
37         void *v;
38         BGZF *fp;
39 } bcf_t;
40
41 struct __bcf_idx_t;
42 typedef struct __bcf_idx_t bcf_idx_t;
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48         bcf_t *bcf_open(const char *fn, const char *mode);
49         int bcf_close(bcf_t *b);
50         int bcf_read(bcf_t *bp, const bcf_hdr_t *h, bcf1_t *b);
51         int bcf_sync(int n_smpl, bcf1_t *b);
52         int bcf_write(bcf_t *bp, const bcf_hdr_t *h, const bcf1_t *b);
53         bcf_hdr_t *bcf_hdr_read(bcf_t *b);
54         int bcf_hdr_write(bcf_t *b, const bcf_hdr_t *h);
55         int bcf_hdr_sync(bcf_hdr_t *b);
56         void bcf_hdr_destroy(bcf_hdr_t *h);
57         int bcf_destroy(bcf1_t *b);
58         char *bcf_fmt(const bcf_hdr_t *h, bcf1_t *b);
59
60         int vcf_close(bcf_t *bp);
61
62         void *bcf_build_refhash(bcf_hdr_t *h);
63         void bcf_str2id_destroy(void *_hash);
64         int bcf_str2id(void *_hash, const char *str);
65
66         int bcf_idx_build(const char *fn);
67         uint64_t bcf_idx_query(const bcf_idx_t *idx, int tid, int beg, int end);
68         int bcf_parse_region(void *str2id, const char *str, int *tid, int *begin, int *end);
69         bcf_idx_t *bcf_idx_load(const char *fn);
70         void bcf_idx_destroy(bcf_idx_t *idx);
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif