This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Command to extract SNPs from VCF file using bcftool

I have a bed file called my.bed with CHROM, START, and END Position. Can someone please explain me how I can use bcftools or command to extract the regions from myvcf.vcf file?

snps bcftools vcf

Doesn't bedtools intersect work with VCF files?

1 answer

my preferred option when dealing with vcf files is bcftools, which requires vcf indexing:

tabix -p vcf my.vcf
bcftools view -R my.bed my.vcf.gz

another perfectly valid alternative, as Devon has just pointed out, would be bedtools intersect:

bedtools intersect -a my.vcf -b my.bed

get this error with bcftools:

`view: invalid option -- 'R'
[bcf_sync] incorrect number of fields (0 != 5) at 0:0

that's strange. it looks like it's asking you for better formed bed file (chr, start, end, value, strand), but I constantly use the --regions-file option with single positions (chr, pos) or regions (chr, start, end) as explained here. maybe you could be using an old bcftools version? I'm using 1.3 (1.3.1 has just been released).

Log in to answer this question.