Skip to main content

poa_consensus/
config.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum AlignmentMode {
3    Global,
4    SemiGlobal,
5}
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ConsensusMode {
9    HeaviestPath,
10    MajorityFrequency,
11}
12
13#[derive(Debug, Clone)]
14pub struct PoaConfig {
15    /// 0 = unbanded (full NW over DAG). Warn if reads exceed ~1 kb and this is 0.
16    pub band_width: usize,
17    /// Enable adaptive band width using the abPOA formula: w = b + f*L.
18    pub adaptive_band: bool,
19    /// Base component of the adaptive band formula (abPOA default: 10).
20    pub adaptive_band_b: usize,
21    /// Length-proportional component of the adaptive band formula (abPOA default: 0.01).
22    pub adaptive_band_f: f32,
23    pub match_score: i32,
24    pub mismatch_score: i32,
25    /// One-time penalty when a gap opens. Negative.
26    pub gap_open: i32,
27    /// Per-base penalty inside a gap. Negative.
28    pub gap_extend: i32,
29    /// Fraction of reads that must cover a node for it to appear in consensus.
30    pub min_coverage_fraction: f64,
31    /// Minimum fraction of reads supporting an allele for bubble detection.
32    pub min_allele_freq: f64,
33    /// Minimum number of reads required to build a consensus.
34    pub min_reads: usize,
35    pub alignment_mode: AlignmentMode,
36    pub consensus_mode: ConsensusMode,
37    /// Emit a warning to stderr when reads exceed ~1 kb with band_width = 0.
38    pub warn_on_long_unbanded: bool,
39    /// Minimum arm span (nodes) for a bubble to be considered a structural variant
40    /// for cross-bubble phasing. Bubbles below this threshold (SNPs, short indels)
41    /// use the existing single-bubble partitioning. Default 10.
42    pub phasing_bubble_min_span: usize,
43    /// Whether this graph is being built for **multi-allele** consensus.
44    ///
45    /// Controls two mode-dependent behaviours whose correct setting differs
46    /// between single- and multi-allele consensus:
47    /// - the O(1) diagonal-skip fast path in alignment (kept in multi-allele
48    ///   mode to lock reads onto their own length-allele track; disabled in
49    ///   single-allele mode where its greedy forward-match over-calls periodic
50    ///   repeats by matching reads through phantom units), and
51    /// - the whole-graph unbanded rebuild on band-retry (needed only for
52    ///   multi-allele bubble-structure consistency).
53    ///
54    /// The functional wrappers set this automatically ([`consensus_multi`]
55    /// builds with it `true`; single-allele paths leave it `false`). Stateful
56    /// callers ([`PoaGraph::new`]) who intend to call
57    /// [`PoaGraph::consensus_multi`] should set it `true` so alignment is built
58    /// in multi-allele mode. Default: `false` (single-allele).
59    ///
60    /// [`consensus_multi`]: crate::consensus_multi
61    /// [`PoaGraph::new`]: crate::PoaGraph::new
62    /// [`PoaGraph::consensus_multi`]: crate::PoaGraph::consensus_multi
63    pub multi_allele: bool,
64}
65
66impl Default for PoaConfig {
67    fn default() -> Self {
68        PoaConfig {
69            band_width: 50,
70            adaptive_band: true,
71            adaptive_band_b: 10,
72            adaptive_band_f: 0.01,
73            match_score: 1,
74            mismatch_score: -1,
75            gap_open: -2,
76            gap_extend: -1,
77            min_coverage_fraction: 0.0,
78            min_allele_freq: 0.2,
79            min_reads: 1,
80            alignment_mode: AlignmentMode::SemiGlobal,
81            consensus_mode: ConsensusMode::HeaviestPath,
82            warn_on_long_unbanded: true,
83            phasing_bubble_min_span: 10,
84            multi_allele: false,
85        }
86    }
87}