This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Manipulating Wiggle Files

I have a wiggle file and I also have a bed file with some features. I want to average the profile defined in the wiggle file over all of the features in the bed file in order to get an average profile.

Is there software out there that can do this? I would be especially interested in Bioconductor packages. Although, I am not commited to Bioconductor and I would be willing to use just about anything.

wiggle bed

4 answers

Sure, just download BEDOPS. Then:


  wig2bed mywig.wig | sort-bed - > mywig.sort.bed
  sort-bed mybed.bed > mybed.sort.bed
  bedmap --echo --mean --delim "\t" mybed.sort.bed mywig.sort.bed 

Each file must be properly sorted as shown above. Once that is completed, all operations with those files are extremely efficient in both time and memory. The bedmap command shown produces results in properly sorted order too, so subsequent analyses with its answer can be done without ever sorting it. bedmap comes loaded with a lot of calculations, including the --mean you're currently after.

wig comes in a variety of formats and it isn't a simple process to convert to bed when one considers all possibilities (for example, a wig file may embed several sub-wig files within itself, and these could be in any mixture of fixedStep, variableStep, or regular wig formats). I won't claim that this is common, but a good tool will deal with all of these possibilities. wig2bed will deal with any/all of those situations. And, you'll find it's really fast and memory efficient in practice.

As far as finer control than what I've shown above, check out --echo-map-score with bedmap. In addition to all of the built-in solutions, it can retrieve the group of overlapping scores for each row of your bed file, so you can process things further on your own. BEDOPS has pre-built binaries. You should consider downloading and giving it a shot.

The ucsc provides some utilities to handle the bigwig/bigbed files: for example bigWigAverageOverBed see http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/

Thanks. Is there something that would give me more fine control of the process?

From the kent source utilities, you can convert the wiggle files to bigWig by using wigToBigWig, the convert the bigWig to bedGraph format using bigWigToBedGraph, then you can use either bedops or bedtools to calculate the overlap statistics

A possible choice would be to convert the wiggle file to bed and use the bedtools package to intersect then perhaps the filo/groupBy to average. This would probably gove you all the control that you need. (I can't seem to find a wiggle to bed converter but that is a simple process)

The rtracklayer package has support for importing bigWig files (or sub ranges of them).

You can define your BED coordinates as some type of *Ranges object (GRanges, for instance), combine that with the rtracklayer::import.bw function (to import the bigWig), and you will be good to go.

This is the example code snippet you'll find at the bottom of the ?import.bw help page to give you an idea of how it works:

  bw <- import(system.file("tests", "test.bw", package = "rtracklayer"),
               ranges = GenomicRanges::GRanges("chr19", IRanges(1, 6e7)))

Log in to answer this question.