arq5x/bedtools — pull request #13 by jakebiesinger (2012-01-24 07:46:30+00:00)
Title: Add ignore options for features up- and downstream of A 

Hi!

You currently have -io to ignore features in B that overlap features in A. This adds -iu and -id to ignore upstream and downstream features, respectively. The determination of exactly what is upstream follows my previously added signed distance (-D) syntax and is a pretty minimal code change for a feature that I need to use all the time. Since the signed distance logic is reused, I made it a prerequisite for this feature. I couldn't think of any cases where the -D orientation would be different than the orientation meant by "ignore upstream" though I guess it's possible.

I have an example/test here that shows the expected output:

```

1 2 3 4 5
A >>>>>>>>>>>>>> <<<<<<<<<<<<
B <<<< >>>>>>>> <<<<<

$ cat A.bed
chr1 10 20 2 . +
chr1 30 40 3 . -
$ cat B.bed
chr1 0 5 1 . -
chr1 50 55 4 . +

# normal bedtools closest -- feature 2 is closest to 1; 3 is closest to 4
$ bedtools closest -a A -b B -> 2,1; 3,4

# ignore upstream features
$ bedtools closest -a A -b B -D ref -iu -> 2,4; 3,4
$ bedtools closest -a A -b B -D a -iu -> 2,4; 3,1
$ bedtools closest -a A -b B -D b -iu -> 2,5; 3,5 (nothing outputted if 5 is missing)

# ignore downstream features
$ bedtools closest -a A -b B -D ref -id -> 2,1; 3,1
$ bedtools closest -a A -b B -D a -id -> 2,1; 3,4
$ bedtools closest -a A -b B -D b -id -> 2,1; 3,4
```