-
I'm iterating over the fn do_something(samples: &vcf::variant::record_buf::Samples) {
for sample in samples.values() {
let gtval = sample.get("GT").unwrap().unwrap();
}
} This would appear to get me what I'm looking for - In general all the methods that do anything with a The documentation for methods on
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Record In a single sample variant file, for example, the genotype (
All together: use std::io;
use noodles_vcf::{
self as vcf,
variant::record::samples::{keys::key, series::Value, Series},
};
fn main() -> io::Result<()> {
const DATA: &[u8] = b"\
##fileformat=VCFv4.3
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tsample0
sq0\t1\t.\tA\t.\t.\tPASS\t.\tGT\t0/0
sq0\t2\t.\tC\t.\t.\tPASS\t.\tGT\t0|1
";
let mut reader = vcf::io::Reader::new(DATA);
let header = reader.read_header()?;
for result in reader.records() {
let record = result?;
let samples = record.samples();
let series = samples.select(key::GENOTYPE).expect("missing GT series");
let value = series
.get(&header, 0)
.expect("missing sample")
.expect("missing GT value")?;
let Value::Genotype(genotype) = value else {
panic!("invalid GT value");
};
for result in genotype.iter() {
let allele = result?;
let (position, phasing) = allele;
print!("({position:?}, {phasing:?}) ");
}
println!();
}
Ok(())
} |
Beta Was this translation helpful? Give feedback.
Record
Samples
are represented as a data frame.In a single sample variant file, for example, the genotype (
GT
) series will only have a singleValue::Genotype
. UseSamples::select
to get the series and thenSeries::get
at index 0 to get the first sample's value.Genotype
is an abstraction over the serialized genotype form. (See § 1.6.2.8 "Genotype fields: GT (String)" (2024-06-28)). It doesn't return the encoded value as a string but position-phasing pairs ((Option<usize>, Phasing)
).All together: