Struct noodles_vcf::header::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

A VCF header builder.

Implementations§

source§

impl Builder

source

pub fn set_file_format(self, file_format: FileFormat) -> Self

Sets the fileformat record (fileformat).

§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 add_info<I>(self, id: I, info: Map<Info>) -> Self
where I: Into<String>,

Adds an information record (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 add_filter<I>(self, id: I, filter: Map<Filter>) -> Self
where I: Into<String>,

Adds a filter record (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 add_format<I>(self, id: I, format: Map<Format>) -> Self
where I: Into<String>,

Adds a genotype format record (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 add_alternative_allele<I>( self, id: I, alternative_allele: Map<AlternativeAllele>, ) -> Self
where I: Into<String>,

Adds an alternative allele record (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 add_contig<I>(self, id: I, contig: Map<Contig>) -> Self
where I: Into<String>,

Adds a contig record (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 set_sample_names(self, sample_names: SampleNames) -> Self

Sets sample names.

§Examples
use indexmap::IndexSet;
use noodles_vcf as vcf;

let sample_names: IndexSet<_> = [String::from("sample0")]
    .into_iter()
    .collect();

let header = vcf::Header::builder()
    .set_sample_names(sample_names.clone())
    .build();

assert_eq!(header.sample_names(), &sample_names);
source

pub fn add_sample_name<I>(self, sample_name: I) -> Self
where I: Into<String>,

Adds a sample name.

Duplicate names are discarded.

§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 insert(self, key: Other, value: Value) -> Result<Self, AddError>

Inserts a key-value pair representing an unstructured record into the header.

§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")]))
);
source

pub fn build(self) -> Header

Builds a VCF header.

§Examples
use noodles_vcf as vcf;
let header = vcf::Header::builder().build();

Trait Implementations§

source§

impl Debug for Builder

source§

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

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

impl Default for Builder

source§

fn default() -> Builder

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

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where 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 T
where 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.