Debian Codegraph @

bcftools/filter.h

raw symbols SCIP
1 /* filter.h -- filter expressions.
2
3 Copyright (C) 2013-2024 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 #ifndef __FILTER_H__
26 #define __FILTER_H__
27
28 #include <htslib/vcf.h>
29
30 typedef struct _filter_t filter_t;
31
32 /**
33 * @hdr: BCF header file
34 * @str: see the bcftools filter command help for description.
35 * See also the extended usage described in filter_test_ext(),
36 * intended for programmatic access
37 * Same as filter_parse() but exits on errors
38 */
39 filter_t *filter_init(bcf_hdr_t *hdr, const char *str);
40
41 void filter_destroy(filter_t *filter);
42
43 /**
44 * filter_test() - test whether the BCF record passes the test
45 * @samples: if not NULL, a pointer to an array with samples statuses is
46 * stored in the location referenced by @samples. The pointer
47 * will be set to NULL if the FORMAT fields were not queried.
48 * Returns 1 if the expression is true and 0 if false.
49 */
50 int filter_test(filter_t *filter, bcf1_t *rec, const uint8_t **samples);
51
52 /**
53 * filter_test_ext() - same as filter_test(), but sets some of the terms
54 * on the fly. An expression initialized with, say,
55 * "STR_TAG={} | INT_TAG={} | FLT_TAG={}" takes three
56 * additional pointer arguments which are expected to point to memory
57 * area occupied by the appropriate type, see also filter_ext_types().
58 * The type determination is not fool-proof, in such case the type can
59 * be given explicitly as eg "TAG={str}".
60 * @ext: array of size 'n_ext' occupied with pointers to the data types
61 * inferred from the expression given at the time of initialization.
62 * The pointers set to NULL will be treated as if missing value "."
63 * was given.
64 * @n_ext: the size of 'ext' array
65 */
66 int filter_test_ext(filter_t *filter, bcf1_t *rec, const uint8_t **samples, const void **ext);
67
68 /**
69 * filter_set_samples() - restrict filtering expression to samples.
70 * Call after filter_init().
71 * @samples: use samples set to 1, ignore samples set 0
72 */
73 void filter_set_samples(filter_t *filter, const uint8_t *samples);
74
75 /**
76 * filter_get_doubles() - return a pointer to values from the last filter_test() evaluation
77 */
78 const double *filter_get_doubles(filter_t *filter, int *nval, int *nval1);
79
80 int filter_max_unpack(filter_t *filter);
81
82 /**
83 * filter_ext_types() - returns the number and BCF_HT_* types of external values
84 * found in the filtering expression
85 */
86 const int *filter_ext_types(filter_t *filter, int *n_ext);
87
88 /**
89 * Same as filter_init() but may not exit on some type of errors. The caller
90 * must check if the returned value is not NULL and if the consequent call
91 * of filter_status() returns FILTER_OK before the filter_pass() can be called.
92 */
93 filter_t *filter_parse(bcf_hdr_t *hdr, const char *str);
94
95 #define FILTER_OK 0
96 #define FILTER_ERR_UNKN_TAGS 1
97 #define FILTER_ERR_OTHER 2
98
99 /**
100 * Check if filter_parse() was successful
101 */
102 int filter_status(filter_t *filter);
103 const char **filter_list_undef_tags(filter_t *filter, int *nundef);
104 const char **filter_list_used_tags(filter_t *filter, int *nused);
105
106 #endif