Struct noodles::vcf::Record[][src]

pub struct Record { /* fields omitted */ }
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

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::try_from(1)?)
    .set_reference_bases("A".parse()?)
    .build()?;

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

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::try_from(8)?)
    .set_reference_bases("A".parse()?)
    .build()?;

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

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::try_from(1)?)
    .set_ids("nd0".parse()?)
    .set_reference_bases("A".parse()?)
    .build()?;

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

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::try_from(1)?)
    .set_reference_bases("A".parse()?)
    .build()?;

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

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::try_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 the quality score of the record.

The quality score is a Phred quality score.

Examples

use std::convert::TryFrom;
use noodles_vcf::{self as vcf, record::{Position, QualityScore}};

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

assert_eq!(*record.quality_score(), 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::try_from(1)?)
    .set_reference_bases("A".parse()?)
    .set_filters(Filters::Pass)
    .build()?;

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

Returns the addition information of the record.

Examples

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

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::try_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, Value::Integer(3)),
    Field::new(Key::AlleleFrequencies, Value::FloatArray(vec![0.5])),
])?;

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

Returns the format of the genotypes of the record.

Examples

use noodles_vcf::{
    self as vcf,
    record::{genotype::field::Key, Format, Genotype, Position},
};

let format: Format = "GT:GQ".parse()?;

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::try_from(1)?)
    .set_reference_bases("A".parse()?)
    .set_format(format.clone())
    .add_genotype(Genotype::from_str_format("0|0:13", &format)?)
    .build()?;

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

Returns the genotypes of the record.

Examples

use noodles_vcf::{
    self as vcf,
    record::{genotype::{field::{Key, Value}, Field}, Format, Genotype, Position},
};

let format: Format = "GT:GQ".parse()?;

let record = vcf::Record::builder()
    .set_chromosome("sq0".parse()?)
    .set_position(Position::try_from(1)?)
    .set_reference_bases("A".parse()?)
    .set_format(format.clone())
    .add_genotype(Genotype::from_str_format("0|0:13", &format)?)
    .build()?;

assert_eq!(record.genotypes(), [
    Genotype::try_from(vec![
        Field::new(Key::Genotype, Some(Value::String(String::from("0|0")))),
        Field::new(Key::ConditionalGenotypeQuality, Some(Value::Integer(13))),
    ])?,
]);

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::try_from(1)?)
    .set_reference_bases("ACGT".parse()?)
    .set_info("END=8".parse()?)
    .build()?;

assert_eq!(record.end(), Ok(Position::try_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::try_from(1)?)
    .set_reference_bases("ACGT".parse()?)
    .build()?;

assert_eq!(record.end(), Ok(Position::try_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

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.