| 1 | /* prob1.h -- mathematical utility functions. |
| 2 | |
| 3 | Copyright (C) 2010, 2011 Broad Institute. |
| 4 | Copyright (C) 2012, 2013-2014 Genome Research Ltd. |
| 5 | |
| 6 | Author: Heng Li <[email protected]> |
| 7 | |
| 8 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | of this software and associated documentation files (the "Software"), to deal |
| 10 | in the Software without restriction, including without limitation the rights |
| 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | copies of the Software, and to permit persons to whom the Software is |
| 13 | furnished to do so, subject to the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be included in |
| 16 | all copies or substantial portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | THE SOFTWARE. */ |
| 25 | |
| 26 | #ifndef BCF_PROB1_H |
| 27 | #define BCF_PROB1_H |
| 28 | |
| 29 | #include <htslib/vcf.h> |
| 30 | #include "call.h" |
| 31 | |
| 32 | typedef struct { |
| 33 | int n; // Number of samples |
| 34 | int M; // Total number of chromosomes across all samples (n*2 if all samples are diploid) |
| 35 | int n1; |
| 36 | int is_indel; |
| 37 | uint8_t *ploidy; // haploid or diploid ONLY |
| 38 | double *q2p, *pdg; // q2p maps from phread scaled to real likelihood, pdg -> P(D|g) |
| 39 | double *phi; // Probability of seeing k reference alleles |
| 40 | double *phi_indel; |
| 41 | double *z, *zswap; // aux for afs |
| 42 | double *z1, *z2, *phi1, *phi2; // only calculated when n1 is set |
| 43 | double **hg; // hypergeometric distribution |
| 44 | double *lf; // log factorial |
| 45 | double t, t1, t2; |
| 46 | double *afs, *afs1; // afs: accumulative allele frequency spectrum (AFS); afs1: site posterior distribution |
| 47 | const int *PL; // point to PL |
| 48 | int PL_len; |
| 49 | int cons_llr; // pair and trio calling |
| 50 | int64_t cons_gt; |
| 51 | } bcf_p1aux_t; |
| 52 | |
| 53 | typedef struct { |
| 54 | int rank0, perm_rank; // NB: perm_rank is always set to -1 by bcf_p1_cal() |
| 55 | int ac; // ML alternative allele count |
| 56 | double f_exp, f_flat, p_ref_folded, p_ref, p_var_folded, p_var; |
| 57 | double cil, cih; |
| 58 | double cmp[3], p_chi2, lrt; // used by contrast2() |
| 59 | } bcf_p1rst_t; |
| 60 | |
| 61 | typedef struct { |
| 62 | double p[4]; |
| 63 | double edb, mqb, bqb; // end distance bias, mapQ bias, baseQ bias |
| 64 | int mq, depth, is_tested, d[4]; |
| 65 | } anno16_t; |
| 66 | |
| 67 | #define MC_PTYPE_FULL 1 |
| 68 | #define MC_PTYPE_COND2 2 |
| 69 | #define MC_PTYPE_FLAT 3 |
| 70 | |
| 71 | #ifdef __cplusplus |
| 72 | extern "C" { |
| 73 | #endif |
| 74 | |
| 75 | bcf_p1aux_t *bcf_p1_init(int n_smpl, uint8_t *ploidy); |
| 76 | void bcf_p1_init_prior(bcf_p1aux_t *ma, int type, double theta); |
| 77 | void bcf_p1_init_subprior(bcf_p1aux_t *ma, int type, double theta); |
| 78 | void bcf_p1_destroy(bcf_p1aux_t *ma); |
| 79 | void bcf_p1_set_ploidy(bcf1_t *b, bcf_p1aux_t *ma); |
| 80 | int bcf_p1_cal(call_t *call, bcf1_t *b, int do_contrast, bcf_p1aux_t *ma, bcf_p1rst_t *rst); |
| 81 | int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k, int is_var); |
| 82 | void bcf_p1_dump_afs(bcf_p1aux_t *ma); |
| 83 | int bcf_p1_read_prior(bcf_p1aux_t *ma, const char *fn); |
| 84 | int bcf_p1_set_n1(bcf_p1aux_t *b, int n1); |
| 85 | void bcf_p1_set_folded(bcf_p1aux_t *p1a); // only effective when set_n1() is not called |
| 86 | |
| 87 | int bcf_em1(call_t *call, const bcf1_t *b, int n1, int flag, double x[10]); |
| 88 | |
| 89 | #ifdef __cplusplus |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | #endif |