Convert per base bedgraph to Bed format
2
0
Entering edit mode
7 days ago
bioyas • 0

Hi everyone,

I have a bed graph file which contains par base intervals. I would like to convert this file to Bed format where we have longer intervals. Here is the BedGraph file.

PvP01_01_v1   0     1   0
PvP01_01_v1   1     2   3.39882
PvP01_01_v1   2     5   3.81385
PvP01_01_v1   5     7   2.81385
PvP01_01_v1   7     10  3.55081

Is there any tool that does the job?

Thanks,

Bedgraph perbase Bed Bedtools • 147 views
ADD COMMENT
2
Entering edit mode
7 days ago
mmmmcandrew ▴ 130

You can use bedtools merge. On your example data, this will create a single entry in the format:

PvP01_01_v1   0   10

It's not clear whether the information in your fourth column here is relevant for your future analyses, but you will likely lose that information.

ADD COMMENT
1
Entering edit mode

Just for information, it is possible to retain the information of the 4th column by using bedtools merge options -c 4 and -o mean (among other possible operators). It will take the mean of the original 4th column values that overlap the new interval.

ADD REPLY
0
Entering edit mode

Hell yea, thanks Carlo!

ADD REPLY
0
Entering edit mode
7 days ago

Convert to sorted bed:

$ awk -v FS="\t" -v OFS="\t" '{ print $1, $2, $3, ".", $4 }' in.bedGraph | sort-bed - > in.bed 

To merge:

$ bedops --merge in.bed > merged_intervals.bed

To map and apply signal operations:

$ bedmap --echo --sum merged_intervals.bed in.bed > signal_sum_over_merged_intervals.bed
$ bedmap --echo --mean merged_intervals.bed in.bed > signal_mean_over_merged_intervals.bed
$ bedmap --echo --median merged_intervals.bed in.bed > signal_median_over_merged_intervals.bed

Etc.

If you don't need to preserve signal, you can just strip it out:

$ sort-bed <(cut -f1-3 in.bedGraph) | bedops --merge - > merged_intervals.bed

If doing set operations that require signal, however, the ideal is to generate five-column BED, in order to follow UCSC specifications.

Ref:

ADD COMMENT

Login before adding your answer.

Traffic: 2310 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