This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bedtools intersect, order of input bed files result in different outputs?

I'm curious as to why I'm getting two different values with bedtools intersect with two sorted bedfiles:

bedtools intersect -u -a test1.bed -b test2.bed | wc -l

This gives me 157,273

However, when swapping -a and -b:

bedtools intersect -u -a test2.bed -b test1.bed | wc -l

This gives me 158,095

bedtools

2 answers

This is normal that order affect the result. Read carfully the help https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html

First you report all sequence from A that overlap B
And secondly you report all sequence B that overlap A

The only case where both will give you the same result it is if the two files are identical

I think -u is the keypoint. If you run intersect without -u option, the result number will be the same.

Log in to answer this question.