bedtools subtract regions within a single file?

133 views
Skip to first unread message

Luke Goodsell

unread,
Nov 17, 2014, 6:07:35 AM11/17/14
to bedtools...@googlegroups.com
Hi,

I have a bed file of many overlapping regions, sorted by precedence (in score column). I would like each basepair defined by the file to be present no more than once, assigned to a the lowest value score of any of the regions in the bed file that contain that basepair.

eg:

➜  cat input.bed
chr1 20 30 Region_B 1 +
chr1 10 40 Region_A 2 +
chr1 35 50 Region_C 3 +

should become:

➜  cat output.bed
chr1 20 30 Region_B 1 +
chr1 10 20 Region_A 2 +
chr1 30 40 Region_A 2 +
chr1 40 50 Region_C 3 +

Is there a bedtools way to do this efficiently?

The 'best' solution I have found is:

    touch output.bed;
    while read regionline; do
        echo "$regionline" \
            | subtractBed -a - -b output.bed \
            >> output.bed; \
    done <input.bed

As you would expect, this is very slow.

Many thanks,
Luke

Aaron Quinlan

unread,
Nov 20, 2014, 11:32:21 AM11/20/14
to bedtools...@googlegroups.com
I am sorry, but I can’t think of a clever way to do this solely with bedtools. There may be one, but it don’t easily come to mind for me.

- Aaron





--
You received this message because you are subscribed to the Google Groups "bedtools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bedtools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages