Skip to main content

mafft_types/
seq.rs

1/// The type of biological sequences being aligned.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum SeqType {
4    Protein,
5    Dna,
6    Rna,
7    Text,
8    Unknown,
9}
10
11impl SeqType {
12    /// Convert from the C `dorp` global variable convention.
13    /// 'd' = DNA/RNA, 'p' = Protein, NOTSPECIFIED = Unknown.
14    pub fn from_dorp(dorp: i32) -> Self {
15        match dorp as u8 {
16            b'd' => Self::Dna,
17            b'p' => Self::Protein,
18            _ => Self::Unknown,
19        }
20    }
21
22    pub fn is_nucleotide(self) -> bool {
23        matches!(self, Self::Dna | Self::Rna)
24    }
25}
26
27/// A named biological sequence.
28#[derive(Debug, Clone)]
29pub struct Sequence {
30    pub name: String,
31    pub data: Vec<u8>,
32}
33
34impl Sequence {
35    pub fn len(&self) -> usize {
36        self.data.len()
37    }
38
39    pub fn is_empty(&self) -> bool {
40        self.data.is_empty()
41    }
42}
43
44/// A collection of sequences to be aligned.
45#[derive(Debug, Clone)]
46pub struct SequenceSet {
47    pub sequences: Vec<Sequence>,
48    pub seq_type: SeqType,
49}
50
51impl SequenceSet {
52    pub fn new(seq_type: SeqType) -> Self {
53        Self {
54            sequences: Vec::new(),
55            seq_type,
56        }
57    }
58
59    pub fn nseq(&self) -> usize {
60        self.sequences.len()
61    }
62
63    pub fn max_len(&self) -> usize {
64        self.sequences.iter().map(|s| s.len()).max().unwrap_or(0)
65    }
66}
67
68/// An RNA base pair probability.
69///
70/// Replaces the C `RNApair` struct.
71#[derive(Debug, Clone, Copy)]
72pub struct RnaBasePair {
73    pub up_pos: i32,
74    pub up_score: f64,
75    pub down_pos: i32,
76    pub down_score: f64,
77    pub best_pos: i32,
78    pub best_score: f64,
79}
80
81impl Default for RnaBasePair {
82    fn default() -> Self {
83        Self {
84            up_pos: -1,
85            up_score: 0.0,
86            down_pos: -1,
87            down_score: 0.0,
88            best_pos: -1,
89            best_score: 0.0,
90        }
91    }
92}