Skip to content

How do I get a Genotype from a Sample? #301

Answered by zaeleus
afontenot asked this question in Q&A
Discussion options

You must be logged in to vote

Record Samples are represented as a data frame.

In a single sample variant file, for example, the genotype (GT) series will only have a single Value::Genotype. Use Samples::select to get the series and then Series::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:

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=VCF…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@afontenot
Comment options

@zaeleus
Comment options

Answer selected by afontenot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants