Debian Codegraph @

bcftools/call.h

raw symbols SCIP
1 /* call.h -- variant calling declarations.
2
3 Copyright (C) 2013-2015, 2019-2020 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 __CALL_H__
26 #define __CALL_H__
27
28 #include <htslib/vcf.h>
29 #include <htslib/synced_bcf_reader.h>
30 #include "vcmp.h"
31
32 #define CALL_KEEPALT 1
33 #define CALL_VARONLY (1<<1)
34 #define CALL_CONSTR_TRIO (1<<2)
35 #define CALL_CONSTR_ALLELES (1<<3)
36 #define CALL_KEEP_UNSEEN (1<<4)
37 #define CALL_FMT_PV4 (1<<5)
38 #define CALL_FMT_GQ (1<<6)
39 #define CALL_FMT_GP (1<<7)
40
41 #define FATHER 0
42 #define MOTHER 1
43 #define CHILD 2
44 typedef struct
45 {
46 char *name;
47 int sample[3]; // father, mother, child
48 int type; // see FTYPE_* definitions in mcall.c
49 }
50 family_t;
51
52 // For the single-sample and grouped -G calling
53 typedef struct
54 {
55 double ref_lk, max_lk, lk_sum;
56 float *qsum; // QS(quality sum) values
57 int nqsum;
58 uint32_t *smpl, nsmpl;
59 uint32_t nals, als;
60 }
61 smpl_grp_t;
62
63 // For the `-C alleles -i` constrained calling
64 typedef struct
65 {
66 uint32_t n:31, used:1;
67 char **allele;
68 }
69 tgt_als_t;
70
71 typedef struct _ccall_t ccall_t;
72 typedef struct
73 {
74 // mcall only
75 int npdg;
76 int *als_map, nals_map; // mapping from full set of alleles to trimmed set of alleles (old -> new)
77 int *pl_map, npl_map; // same as above for PLs, but reverse (new -> old)
78 char **als; // array to hold the trimmed set of alleles to appear on output
79 int nals; // size of the als array
80 int als_new, nals_new; // bitmask with final alleles and their number
81 family_t *fams; // list of families and samples for trio calling
82 int nfams, mfams;
83 int ntrio[5][5]; // possible trio genotype combinations and their counts; first idx:
84 uint16_t *trio[5][5]; // family type, second index: allele count (2-4, first two are unused)
85 double *GLs;
86 float *GPs; // FORMAT/GP: posterior probabilities
87 int32_t *GQs, *ADs; // FORMAT/GQ: genotype qualities; AD: allelic depth for -G
88 int32_t *itmp; // temporary int array, used for new PLs with CALL_CONSTR_ALLELES
89 int n_itmp, nGPs, nADs;
90 vcmp_t *vcmp;
91 double trio_Pm_SNPs, trio_Pm_del, trio_Pm_ins; // P(mendelian) for trio calling, see mcall_call_trio_genotypes()
92 int32_t *ugts, *cgts; // unconstraind and constrained GTs
93 uint32_t output_tags;
94 char *prior_AN, *prior_AC; // reference panel AF tags (AF=AC/AN)
95 tgt_als_t *tgt_als; // for CALL_CONSTR_ALLELES
96 char *sample_groups; // for single-sample or grouped calling with -G
97 char *sample_groups_tag; // for -G [AD|QS:]
98 smpl_grp_t *smpl_grp;
99 int nsmpl_grp;
100
101 // ccall only
102 double indel_frac, min_perm_p, min_lrt;
103 double prior_type, pref;
104 int ngrp1_samples, n_perm;
105 char *prior_file;
106 ccall_t *cdat;
107
108 // shared
109 bcf_srs_t *srs; // BCF synced readers holding target alleles for CALL_CONSTR_ALLELES
110 bcf1_t *rec;
111 bcf_hdr_t *hdr;
112 uint32_t flag; // One or more of the CALL_* flags defined above
113 uint8_t *ploidy, all_diploid, unseen;
114
115 double pl2p[256]; // PL to 10^(-PL/10) table
116 int32_t *PLs; // VCF PL likelihoods (rw)
117 int nPLs, mPLs, nac;
118 int32_t *gts, *ac; // GTs and AC (w)
119 double *pdg; // PLs converted to P(D|G)
120 float *anno16; int n16; // see anno[16] in bam2bcf.h
121 double theta; // prior
122 }
123 call_t;
124
125 void error(const char *format, ...);
126
127 /*
128 * call() - return -1 value on critical error; -2 to skip the site; or the number of alleles on success
129 */
130 int mcall(call_t *call, bcf1_t *rec); // multiallic and rare-variant calling model
131 int ccall(call_t *call, bcf1_t *rec); // the default consensus calling model
132 int qcall(call_t *call, bcf1_t *rec); // QCall output
133
134 void mcall_init(call_t *call);
135 void ccall_init(call_t *call);
136 void qcall_init(call_t *call);
137
138 void mcall_destroy(call_t *call);
139 void ccall_destroy(call_t *call);
140 void qcall_destroy(call_t *call);
141
142 void call_init_pl2p(call_t *call);
143 uint32_t *call_trio_prep(int is_x, int is_son);
144
145 void init_allele_trimming_maps(call_t *call, int nals_ori, int als_out);
146 void mcall_trim_and_update_numberR(call_t *call, bcf1_t *rec, int nals_ori, int nals_new);
147
148 #endif