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

BAM alignment-record codec.

The 32-bit `block_size` that precedes a record is the number of bytes that
follow it. Those bytes are the fixed core, the read name, the CIGAR words,
the packed sequence, the qualities, and the auxiliary tags. Each length is
checked against `block_size` before the corresponding slice is decoded.

`pos` and `next_pos` stay in the BAM coordinate system. Reference names are
filled from the header when the caller passes one.

# `decode`

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

Decodes one framed record. `binary` includes the leading `block_size`.

# `encode`

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

Encodes one alignment, including `block_size`.

The bin field is recomputed with the BAI `reg2bin` rule. A record whose
exclusive end passes `2^29` cannot store that bin in the 16-bit BAM field
and is rejected.

# `place`

```elixir
@spec place(BAM.Alignment.t(), BAM.Header.t()) ::
  {:ok, BAM.Alignment.t()} | {:error, BAM.Error.t()}
```

Fills reference ids and `end_pos` from the header.

A reference name wins over a default `ref_id` of `-1`. The index builder
uses this placement, because the alignment a caller constructs often has
a name and no id.

---

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