Question: Finding minima from bigwig in specific regions from bed file
gravatar for mmmmcandrew
3.2 years ago by
mmmmcandrew70 wrote:

Hi all- I have a bigwig file that contains a score for each base pair of the genome. I also have a bed file containing ~70000 regions of interest with average size ~1500 bp. I would like to use this bed file to find the minimum score (from the bigwig) within each of these ~70000 regions of interest, as well as the position of that minimum. bwtool find provides a tool to find local minima, etc., but there is no option to limit this to specific regions, unless I were to do the analysis ~70000 times and limit it to each individual region. Any ideas?

bigwig bed • 997 views
ADD COMMENTlink modified 3.2 years ago by Alex Reynolds30k • written 3.2 years ago by mmmmcandrew70
gravatar for Devon Ryan
3.2 years ago by
Devon Ryan95k
Freiburg, Germany
Devon Ryan95k wrote:
#!/usr/bin/env python
import pyBigWig

bw ="some bigwig")
f = open("some bed file.bed")
for line in f:
    cols = line.strip().split()
    val = bw.stats(cols[0], int(cols[1]), int(cols[2]), type="min")
    print("The minimum in the range {}:{}-{} is {}".format(cols[0], int(cols[1])+1, cols[2], val))

Or something along those lines.

ADD COMMENTlink written 3.2 years ago by Devon Ryan95k
gravatar for Alex Reynolds
3.2 years ago by
Alex Reynolds30k
Seattle, WA USA
Alex Reynolds30k wrote:

Sure, you can use Kent tools and BEDOPS to solve this.

Convert from bigwig to wiggle:

$ bigWigToWig signal.wig

Convert from wiggle to BED with wig2bed:

$ wig2bed < signal.wig > signal.bed

Sort your regions-of-interest file with sort-bed:

$ sort-bed roi.unsorted.bed > roi.bed

Map your regions-of-interest to your signal file with bedmap:

$ bedmap --echo --min-element roi.bed signal.bed > answer.bed

On each line in answer.bed, you get a region of interest from roi.bed and its associated minimum-scoring element from signal.bed.

If you're doing statistical tests, you might be interested in the --min-element-rand option in bedmap, which grabs a random map-set element in the case of ties. For instance, your signal might have a multimodal distribution and always grabbing the first of a set of tied minima (which --min-element and other approaches will do) may impart positional bias.

ADD COMMENTlink modified 3.2 years ago • written 3.2 years ago by Alex Reynolds30k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1661 users visited in the last hour