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:
| Code | Op | Consumes query | Consumes reference |
|---|---|---|---|
| 0 | M | yes | yes |
| 1 | I | yes | no |
| 2 | D | no | yes |
| 3 | N | no | yes |
| 4 | S | yes | no |
| 5 | H | no | no |
| 6 | P | no | no |
| 7 | = | yes | yes |
| 8 | X | yes | yes |
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
@type op() :: String.t()
@type operation() :: {op(), non_neg_integer()}
Functions
@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
@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}
Formats operations as a SAM CIGAR string. An empty list is *.
Examples
iex> BAM.Cigar.format([{"M", 8}, {"D", 2}])
"8M2D"
@spec op(non_neg_integer()) :: op() | nil
Operation character for a BAM code, or nil.
@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, []}
@spec query_length([operation()]) :: non_neg_integer()
Query bases consumed by the operations. Hard clipping and padding are excluded.
@spec reference_length([operation()]) :: non_neg_integer()
Reference bases consumed by the operations.