Module bio::data_structures::bitenc[][src]

A fixed-width bit encoding implementation. This allows to store a sequence of values over a reduced alphabet by packing them bit-encoded into a sequence of bytes.

Similar behaviour can be achieved using a PackedVec from the packedvec crate.

Example

use bio::data_structures::bitenc::BitEnc;
let mut bitenc = BitEnc::new(2);
bitenc.push(0);
bitenc.push(2);
bitenc.push(1);
let values: Vec<u8> = bitenc.iter().collect();
assert_eq!(values, [0, 2, 1]);

BitEnc can be used in combination with alphabets::RankTransform to generate rank-encoded values, like 2-bit encoded DNA bases, and store these using BitEnc.

use bio::alphabets;
use bio::data_structures::bitenc::BitEnc;

let dna_alphabet = alphabets::Alphabet::new(b"ACGT");
let dna_ranks = alphabets::RankTransform::new(&dna_alphabet);

// Compute the number of bits required for the largest rank
let mut bit_enc = BitEnc::new(dna_ranks.get_width());

let text = b"GATTACA";
assert_eq!(dna_ranks.transform(text), [2, 0, 3, 3, 0, 1, 0]);

Structs

BitEnc

A sequence of bitencoded values.

BitEncIter

Iterator over values of a bitencoded sequence (values will be unpacked into bytes). Used to implement the iter method of BitEnc.