BAM.Record (BAM v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Decodes one framed record. binary includes the leading block_size.

Encodes one alignment, including block_size.

Fills reference ids and end_pos from the header.

Functions

decode(binary, header, limits, mode \\ :strict)

@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(alignment, header)

@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(alignment, header)

@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.