iirs/
constants.rs

1use std::collections::BTreeSet;
2
3pub const DEFAULT_MIN_LEN: usize = 10;
4pub const DEFAULT_MAX_LEN: usize = 100;
5pub const DEFAULT_MAX_GAP: usize = 100;
6pub const DEFAULT_MISMATCHES: usize = 0;
7
8pub const DEFAULT_INPUT_FILE: &str = "input.fasta";
9pub const DEFAULT_SEQ_NAME: &str = "seq0";
10pub const DEFAULT_OUTPUT_FILE: &str = "iirs.out";
11
12#[derive(clap::ValueEnum, Debug, Clone, Default, PartialEq, Eq)]
13pub enum OutputFormat {
14    #[default]
15    Classic,
16    Csv,
17    Custom,
18}
19
20impl std::fmt::Display for OutputFormat {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        let fmted = match self {
23            Self::Classic => "classic",
24            Self::Csv => "csv",
25            Self::Custom => "custom",
26        };
27        write!(f, "{fmted}")
28    }
29}
30
31pub const IUPAC_SYMBOLS: &str = "acgturyswkmbdhvn*-";
32#[allow(dead_code)] // used in the tests
33pub const ALL_SYMBOLS: &str = "acgturyswkmbdhvn*-$#";
34pub const ALL_SYMBOLS_COUNT: usize = 20;
35const COMPLEMENT_RULES: [(char, char); 18] = [
36    ('a', 't'),
37    ('c', 'g'),
38    ('g', 'c'),
39    ('t', 'a'),
40    ('u', 'a'),
41    ('r', 'y'),
42    ('y', 'r'),
43    ('s', 's'),
44    ('w', 'w'),
45    ('k', 'm'),
46    ('m', 'k'),
47    ('b', 'v'),
48    ('d', 'h'),
49    ('h', 'd'),
50    ('v', 'b'),
51    ('n', 'n'),
52    ('*', 'n'),
53    ('-', 'n'),
54];
55const IUPAC_RULES: [(char, &str); 20] = [
56    ('a', "a"),
57    ('c', "c"),
58    ('g', "g"),
59    ('t', "t"),
60    ('u', "t"),
61    ('r', "ag"),
62    ('y', "ct"),
63    ('s', "gc"),
64    ('w', "at"),
65    ('k', "gt"),
66    ('m', "ac"),
67    ('b', "cgt"),
68    ('d', "agt"),
69    ('h', "act"),
70    ('v', "acg"),
71    ('n', "acgt"),
72    ('*', "acgt"),
73    ('-', "acgt"),
74    ('$', "$"),
75    ('#', "#"),
76];
77
78pub fn build_complement_array() -> [u8; 128] {
79    let mut complement: [u8; 128] = [0; 128];
80
81    for (key, value) in COMPLEMENT_RULES {
82        complement[key as usize] = value as u8;
83    }
84
85    complement
86}
87
88pub fn build_iupac_rules() -> Vec<(char, BTreeSet<char>)> {
89    IUPAC_RULES
90        .iter()
91        .map(|&(c, t)| (c, t.chars().collect::<BTreeSet<_>>()))
92        .collect()
93}
94
95mod tests {
96    #[test]
97    fn test_constants() {
98        assert_eq!(super::ALL_SYMBOLS.len(), super::ALL_SYMBOLS_COUNT);
99    }
100}