Skip to content

How to add new INFO fileds into VCF #475

@AuroUTU

Description

@AuroUTU

Hi,
Thank you for this nice rust crate.
In my use, I want to read a vcf file, then add some custom fields into the INFO column, and then write back as an output vcf. I understand that "any record you push has first to be defined in the header" #342 , but even after pushing the new field into header, reader still cannot recognise it.

let mut reader = Reader::from_path("test.vcf.gz").expect("Cannot open input VCF");
let mut header = Header::from_template(reader.header());
header.push_record(br#"##INFO="#);
for result in reader.records() {
    let mut record = result.expect("Failed to read record");
    record.push_info_string(b"NewInfo", &[b"1"]).expect("Failed to add INFO field");
}

The only thing I can achieve my goal, is that first write the new header into an intermediate vcf file (either rust-htslib or bcftools), then read this intermediate vcf and add new fields into each vcf record. Is there any way that can allow me to add new fields into INFO and write them back as an output.vcf in a single read-write run?

Thank you very much

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions