This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting reads outside the boundaries in a BED file

HI,

I am new to bed file manipulations. I have two bed files like follows:

A.BED
Chr1    90       111    
Chr1    95       110
Chr1    102     115
Chr1    105     118
Chr1    107     119
Chr1    117     130

B.BED
Chr1 100   120

Now I would like to retain reads that is outside the range of B.BED. I mean I would like get the following as output

Chr1    90       111    
Chr1    95       110
Chr1    117     130

How can I get the above following output using bedtools or bedops. Kindly guide me

bed_file bedtools

2 answers

Via bedops, you can get all elements from set A which do not overlap entirely in set B via the -n 100% option:

$ bedops -n 100% A.bed B.bed > answer.bed
$ more answer.bed
Chr1    90  111
Chr1    95  110
Chr1    117 130

Basically, if there is any portion of an interval in A that is outside of B, -n 100% will report that interval.

It is the converse operation of -e 100%, if that helps. The -e 100% option reports all elements in A that are contained fully within elements in B, and, accordingly, -n 100% reports all elements which are not.

For details, please see: https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#not-element-of-n-not-element-of

bedtools intersect -v -a <A.BED>  -b <B.BED>

for more instruction read this: http://bedtools.readthedocs.io/en/latest/content/tools/intersect.html

That does not produce the output @Tom wants.

-v option -> Only report those entries in A that have no overlap in B!

Based on the example posted above what @Tom wants is entries that either have a start/stop outside of the interval in B file.

This can easily be done in AWK!

Can you replace the answer above with awk version then?

Log in to answer this question.