14 months ago
Seattle, WA USA
You could use
bedops --partition to make disjoint elements from overlapping regions, and
bedmap --mean (or
--max, etc.) to get a unique signal value for each disjoint element.
$ bedops --partition diff.bed5 > diff.partition.bed3
$ bedmap --echo --mean --delim '\t' diff.partition.bed3 diff.bed5 > diff.partition.map.bedgraph
To skip creating an intermediate file, use file streams:
$ bedops --partition diff.bed5 | bedmap --echo --mean --delim '\t' - diff.bed5 > diff.partition.map.bedgraph
The file extension
.bedgraph indicates that the file is four columns, the first three columns being each disjoint element, and the fourth column representing the mean signal over that disjoint element.
If you don't want the mean signal, you can replace
--mean with other statistical/score operations. See
bedmap --help for more detail.
Finally, you can use Kent utilities to convert the bedgraph file to bigWig, and from there convert from bigWig to wig:
$ fetchChromSizes hg38 > hg38.sizes
$ bedGraphToBigWig diff.partition.map.bedgraph hg38.sizes diff.partition.map.bw
$ bigWigToWig diff.partition.map.bw diff.partition.map.wig
hg38 with the name of whatever assembly you are using, if it is not
If you are doing visualization with the UCSC genome browser, you can skip creating a wig file and just use the bigWig file directly. The bigWig file is smaller and optimized for viewing at different scales.