pub struct HeaderView { /* private fields */ }Implementations§
Source§impl HeaderView
impl HeaderView
Sourcepub unsafe fn from_ptr(inner: *mut bcf_hdr_t) -> Self
pub unsafe fn from_ptr(inner: *mut bcf_hdr_t) -> Self
Create a view from a raw pointer to a header.
§Safety
The caller must ensure that the header is initialized.
Sourcepub unsafe fn as_ptr(&self) -> *mut bcf_hdr_t
pub unsafe fn as_ptr(&self) -> *mut bcf_hdr_t
Get a pointer to the underlying raw header.
§Safety
The caller must ensure that the pointer is not used after this
HeaderView is dropped
Sourcepub fn sample_count(&self) -> u32
pub fn sample_count(&self) -> u32
Get the number of samples defined in the header.
Sourcepub fn sample_id(&self, sample: &[u8]) -> Option<usize>
pub fn sample_id(&self, sample: &[u8]) -> Option<usize>
Obtain id (column index) of given sample.
Returns None if sample is not present in header.
Sourcepub fn contig_count(&self) -> u32
pub fn contig_count(&self) -> u32
Get the number of contigs defined in the header.
pub fn rid2name(&self, rid: u32) -> Result<&[u8]>
Sourcepub fn name2rid(&self, name: &[u8]) -> Result<u32>
pub fn name2rid(&self, name: &[u8]) -> Result<u32>
Retrieve the (internal) chromosome identifier
§Examples
use rust_htslib::bcf::header::Header;
use rust_htslib::bcf::{Format, Writer};
let mut header = Header::new();
let contig_field = br#"##contig=<ID=foo,length=10>"#;
header.push_record(contig_field);
let mut vcf = Writer::from_stdout(&header, true, Format::Vcf).unwrap();
let header_view = vcf.header();
let rid = header_view.name2rid(b"foo").unwrap();
assert_eq!(rid, 0);
// try and retrieve a contig not in the header
let result = header_view.name2rid(b"bar");
assert!(result.is_err())§Errors
If name does not match a chromosome currently in the VCF header, returns Error::BcfUnknownContig
pub fn info_type(&self, tag: &[u8]) -> Result<(TagType, TagLength)>
pub fn format_type(&self, tag: &[u8]) -> Result<(TagType, TagLength)>
Sourcepub fn name_to_id(&self, id: &[u8]) -> Result<Id>
pub fn name_to_id(&self, id: &[u8]) -> Result<Id>
Convert string ID (e.g., for a FILTER value) to its numeric identifier.
Sourcepub fn id_to_name(&self, id: Id) -> Vec<u8> ⓘ
pub fn id_to_name(&self, id: Id) -> Vec<u8> ⓘ
Convert integer representing an identifier (e.g., a FILTER value) to its string
name.bam.
Sourcepub fn sample_to_id(&self, id: &[u8]) -> Result<Id>
pub fn sample_to_id(&self, id: &[u8]) -> Result<Id>
Convert string sample name to its numeric identifier.
Sourcepub fn id_to_sample(&self, id: Id) -> Vec<u8> ⓘ
pub fn id_to_sample(&self, id: Id) -> Vec<u8> ⓘ
Convert integer representing an contig to its name.
Sourcepub fn header_records(&self) -> Vec<HeaderRecord>
pub fn header_records(&self) -> Vec<HeaderRecord>
Return structured HeaderRecords.
Sourcepub fn empty_record(self: &Arc<Self>) -> Record
pub fn empty_record(self: &Arc<Self>) -> Record
Create an empty record using this header view.
The record can be reused multiple times.