# `BAM.Sequence`
[🔗](https://github.com/baoulo/bam-elixir/blob/v0.1.0/lib/bam/sequence.ex#L1)

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.

# `alphabet`

```elixir
@spec alphabet() :: String.t()
```

The 16 codes in nibble order.

# `decode`

```elixir
@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"}

# `encode`

```elixir
@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>>}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
