This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bedtools map to generate a new bedgraph

Hello

I have a bed file with Start and End co-ordinates and I also have a bedgraph file with scores. I want to create a new bedgraph file using the co-ordinates in my bed file.

I know that bedtools map can do this. However, I cannot figure out which of the options to use

-o options

sum - numeric only
count - numeric or text
count_distinct - numeric or text
min - numeric only
max - numeric only
absmin - numeric only
absmax - numeric only
mean - numeric only
median - numeric only
antimode - numeric or text
collapse (i.e., print a comma separated list) - numeric or text
distinct (i.e., print a comma separated list) - numeric or text
concat (i.e., print a comma separated list) - numeric or text

If I have a bed file a.bed

Start End
4     9

And if I have a bdg file b.bdg

Start End Score
1     5   15
6     10  7

I want an output bdg file like this

Start End Score
4     5   15
6     9   7

So the number of entries in the new bdg files increase.

bedtools map

1 answer

Hi Seigfried,

you can use intersectBed to generate the overlaps (I think you need to include a chromosome name - I used "1"):

intersectBed -a a.bed -b b.bed 
1   4   5
1   6   9

With -wb you can include the b.bed information:

intersectBed -a a.bed -b b.bed -wb
1   4   5   1   1   5   15
1   6   9   1   6   10  7

Afterwards you can use e.g. cut to get the columns of interest:

intersectBed -a a.bed -b b.bed -wb | cut -f 1-3,7
1   4   5   15
1   6   9   7

Cheers,

Michael

I used intersectbed but forgot about -wb. Amazing. Thank you so much.

Log in to answer this question.