I am trying to find the distance to the closest downstream gene. Running into a problem. Some genes overlap in the opposite strand at the 3' end. But I need to use ignore overlap or it just reports my genes back to me since all genes in my -a file are also -b file. Is there a way to report closest downstream gene including if it overlaps on the opposite strand, but make bedtools ignore the fact that all genes in -a are also in -b so it doesn't report 0 for every gene?
Here's two examples with the various ways I've tried. One is where the closest gene overlaps some at the 3' end example one
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -fd -D a | grep YPL260W
chrXVI 49217 51097 YPL260W 0 + chrXVI 63225 64793 YPL257W 0 + 12129
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -iu -D a -io | grep YPL260W
chrXVI 49217 51097 YPL260W 0 + chrXVI 63225 64793 YPL257W 0 + 12129
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -iu -D a | grep YPL260W
chrXVI 49217 51097 **YPL260W** 0 + chrXVI 49217 51097 **YPL260W** 0 + 0
chrXVI 49217 51097 YPL260W 0 + chrXVI 51013 52701 YPL259C 0 - 0
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -iu -D a -S | grep YPL260W
chrXVI 49217 51097 YPL260W 0 + chrXVI 51013 52701 YPL259C 0 - 0
So -S works for this example, but what if the closest gene is on the same strand example two
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -fd -D a | grep YPL239W
chrXVI 99001 100265 YPL239W 0 + chrXVI 100441 101393 YPL237W 0 + 177
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -iu -D a | grep YPL239W
chrXVI 99001 100265 **YPL239W** 0 + chrXVI 99001 100265 **YPL239W** 0 +
bedtools closest -a ORFs_1.5termratio_swrvswt_20180608_sort.txt -b steinmetzgenes_sorted.txt -iu -D a -S | grep YPL239W
chrXVI 99001 100265 YPL239W 0 + chrXVI 101397 102997 YPL236C 0 - 1133
This time YPL237W is the closest so can't use -S
it'd be easier to help if you had posted your full command(s) including a minimal test set (e.g., three or four genes)