packed-seq
A library for constructing and iterating packed PackedSeq DNA sequences that
handles the encoding, decoding, and complements of packed bases.
ASCII ACTG representations of DNA and general ASCII text are also supported via the Seq trait.
Fast SIMD-based iteration over sequences is supported by splitting the sequence into 8 (slightly overlapping) chunks and iterating those in parallel in a memory-efficient way.
The underlying algorithm is described in the following
preprint on
simd-minimizers, for which this
crate was developed:
- SimdMinimizers: Computing random minimizers, fast. Ragnar Groot Koerkamp, Igor Martayan bioRxiv 2025.01.27 doi.org/10.1101/2025.01.27.634998
Requirements
This library supports AVX2 and NEON instruction sets.
Make sure to set RUSTFLAGS="-C target-cpu=native" when compiling to use the instruction sets available on your architecture.
RUSTFLAGS="-C target-cpu=native" cargo run --release
Usage example
Full documentation can be found on docs.rs.
use ;
// Plain ASCII sequence.
let seq = b"ACTGCAGCGCATATGTAGT";
// ASCII DNA sequence.
let ascii_seq = from_ascii;
// Packed DNA sequence.
let packed_seq = from_ascii;
assert_eq!;
// Iterate the ASCII characters.
let characters: = seq.iter_bp.collect;
assert_eq!;
// Iterate the bases with 0..4 values.
let bases: = seq.iter.copied.map.collect;
assert_eq!;
let ascii_bases: = ascii_seq.as_slice.iter_bp.collect;
assert_eq!;
let packed_bases: = ascii_seq.as_slice.iter_bp.collect;
assert_eq!;
// Iterate over 8 chunks at the same time.
let seq = b"AAAACCTTGGTTACTG"; // plain ASCII sequence
// chunks: ^ ^ ^ ^ ^ ^ ^ ^
let = seq.as_slice.par_iter_bp;
let mut par_iter_u8 = par_iter.map;
assert_eq!;
assert_eq!;
assert_eq!;