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
impl Header
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Returns a builder to create a SAM header.
§Examples
use noodles_sam as sam;
let builder = sam::Header::builder();
sourcepub fn header(&self) -> Option<&Map<Header>>
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());
sourcepub fn header_mut(&mut self) -> &mut Option<Map<Header>>
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));
sourcepub fn reference_sequences(&self) -> &ReferenceSequences
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"[..]));
sourcepub fn reference_sequences_mut(&mut self) -> &mut ReferenceSequences
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"[..]));
sourcepub fn read_groups(&self) -> &ReadGroups
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"[..]));
sourcepub fn read_groups_mut(&mut self) -> &mut ReadGroups
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"[..]));
sourcepub fn programs(&self) -> &Programs
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"[..]));
sourcepub fn programs_mut(&mut self) -> &mut Programs
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"[..]));
sourcepub fn comments(&self) -> &[BString]
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")]);
sourcepub fn comments_mut(&mut self) -> &mut Vec<BString>
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")]);
sourcepub fn add_comment<C>(&mut self, comment: C)
pub fn add_comment<C>(&mut self, comment: C)
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")]);
Trait Implementations§
source§impl FromStr for Header
impl FromStr for Header
source§fn from_str(s: &str) -> Result<Self, Self::Err>
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());
§type Err = ParseError
type Err = ParseError
source§impl PartialEq for Header
impl PartialEq for Header
impl Eq for Header
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.