This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove overlapping genes and remove genes with distance < 5000kb

Hello,

I'm working on a file .bed. I would like to create a new file without genes that are overlapping. I have the coordinates of the beginning and the end of the genes. For example:

gene1 start = 1 end = 10
gene2 start=5 end = 7
gene3 start = 9 end = 12
gene4 start = 10 end = 15

I would like to remove all these genes.

And in a second time, i would like to remove genes that they have a distance of less than 5000kb between them.

I tried to do Rstudio and Python script, but I did not succeed. I also tried to do the two steps in one.

If someone have an idea with a script or maybe an other tool ?

Thanks
A

bedtools rstudio igv bed python

Yes i did that, but i only have one file

I'm sorry but i didn't see how it's work. If i use the file twice, it return an error message " No input file given"

$ cat << EOF | awk -F '[ =]+' '{printf("X\t%s\t%s\t%s\n",$3,$5,$1);}' | sort -t $'\t' -k1,1 -k2,2n > jeter.bed
gene1 start = 1 end = 10
gene2 start=5 end = 7
gene3 start = 9 end = 12
gene4 start = 10 end = 15
EOF


 bedtools intersect -wa -wb -a  jeter.bed   -b jeter.bed  | awk '($4!=$8)' | cut -f4,8 | tr "\t" "\n" | sort | uniq > exclude.txt

Thanks for the code ! I understand that "exclude.txt" contain the names of the genes that i don't want. But how to collect all the "good" genes ?

When i tried on my bed file, i put awk '($4!=$10)' because i have 6 column, and i obtained an aberrant result (to much genes exclude). I think the command doesn't take into account the different chromosomes. The genes were already sorted so i didn't apply the first command.

I tested to change awk and cut, but the result remains aberrant.

Maybe the solution is simple but it's the first time i work with bash commands and bedtools. I searched the meaning of all parameters but i didn't understand all yet

1 answer

I finally succeed ! I used : $bedtools cluster -i A.bed -d 5000 to obtained any features that overlap or are within 5000 base pairs. And with Panda i remove all the duplicates !

Log in to answer this question.