Struct noodles_vcf::header::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},
    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},
    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, 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},
    record::genotypes::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},
    record::genotypes::keys::key,
};

let mut header = vcf::Header::default();

let id = key::GENOTYPE;
let format = Map::<Format>::from(&id);
header.formats_mut().insert(id, 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},
    record::alternate_bases::allele::{
        symbol::{structural_variant::Type, StructuralVariant},
        Symbol,
    },
};

let id = Symbol::StructuralVariant(StructuralVariant::from(Type::Deletion));
let alt = Map::<AlternativeAllele>::new("Deletion");

let header = vcf::Header::builder()
    .add_alternative_allele(id, 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},
    record::alternate_bases::allele::{
        symbol::{structural_variant::Type, StructuralVariant},
        Symbol,
    },
};

let mut header = vcf::Header::default();

let id = Symbol::StructuralVariant(StructuralVariant::from(Type::Deletion));
let alt = Map::<AlternativeAllele>::new("Deletion");
header.alternative_alleles_mut().insert(id, 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 id = "sq0".parse()?;
let contig = Map::<Contig>::new();

let header = vcf::Header::builder()
    .add_contig(id, 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 id = "sq0".parse()?;
let contig = Map::<Contig>::new();
header.contigs_mut().insert(id, 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 Display for Header

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Header

§

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<Header> for Header

source§

fn eq(&self, other: &Header) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Header

source§

impl StructuralEq for Header

source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more