If you wanted to edit "DP", for example, it would look somewhat like this:
vf = VariantFile("file.vcf")
record = next(iter(vf))
record.samples["my_sample_name"]["DP"] = 29
- record.samples is a VariantRecordSamples object
- record.samples["my_sample_name"] is a VariantRecordSample object
- Instead of indexing samples by sample name, I think you can also index
with an int.
If you want to write a format that is not listed in the header, you’ll
get an error, so you need to make sure that you add the appropriate
header line beforehand.
You may want to have a look at how we do this in WhatsHap. Phasing
information (PS or HP tags) is written by a "PhasedVcfWriter" class:
<
https://github.com/whatshap/whatshap/blob/main/whatshap/vcf.py#L861>
Regards,
Marcel