Struct noodles_vcf::record::Record

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

A VCF record.

A VCF record has 8 required fields: chromosome (CHROM), position (POS), IDs (ID), reference bases (REF), alternate bases (ALT), quality score (QUAL), filters (FILTER), and information (INFO).

Additionally, each record can have genotype information. This adds the extra FORMAT field and a number of genotype fields.

Implementations§

source§

impl Record

source

pub fn try_from_str(s: &str, header: &Header) -> Result<Self, ParseError>

👎Deprecated since 0.27.0: Use TryFrom<(&Header, &str)> instead.

Parses a raw VCF record using a VCF header as context.

Examples
use noodles_vcf as vcf;

let s = "sq0\t8\t.\tA\t.\t.\tPASS\t.";
let header = vcf::Header::default();
let record = vcf::Record::try_from_str(s, &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::Record::builder();
source

pub fn chromosome(&self) -> &Chromosome

Returns the chromosome of the record.

The chromosome is either a reference sequence name or a symbol (<identifier>).

This is a required field and guaranteed to be set.

Examples
use noodles_vcf::{self as vcf, record::{Chromosome, Position}};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

assert_eq!(record.chromosome(), &Chromosome::Name(String::from("sq0")));
source

pub fn chromosome_mut(&mut self) -> &mut Chromosome

Returns a mutable reference to the chromosome.

Examples
use noodles_vcf::{self as vcf, record::{Chromosome, Position}};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.chromosome_mut() = "sq1".parse()?;

assert_eq!(record.chromosome().to_string(), "sq1");
source

pub fn position(&self) -> Position

Returns the start position of the reference bases or indicates a telomeric breakend.

This field is overloaded. If the record represents a telomere, the telomeric breakends are set to 0 and n + 1, where n is the length of the chromosome. Otherwise, it is a 1-based start position of the reference bases.

This is a required field. It is guaranteed to be set and >= 0.

Examples
use noodles_vcf::{self as vcf, record::Position};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(8))
    .set_reference_bases("A".parse()?)
    .build()?;

assert_eq!(usize::from(record.position()), 8);
source

pub fn position_mut(&mut self) -> &mut Position

Returns a mutable reference to the start position of the reference bases.

This field is overloaded. If the record represents a telomere, the telomeric breakends are set to 0 and n + 1, where n is the length of the chromosome. Otherwise, it is a 1-based start position of the reference bases.

Examples
use noodles_vcf::{self as vcf, record::Position};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(8))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.position_mut() = Position::from(13);

assert_eq!(usize::from(record.position()), 13);
source

pub fn ids(&self) -> &Ids

Returns a list of IDs of the record.

Examples
use noodles_vcf::{self as vcf, record::Position};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_ids("nd0".parse()?)
    .set_reference_bases("A".parse()?)
    .build()?;

assert_eq!(*record.ids(), "nd0".parse()?);
source

pub fn ids_mut(&mut self) -> &mut Ids

Returns a mutable reference to the IDs.

Examples
use noodles_vcf::{self as vcf, record::{Ids, Position}};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

let ids: Ids = "nd0".parse()?;
*record.ids_mut() = ids.clone();

assert_eq!(record.ids(), &ids);
source

pub fn reference_bases(&self) -> &ReferenceBases

Returns the reference bases of the record.

This is a required field and guaranteed to be nonempty.

Examples
use noodles_vcf::{
    self as vcf,
    record::{reference_bases::Base, Position, ReferenceBases},
};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

assert_eq!(
    record.reference_bases(),
    &ReferenceBases::try_from(vec![Base::A])?,
);
source

pub fn reference_bases_mut(&mut self) -> &mut ReferenceBases

Returns a mutable reference to the reference bases of the record.

This is a required field and guaranteed to be nonempty.

Examples
use noodles_vcf::{
    self as vcf,
    record::{reference_bases::Base, Position, ReferenceBases},
};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.reference_bases_mut() = "T".parse()?;

assert_eq!(
    record.reference_bases(),
    &ReferenceBases::try_from(vec![Base::T])?,
);
source

pub fn alternate_bases(&self) -> &AlternateBases

Returns the alternate bases of the record.

Examples
use noodles_vcf::{
    self as vcf,
    record::{alternate_bases::Allele, reference_bases::Base, AlternateBases, Position},
};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_alternate_bases("C".parse()?)
    .build()?;

assert_eq!(
    record.alternate_bases(),
    &AlternateBases::from(vec![Allele::Bases(vec![Base::C])]),
);
source

pub fn alternate_bases_mut(&mut self) -> &mut AlternateBases

Returns a mutable reference to the alternate bases of the record.

Examples
use noodles_vcf::{
    self as vcf,
    record::{alternate_bases::Allele, reference_bases::Base, AlternateBases, Position},
};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.alternate_bases_mut() = "C".parse()?;

assert_eq!(
    record.alternate_bases(),
    &AlternateBases::from(vec![Allele::Bases(vec![Base::C])]),
);
source

pub fn quality_score(&self) -> Option<QualityScore>

Returns the quality score of the record.

The quality score is a Phred quality score.

Examples
use noodles_vcf::{self as vcf, record::{Position, QualityScore}};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_quality_score(QualityScore::try_from(13.0)?)
    .build()?;

assert_eq!(record.quality_score().map(f32::from), Some(13.0));
source

pub fn quality_score_mut(&mut self) -> &mut Option<QualityScore>

Returns a mutable reference to the quality score.

Examples
use noodles_vcf::{self as vcf, record::{Position, QualityScore}};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.quality_score_mut() = QualityScore::try_from(13.0).map(Some)?;

assert_eq!(record.quality_score().map(f32::from), Some(13.0));
source

pub fn filters(&self) -> Option<&Filters>

Returns the filters of the record.

The filters can either be pass (PASS), a list of filter names that caused the record to fail, (e.g., q10), or missing (.).

Examples
use noodles_vcf::{self as vcf, record::{Filters, Position}};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_filters(Filters::Pass)
    .build()?;

assert_eq!(record.filters(), Some(&Filters::Pass));
source

pub fn filters_mut(&mut self) -> &mut Option<Filters>

Returns a mutable reference to the filters.

Examples
use noodles_vcf::{self as vcf, record::{Filters, Position}};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

*record.filters_mut() = Some(Filters::Pass);

assert_eq!(record.filters(), Some(&Filters::Pass));
source

pub fn info(&self) -> &Info

Returns the addition information of the record.

Examples
use noodles_vcf::{
    self as vcf,
    record::{info::field::{key, Value}, Info, Position},
};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_alternate_bases("C".parse()?)
    .set_info("NS=3;AF=0.5".parse()?)
    .build()?;

let expected = [
    (key::SAMPLES_WITH_DATA_COUNT, Some(Value::from(3))),
    (key::ALLELE_FREQUENCIES, Some(Value::from(vec![Some(0.5)]))),
].into_iter().collect();

assert_eq!(record.info(), &expected);
source

pub fn info_mut(&mut self) -> &mut Info

Returns a mutable reference to the additional info fields.

Examples
use noodles_vcf::{
    self as vcf,
    record::{info::field::{key, Value}, Info, Position},
};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_alternate_bases("C".parse()?)
    .set_info("NS=3;AF=0.5".parse()?)
    .build()?;

record.info_mut().insert(key::TOTAL_DEPTH, Some(Value::Integer(13)));

let expected = [
    (key::SAMPLES_WITH_DATA_COUNT, Some(Value::Integer(3))),
    (key::ALLELE_FREQUENCIES, Some(Value::from(vec![Some(0.5)]))),
    (key::TOTAL_DEPTH, Some(Value::Integer(13))),
].into_iter().collect();

assert_eq!(record.info(), &expected);
source

pub fn format(&self) -> &Keys

Returns the format of the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    header::{record::value::{map::Format, Map}},
    record::{genotypes::{keys::key, Keys}, Genotypes, Position},
};

let header = vcf::Header::builder()
    .add_format(key::GENOTYPE, Map::<Format>::from(&key::GENOTYPE))
    .add_format(key::CONDITIONAL_GENOTYPE_QUALITY, Map::<Format>::from(&key::CONDITIONAL_GENOTYPE_QUALITY))
    .build();

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_genotypes(Genotypes::parse("GT:GQ\t0|0:13", &header)?)
    .build()?;

assert_eq!(record.format(), &Keys::try_from(vec![
    key::GENOTYPE,
    key::CONDITIONAL_GENOTYPE_QUALITY,
])?);
source

pub fn genotypes(&self) -> &Genotypes

Returns the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    record::{
        genotypes::{sample::Value, Genotypes},
        Position,
    },
};

let keys = "GT:GQ".parse()?;
let genotypes = Genotypes::new(
    keys,
    vec![vec![Some(Value::from("0|0")), Some(Value::from(13))]],
);

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .set_genotypes(genotypes.clone())
    .build()?;

assert_eq!(record.genotypes(), &genotypes);
source

pub fn genotypes_mut(&mut self) -> &mut Genotypes

Returns a mutable reference to the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    record::{
        genotypes::{sample::Value, Genotypes},
        Position,
    },
};

let mut record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("A".parse()?)
    .build()?;

let keys = "GT:GQ".parse()?;
let genotypes = Genotypes::new(
    keys,
    vec![vec![Some(Value::from("0|0")), Some(Value::from(13))]],
);

*record.genotypes_mut() = genotypes.clone();

assert_eq!(record.genotypes(), &genotypes);
source§

impl Record

source

pub fn end(&self) -> Result<Position, EndError>

Returns or calculates the end position on the reference sequence.

If available, this returns the value of the END INFO field. Otherwise, it is calculated using the start position and reference bases length.

The end position is 1-based, inclusive.

Examples
From the END INFO field value
use noodles_vcf::{self as vcf, record::{Chromosome, Position}};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("ACGT".parse()?)
    .set_info("END=8".parse()?)
    .build()?;

assert_eq!(record.end(), Ok(Position::from(8)));
Calculated using the start position and reference bases length
use noodles_vcf::{self as vcf, record::{Chromosome, Position}};

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::from(1))
    .set_reference_bases("ACGT".parse()?)
    .build()?;

assert_eq!(record.end(), Ok(Position::from(4)));

Trait Implementations§

source§

impl Clone for Record

source§

fn clone(&self) -> Record

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 Record

source§

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

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

impl Default for Record

source§

fn default() -> Self

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

impl Display for Record

source§

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

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

impl FromStr for Record

§

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

source§

fn eq(&self, other: &Record) -> 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 TryFrom<(&Header, &str)> for Record

§

type Error = ParseError

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

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

Performs the conversion.
source§

impl StructuralPartialEq for Record

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