Question: converting Bed to Wig
0
gravatar for rahel14350
6 months ago by
rahel1435030
United States
rahel1435030 wrote:

Dear all, I want to convert a bed file to wig one for a better visualization on UCSC but I have an error (below). Do you have any idea how can I solve the error when I am aware of overlaps in the output file?

    library(rtracklayer) #bioconductor
    bed_loaded <- import.bed(con="diff.bed") 
    export.wig(object=bed_loaded, con="diff.wig")
Error in FUN(extractROWS(unlisted_X, IRanges(X_elt_start[i], X_elt_end[i])),  : 
 Features cannot overlap. Note that WIG does not distinguish between strands - try exporting two tracks, one for each strand.

Kind Regards, Rahel

rtracklayer bigwig wig bed overlap • 428 views
ADD COMMENTlink modified 6 months ago by Alex Reynolds29k • written 6 months ago by rahel1435030
2

I would not do that in R. Use bedtools genomecov to get a bedGraph. bedGraph can then be transformed into wig or bigwig. I personally like bigwig as it is a binary (=compressed version).

Bedgraph To Wig

ADD REPLYlink written 6 months ago by ATpoint25k

Thank you so very much for your help. I will go try it but do you think in bedtools there is no problem with overlaps?

ADD REPLYlink written 6 months ago by rahel1435030

Not that I know of.

ADD REPLYlink written 6 months ago by ATpoint25k
1
gravatar for Alex Reynolds
6 months ago by
Alex Reynolds29k
Seattle, WA USA
Alex Reynolds29k wrote:

You could use bedops --partition to make disjoint elements from overlapping regions, and bedmap --mean (or --min, --max, etc.) to get a unique signal value for each disjoint element.

$ bedops --partition diff.bed5 > diff.partition.bed3
$ bedmap --echo --mean --delim '\t' diff.partition.bed3 diff.bed5 > diff.partition.map.bedgraph

To skip creating an intermediate file, use file streams:

$ bedops --partition diff.bed5 | bedmap --echo --mean --delim '\t' - diff.bed5 > diff.partition.map.bedgraph

The file extension .bedgraph indicates that the file is four columns, the first three columns being each disjoint element, and the fourth column representing the mean signal over that disjoint element.

If you don't want the mean signal, you can replace --mean with other statistical/score operations. See bedmap --help for more detail.

Finally, you can use Kent utilities to convert the bedgraph file to bigWig, and from there convert from bigWig to wig:

$ fetchChromSizes hg38 > hg38.sizes
$ bedGraphToBigWig diff.partition.map.bedgraph hg38.sizes diff.partition.map.bw
$ bigWigToWig diff.partition.map.bw diff.partition.map.wig

Replace hg38 with the name of whatever assembly you are using, if it is not hg38.

If you are doing visualization with the UCSC genome browser, you can skip creating a wig file and just use the bigWig file directly. The bigWig file is smaller and optimized for viewing at different scales.

ADD COMMENTlink modified 6 months ago • written 6 months ago by Alex Reynolds29k
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: 1965 users visited in the last hour