This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to find Overlapping coordinates on their 3' or 5'?

Given many genomic coordinates, how do I find those that have matching 5' or 3' ends, regardless of length. for example:

chr1    10  20  feat1   .   +

chr1    10  25  feat2   .   +

chr1    12  20  feat3   .   +

All the features overlap, but I am only interested in feat1 and feat2 which share the same start position, or in this case the 5'. Should I be interested in the 3' end, than, feat1 and feat3 (plus the coordinates).

I have looked at the options of bedtools but couldn't find out how to do this. Is there a tool out there that allows me to do this, if so which, or go I have to cobble something together? I guess awk is always an option.

bed bedtools intersection genomic coordinates

1 answer

I am only interested in feat1 and feat2

create a pseudo-column [chrom/start] , join the file with itlself, remove the self/self

join -t $'\t' -1 1 -2 1 <(sed 's/\t/_/' input.txt | sort -t $'\t' -k1,1 )  <(sed 's/\t/_/' input.txt | sort -t $'\t' -k1,1 ) | awk -F '\t' '($2!=$6)' | tr "_" "\t"

Nice idea, but the the join does not seem to be working:


join -t $'\t' -1 1 -2 1 <(sed 's/\t/_/' a.bed | sort -t $'\t' -k1,1 )  <(sed 's/\t/_/' a.bed | sort -t $'\t' -k1,1 ) 

chr1 10 20 feat1 . +

chr1 10 25 feat2 . +

chr1 12 20 feat3 . +

The full command returns nothing.

Tabs but these were converted to spaces, so I double checked, and also with "," as a separator, and the problems is awk:

join -t $'\t' -1 1 -2 1 <(sed 's/\t/_/' a.bed | sort -t $'\t' -k1,1 )  <(sed 's/\t/_/' a.bed | sort -t $'\t' -k1,1 ) 
chr1_10 25  feat2   .   +   25  feat2   .   +
chr1_100    20  feat1   .   +   20  feat1   .   +
chr1_12 20  feat3   .   +   20  feat3   .   +

In this example, the second field is always similar to the sixth and thus awk -F '\t' '($2!=$6)' fails. Anyway, your idea gave me something to work with. Thanks.

Log in to answer this question.