CRAM.Header (cram v0.1.0)

Copy Markdown View Source

SAM header text stored in a CRAM file, plus the fields this library reads.

Unknown header lines are kept as binaries in other. Tag names from the file stay strings. They are never turned into atoms.

Summary

Types

t()

A parsed SAM header.

Functions

Parse SAM header text.

Types

t()

@type t() :: %CRAM.Header{
  comments: [String.t()],
  other: [binary()],
  programs: [map()],
  raw: binary(),
  read_groups: [map()],
  sequences: [CRAM.Header.Sequence.t()],
  sort_order: String.t() | nil,
  version: String.t() | nil
}

A parsed SAM header.

  • :raw — the header text that was parsed

  • :version — @HD VN, or nil

  • :sort_order — @HD SO, or nil

  • :sequences — @SQ lines, in file order

  • :read_groups — @RG lines as string-keyed maps

  • :programs — @PG lines as string-keyed maps

  • :comments — @CO text, without the type tag

  • :other — lines this parser does not classify

    iex> {:ok, header} = CRAM.Header.parse("@HD\tVN:1.6\n") iex> header.version "1.6"

Functions

parse(text)

@spec parse(binary()) :: {:ok, t()} | {:error, CRAM.Error.t()}

Parse SAM header text.

Returns {:ok, header}. An @SQ line without LN is reason: :bad_header. An LN that is not a non-negative integer is the same reason. Tag names stay strings. Does not raise.

iex> text = "@HD\tVN:1.6\tSO:unsorted\n@SQ\tSN:sq0\tLN:8\tM5:be19336b7e15968f7ac7dc82493d9cd8\n"
iex> {:ok, header} = CRAM.Header.parse(text)
iex> hd(header.sequences).name
"sq0"
iex> {:error, missing} = CRAM.Header.parse("@SQ\tSN:sq0\n")
iex> missing.detail
"@SQ line is missing LN"
iex> {:error, bad} = CRAM.Header.parse("@SQ\tSN:sq0\tLN:x\n")
iex> bad.detail
"@SQ LN is not a non-negative integer"