Manipulating Wiggle Files
4
2
Entering edit mode
12.5 years ago
KCC ★ 4.1k

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 • 9.3k views
ADD COMMENT
5
Entering edit mode
11.2 years ago
sjneph ▴ 690

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.

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
12.5 years ago

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/

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

more control ? the sources for the bigWIG format are available in the UCSC git repository. A big* library is also available for java: http://biostar.stackexchange.com/questions/6146

ADD REPLY
1
Entering edit mode
12.5 years ago

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)

ADD COMMENT
1
Entering edit mode
12.5 years ago

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)))
ADD COMMENT

Login before adding your answer.

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