Question: Bedgraph To Wig
4
gravatar for alive
7.0 years ago by
alive50
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 • 15k views
ADD COMMENTlink modified 4.1 years ago by Biostar ♦♦ 20 • written 7.0 years ago by alive50
1
gravatar for Alastair Kerr
7.0 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.0 years ago • written 7.0 years ago by Alastair Kerr5.2k
1

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

ADD REPLYlink written 7.0 years ago by alive50
1
gravatar for dli
7.0 years ago by
dli220
WUSTL
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.

usage:
   bedGraphToBigWig in.bedGraph chrom.sizes out.bw

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 out.bw 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

options:

   -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.0 years ago • written 7.0 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.2 years ago by Shicheng Guo7.4k
1
gravatar for Sukhdeep Singh
7.0 years ago by
Sukhdeep Singh9.7k
Netherlands
Sukhdeep Singh9.7k 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.

Cheers

ADD COMMENTlink written 7.0 years ago by Sukhdeep Singh9.7k
Please log in to add an answer.

Help
Access

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