This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bedtools window: getting feature from bedfile instead of GFF3 file

Hello,

I want to get features from a GFF3 file by using a bedfile and betools window. From what I understand from the documentation (![screencap][1] attached), I should get the desired result (features from B), however it seems that I get feature from the bedfile instead (file A).

I'm using this type of command:

bedtools window -a input.bed -b input.gff3 -l 50 -r 500 -sm > output

[1] : https://ibb.co/febExG

bedtools window

1 answer

BEDOPS bedops --range L:R with bedmap and gff2bed may be another option. The order of the two input files in bedmap specifies whether they are reference or map, respectively.

First, use awk to separate inputs by strand:

$ awk '($6=="+")' input.bed > input.for.bed 
$ awk '($6=="-")' input.bed > input.rev.bed 
$ gff2bed < input.gff3 > input.gff3.bed
$ awk '($6=="+")' input.gff3.bed > input.gff3.for.bed 
$ awk '($6=="-")' input.gff3.bed > input.gff3.rev.bed

Then map the GFF annotations to asymmetrically-padded regions, leaving out any GFF annotations that do not overlap padded reference elements:

$ bedops --range -50:500 --everything input.for.bed | bedmap --echo-map --skip-unmapped - input.gff3.for.bed | sort-bed - > answer.for.bed
$ bedops --range -500:50 --everything input.rev.bed | bedmap --echo-map --skip-unmapped - input.gff3.rev.bed | sort-bed - > answer.rev.bed

Then take the union the two stranded results:

$ bedops --everything answer.for.bed answer.rev.bed > answer.bed

Hope this helps!

@Alex: Slightly unrelated comment. Do you keep a running tally of answers (like this one) that you provide somewhere (like @Pierre has been doing on his GitHub site)? These would be hard to find by googling but can save someone a bunch of time, when needed.

I sometimes use the Biostars or Google search engine with various keywords. I'll look into this, maybe, but the documentation and examples cover most of this, too.

the documentation and examples cover most of this, too.

It is certainly possible considering your detailed answers (I confess that I am not a current BEDOPS user but will likely use it in future). The linear nature of program documentation is not able to capture dedicated solutions like this (how to do X with BEDOPS). A section on Biostars with practical answers like this would be a very useful section.

Log in to answer this question.