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

Optional alignment fields, called auxiliary tags.

A tag name is a two-byte binary taken from the file. This module does not
convert that name to an atom. The type code stays a one-byte binary as
well: `A`, `c`, `C`, `s`, `S`, `i`, `I`, `f`, `Z`, `H`, or `B`.

Numeric and float values keep the little-endian bytes from the file in
`:raw` so a BAM round trip does not re-encode a float and change its bits.
Array values are `%{element_type: type, values: list}`.

SAM text writes integers with type `i` and lets the BAM encoder pick the
narrowest integer code that fits.

# `array`

```elixir
@type array() :: %{element_type: &lt;&lt;_::8&gt;&gt;, values: [number()]}
```

# `t`

```elixir
@type t() :: %BAM.Tag{
  name: &lt;&lt;_::16&gt;&gt;,
  raw: binary() | nil,
  type: &lt;&lt;_::8&gt;&gt;,
  value: term()
}
```

# `decode`

```elixir
@spec decode(binary(), BAM.Limits.t(), :strict | :permissive) ::
  {:ok, [t()]} | {:error, BAM.Error.t()}
```

Decodes the auxiliary blob that follows the qualities in one BAM record.

# `encode`

```elixir
@spec encode([t()]) :: {:ok, binary()} | {:error, BAM.Error.t()}
```

Encodes tags into a BAM auxiliary blob.

# `format_sam`

```elixir
@spec format_sam(t()) :: {:ok, binary()} | {:error, BAM.Error.t()}
```

Formats one tag as a SAM optional field.

# `parse_sam`

```elixir
@spec parse_sam(binary()) :: {:ok, t()} | {:error, BAM.Error.t()}
```

Parses one SAM optional field, such as `NM:i:2` or `XA:B:i,1,2`.

# `smallest_integer`

```elixir
@spec smallest_integer(integer()) :: &lt;&lt;_::8&gt;&gt;
```

Chooses the narrowest BAM integer code for a SAM `i` value.

---

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