BAM.Tag (BAM v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

Encodes tags into a BAM auxiliary blob.

Formats one tag as a SAM optional field.

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

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

Types

array()

@type array() :: %{element_type: <<_::8>>, values: [number()]}

t()

@type t() :: %BAM.Tag{
  name: <<_::16>>,
  raw: binary() | nil,
  type: <<_::8>>,
  value: term()
}

Functions

decode(blob, limits, mode \\ :strict)

@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(tags)

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

Encodes tags into a BAM auxiliary blob.

format_sam(tag)

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

Formats one tag as a SAM optional field.

parse_sam(arg1)

@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(value)

@spec smallest_integer(integer()) :: <<_::8>>

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