Question: Customize bedtools intersect output
0
gravatar for RamRS
6 months ago by
RamRS30k
Baylor College of Medicine, Houston, TX
RamRS30k wrote:

I have two bed files with 4 columns each and I'd like to intersect the bed files, then carry over the 4th column of one of the files as the 4th column of the result.

depth.bed, an output file from mosdepth, has very short intervals (from 1bp to ~200bp each).

exons.bed is a regular BED file with exon coordinates

When I tried bedtools intersect -a depth.bed -b exons.bed, there was no result as (I'm guessing) bedtools expect -a to be the file with the large intervals. I flipped the inputs and used bedtools intersect -a exons.bed -b depth.bed and this time, it worked fine.

However, the output now has the 4th column from exons.bed whereas I need the 4th column from depth.bed. I added the -wb option to get that included but what happens now is that I get the 4th column from exons.bed AND all 4 columns from depth.bed. I can use cut or awk to get just the columns I need, but is there any way to ask bedtools to give me just depth.bed's 4th column without adding a bunch of other stuff? Essentially, can I annotate my damn BED file with one column from another bed file?

intersect bed bedtools • 187 views
ADD COMMENTlink written 6 months ago by RamRS30k
3
gravatar for ATpoint
6 months ago by
ATpoint39k
Germany
ATpoint39k wrote:

This is odd. It should not matter which file is a and which is b. The overlap should always be reported.

$ cat small.bed 
chr1    1   10

$ cat large.bed 
chr1    1   100000

$ bedtools intersect -a small.bed -b large.bed 
chr1    1   10

$ bedtools intersect -b small.bed -a large.bed 
chr1    1   10
ADD COMMENTlink written 6 months ago by ATpoint39k
1

You're right. Maybe I made a typo or some other stupid mistake that caused my command to exit without any error or output.

Swapping the -a and -b solves the overall problem too, as the last field is picked from -a file by default. Thank you!

ADD REPLYlink written 6 months ago by RamRS30k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1547 users visited in the last hour