This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Converstion of BED with scores into bigWig

I have some profiles with scores in BED format and I would like to convert them into bigWig format to visualise these data in jBrowse.

9    35084375    35084376    ENSDART00000000004    160.9480969    -
9    35060460    35060461    ENSDART00000000005    752.3776435    +
4    14148184    14148185    ENSDART00000000019    5226.62898     -
2    50770137    50770138    ENSDART00000000042    3513.471655    -

Typically (genomeCoverageBed + bedGraphToBigWig), the intervals from BED file are summed up into bigWig, but this is not what I want. I would like the scores from BED to be visible directly in bigWig track.

Can you recommend me some way of converting such BED in bigWig?

bed bigwig

1 answer

You can use awk to get a bedgraph:

awk '{printf "%s\t%d\t%d\t%2.3f\n" , $1,$2,$3,$5}' myBed.bed > myFile.bedgraph

In case the BED file was not sorted properly:

sort -k1,1 -k2,2n myFile.bedgraph > myFile_sorted.bedgraph

Finally, use the UCSC bedGraphToBigWig tool:

bedGraphToBigWig myFile_sorted.bedgraph myChrom.sizes myBigWig.bw

Beware of the naming conventions (sometimes you need to add a chr to your chromosomes' name).

Cheers,
Michael

[edit] updated awk-command after comment

Nice reply, but how to get the "myChrom.sizes"? Thanks.

samtools faidx genome.fasta 
cut -f1,2 genome.fasta.fai > genome.size

Thank you michael.ante ! But watch out, there's an extra apostrophe at the end of the awk syntax ' (on the answer)

Has someone encountered a problem with this? I did exactly this and the bigwigs look a bit weird. The bedGraph (MACS2 output .bdg file) shows nicely the peak-like bumps of signal whereas the bigwig shows narrow, rectangular towers as if it's just marking summits or the presence/absence of a peak instead of the different heights along the peak interval. I followed exactly the steps that are in this answer.. (sorted, created the chrom file and converted to bigwig - human chipseq data, hg38) could it be that there is some other parameter that I should add that I am ignoring?

Hi msimmer92,

Currently, I'm not 100% into this topic. I think it would be best to post this as a new question referring to this thread. I can remember that there are two ways of structuring a wig file, but which way is the more appropriate one I cannot remember.

Best,

Michael

I tried again with other of my samples and it seems the one I was handling had a problem or something, because the same exact procedure with others worked well. So your answer is still working! Forget my previous comment. For the record, there's also a tool called bedSort from UCSC that can be used for the sorting step.

Sorry , another comment. If you want to include this on a Bash script (that has arguments) the line with the awk crashes (since the $1, $2.. are substituted with the parameter values you feed into the script). An alternative might be cut -f1-3,5 instead of awk. That could be a nice edit to the answer. Thank you!

Log in to answer this question.