11 unstable releases

0.6.1 Oct 2, 2022
0.6.0 Jul 24, 2021
0.5.0 Oct 6, 2020
0.4.0 May 9, 2020
0.1.0 Jun 29, 2019

#1427 in Parser implementations

Download history 209/week @ 2024-07-20 41/week @ 2024-07-27 34/week @ 2024-08-03 37/week @ 2024-08-10 68/week @ 2024-08-17 29/week @ 2024-08-24 22/week @ 2024-08-31 28/week @ 2024-09-07 10/week @ 2024-09-14 50/week @ 2024-09-21 39/week @ 2024-09-28 21/week @ 2024-10-05 12/week @ 2024-10-12 17/week @ 2024-10-19 4/week @ 2024-10-26 31/week @ 2024-11-02

66 downloads per month
Used in 3 crates

Apache-2.0

96KB
2.5K SLoC

vcf-rs

Build Crates.io doc-rs GitHub GitHub top language

Rust implementation of VCF parser.

License

Apache 2.0

Example

use vcf::*;
use flate2::read::MultiGzDecoder;
use std::fs::File;

fn usage_test() -> Result<(), VCFError> {
    let mut reader = VCFReader::new(BufReader::new(MultiGzDecoder::new(File::open(
        "./testfiles/NA12878-subset.vcf.gz",
    )?)))?;

    // access FILTER contents
    assert_eq!(
        Some(VCFHeaderFilterAlt {
            id: b"PASS",
            description: b"All filters passed"
        }),
        reader.header().filter(b"PASS")
    );

    // access INFO contents
    assert_eq!(
        b"Stop position of the interval",
        reader.header().info(b"END").unwrap().description
    );

    // prepare VCFRecord object
    let mut vcf_record = VCFRecord::new(reader.header());

    // read one record
    reader.next_record(&mut vcf_record)?;

    // get record attributes
    assert_eq!(vcf_record.chromosome, b"13");
    assert_eq!(vcf_record.position, 32889968);
    assert_eq!(vcf_record.id, Vec::<U8Vec>::new());
    assert_eq!(vcf_record.reference, b"G");
    assert_eq!(vcf_record.alternative, vec![b"A"]);
    assert_eq!(vcf_record.qual, Some(25743.5));
    assert_eq!(vcf_record.info(b"AC"), Some(&vec![b"54".to_vec()]));
    assert_eq!(
        vcf_record.genotype(b"ERP001775_HiSeq2000_SAMEA1531955-1", b"GT"),
        Some(&vec![b"1/1".to_vec()])
    );
    assert_eq!(
        vcf_record.genotype(b"ERP001775_HiSeq2000_SAMEA1531955-1", b"AD"),
        Some(&vec![b"0".to_vec(), b"14".to_vec()])
    );

    Ok(())
}

Dependencies

~1–1.8MB
~36K SLoC