This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to split the .bigWig file into equal size of bin?

I am trying to output a .bedgraph like the following:

chrom start    end   mean
chr1  554300  554400  34 
chr1  554400  554500  43 
chr1  554500  554600  45 
chr1  554600  554700  65 
chr1  554700  554800  34

from a .bigWig file. how can i do this?

programming mapping alignment

2 answers

use the UCSC tool bigWigAverageOverBed (not tested)

Here's another way that lets you control more parameters:

$ assembly=hg38
$ bin_size=100
$ bigWigToWig signal.bw signal.wig
$ wig2bed < signal.wig > signal.bed
$ fetchChromSizes ${assembly} \
    | grep -v '_*_' \
    | awk -v FS="\t" -v OFS="\t" '{ print $1, "0", $2 }' \
    | sort-bed - \
    | bedops --split ${bin_size} - \
    | bedmap --echo --mean --delim '\t' - signal.bed \
    > answer.bg

The bedmap tool will let you swap out --mean with various other statistical operations, for instance (median, max, min, etc.).

Log in to answer this question.