Debian Codegraph @

bcftools/tsv2vcf.h

raw symbols SCIP
1 /* tsv2vcf.h -- convert from whitespace-separated fields to VCF
2
3 Copyright (C) 2014-2021 Genome Research Ltd.
4
5 Author: Petr Danecek <[email protected]>
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25
26 #ifndef __TSV2VCF_H__
27 #define __TSV2VCF_H__
28
29 #include <htslib/vcf.h>
30
31 typedef struct _tsv_t tsv_t;
32 typedef int (*tsv_setter_t)(tsv_t *, bcf1_t *, void *);
33
34 typedef struct
35 {
36 char *name;
37 tsv_setter_t setter;
38 void *usr;
39 }
40 tsv_col_t;
41
42 struct _tsv_t
43 {
44 int ncols, icol;
45 tsv_col_t *cols;
46 char *se, *ss;
47 };
48
49 tsv_t *tsv_init(const char *str);
50 void tsv_destroy(tsv_t *tsv);
51 int tsv_register(tsv_t *tsv, const char *id, tsv_setter_t setter, void *usr);
52
53 /**
54 * tsv_parse() - parse tsv line and fill VCF record
55 * Returns 0 on success or -1 on parse error
56 */
57 int tsv_parse(tsv_t *tsv, bcf1_t *rec, char *str);
58
59 /**
60 * tstv_next() - position ss,se to next field; first pass with ss=se=str
61 * Returns 0 on success, or -1 if no more fields
62 */
63 static inline int tsv_next(tsv_t *tsv)
64 {
65 if ( !*tsv->se ) return -1;
66 if ( tsv->ss==tsv->se )
67 {
68 while ( *tsv->se && !isspace(*tsv->se) ) tsv->se++;
69 return 0;
70 }
71 while ( *tsv->se && isspace(*tsv->se) ) tsv->se++;
72 tsv->ss = tsv->se;
73 while ( *tsv->se && !isspace(*tsv->se) ) tsv->se++;
74 return 0;
75 }
76
77 /**
78 * The setters return 0 on success or negative value if the line is to be skipped.
79 */
80 int tsv_setter_chrom(tsv_t *tsv, bcf1_t *rec, void *usr);
81 int tsv_setter_pos(tsv_t *tsv, bcf1_t *rec, void *usr);
82 int tsv_setter_id(tsv_t *tsv, bcf1_t *rec, void *usr);
83 int tsv_setter_ref_alt(tsv_t *tsv, bcf1_t *rec, void *usr); // usr must point to bcf_hdr_t
84
85 #endif
86