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
This is normal that order affect the result. Read carfully the help [https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html][1]  

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

  [1]: https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html