noodles_sam::header

Struct 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.as_ref().len(), 1);
assert!(programs.as_ref().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()
    .as_mut()
    .insert(String::from("noodles-sam").into(), program);

let programs = header.programs();
assert_eq!(programs.as_ref().len(), 1);
assert!(programs.as_ref().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().as_ref().is_empty());
assert!(header.comments().is_empty());
Source§

type Err = ParseError

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

impl PartialEq for Header

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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,

Source§

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>,

Source§

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>,

Source§

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.