BAM.Index.Builder (BAM v0.1.0)

Copy Markdown View Source

Builds a BAI or CSI binning index while a BAM file is written.

Records must arrive grouped by reference id and, within a reference, sorted by pos. Mapped records become chunks. A run of records that share a bin is one chunk, from the virtual offset of the first record to the virtual offset of the following record. Placed unmapped reads increment the reference's unmapped count and do not open a chunk. Reads with no reference increment n_no_coor.

The BAM bin field itself always uses the 14/5 scheme. A CSI builder may use another min_shift and depth for the index only.

Summary

Functions

Closes the last chunk at final_voff and returns an index with one slot per reference in the header.

New builder. :format is :bai or :csi. CSI defaults match BAI (min_shift 14, depth 5) unless overridden.

Accounts for one alignment whose first byte is at voff.

Types

t()

@type t() :: %BAM.Index.Builder{
  depth: term(),
  format: term(),
  last_pos: term(),
  last_ref: term(),
  min_shift: term(),
  n_no_coor: term(),
  open: term(),
  refs: term()
}

Functions

finish(builder, final_voff, reference_count)

@spec finish(t(), non_neg_integer(), non_neg_integer()) :: {:ok, BAM.Index.t()}

Closes the last chunk at final_voff and returns an index with one slot per reference in the header.

new(opts \\ [])

@spec new(keyword()) :: t()

New builder. :format is :bai or :csi. CSI defaults match BAI (min_shift 14, depth 5) unless overridden.

push(builder, alignment, voff)

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

Accounts for one alignment whose first byte is at voff.