Customize bedtools intersect output
1
0
Entering edit mode
4.1 years ago
Ram 43k

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?

bedtools bed intersect • 809 views
ADD COMMENT
3
Entering edit mode
4.1 years ago
ATpoint 81k

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 COMMENT
1
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2527 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6