Module variant

Module variant 

Source
Expand description

VCF variant record representation and field access.

This module provides types and functions for working with VCF/BCF variant records. The Variant struct wraps a bcf::Record and provides convenient access to standard VCF fields (CHROM, POS, REF, ALT, etc.) as well as INFO and FORMAT data.

§Value Types

  • InfoValue: Represents INFO field values (scalar, array, flag, or absent)
  • FormatValue: Represents FORMAT field values (per-sample data)

§Standalone Functions

For cases where you have a borrowed bcf::Record reference (e.g., from a GcCell in V8 bindings), standalone helper functions are provided:

§Example

use htsvcf_core::variant::{Variant, InfoValue};
use htsvcf_core::header::Header;
use rust_htslib::bcf::{self, Read};

let mut reader = bcf::Reader::from_path("input.vcf.gz").unwrap();
let header = unsafe { Header::new(reader.header().inner) };

for result in reader.records() {
    let record = result.unwrap();
    let variant = Variant::from_record(record);

    println!("{}:{}", variant.chrom(), variant.pos());

    // Access INFO fields
    match variant.info(&header, "DP") {
        InfoValue::Int(dp) => println!("DP = {}", dp),
        InfoValue::Absent => println!("No DP"),
        _ => {}
    }
}

Structs§

Variant
A VCF/BCF variant record with convenient field accessors.

Enums§

FormatValue
Represents a value from a FORMAT field in a VCF record.
InfoValue
Represents a value from an INFO field in a VCF record.

Functions§

format_float_missing
Get the missing value sentinel for FORMAT float fields.
format_int_missing
Get the missing value sentinel for FORMAT integer fields.
get_format_tag_names
Get the list of FORMAT tag names present in a record.
record_clear_format
Clear (remove) a FORMAT field from a record.
record_clear_info
Clear an INFO field from a record.
record_format
Get a FORMAT field value from a record (per-sample).
record_info
Get an INFO field value from a record.
record_sample
Get sample data from a record for a single sample by name.
record_samples
Get sample data from a record for all samples or a subset.
record_set_format_float
Set a FORMAT float field on a record.
record_set_format_integer
Set a FORMAT integer field on a record.
record_set_format_string
Set a FORMAT string field on a record.
record_set_info_flag
Set an INFO flag value on a record.
record_set_info_float
Set an INFO float value on a record.
record_set_info_integer
Set an INFO integer value on a record.
record_set_info_string
Set an INFO string value on a record.
record_to_string
Format a record as a VCF line string.