Finding minima from bigwig in specific regions from bed file
2
0
Entering edit mode
7.1 years ago
mmmmcandrew ▴ 190

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 • 2.0k views
ADD COMMENT
2
Entering edit mode
7.1 years ago
#!/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 COMMENT
2
Entering edit mode
7.1 years ago

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 COMMENT

Login before adding your answer.

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