# bigWig to bed for regions above/below threshold

I'd like to threshold a bigWig file on a value and get all regions above or below that value in bed format. Ideally without too many file conversions. Are there any tools to do that?

• Welcome to Bioinformatics. What have you found? Where did you look up ? (To avoid looking at the same sites) What have you tried? I think that we have some other questions in this site about bed and bigwig. Aren't they helpful? – llrs Nov 8 '17 at 15:01
• cross posted: biostars.org/p/282410 – Pierre Nov 8 '17 at 15:11

You can do that with a bit of python:

#!/usr/bin/env python
import pyBigWig
threshold = 10  # Change me
bw = pyBigWig.open("file.bw")  # Change me
of = open("regions.bed", "w")  # Change me

for chrom, len in bw.chroms().items():
intervals = bw.intervals(chrom)
for interval in interals:
if abs(interval[2]) > threshold:
of.write("{}\t{}\t{}\n".format(chrom, interval[0], interval[1]))
bw.close()
of.close()


You'll need to install pyBigWig (it's available via pip or conda install) and change the lines with Change me in them.

Convert bigWig to WIG via bigWigToWig:

$bigWigToWig signal.bw signal.wig  Convert WIG to BED via BEDOPS wig2bed: $ wig2bed < signal.wig > signal.bed


Filter BED by its score column with awk:

$awk '($5 < 1)' signal.bed > signal.filtered.bed