BAM.Cigar (BAM v0.1.0)

Copy Markdown View Source

CIGAR operations.

On disk, each BAM operation is a 32-bit little-endian word. The low 4 bits are the operation code and the high 28 bits are the length. This module keeps both the word (cigar_raw on an alignment) and the pair {op, length} where op is one of the nine characters defined by SAMv1:

CodeOpConsumes queryConsumes reference
0Myesyes
1Iyesno
2Dnoyes
3Nnoyes
4Syesno
5Hnono
6Pnono
7=yesyes
8Xyesyes

H and P do not appear in the SEQ field. Query length is M + I + S + = + X. Reference length is M + D + N + = + X. An empty operation list is the SAM sentinel *.

Summary

Functions

Decodes one BAM word.

Encodes one operation as a BAM word.

Formats operations as a SAM CIGAR string. An empty list is *.

Operation character for a BAM code, or nil.

Parses a SAM CIGAR string. * is an empty list.

Query bases consumed by the operations. Hard clipping and padding are excluded.

Reference bases consumed by the operations.

Types

op()

@type op() :: String.t()

operation()

@type operation() :: {op(), non_neg_integer()}

Functions

decode_word(word)

@spec decode_word(non_neg_integer()) :: {:ok, operation()} | :error

Decodes one BAM word.

Examples

iex> BAM.Cigar.decode_word(0xA0)
{:ok, {"M", 10}}

iex> BAM.Cigar.decode_word(0xF)
:error

encode_word(arg1)

@spec encode_word(operation()) :: {:ok, non_neg_integer()} | {:error, BAM.Error.t()}

Encodes one operation as a BAM word.

Examples

iex> BAM.Cigar.encode_word({"M", 10})
{:ok, 0xA0}

format(ops)

@spec format([operation()]) :: String.t()

Formats operations as a SAM CIGAR string. An empty list is *.

Examples

iex> BAM.Cigar.format([{"M", 8}, {"D", 2}])
"8M2D"

op(code)

@spec op(non_neg_integer()) :: op() | nil

Operation character for a BAM code, or nil.

parse(text)

@spec parse(String.t()) :: {:ok, [operation()]} | {:error, BAM.Error.t()}

Parses a SAM CIGAR string. * is an empty list.

Examples

iex> BAM.Cigar.parse("8M2I4M")
{:ok, [{"M", 8}, {"I", 2}, {"M", 4}]}

iex> BAM.Cigar.parse("*")
{:ok, []}

query_length(ops)

@spec query_length([operation()]) :: non_neg_integer()

Query bases consumed by the operations. Hard clipping and padding are excluded.

reference_length(ops)

@spec reference_length([operation()]) :: non_neg_integer()

Reference bases consumed by the operations.