Thank you, is exactly what I need!
Dear community,
I am interested in calculate the distances of a specific position list to the peaks called before.
Lets say I have some chip seq peaks (bed files, with chr, start and end) and I have other list with different position in which I am interested (again bed file, chr, start and end).
First I want to see if there is any overlapping, that is something easy to do with bedtools intersect, but if the position is not in the peak, I would like to calculate the distance from my position to the peak (beginning and end), choosing the smallest one.
I don't know if there is any tool that can help me for doing that or if is something that I should figure out. In both cases, I really appreciate any advice :)
Thank you very much
1 answer
Maybe take a look at closest-features:
$ closest-features --closest --dist peaks.bed snps.bed > answer.bed
If the inputs are not sorted, you can pipe in sorted data via sort-bed:
$ closest-features --closest --dist <(sort-bed peaks.bed) <(sort-bed snps.bed) > answer.bed
The file answer.bed will contain the peak, the nearest SNP to that peak, and the signed distance between peak and SNP, separated by a | character. You can add the --delim <delimiter> option to specify a different delimiter, depending on what you might do downstream of this result.
Log in to answer this question.