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
impl Record
sourcepub fn try_from_str(s: &str, header: &Header) -> Result<Self, ParseError>
👎Deprecated since 0.27.0: Use TryFrom<(&Header, &str)>
instead.
pub fn try_from_str(s: &str, header: &Header) -> Result<Self, ParseError>
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)?;
sourcepub fn builder() -> Builder
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();
sourcepub fn chromosome(&self) -> &Chromosome
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")));
sourcepub fn chromosome_mut(&mut self) -> &mut Chromosome
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");
sourcepub fn position(&self) -> Position
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);
sourcepub fn position_mut(&mut self) -> &mut Position
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);
sourcepub fn ids(&self) -> &Ids
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()?);
sourcepub fn ids_mut(&mut self) -> &mut Ids
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);
sourcepub fn reference_bases(&self) -> &ReferenceBases
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])?,
);
sourcepub fn reference_bases_mut(&mut self) -> &mut ReferenceBases
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])?,
);
sourcepub fn alternate_bases(&self) -> &AlternateBases
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])]),
);
sourcepub fn alternate_bases_mut(&mut self) -> &mut AlternateBases
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])]),
);
sourcepub fn quality_score(&self) -> Option<QualityScore>
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));
sourcepub fn quality_score_mut(&mut self) -> &mut Option<QualityScore>
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));
sourcepub fn filters(&self) -> Option<&Filters>
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));
sourcepub fn filters_mut(&mut self) -> &mut Option<Filters>
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));
sourcepub fn info(&self) -> &Info
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);
sourcepub fn info_mut(&mut self) -> &mut Info
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);
sourcepub fn format(&self) -> &Keys
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,
])?);
sourcepub fn genotypes(&self) -> &Genotypes
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);
sourcepub fn genotypes_mut(&mut self) -> &mut Genotypes
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
impl Record
sourcepub fn end(&self) -> Result<Position, EndError>
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)));