pub struct Header { /* private fields */ }Expand description
A VCF header.
Implementations§
Source§impl Header
impl Header
Sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Returns a builder to create a record from each of its fields.
§Examples
use noodles_vcf as vcf;
let builder = vcf::Header::builder();Sourcepub fn file_format(&self) -> FileFormat
pub fn file_format(&self) -> FileFormat
Returns the file format (fileformat) of the VCF.
fileformat is a required meta record and is guaranteed to be set.
§Examples
use noodles_vcf::{self as vcf, header::FileFormat};
let header = vcf::Header::builder()
.set_file_format(FileFormat::default())
.build();
assert_eq!(header.file_format(), FileFormat::default());Sourcepub fn file_format_mut(&mut self) -> &mut FileFormat
pub fn file_format_mut(&mut self) -> &mut FileFormat
Returns a mutable reference to the file format (fileformat) of the VCF.
fileformat is a required meta record and is guaranteed to be set.
§Examples
use noodles_vcf::{self as vcf, header::FileFormat};
let mut header = vcf::Header::default();
let file_format = FileFormat::new(4, 2);
*header.file_format_mut() = file_format;
assert_eq!(header.file_format(), file_format);Sourcepub fn infos(&self) -> &IndexMap<String, Map<Info>>
pub fn infos(&self) -> &IndexMap<String, Map<Info>>
Returns a map of information records (INFO).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::Info, Map},
variant::record::info::field::key,
};
let id = key::SAMPLES_WITH_DATA_COUNT;
let info = Map::<Info>::from(id);
let header = vcf::Header::builder()
.add_info(id, info.clone())
.build();
let infos = header.infos();
assert_eq!(infos.len(), 1);
assert_eq!(&infos[0], &info);Sourcepub fn infos_mut(&mut self) -> &mut IndexMap<String, Map<Info>>
pub fn infos_mut(&mut self) -> &mut IndexMap<String, Map<Info>>
Returns a mutable reference to a map of information records (INFO).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::Info, Map},
variant::record::info::field::key,
};
let mut header = vcf::Header::default();
let id = key::SAMPLES_WITH_DATA_COUNT;
let info = Map::<Info>::from(id);
header.infos_mut().insert(id.into(), info.clone());
let infos = header.infos();
assert_eq!(infos.len(), 1);
assert_eq!(&infos[0], &info);Sourcepub fn filters(&self) -> &IndexMap<String, Map<Filter>>
pub fn filters(&self) -> &IndexMap<String, Map<Filter>>
Returns a map of filter records (FILTER).
§Examples
use noodles_vcf::{self as vcf, header::record::value::{map::Filter, Map}};
let filter = Map::<Filter>::new("Quality below 10");
let header = vcf::Header::builder()
.add_filter("q10", filter.clone())
.build();
let filters = header.filters();
assert_eq!(filters.len(), 1);
assert_eq!(&filters[0], &filter);Sourcepub fn filters_mut(&mut self) -> &mut IndexMap<String, Map<Filter>>
pub fn filters_mut(&mut self) -> &mut IndexMap<String, Map<Filter>>
Returns a mutable reference to a map of filter records (FILTER).
§Examples
use noodles_vcf::{self as vcf, header::record::value::{map::Filter, Map}};
let mut header = vcf::Header::default();
let filter = Map::<Filter>::new("Quality below 10");
header.filters_mut().insert(String::from("q10"), filter.clone());
let filters = header.filters();
assert_eq!(filters.len(), 1);
assert_eq!(&filters[0], &filter);Sourcepub fn formats(&self) -> &IndexMap<String, Map<Format>>
pub fn formats(&self) -> &IndexMap<String, Map<Format>>
Returns a list of genotype format records (FORMAT).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::Format, Map},
variant::record::samples::keys::key,
};
let id = key::GENOTYPE;
let format = Map::<Format>::from(id);
let header = vcf::Header::builder()
.add_format(id, format.clone())
.build();
let formats = header.formats();
assert_eq!(formats.len(), 1);
assert_eq!(&formats[0], &format);Sourcepub fn formats_mut(&mut self) -> &mut IndexMap<String, Map<Format>>
pub fn formats_mut(&mut self) -> &mut IndexMap<String, Map<Format>>
Returns a mutable reference to a list of genotype format records (FORMAT).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::Format, Map},
variant::record::samples::keys::key,
};
let mut header = vcf::Header::default();
let id = key::GENOTYPE;
let format = Map::<Format>::from(id);
header.formats_mut().insert(id.into(), format.clone());
let formats = header.formats();
assert_eq!(formats.len(), 1);
assert_eq!(&formats[0], &format);Sourcepub fn alternative_alleles(&self) -> &IndexMap<String, Map<AlternativeAllele>>
pub fn alternative_alleles(&self) -> &IndexMap<String, Map<AlternativeAllele>>
Returns a map of symbolic alternate alleles (ALT).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::AlternativeAllele, Map},
};
let alt = Map::<AlternativeAllele>::new("Deletion");
let header = vcf::Header::builder()
.add_alternative_allele("DEL", alt.clone())
.build();
let alternative_alleles = header.alternative_alleles();
assert_eq!(alternative_alleles.len(), 1);
assert_eq!(&alternative_alleles[0], &alt);Sourcepub fn alternative_alleles_mut(
&mut self,
) -> &mut IndexMap<String, Map<AlternativeAllele>>
pub fn alternative_alleles_mut( &mut self, ) -> &mut IndexMap<String, Map<AlternativeAllele>>
Returns a mutable reference to a map of symbolic alternate alleles (ALT).
§Examples
use noodles_vcf::{
self as vcf,
header::record::value::{map::AlternativeAllele, Map},
};
let mut header = vcf::Header::default();
let alt = Map::<AlternativeAllele>::new("Deletion");
header.alternative_alleles_mut().insert(String::from("DEL"), alt.clone());
let alternative_alleles = header.alternative_alleles();
assert_eq!(alternative_alleles.len(), 1);
assert_eq!(&alternative_alleles[0], &alt);Sourcepub fn contigs(&self) -> &IndexMap<String, Map<Contig>>
pub fn contigs(&self) -> &IndexMap<String, Map<Contig>>
Returns a map of contig records (contig).
§Examples
use noodles_vcf::{self as vcf, header::record::value::{map::Contig, Map}};
let contig = Map::<Contig>::new();
let header = vcf::Header::builder()
.add_contig("sq0", contig.clone())
.build();
let contigs = header.contigs();
assert_eq!(contigs.len(), 1);
assert_eq!(&contigs[0], &contig);Sourcepub fn contigs_mut(&mut self) -> &mut IndexMap<String, Map<Contig>>
pub fn contigs_mut(&mut self) -> &mut IndexMap<String, Map<Contig>>
Returns a mutable reference to a map of contig records (contig).
§Examples
use noodles_vcf::{self as vcf, header::record::value::{map::Contig, Map}};
let mut header = vcf::Header::default();
let contig = Map::<Contig>::new();
header.contigs_mut().insert(String::from("sq0"), contig.clone());
let contigs = header.contigs();
assert_eq!(contigs.len(), 1);
assert_eq!(&contigs[0], &contig);Sourcepub fn sample_names(&self) -> &IndexSet<String>
pub fn sample_names(&self) -> &IndexSet<String>
Returns a list of sample names that come after the FORMAT column in the header record.
§Examples
use indexmap::IndexSet;
use noodles_vcf as vcf;
let header = vcf::Header::builder()
.add_sample_name("sample0")
.add_sample_name("sample1")
.build();
let expected: IndexSet<_> = [String::from("sample0"), String::from("sample1")]
.into_iter()
.collect();
assert_eq!(header.sample_names(), &expected);Sourcepub fn sample_names_mut(&mut self) -> &mut IndexSet<String>
pub fn sample_names_mut(&mut self) -> &mut IndexSet<String>
Returns a mutable reference to a list of sample names that come after the FORMAT column in the header record.
§Examples
use indexmap::IndexSet;
use noodles_vcf as vcf;
let mut header = vcf::Header::builder().add_sample_name("sample0").build();
header.sample_names_mut().insert(String::from("sample1"));
let expected: IndexSet<_> = [String::from("sample0"), String::from("sample1")]
.into_iter()
.collect();
assert_eq!(header.sample_names(), &expected);Sourcepub fn other_records(&self) -> &IndexMap<Other, Collection>
pub fn other_records(&self) -> &IndexMap<Other, Collection>
Returns a map of records with nonstandard keys.
This includes all records other than fileformat, INFO, FILTER, FORMAT, ALT, and
contig.
§Examples
use noodles_vcf::{self as vcf, header::record::Value};
let header = vcf::Header::builder()
.insert("fileDate".parse()?, Value::from("20200709"))?
.build();
assert_eq!(header.other_records().len(), 1);Sourcepub fn other_records_mut(&mut self) -> &mut IndexMap<Other, Collection>
pub fn other_records_mut(&mut self) -> &mut IndexMap<Other, Collection>
Returns a mutable reference to a map of collections of records with nonstandard keys.
This includes all records other than fileformat, INFO, FILTER, FORMAT, ALT, and
contig.
To simply add an nonstandard record, consider using Self::insert instead.
§Examples
use noodles_vcf::{
self as vcf,
header::record::{value::Collection, Value},
};
let mut header = vcf::Header::default();
let collection = Collection::Unstructured(vec![String::from("20200709")]);
header.other_records_mut().insert("fileDate".parse()?, collection.clone());
assert_eq!(header.other_records().get("fileDate"), Some(&collection));Sourcepub fn get<Q>(&self, key: &Q) -> Option<&Collection>
pub fn get<Q>(&self, key: &Q) -> Option<&Collection>
Returns a collection of header values with the given key.
This includes all records other than fileformat, INFO, FILTER, FORMAT, ALT, and
contig.
§Examples
use noodles_vcf::{
self as vcf,
header::record::{value::Collection, Value},
};
let header = vcf::Header::builder()
.insert("fileDate".parse()?, Value::from("20200709"))?
.build();
assert_eq!(
header.get("fileDate"),
Some(&Collection::Unstructured(vec![String::from("20200709")]))
);
assert!(header.get("reference").is_none());Sourcepub fn insert(&mut self, key: Other, value: Value) -> Result<(), AddError>
pub fn insert(&mut self, key: Other, value: Value) -> Result<(), AddError>
Inserts a key-value pair representing a nonstandard record into the header.
§Examples
use noodles_vcf::{
self as vcf,
header::record::{value::Collection, Value},
};
let mut header = vcf::Header::default();
assert!(header.get("fileDate").is_none());
header.insert("fileDate".parse()?, Value::from("20200709"))?;
assert_eq!(
header.get("fileDate"),
Some(&Collection::Unstructured(vec![String::from("20200709")]))
);Trait Implementations§
Source§impl TryFrom<&Header> for StringMaps
impl TryFrom<&Header> for StringMaps
Source§type Error = ParseError
type Error = ParseError
Source§fn try_from(
header: &Header,
) -> Result<StringMaps, <StringMaps as TryFrom<&Header>>::Error>
fn try_from( header: &Header, ) -> Result<StringMaps, <StringMaps as TryFrom<&Header>>::Error>
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 UnsafeUnpin 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.