mafft_types/local_hom.rs
1/// A single local homology region between two sequences.
2///
3/// Replaces the C `LocalHom` linked-list node with a plain struct.
4/// Collections of these are stored in a `Vec` rather than a linked list.
5#[derive(Debug, Clone, PartialEq)]
6pub struct HomologyRegion {
7 /// Start position in sequence 1.
8 pub start1: i32,
9 /// End position in sequence 1.
10 pub end1: i32,
11 /// Start position in sequence 2.
12 pub start2: i32,
13 /// End position in sequence 2.
14 pub end2: i32,
15 /// Optimal alignment score for this region.
16 pub opt: f64,
17 /// Overlap in amino acids.
18 pub overlapaa: i32,
19 /// Whether this region was extended.
20 pub extended: bool,
21 /// Importance weight (used in consistency scoring).
22 pub importance: f64,
23 /// Reverse importance weight.
24 pub rimportance: f64,
25 /// 'k' (keep) or 'h' (homolog) classification.
26 pub korh: u8,
27 /// Remaining count.
28 pub nokori: i32,
29}
30
31impl Default for HomologyRegion {
32 fn default() -> Self {
33 Self {
34 start1: 0,
35 end1: 0,
36 start2: 0,
37 end2: 0,
38 opt: 0.0,
39 overlapaa: 0,
40 extended: false,
41 importance: 0.0,
42 rimportance: 0.0,
43 korh: b'h',
44 nokori: 0,
45 }
46 }
47}
48
49/// Table of pairwise local homology information.
50///
51/// Replaces the C `LocalHom **localhomtable` (njob x njob linked lists)
52/// with a flat map keyed by sequence pair indices.
53#[derive(Debug, Clone, Default)]
54pub struct LocalHomologyTable {
55 /// Number of sequences.
56 pub nseq: usize,
57 /// Homology regions for each pair (i, j) where i < j.
58 /// Indexed as `regions[i * nseq + j]`.
59 entries: Vec<Vec<HomologyRegion>>,
60}
61
62impl LocalHomologyTable {
63 pub fn new(nseq: usize) -> Self {
64 Self {
65 nseq,
66 entries: vec![Vec::new(); nseq * nseq],
67 }
68 }
69
70 /// Get homology regions between sequences i and j.
71 pub fn get(&self, i: usize, j: usize) -> &[HomologyRegion] {
72 &self.entries[i * self.nseq + j]
73 }
74
75 /// Get mutable homology regions between sequences i and j.
76 pub fn get_mut(&mut self, i: usize, j: usize) -> &mut Vec<HomologyRegion> {
77 &mut self.entries[i * self.nseq + j]
78 }
79
80 /// Add a homology region between sequences i and j.
81 pub fn push(&mut self, i: usize, j: usize, region: HomologyRegion) {
82 self.entries[i * self.nseq + j].push(region);
83 }
84}
85