Conversion BED to WIG

8,871 views
Skip to first unread message

Aurore Puy

unread,
Apr 22, 2011, 6:41:05 AM4/22/11
to bedtools-discuss
I would like to convert BED file into WIG file.
Is it possible with BedTools ?

Thank you by advance of your response.

Aurore Puy
Biostatistician
---------------------------------------------------------
IGH - Institut de Génétique Humaine
CNRS - UPR 1142
141, rue de la Cardonille
34396 Montpellier Cedex 5 - France
Tel : 04.34.35.99.51
Mail: auror...@igh.cnrs.fr

Aaron Quinlan

unread,
Apr 22, 2011, 10:05:09 AM4/22/11
to bedtools...@googlegroups.com
Hi Aurore,

BEDTools alone will not create WIG format. However, using the genomeCoverageBed program, one can create BEDGRAPH format using the "-bg" option. From there, one can use Jim Kent's tools to convert from BEDGRAPH to bigWig.

Does anyone else know of a more direct approach? This is asked frequently enough that it might be wise to add WIG as an output of genomeCoverageBed.

The following thread touches on the above approach:
http://seqanswers.com/forums/showthread.php?t=4731


Best,
Aaron

Aaron Quinlan, Ph.D.
Assistant Professor
Department of Public Health Sciences
Center for Public Health Genomics
University of Virginia
West Complex
Box 800717, Charlottesville, VA 22908
(T) 434.243.1669 (F) 434.924.1312
cphg.virginia.edu/quinlan
ar...@virginia.edu

Assaf Gordon

unread,
Apr 22, 2011, 10:37:57 AM4/22/11
to bedtools...@googlegroups.com, Aaron Quinlan
Hi Aaron,

Aaron Quinlan wrote, On 04/22/2011 10:05 AM:
> Hi Aurore,


>
> Does anyone else know of a more direct approach? This is asked
> frequently enough that it might be wise to add WIG as an output of
> genomeCoverageBed.
>
> The following thread touches on the above approach:
> http://seqanswers.com/forums/showthread.php?t=4731

I think a simpler approach is to create a FAQ section and explain that WIG is an outdated format, and bedgraph succeeded it.

I believe the main goal of people asking about Wig format is to upload the files as tracks to the UCSC Genome Browser - because that's what they are familiar with (bedGraph/BigWig being a recent addition).

One can upload BedGraph files directly into the genome browser (just like Wig files), without the need to create a BigWig file and put it on a FTP server.

All that's required is adding the following header line:
"track type=bedGraph"
followed by the rest of the bedGraph output of genomeCoverageBed.

More information is available here:
http://genome.ucsc.edu/goldenPath/help/bedgraph.html

One option that I can easily add is something like "-trackline" which will add this one line to the output genomeCoverageBed - this will enable users to immediately upload it to the genome browser (but will prevent it from being converted into BigWig, without first remove this line).

Then a flow would be:

sortBed -i input.bed | genomeCoverageBed -bg -i stdin -trackline | gzip > output.bedgraph.gz

And we just need to tell people to upload "output.bedgraph.gz" as a custom track to the genome browser.

Just my two cents,
-gordon

Aaron Quinlan

unread,
Apr 22, 2011, 3:21:49 PM4/22/11
to Assaf Gordon, bedtools...@googlegroups.com
Hi Gordon,

You raise valid points. In particular, the need for a proper FAQ and stable community example site is clear. I just created a preliminary stub of an FAQ page on the Google Code site (http://code.google.com/p/bedtools/wiki/FAQ).

If interest exists, I can add people as contributors. Thus, those contributors could add/edit content to the FAQ. This may be an interesting solution to the fact that the Google powers that be decommissioned the "Community Usage Examples" page.

Please let me know if you are interested in contributing to the FAQ or a possible new "Community Examples" page on the Google Code site.

Best,
Aaron

Assaf Gordon

unread,
Apr 26, 2011, 11:26:44 AM4/26/11
to bedtools...@googlegroups.com
Hi Aaron,

I've added the "-trackline" option as discussed, so now it's possible to quickly upload a bedGraph file into the genome browser without creating a BigWig and the hassle bigDataURL ( of course, uploading huge text files as custom tracks is still annoying ).

Example without trackline (the default):
============
$ genomeCoverageBed -ibam lane5.bam -g mm9.sizes.txt -bg | head
chr1 3000858 3000898 1
chr1 3000926 3000966 1
chr1 3001800 3001840 1
chr1 3002108 3002110 1
chr1 3002110 3002112 2
chr1 3002112 3002148 3
chr1 3002148 3002152 2
chr1 3002152 3002178 1
============

Example with track line:
$ genomeCoverageBed -ibam lane5.bam -g mm9.sizes.txt -bg -trackline| head
track type=bedGraph
chr1 3000858 3000898 1
chr1 3000926 3000966 1
chr1 3001800 3001840 1
chr1 3002108 3002110 1
chr1 3002110 3002112 2
chr1 3002112 3002148 3
chr1 3002148 3002152 2
========================


Example with track line setting custom track options (e.g. name and color):
==============
$ genomeCoverageBed -ibam lane5.bam -g mm9.sizes.txt -bg -trackline -trackopts 'name="My Track" visibility=2 color=255,30,0' | head
track type=bedGraph name="My Track" visibility=2 color=255,30,0
chr1 3000858 3000898 1
chr1 3000926 3000966 1
chr1 3001800 3001840 1
chr1 3002108 3002110 1
chr1 3002110 3002112 2
chr1 3002112 3002148 3
chr1 3002148 3002152 2
chr1 3002152 3002178 1
==============


So now the FAQ can say:
To upload a BedGraph file (similar to a Wiggle file), run the following command:

$ genomeCoverageBed -ibam lane5.bam -g mm9.sizes.txt -bg -trackline -trackopts 'name=MyDataLibrary' | gzip > output.bedgraph.gz

And simply upload the file "output.bedgraph.gz" as a custom track to the genome browser.


This feature is available here:
https://github.com/agordon/bedtools/tree/genomeCoverageBed


Regards,
-gordon

Aaron Quinlan

unread,
Apr 27, 2011, 7:52:50 AM4/27/11
to bedtools...@googlegroups.com
Hi Gordon,

This is very convenient, thank you! I will add this, as well as your other changes to gCB to the next release.

Best,
Aaron

cajan...@gmail.com

unread,
Mar 5, 2015, 4:24:04 PM3/5/15
to bedtools...@googlegroups.com, aaronq...@gmail.com
Hi Gordon,

Notice that in your proposed flow you're missing the "-g" parameter (the size of chroms in genome of interest) in the call to "genomeCoverageBed", so it would need to be corrected to:

sortBed -i input.bed | genomeCoverageBed -bg -i stdin -trackline -g [genomeFile] | gzip > output.bedgraph.gz

Other than that, this is working for me.

Thanks,

- Alvaro.
Reply all
Reply to author
Forward
0 new messages