Question: Finding minima from bigwig in specific regions from bed file
0
gravatar for mmmmcandrew
2.1 years ago by
mmmmcandrew60
mmmmcandrew60 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 • 747 views
ADD COMMENTlink modified 2.1 years ago by Alex Reynolds28k • written 2.1 years ago by mmmmcandrew60
2
gravatar for Devon Ryan
2.1 years ago by
Devon Ryan90k
Freiburg, Germany
Devon Ryan90k wrote:
#!/usr/bin/env python
import pyBigWig

bw = pyBigWig.open("some bigwig file.bw")
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))
f.close()
bw.close()

Or something along those lines.

ADD COMMENTlink written 2.1 years ago by Devon Ryan90k
2
gravatar for Alex Reynolds
2.1 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

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

Convert from bigwig to wiggle:

$ bigWigToWig signal.bw 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 2.1 years ago • written 2.1 years ago by Alex Reynolds28k
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: 1328 users visited in the last hour