Skip to main content

encode_sequence

Function encode_sequence 

Source
pub fn encode_sequence<T: AsRef<[u8]>>(
    sequence: T,
    alphabet: &Alphabet,
) -> Vec<u8> 
Expand description

Encodes a sequence using the specified encoding array.

This function takes a sequence of bytes and encodes it using the provided encoding array. The encoding is done by converting each byte in the sequence to its corresponding code in the encoding array, and then packing those codes into a byte array. The number of bits used to represent each symbol is specified by the bits_per_symbol parameter. The function returns a bit-packed vector of bytes containing the encoded sequence.

Bit Ordering: MSB-first (Most Significant Bit first)

Example with 2-bit DNA encoding (A=00, C=01, G=10, T=11):

  • Sequence “ACGT” → byte 0x1B (00011011)
  • A (00) in bits 7-6, C (01) in bits 5-4, G (10) in bits 3-2, T (11) in bits 1-0

§Arguments

  • sequence - The sequence to encode
  • alphabet - The alphabet defining the encoding

§Returns

A vector containing the encoded (bit-packed) sequence