Friday, May 9, 2014

How to get closest feature with bedtools in both directions

Using bedtools closest feature you can get two closest intervals when comparing two bed files. Bedtools closest option will report closest interval that is either upstream or downstream. To get both upstream and downstream intervals, run bedtools twice with the following commands:

bedtools closest -D ref -id -a peaks.bed -b RefSeq_genes.bed > upstream_genes
bedtools closest -D ref -iu -a peaks.bed -b RefSeq_genes.bed > downstream_genes


-id will ignore downstream
-iu will ignore upstream

No comments:

Post a Comment