Skip to content

How to add new INFO fileds into VCF #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AuroUTU opened this issue May 4, 2025 · 0 comments
Open

How to add new INFO fileds into VCF #475

AuroUTU opened this issue May 4, 2025 · 0 comments

Comments

@AuroUTU
Copy link

AuroUTU commented May 4, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant