Struct noodles_vcf::header::Header
source · 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) -> &Infos
pub fn infos(&self) -> &Infos
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 Infos
pub fn infos_mut(&mut self) -> &mut Infos
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) -> &Filters
pub fn filters(&self) -> &Filters
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 Filters
pub fn filters_mut(&mut self) -> &mut Filters
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) -> &Formats
pub fn formats(&self) -> &Formats
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 Formats
pub fn formats_mut(&mut self) -> &mut Formats
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) -> &AlternativeAlleles
pub fn alternative_alleles(&self) -> &AlternativeAlleles
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 AlternativeAlleles
pub fn alternative_alleles_mut(&mut self) -> &mut AlternativeAlleles
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) -> &Contigs
pub fn contigs(&self) -> &Contigs
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 Contigs
pub fn contigs_mut(&mut self) -> &mut Contigs
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) -> &SampleNames
pub fn sample_names(&self) -> &SampleNames
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 SampleNames
pub fn sample_names_mut(&mut self) -> &mut SampleNames
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) -> &OtherRecords
pub fn other_records(&self) -> &OtherRecords
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 OtherRecords
pub fn other_records_mut(&mut self) -> &mut OtherRecords
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 PartialEq for Header
impl PartialEq for Header
source§impl TryFrom<&Header> for StringMaps
impl TryFrom<&Header> for StringMaps
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.