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

Parses a raw VCF record.

Returns a builder to create a record from each of its fields.

Examples
use noodles_vcf as vcf;
let builder = vcf::Record::builder();

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

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

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

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

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

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

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])?,
);

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])?,
);

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])]),
);

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])]),
);

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

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

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

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

Returns the addition information of the record.

Examples
use noodles_vcf::{
    self as vcf,
    header::info::Key,
    record::{info::{field::Value, Field}, 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 = Info::try_from(vec![
    Field::new(Key::SamplesWithDataCount, Some(Value::Integer(3))),
    Field::new(Key::AlleleFrequencies, Some(Value::FloatArray(vec![Some(0.5)]))),
])?;

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

Returns a mutable reference to the additional info fields.

Examples
use noodles_vcf::{
    self as vcf,
    header::info::Key,
    record::{info::{field::Value, Field}, 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()?;

let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
record.info_mut().insert(dp.clone());

let expected = Info::try_from(vec![
    Field::new(Key::SamplesWithDataCount, Some(Value::Integer(3))),
    Field::new(Key::AlleleFrequencies, Some(Value::FloatArray(vec![Some(0.5)]))),
    dp,
])?;

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

Returns the format of the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    header::{format::Key, Format},
    record::{genotypes::{Genotype, Keys}, Genotypes, Position},
};

let header = vcf::Header::builder()
    .add_format(Format::from(Key::Genotype))
    .add_format(Format::from(Key::ConditionalGenotypeQuality))
    .build();

let keys = "GT:GQ".parse()?;
let genotypes = vec![Genotype::parse("0|0:13", header.formats(), &keys)?];

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

assert_eq!(record.format(), &Keys::try_from(vec![
    Key::Genotype,
    Key::ConditionalGenotypeQuality,
])?);

Returns the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    header::format::Key,
    record::{
        genotypes::{genotype::{field::Value, Field}, Genotype, Genotypes},
        Position,
    },
};

let keys = "GT:GQ".parse()?;
let genotypes = Genotypes::new(
    keys,
    vec![Genotype::try_from(vec![
        Field::new(Key::Genotype, Some(Value::String(String::from("0|0")))),
        Field::new(Key::ConditionalGenotypeQuality, Some(Value::Integer(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);

Returns a mutable reference to the genotypes of the record.

Examples
use noodles_vcf::{
    self as vcf,
    header::format::Key,
    record::{
        genotypes::{genotype::{field::Value, Field}, Genotype, 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![Genotype::try_from(vec![
        Field::new(Key::Genotype, Some(Value::String(String::from("0|0")))),
        Field::new(Key::ConditionalGenotypeQuality, Some(Value::Integer(13))),
    ])?],
);

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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