noodles_sam

Module header

Source
Expand description

SAM header.

A SAM header is a list of header records. There are four map-like record types (header (HD), reference sequence (SQ), read group (RG), and program (PG)) and one string type (comment (CO)).

Records are optional, which means an empty header is considered a valid SAM header.

If there is a header (HD) record, it must appear as the first record.

Reference sequence, read group, and program records are maps of records with unique identifiers. Comments are a list of strings. Reference sequences must be ordered; whereas read groups, programs, and comments can be unordered. (sam::Header defines them to be ordered.)

§Examples

§Parse a SAM header

use noodles_sam as sam;

let s = "\
@HD\tVN:1.6\tSO:coordinate
@SQ\tSN:sq0\tLN:8
@SQ\tSN:sq1\tLN:13
";

let header: sam::Header = s.parse()?;

assert!(header.header().is_some());
assert_eq!(header.reference_sequences().len(), 2);
assert!(header.read_groups().is_empty());
assert!(header.programs().as_ref().is_empty());
assert!(header.comments().is_empty());

§Create a SAM header

use std::num::NonZeroUsize;

use noodles_sam::{
    self as sam,
    header::record::value::{map::ReferenceSequence, Map},
};

let header = sam::Header::builder()
    .set_header(Default::default())
    .add_reference_sequence(
        "sq0",
        Map::<ReferenceSequence>::new(NonZeroUsize::try_from(8)?),
    )
    .add_reference_sequence(
        "sq1",
        Map::<ReferenceSequence>::new(NonZeroUsize::try_from(13)?),
    )
    .build();

assert!(header.header().is_some());
assert_eq!(header.reference_sequences().len(), 2);
assert!(header.read_groups().is_empty());
assert!(header.programs().as_ref().is_empty());
assert!(header.comments().is_empty());

Re-exports§

Modules§

Structs§

Enums§

  • An error returned when a raw SAM header fails to parse.

Type Aliases§