Bedgraph To Wig
3
4
Entering edit mode
12.7 years ago
alive ▴ 50

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 • 24k views
ADD COMMENT
3
Entering edit mode
12.7 years ago
dli ▴ 250

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 COMMENT
0
Entering edit mode
  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 has 4 columns.

ADD REPLY
1
Entering edit mode
12.7 years ago

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 COMMENT
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode
12.6 years ago

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 COMMENT

Login before adding your answer.

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