BAM.Alignment (BAM v0.1.0)

Copy Markdown View Source

One alignment record.

pos is the BAM coordinate: zero-based, or -1 when the segment has no position. SAM text uses a one-based POS, and writes 0 when the segment is unmapped. end_pos is the zero-based exclusive end used by region queries. It follows HTSlib bam_endpos: unmapped segments and CIGAR strings that consume no reference bases have length 1, so the exclusive end is pos + 1 when pos is not negative.

cigar_raw holds the 32-bit BAM words. sequence_raw and quality_raw hold the packed bases and the Phred bytes. Tag names stay binaries.

Summary

Functions

True when the alignment is mapped to ref_id and overlaps the half-open interval [start, stop). stop may be :end.

Fills end_pos from the flag, position, and CIGAR.

Zero-based exclusive reference end, or nil when pos is negative.

Types

t()

@type t() :: %BAM.Alignment{
  bin: non_neg_integer(),
  block_size: non_neg_integer() | nil,
  cigar: [BAM.Cigar.operation()],
  cigar_raw: [non_neg_integer()],
  end_pos: non_neg_integer() | nil,
  flag: non_neg_integer(),
  mapq: non_neg_integer(),
  next_pos: integer(),
  next_ref_id: integer(),
  next_reference: binary() | nil,
  pos: integer(),
  qname: binary(),
  quality_raw: binary(),
  ref_id: integer(),
  reference: binary() | nil,
  sequence: binary(),
  sequence_raw: binary(),
  tags: [BAM.Tag.t()],
  tlen: integer(),
  virtual_offset: non_neg_integer() | nil
}

Functions

overlaps?(alignment, ref_id, start, stop)

@spec overlaps?(t(), integer(), non_neg_integer(), non_neg_integer() | :end) ::
  boolean()

True when the alignment is mapped to ref_id and overlaps the half-open interval [start, stop). stop may be :end.

put_end(alignment)

@spec put_end(t()) :: t()

Fills end_pos from the flag, position, and CIGAR.

reference_end(alignment)

@spec reference_end(t()) :: non_neg_integer() | nil

Zero-based exclusive reference end, or nil when pos is negative.

Examples

iex> BAM.Alignment.reference_end(%BAM.Alignment{pos: 0, flag: 0, cigar: [{"M", 4}]})
4

iex> BAM.Alignment.reference_end(%BAM.Alignment{pos: 10, flag: 0, cigar: [{"I", 3}]})
11

iex> BAM.Alignment.reference_end(%BAM.Alignment{pos: -1, flag: 4, cigar: []})
nil