The noodles_bcf::io::Writer is used to write BCF (Binary Call Format) files. You can initialize it with a standard writer (like a file or std::io::sink) or wrap it in a BGZF encoder for compressed output.
To write a valid BCF file, you must first write a VCF header using write_header, which also initializes the internal string maps required for record encoding. Subsequently, you can write individual records using write_record.
use std::io;
use noodles_bcf as bcf;
use noodles_vcf as vcf;
use noodles_core::Position;
// 1. Initialize the writer (using sink for this example)
let mut writer = bcf::io::Writer::new(io::sink());
// 2. Prepare and write the header
let mut header = vcf::Header::builder()
.add_contig("sq0", vcf::header::record::value::map::Contig::new())
.build();
// Note: StringMaps must be synchronized with the header
*header.string_maps_mut() = vcf::header::StringMaps::try_from(&header)?;
writer.write_header(&header)?;
// 3. Write a record
let record = bcf::Record::default();
writer.write_record(&header, &record)?;