bcftools plugin to convert a VCF file to the BED format

bcftools provides a convenient way to extend its functionality using plugins. Technically,  the bcftools plugins are dynamic libraries that are executed when a user launches the bcftools plugin tool.

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

or


bcftools +vcf2bed input.vcf > output.bed

The output BED file contains four columns:

  1. the chromosome name;
  2. the starting position of a variant that is equal to its POS field value minus 1 because coordinates in BED files are zero-based;
  3. the ending position of a variant that is equal to its starting position plus its REF field length;
  4. 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.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s