1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! The `u64` kmer boundary.
//!
//! These are the only functions in the crate that reinterpret encoded bytes
//! as `u64` values. The conversion is pinned to little-endian
//! (`u64::{from,to}_le_bytes`), so packed values are bit-identical on every
//! platform and to the values produced by bitnuc 0.4.x. On little-endian
//! targets the conversion compiles to a plain load/store.
use crate::;
/// Packs a sequence of up to 32 bases into a `u64`, 2 bits per base.
///
/// Base `i` occupies bits `2i..2i + 2` (`A=00`, `C=01`, `G=10`, `T=11`);
/// unused high bits are zero. Bases outside `ACGTacgt` map to an unspecified
/// code — see the [crate docs](crate#encoded-format).
///
/// # Errors
///
/// Returns [`BitnucError::SequenceTooLong`] if `seq` is longer than 32 bases.
///
/// # Examples
///
/// ```rust
/// let packed = bitnuc::as_2bit(b"ACGT")?;
/// assert_eq!(packed, 0b11100100);
/// # Ok::<(), bitnuc::BitnucError>(())
/// ```
/// Unpacks a 2-bit packed `u64` into a stack array of 32 ASCII bases.
///
/// All 32 positions decode; the caller slices to their sequence length.
/// Positions past the packed sequence decode the kmer's unused high bits,
/// i.e. `b'A'` for values produced by [`as_2bit`].
///
/// # Examples
///
/// ```rust
/// let packed = bitnuc::as_2bit(b"ACGT")?;
/// let unpacked = bitnuc::from_2bit(packed);
/// assert_eq!(&unpacked[..4], b"ACGT");
/// # Ok::<(), bitnuc::BitnucError>(())
/// ```