noodles_vcf::header

Struct Header

Source
pub struct Header { /* private fields */ }
Expand description

A VCF header.

Implementations§

Source§

impl Header

Source

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();
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

pub fn get<Q>(&self, key: &Q) -> Option<&Collection>
where Q: ?Sized + Hash + Equivalent<Other>,

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());
Source

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 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() -> Self

Returns the “default value” for a type. Read more
Source§

impl FromStr for Header

Source§

type Err = ParseError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
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 TryFrom<&Header> for StringMaps

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(header: &Header) -> Result<Self, Self::Error>

Performs the conversion.
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.