Struct noodles_sam::header::Header

source ·
pub struct Header { /* private fields */ }
Expand description

A SAM header.

Records are grouped by their types: header, reference sequence, read group, program, and comment.

Implementations§

source§

impl Header

source

pub fn builder() -> Builder

Returns a builder to create a SAM header.

§Examples
use noodles_sam as sam;
let builder = sam::Header::builder();
source

pub fn header(&self) -> Option<&Map<Header>>

Returns the SAM header header if it is set.

§Examples
use noodles_sam::{
    self as sam,
    header::record::value::{map::Header, Map},
};

let header = sam::Header::default();
assert!(header.header().is_none());

let header = sam::Header::builder()
    .set_header(Map::<Header>::default())
    .build();

assert!(header.header().is_some());
source

pub fn header_mut(&mut self) -> &mut Option<Map<Header>>

Returns a mutable reference to the SAM header header if it is set.

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

let mut header = sam::Header::default();
assert!(header.header().is_none());

let hd = Map::<map::Header>::default();
*header.header_mut() = Some(hd.clone());
assert_eq!(header.header(), Some(&hd));
source

pub fn reference_sequences(&self) -> &ReferenceSequences

Returns the SAM header reference sequences.

This is also called the reference sequence dictionary.

§Examples
use std::num::NonZeroUsize;

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

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

let reference_sequences = header.reference_sequences();
assert_eq!(reference_sequences.len(), 1);
assert!(reference_sequences.contains_key(&b"sq0"[..]));
source

pub fn reference_sequences_mut(&mut self) -> &mut ReferenceSequences

Returns a mutable reference to the SAM header reference sequences.

This is also called the reference sequence dictionary.

§Examples
use std::num::NonZeroUsize;

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

let mut header = sam::Header::default();

header.reference_sequences_mut().insert(
    String::from("sq0").into(),
    Map::<ReferenceSequence>::new(NonZeroUsize::try_from(13)?),
);

let reference_sequences = header.reference_sequences();
assert_eq!(reference_sequences.len(), 1);
assert!(reference_sequences.contains_key(&b"sq0"[..]));
source

pub fn read_groups(&self) -> &ReadGroups

Returns the SAM header read groups.

§Examples
use noodles_sam::{
    self as sam,
    header::record::value::{map::ReadGroup, Map},
};

let header = sam::Header::builder()
    .add_read_group("rg0", Map::<ReadGroup>::default())
    .build();

let read_groups = header.read_groups();
assert_eq!(read_groups.len(), 1);
assert!(read_groups.contains_key(&b"rg0"[..]));
source

pub fn read_groups_mut(&mut self) -> &mut ReadGroups

Returns a mutable reference to the SAM header read groups.

§Examples
use noodles_sam::{
    self as sam,
    header::record::value::{map::ReadGroup, Map},
};

let mut header = sam::Header::default();
assert!(header.read_groups().is_empty());

let read_group = Map::<ReadGroup>::default();
header.read_groups_mut().insert(String::from("rg0").into(), read_group);

let read_groups = header.read_groups();
assert_eq!(read_groups.len(), 1);
assert!(read_groups.contains_key(&b"rg0"[..]));
source

pub fn programs(&self) -> &Programs

Returns the SAM header programs.

§Examples
use noodles_sam::{self as sam, header::record::value::{map::Program, Map}};

let program = Map::<Program>::default();
let header = sam::Header::builder().add_program("noodles-sam", program).build();

let programs = header.programs();
assert_eq!(programs.len(), 1);
assert!(programs.contains_key(&b"noodles-sam"[..]));
source

pub fn programs_mut(&mut self) -> &mut Programs

Returns a mutable reference to the SAM header programs.

§Examples
use noodles_sam::{self as sam, header::record::value::{map::Program, Map}};

let mut header = sam::Header::default();

let program = Map::<Program>::default();
header.programs_mut().insert(String::from("noodles-sam").into(), program);

let programs = header.programs();
assert_eq!(programs.len(), 1);
assert!(programs.contains_key(&b"noodles-sam"[..]));
source

pub fn comments(&self) -> &[BString]

Returns the SAM header comments.

§Examples
use bstr::BString;
use noodles_sam as sam;
let header = sam::Header::builder().add_comment("noodles-sam").build();
let comments = header.comments();
assert_eq!(header.comments(), [BString::from("noodles-sam")]);
source

pub fn comments_mut(&mut self) -> &mut Vec<BString>

Returns a mutable reference to the SAM header comments.

To simply append a comment record, consider using Self::add_comment instead.

§Examples
use bstr::BString;
use noodles_sam as sam;
let mut header = sam::Header::default();
header.comments_mut().push(BString::from("noodles-sam"));
assert_eq!(header.comments(), [BString::from("noodles-sam")]);
source

pub fn add_comment<C>(&mut self, comment: C)
where C: Into<BString>,

Adds a comment.

§Examples
use bstr::BString;
use noodles_sam as sam;
let mut header = sam::Header::default();
header.add_comment("noodles-sam");
assert_eq!(header.comments(), [BString::from("noodles-sam")]);
source

pub fn is_empty(&self) -> bool

Returns whether there are no records in this SAM header.

§Examples
use noodles_sam as sam;

let header = sam::Header::default();
assert!(header.is_empty());

let header = sam::Header::builder().add_comment("noodles-sam").build();
assert!(!header.is_empty());
source

pub fn clear(&mut self)

Removes all records from the header.

§Examples
use noodles_sam as sam;

let mut header = sam::Header::builder().add_comment("ndls").build();
assert!(!header.is_empty());

header.clear();
assert!(header.is_empty());

Trait Implementations§

source§

impl Clone for Header

source§

fn clone(&self) -> Header

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Header

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Header

source§

fn default() -> Header

Returns the “default value” for a type. Read more
source§

impl FromStr for Header

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a raw SAM header.

§Examples
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().is_empty());
assert!(header.comments().is_empty());
§

type Err = ParseError

The associated error which can be returned from parsing.
source§

impl PartialEq for Header

source§

fn eq(&self, other: &Header) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Header

source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more