15 months ago
Seattle, WA USA
You could use BEDOPS
bedops for this. There are a couple approaches, depending on what you mean by intersect.
There is the set operation on elements, which is probably what most mean by "intersect":
$ bedops --element-of 1 <(vcf2bed < one.vcf) <(vcf2bed < two.vcf) > answer.bed
An element-of operation is not a symmetric result — in this case, the result contains elements of
one.vcf that overlap elements in
two.vcf. You would reverse the order of inputs to get the other result.
Alternatively, and perhaps less commonly, you could do an operation on genomic regions:
$ bedops --intersect <(vcf2bed < one.vcf) <(vcf2bed < two.vcf) > answer.bed
The by-region operation is symmetric; inputs can be entered in any order to get the same result.
If you want VCF elements "common" to or overlapping between both input files, you can do the following series of operations:
$ bedops --intersect <(vcf2bed < one.vcf) <(vcf2bed < two.vcf) > common-regions.bed
$ bedops --everything <(vcf2bed < one.vcf) <(vcf2bed < two.vcf) > all-elements.bed
$ bedops --element-of 1 all-elements.bed common-regions.bed > common-elements.bed