This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to remove the same genome coordinate in two bed files?

Hi, I have two bed files, say file A and file B.


File A:


  • chr3 181879479 181879497
  • chr3 181879496 181879514
  • chr3 181879507 181879525
  • chr3 181879555 181879573

File B:


  • chr3 181879496 181879514
  • chr3 181879507 181879525

How can I subtract the common items in A and B from A, and get bed file C as follow


  • chr3 181879479 181879497
  • chr3 181879555 181879573

Thanks a lot for your help.

next-gen genome r sequencing

2 answers

use the following command to remove intersected `regions' of A and B from A:

bedtools subtract -a A.bed -b B.bed > C.bed

or if you just want to remove the shared `lines' from A:

awk -F'\t' 'BEGIN{OFS="\t"}NR==FNR{a[$0];next}{if(!($0 in a)){print}}' B.bed A.bed > C.bed

Try bedtools intersect -v -a A.bed -b B.bed: http://bedtools.readthedocs.io/en/latest/content/tools/intersect.html

Thank you, I tried using bedtools, but it turns out lots of item are lost. In the case above, it only shows chr3 181879555 181879573

Log in to answer this question.