You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

141 line
5.0 KiB

  1. /* bam2bcf.h -- variant calling.
  2. Copyright (C) 2010-2012 Broad Institute.
  3. Copyright (C) 2012-2014, 2019 Genome Research Ltd.
  4. Author: Heng Li <lh3@sanger.ac.uk>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  16. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. DEALINGS IN THE SOFTWARE. */
  20. #ifndef BAM2BCF_H
  21. #define BAM2BCF_H
  22. #include <stdint.h>
  23. #include <htslib/hts.h>
  24. #include <htslib/vcf.h>
  25. /**
  26. * A simplified version of Mann-Whitney U-test is calculated
  27. * by default (no CDF) because it is faster and seems to work
  28. * better in machine learning filtering. When enabled by setting
  29. * CDF_MWU_TESTS, additional annotations will appear on mpileup's
  30. * output (RPB2 in addition to RPB, etc.).
  31. */
  32. #ifndef CDF_MWU_TESTS
  33. #define CDF_MWU_TESTS 0
  34. #endif
  35. #define B2B_INDEL_NULL 10000
  36. #define B2B_FMT_DP (1<<0)
  37. #define B2B_FMT_SP (1<<1)
  38. #define B2B_FMT_DV (1<<2)
  39. #define B2B_FMT_DP4 (1<<3)
  40. #define B2B_FMT_DPR (1<<4)
  41. #define B2B_INFO_DPR (1<<5)
  42. #define B2B_FMT_AD (1<<6)
  43. #define B2B_FMT_ADF (1<<7)
  44. #define B2B_FMT_ADR (1<<8)
  45. #define B2B_INFO_AD (1<<9)
  46. #define B2B_INFO_ADF (1<<10)
  47. #define B2B_INFO_ADR (1<<11)
  48. #define B2B_MAX_ALLELES 5
  49. typedef struct __bcf_callaux_t {
  50. int capQ, min_baseQ;
  51. int openQ, extQ, tandemQ; // for indels
  52. uint32_t min_support, max_support; // for collecting indel candidates
  53. double min_frac; // for collecting indel candidates
  54. float max_frac; // for collecting indel candidates
  55. int per_sample_flt; // indel filtering strategy
  56. int *ref_pos, *alt_pos, npos, *ref_mq, *alt_mq, *ref_bq, *alt_bq, *fwd_mqs, *rev_mqs, nqual; // for bias tests
  57. // for internal uses
  58. int max_bases;
  59. int indel_types[4]; // indel lengths
  60. int maxins, indelreg;
  61. int read_len;
  62. char *inscns;
  63. uint16_t *bases; // 5bit: unused, 6:quality, 1:is_rev, 4:2-bit base or indel allele (index to bcf_callaux_t.indel_types)
  64. errmod_t *e;
  65. void *rghash;
  66. } bcf_callaux_t;
  67. typedef struct {
  68. uint32_t ori_depth;
  69. unsigned int mq0;
  70. int32_t *ADF, *ADR;
  71. float qsum[4];
  72. // The fields are:
  73. // depth fwd .. ref (0) and non-ref (2)
  74. // depth rev .. ref (1) and non-ref (3)
  75. // baseQ .. ref (4) and non-ref (6)
  76. // baseQ^2 .. ref (5) and non-ref (7)
  77. // mapQ .. ref (8) and non-ref (10)
  78. // mapQ^2 .. ref (9) and non-ref (11)
  79. // minDist .. ref (12) and non-ref (14)
  80. // minDist^2 .. ref (13) and non-ref (15)
  81. // Note that this probably needs a more thorough fix: int types in
  82. // bcf_call_t do overflow with high-coverage data, such as exomes, and
  83. // BCFv2 supports only floats which may not suffice.
  84. double anno[16];
  85. float p[25]; // phred-scaled likelihood of each genotype
  86. } bcf_callret1_t;
  87. typedef struct {
  88. int tid;
  89. hts_pos_t pos;
  90. bcf_hdr_t *bcf_hdr;
  91. int a[5]; // alleles: ref, alt, alt2, alt3
  92. float qsum[5]; // for the QS tag
  93. int n, n_alleles, shift, ori_ref, unseen;
  94. int n_supp; // number of supporting non-reference reads
  95. double anno[16];
  96. unsigned int depth, ori_depth, mq0;
  97. int32_t *PL, *DP4, *ADR, *ADF;
  98. uint8_t *fmt_arr;
  99. float vdb; // variant distance bias
  100. float mwu_pos, mwu_mq, mwu_bq, mwu_mqs;
  101. #if CDF_MWU_TESTS
  102. float mwu_pos_cdf, mwu_mq_cdf, mwu_bq_cdf, mwu_mqs_cdf;
  103. #endif
  104. float seg_bias;
  105. kstring_t tmp;
  106. } bcf_call_t;
  107. #ifdef __cplusplus
  108. extern "C" {
  109. #endif
  110. bcf_callaux_t *bcf_call_init(double theta, int min_baseQ);
  111. void bcf_call_destroy(bcf_callaux_t *bca);
  112. int bcf_call_glfgen(int _n, const bam_pileup1_t *pl, int ref_base, bcf_callaux_t *bca, bcf_callret1_t *r);
  113. int bcf_call_combine(int n, const bcf_callret1_t *calls, bcf_callaux_t *bca, int ref_base /*4-bit*/, bcf_call_t *call);
  114. int bcf_call2bcf(bcf_call_t *bc, bcf1_t *b, bcf_callret1_t *bcr, int fmt_flag,
  115. const bcf_callaux_t *bca, const char *ref);
  116. int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, hts_pos_t pos, bcf_callaux_t *bca, const char *ref,
  117. const void *rghash);
  118. void bcf_callaux_clean(bcf_callaux_t *bca, bcf_call_t *call);
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif