bitnuc_mismatch/
lib.rs

1//! # bitnuc-mismatch
2//!
3//! This is a library for generating unambiguous one-off mismatches for bitnuc scalars.
4//! The library provides a function to generate all possible one-off mismatches for a given bitnuc scalar.
5//! The library also provides a function to build a mismatch table, which maps mismatches to their parent sequences.
6//! The library is designed to be used in the context of generating mismatches for a set of parent sequences while avoiding ambiguous mismatches.
7//! Ambiguous mismatches are mismatches that are within the one-off distance of multiple parent sequences.
8//!
9//! Note that parent sequences will be members of the mismatch table.
10//!
11//! ## Example
12//! ```rust
13//!
14//! use bitnuc_mismatch::build_mismatch_table;
15//!
16//! let parent_sequences = vec![
17//!     b"ACTG",
18//!     b"ACCG",
19//! ];
20//! let parent_scalars: Vec<u64> = parent_sequences
21//!     .into_iter()
22//!     .map(|seq| bitnuc::as_2bit(seq).unwrap())
23//!     .collect();
24//!
25//! let mismatch_table = build_mismatch_table(&parent_scalars, 4).unwrap();
26//!
27//! // Test some expected mismatches
28//! let gcta = bitnuc::as_2bit(b"GCTG").unwrap();
29//! assert_eq!(mismatch_table.get(&gcta), Some(&parent_scalars[0]));
30//!
31//! // Validate that unexpected mismatches are not present
32//! let acgg = bitnuc::as_2bit(b"ACGG").unwrap();
33//! assert!(mismatch_table.get(&acgg).is_none());
34//!
35//! // Validate that parent sequences are members of the mismatch table
36//! assert!(mismatch_table.contains_key(&parent_scalars[0]));
37//! assert!(mismatch_table.contains_key(&parent_scalars[1]));
38//! ```
39
40mod error;
41mod utils;
42
43pub use error::MismatchError;
44pub use utils::{build_mismatch_table, build_mismatch_table_with_ambiguous, generate_mismatches};
45
46/// Type alias for a mismatch table mapping mismatches to their parent sequences
47pub type MismatchTable = hashbrown::HashMap<BitSeqMut, BitSeq>;
48
49/// Type alias for a mismatch table mapping ambiguous mismatches to their parent sequences
50pub type AmbiguousMismatchTable = hashbrown::HashMap<BitSeqMut, Vec<BitSeq>>;
51
52/// Type alias for a bitnuc scalar sequence (child or parent sequence)
53pub type BitSeqMut = u64;
54
55/// Type alias for a bitnuc scalar sequence (parent sequence)
56pub type BitSeq = u64;