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?

  • 1
    $\begingroup$ 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? $\endgroup$
    – llrs
    Commented Nov 8, 2017 at 15:01
  • $\begingroup$ cross posted: biostars.org/p/282410 $\endgroup$
    – Pierre
    Commented Nov 8, 2017 at 15:11

2 Answers 2


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]))

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

The test $5 < 1 filters elements from signal.bed that have a score value less than 1. Change this to the threshold test you would want to apply.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.