Convert BED file to WIG file

3.4k views Asked by At

Do you know any way to convert easily (either by R, or with other program) a BED file to WIG?

Can you give me some guidelines?

2

There are 2 answers

2
Paolo On BEST ANSWER

Take a look at the rtracklayer package and specifically at the following man pages:

 ?import
 ?export
0
David C. On

Here is a specific example of how I would convert .bed to .wig. As @Paolo implied, it's a straight-forward procedure:

library(rtracklayer) #bioconductor

bed_loaded <- import(con="~/Downloads/my_bed.bed.gz", format="bed") #no need to unzip .gz
# bed_loaded <- import.bed(con="~/Downloads/my_bed.bed") #if you unzip 

export.wig(object=bed_loaded, con="~/Downloads/bed2wig.wig")

Note that you import and export both have methods (wig, bed, bigwig or bw, etc.). You may directly use them without specifying the method but specifying format argument.

This GitHub tutorial will be helpful.