<p>I do not know <code>bedops</code>, so I assume that this two-step pipe at the end of <code>bedmap</code> produces a regular bedGraph.</p>
<p>The problem is that both <code>bedGraphToBigWig</code> and <code>bigWigToWig</code> like any of the kentUtils tools does not read or write from/to <code>stdin</code>/<code>stdout</code>. Hence, write the bedGraph to disk, then convert to BigWig, then convert to Wig. Tedious, but that's what kentUtils support -- they do not allow piping.</p>

CC BY-SA 4.0
2024-06-01T13:29:40.603Z
Could you add the relevant command please? As it stands, this is pointing the OP in the right direction, but it isn't actually giving the answer.
terdon
CC BY-SA 4.0
2024-05-31T06:59:26.930Z
2024-05-31T06:59:26.930Z
ATpoint
<p>I was wondering how can I convert bed file to wig file.</p>
<p>I have several bed files which look like</p>
<pre><code>head EE88324.shortlong.frag.bed
chr1    10003   10117   1
chr1    10003   10138   1
chr1    10003   10146   1
chr1    10008   10152   1
chr1    10009   10129   1
chr1    10009   10130   1
chr1    10025   10169   1
chr1    10026   10145   1
chr1    10030   10172   1
chr1    10052   10245   1
</code></pre>
<p>Now I want convert this bed file to wig file, which should look like this, (this toy bed and wig samples are different)</p>
<pre><code>head -n 50 S9U_ZKDN240002406-1A_H5VMFDSXC_L1_bwaM_readCounts.w1000k.wig
fixedStep chrom=chr1 start=1 step=1000000 span=1000000
2682
8134
7087
6923
5585
5579
7056
5953
6174
7058
6606
6682
5630
4705
5432
6755
9442
6563
5891
6427
6033
6871
6360
6574
</code></pre>
<p>What I tried so far,</p>
<pre><code>#bed to wig conversion
chromsizes=&quot;~/mapF/GRCh38_chr.txt&quot;
bedGraphToBigWig=&quot;~/KentUtils/exe/linux.x86_64/bedGraphToBigWig&quot;
bigWigToWig=&quot;~/KentUtils/exe/linux.x86_64/bigWigToWig&quot;


conda activate bedops_env
    bedops --partition EE88324.shortlong.frag.bed |
    bedmap --echo --mean --delim '\t' --window 1000000 --fixed 1000000 - EE88324.shortlong.frag.bed |
    <span class="math-container">$bedGraphToBigWig - $</span>chromsizes |
    $bigWigToWig - EE88324.shortlong.diff.partition.map.1MB.wig
</code></pre>

<bed><ucsc><bigwig><conversion>
How to convert bed to wig file!
# How to convert bed to wig file!

(Asked by: username_0 on 2024-05-31)

I was wondering how can I convert bed file to wig file.
I have several bed files which look like
head EE88324.shortlong.frag.bed
chr1    10003   10117   1
chr1    10003   10138   1
chr1    10003   10146   1
chr1    10008   10152   1
chr1    10009   10129   1
chr1    10009   10130   1
chr1    10025   10169   1
chr1    10026   10145   1
chr1    10030   10172   1
chr1    10052   10245   1

Now I want convert this bed file to wig file, which should look like this, (this toy bed and wig samples are different)
head -n 50 S9U_ZKDN240002406-1A_H5VMFDSXC_L1_bwaM_readCounts.w1000k.wig
fixedStep chrom=chr1 start=1 step=1000000 span=1000000
2682
8134
7087
6923
5585
5579
7056
5953
6174
7058
6606
6682
5630
4705
5432
6755
9442
6563
5891
6427
6033
6871
6360
6574

What I tried so far,
#bed to wig conversion
chromsizes="~/mapF/GRCh38_chr.txt"
bedGraphToBigWig="~/KentUtils/exe/linux.x86_64/bedGraphToBigWig"
bigWigToWig="~/KentUtils/exe/linux.x86_64/bigWigToWig"


conda activate bedops_env
    bedops --partition EE88324.shortlong.frag.bed |
    bedmap --echo --mean --delim '\t' --window 1000000 --fixed 1000000 - EE88324.shortlong.frag.bed |
    $bedGraphToBigWig - $chromsizes |
    $bigWigToWig - EE88324.shortlong.diff.partition.map.1MB.wig

**Tags:** bed, ucsc, bigwig, conversion

---

## 1 answers

### Answer by username_1 on 2024-05-31. Score: 0

I do not know `bedops`, so I assume that this two-step pipe at the end of `bedmap` produces a regular bedGraph.

The problem is that both `bedGraphToBigWig` and `bigWigToWig` like any of the kentUtils tools does not read or write from/to `stdin`/`stdout`. Hence, write the bedGraph to disk, then convert to BigWig, then convert to Wig. Tedious, but that's what kentUtils support -- they do not allow piping.

> **Comments:**
> **username_2**: Could you add the relevant command please? As it stands, this is pointing the OP in the right direction, but it isn't actually giving the answer.  

---

