Question: Converting a VCF with SNPs and indels to BED format
3
gravatar for gareth862
4.4 years ago by
gareth86280
United States
gareth86280 wrote:

Does anyone know of tools or have custom  scripts (aside from "vcf2bed") that are able to convert between a VCF containing both indels and SNPs into BED format? The tricky part is creating the correct BED regions to capture the indel variants, and I haven't been able to find anything on the internet thus far.

 

next-gen • 11k views
ADD COMMENTlink modified 20 months ago by anita0 • written 4.4 years ago by gareth86280
3

Hello gareth862!

It appears that your post has been cross-posted to another site: SEQanswers.

This is typically not recommended as it runs the risk of annoying people in both communities.

ADD REPLYlink modified 4.4 years ago • written 4.4 years ago by Devon Ryan86k

What result are you expecting?

ADD REPLYlink written 4.4 years ago by Alex Reynolds26k
1

We are trying to get the "affected positions" from the vcf. Our plan was to use bed tools to intersect our bed file with the vcf affected positions to produce a bed file of reference ranges

  • If the allele matches the ref then it wouldn't write a range for it
  • If deletion the range would include all deleted positions
  • If a variation the range would be only the changed bases
  • 1 vcf line can generate multiple bed lines

 

 

ADD REPLYlink modified 4.4 years ago • written 4.4 years ago by carterc10
5
gravatar for Alex Reynolds
4.4 years ago by
Alex Reynolds26k
Seattle, WA USA
Alex Reynolds26k wrote:

The vcf2bed script will handle the last three issues:

  • Use --deletions to convert deletions to one set
  • Use --snvs to convert single-nucleotide variants to convert to a second set
  • Conversion of one VCF line will generate multiple BED lines if there are multiple alternate alleles

You can use bedops --everything to union the deletion and single-base variant sets:

$ vcf2bed --deletions < foo.vcf > foo_deletions.bed
$ vcf2bed --snvs < foo.vcf > foo_snvs.bed
$ bedops --everything foo_{deletions,snvs}.bed > foo.bed

Once you have your deletions and SNVs in one file, it's easy to deal with the first issue. The conversion script maps the REF and ALT fields of the VCF input to the sixth and seventh columns of the BED output. So you can filter out lines from the BED output where those columns are equivalent, using a simple awk statement:

$ awk '$6 != $7' foo.bed > foo_filtered.bed
ADD COMMENTlink modified 4.4 years ago • written 4.4 years ago by Alex Reynolds26k

Alex, I get following error with the above command.

Error: Could not allocate space for VCF INFO string

I have updated the bedops to the latest version (2.4.28) as you mentioned here. This update resolves the same error from convert2bed command. But the issue with vcf2bed remains. I would like to use vcf2bed over convert2bed since the deletions and the SNVs can be processed separately using vcf2bed.

Any suggestions?

ADD REPLYlink modified 15 months ago • written 15 months ago by Satyajeet Khare1.3k

vcf2bed is just a wrapper that calls convert2bed. If the issue shows up with vcf2bed and does not happen with convert2bed, I would suggest there's a problem with your installation. I would look in /usr/local/bin and make sure that vcf2bed is pointing to the current convert2bed.

ADD REPLYlink written 15 months ago by Alex Reynolds26k

Oh yes. I am running the latest version locally (through directory). Its probably trying to access the old version which is installed globally.

ADD REPLYlink written 15 months ago by Satyajeet Khare1.3k
1

The wrapper vcf2bed just uses whatever convert2bed it can find first in your environment PATH. You might try editing your PATH so that your local copy comes up first, or just upgrade the global copy.

Otherwise, you can use all the same functions in convert2bed as in vcf2bed, e.g.:

$ convert2bed --input=vcf --insertions < snps.vcf > insertions.bed

Etc.

You can run convert2bed --help-vcf for a listing of VCF-specific options, which should be exactly those offered by the wrapper script.

ADD REPLYlink written 15 months ago by Alex Reynolds26k

I used the same functions in the convert2bed as you mentioned. It works clean. Thanks!

ADD REPLYlink written 15 months ago by Satyajeet Khare1.3k
1

Great to hear! Feel free to follow up if you have any more questions or problems.

ADD REPLYlink written 15 months ago by Alex Reynolds26k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1734 users visited in the last hour