Skip to main content

nlr_core/
strand.rs

1//! Strand enum.
2
3/// Strand: forward strand / reverse strand.
4///
5/// Whether a motif is on the forward or reverse strand.
6///
7/// Note: on both strands, `Motif.dna_start` is always leftmost and `dna_end` always rightmost
8/// (i.e. `dna_start < dna_end` always holds). The only special behavior of the reverse strand
9/// is that it is **sorted descending** (genomic coordinates decrease when reading in the
10/// translation direction N->C); the coordinates themselves are not inverted.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum Strand {
13    Forward,
14    Reverse,
15}
16
17impl Strand {
18    /// Construct from a boolean.
19    #[inline]
20    pub fn from_bool(forward: bool) -> Self {
21        if forward {
22            Strand::Forward
23        } else {
24            Strand::Reverse
25        }
26    }
27
28    /// Convert to boolean (true = forward strand).
29    #[inline]
30    pub fn is_forward(self) -> bool {
31        matches!(self, Strand::Forward)
32    }
33
34    /// Convert to output symbol `+` / `-`.
35    #[inline]
36    pub fn symbol(self) -> char {
37        match self {
38            Strand::Forward => '+',
39            Strand::Reverse => '-',
40        }
41    }
42}