Here I present a simple plugin named vcf2bed that converts a VCF file to the BED format.
The plugin is launched in the following way:
bcftools plugin vcf2bed input.vcf > output.bed
bcftools +vcf2bed input.vcf > output.bed
The output BED file contains four columns:
- the chromosome name;
- the starting position of a variant that is equal to its POS field value minus 1 because coordinates in BED files are zero-based;
- the ending position of a variant that is equal to its starting position plus its REF field length;
- the variant ID.
The plugin source code is given below.
To compile the plugin, one should put it to the plugins directory of the bcftools source tree and run make. The obtained vcf2bed.so shared object file should be moved to the directory containing other bcftools plugins.