This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Intersecting vcf files with bedtools

Hello,

I want to intersect two vcf files :

File 1 :

CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  7.bam

Scaffold_1        223     .       G       T       10.8428 . DP=7;DPR=5,2;VDB=0.18;SGB=-0.453602;RPB=0.8;MQB=1;MQSB=1;BQB=0.9;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=5,0,0,2;MQ=60 GT:PL:DP:DV:SP:DP4:DPR   0/1:44,0,110:7:2:13:5,0,0,2:5,2

Scaffold_1        435     .       T       C       20.145  .       DP=3;DPR=1,2;VDB=0.1;SGB=-0.453602;RPB=1;MQB=1;MQSB=1;BQB=1;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=0,1,2,0;MQ=60    GT:PL:DP:DV:SP:DP4:DPR     0/1:53,0,30:3:2:0:0,1,2,0:1,2

File 2 : 

CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  S07

scaffold_11       651457  929888  G       T       .       PASS    Ty=SNP;Rk=1;UL=.;UR=.;CL=.;CR=.;Genome=C;Sd=1   GT:DP:PL:AD:HQ  0/0:4:4,16,84:4,0:70,0

scaffold_1188     2186    894758  T       G       .       PASS    Ty=SNP;Rk=1;UL=.;UR=.;CL=.;CR=.;Genome=T;Sd=1   GT:DP:PL:AD:HQ  1/1:4:84,16,4:0,4:0,70

This is the error :

bedtools intersect -a 7.variant_snp.vcf -b 7.variant_snp2.vcf | head

ERROR: file 7.variant_snp.vcf has non positional records, which are only valid for the groupBy tool.

I don't know how to deal with this issue. Does anyone have experience of this kind of error?

Thanks in advance

bedtools vcf intersectbed

might be worth simply parsing the "VCF" files into a BED format? Should be able to just include the POS field twice to stand in for the Start & Stop positions.

2 answers

First may be you get rid of headers As per I remember, I always used one vcf and one bed file to intersect by bedtools

May be you use vcftools to intersect two vcf files

It has nice command as "vcf-isec" Creates intersections and complements of two or more VCF files Nice documentation is here

Thank you :) I tried it but now i have a new error "The command "tabix" not found, please add it to your PATH" I'm trying to fix it. Thank you again

The examples you show do not match the VCF format specs. The header line (beginning with 'CHROM') should be preceded by a hash '#'. Otherwise, 'POS' is read as a value that should be an integer but is not (i.e., non-positional).

Also, bedtools 'intersect' does not output headers by default, and using the output for subsequent 'intersect' operations can produce errors. You can include by using the '-header' flag.

Log in to answer this question.