Packed BAM sequence codec.
Each base is a nibble. The high nibble of a byte is the earlier base.
The alphabet, in nibble order, is =ACMGRSVTWYHKDBN. A sequence whose
length is odd stores a zero in the final low nibble.
The decoded value is an uppercase binary. Encoding accepts the same alphabet in either case. Any other byte is rejected. The packed form is kept on the alignment so a round trip does not have to repack.
Summary
Functions
The 16 codes in nibble order.
Decodes byte_size bytes of packed sequence into length bases.
Packs a base string. An empty string packs to an empty binary, which is
how BAM stores a missing sequence (*).
Functions
@spec alphabet() :: String.t()
The 16 codes in nibble order.
@spec decode(binary(), non_neg_integer()) :: {:ok, binary()} | {:error, BAM.Error.t()}
Decodes byte_size bytes of packed sequence into length bases.
Examples
iex> BAM.Sequence.decode(<<0x12, 0x40>>, 3)
{:ok, "ACG"}
@spec encode(binary()) :: {:ok, binary()} | {:error, BAM.Error.t()}
Packs a base string. An empty string packs to an empty binary, which is
how BAM stores a missing sequence (*).
Examples
iex> BAM.Sequence.encode("ACG")
{:ok, <<0x12, 0x40>>}