Question: Bedgraph To Wig
gravatar for alive
7.8 years ago by
alive50 wrote:

How to convert bedgraph to wig ? I tried converting bedgraph to bigwig and bigwig to wig using the kent tools. But no luck!

input looks like this

chr19 59302000 59302300 -1.0
chr19 59302300 59302600 -0.75
chr19 59302600 59302900 -0.50
chr19 59302900 59303200 -0.25
chr19 59303200 59303500 0.0
chr19 59303500 59303800 0.25
chr19 59303800 59304100 0.50
chr19 59304100 59304400 0.75
chr19 59304400 59304700 1.00
wiggle • 17k views
ADD COMMENTlink modified 4.8 years ago by Biostar ♦♦ 20 • written 7.8 years ago by alive50
gravatar for Alastair Kerr
7.8 years ago by
Alastair Kerr5.2k
The University of Edinburgh, UK
Alastair Kerr5.2k wrote:

They are already a very similar format. Indeed the wigToBigWig program in the kent package can use a bedgraph format as input.

Note there are many different type of wig format. (Variable step etc). So it depends what you are looking for.

  • Some wig files (aka wigbed) start conting from 0, others from 1. Bed (and bedgraph) usually starts from 0.
  • bedgraph is usually tab separated, whereas wig is space separated.

Therefore the simplest way to convert bg to wig:

  1. Optional: you may need to subtract 1 from each number in the bedgraph and convert tabs to spaces
    • perl -ne '@a = split; $a[1]--; $a[2]--; join (" ", @a)' infile > outfile
  2. add a track line to the top of the file
    • track type=wiggle_0 name=\"COMBINED\" description=FILENAME"
  3. convert tabs to spaces ( alternative to step one)
    • tr '\t' ' ' < infile > outfile
ADD COMMENTlink modified 7.8 years ago • written 7.8 years ago by Alastair Kerr5.2k

I would like it to be in variable step wiggle format.

ADD REPLYlink written 7.8 years ago by alive50
gravatar for dli
7.8 years ago by
dli220 wrote:

What error messages does bedGraphToBigWig claim?

Do you use the right chrom.sizes file?

Please also notice that bedGraphToBigWig require a sorted input file

$ bedGraphToBigWig 

bedGraphToBigWig v 4 - Convert a bedGraph program to bigWig.

   bedGraphToBigWig in.bedGraph chrom.sizes

where in.bedGraph is a four column file in the format:

 <chrom> <start> <end> <value>

and chrom.sizes is two column:  

 <chromosome_name> <size_in_bases>

and is the output indexed big wig file.

The input bedGraph file must be sorted, use the unix sort command:

  sort -k1,1 -k2,2 unsorted.bedGraph > sorted.bedGraph


   -blockSize=N - Number of items to bundle in r-tree.  Default 256

   -itemsPerSlot=N - Number of data points bundled at lowest level. Default 1024

   -unc - If set, do not use compression.
ADD COMMENTlink modified 7.7 years ago • written 7.8 years ago by dli220

1, bedGraph has a header: track type="bedGraph" description="***", I think you can not sort directly with 

  sort -k1,1 -k2,2 unsorted.bedGraph > sorted.bedGraph

2, be sure your bedGraph only have 4 column.


ADD REPLYlink written 3.9 years ago by Shicheng Guo8.0k
gravatar for Sukhdeep Singh
7.8 years ago by
Sukhdeep Singh10.0k
Sukhdeep Singh10.0k wrote:

Please give the error messages, I have experienced 5 different kinds of errors while doing this conversion and each error is linked to a different solution. Also, check this tutorial for bigWig conversion and viewing. Also, if bedgraph file is big, you should stick to bigBed or bigWig.


ADD COMMENTlink written 7.8 years ago by Sukhdeep Singh10.0k
Please log in to add an answer.


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