Answers.Body: <p>You can do that with a bit of python:</p>
  
  <pre class="lang-py prettyprint-override"><code>#!/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]) &gt; threshold:
              of.write("{}\t{}\t{}\n".format(chrom, interval[0], interval[1]))
  bw.close()
  of.close()
  </code></pre>
  
  <p>You'll need to install pyBigWig (it's available via <code>pip</code> or <code>conda install</code>) and change the lines with <code>Change me</code> in them.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-08T15:03:34.553Z
Answers.LastActivityDate: 2017-11-08T15:03:34.553Z
Answers.UserDisplayName: Devon Ryan
Answers.Body: <p>Convert bigWig to WIG via <a href="https://www.encodeproject.org/software/bigwigtowig/" rel="nofollow noreferrer"><code>bigWigToWig</code></a>:</p>
  <pre><code>$ bigWigToWig signal.bw signal.wig
  </code></pre>
  <p>Convert WIG to BED via BEDOPS <a href="http://bedops.readthedocs.io/en/latest/content/reference/file-management/conversion/wig2bed.html" rel="nofollow noreferrer"><code>wig2bed</code></a>:</p>
  <pre><code>$ wig2bed &lt; signal.wig &gt; signal.bed
  </code></pre>
  <p>Filter BED by its score column with <code>awk</code>:</p>
  <pre><code><span class="math-container">$ awk '($</span>5 &lt; 1)' signal.bed &gt; signal.filtered.bed
  </code></pre>
  <p>The test <code>$5 &lt; 1</code> filters elements from <code>signal.bed</code> that have a score value less than <code>1</code>. Change this to the threshold test you would want to apply.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-11-08T18:22:51.137Z
Answers.LastActivityDate: 2023-09-13T06:41:09.323Z
Answers.LastEditDate: 2023-09-13T06:41:09.323Z
Answers.UserDisplayName: Alex Reynolds
Body: <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-08T15:01:47.960Z
Comments.Text: 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?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-08T15:11:01.287Z
Comments.Text: cross posted: https://www.biostars.org/p/282410/
Comments.UserDisplayName: Pierre
Tags: <bed><bigwig>
Title: bigWig to bed for regions above/below threshold
ThreadText: # bigWig to bed for regions above/below threshold
  
  (Asked by: username_0 on 2017-11-08)
  
  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?
  
  **Tags:** bed, bigwig
  
  > **Comments:**
  > **username_1**: 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?  
  > **username_2**: cross posted: https://www.biostars.org/p/282410/  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-11-08. Score: 1 | Accepted answer
  
  You can do that with a bit of python:
  
  ```py
  #!/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.
  
  
  ---
  
  ### Answer by username_4 on 2017-11-08. Score: 1
  
  Convert bigWig to WIG via [`bigWigToWig`](https://www.encodeproject.org/software/bigwigtowig/):
  
  ```
  $ bigWigToWig signal.bw signal.wig
  
  ```
  
  Convert WIG to BED via BEDOPS [`wig2bed`](http://bedops.readthedocs.io/en/latest/content/reference/file-management/conversion/wig2bed.html):
  
  ```
  $ 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.
  
  
  ---
  
  