wig2bed will do the work of steps 1 and 2: http://code.google.com/p/bedops/wiki/wig2bed
Hi,
I would like to convert the wiggle file from hg18 to hg19 version. LifeOver can do that conversation for BED but not wiggle file. Could you pls let me know if any tools can do that conversion? Many thanks!
Chan
5 answers
Using the ucsc tools:http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/
- convert wig to bigwig if needed with wigToBigWig
- convert the bigwig to bed using bigwigToBedGraph
- lift over the bed
- convert the bed back to wig using bedGraphToBigWig
I am currently doing the similar task (liftover a bigwig file from mm9 to mm10). The above answers are helpful, but I think they are not comprehensive enough for beginners to work with. So, I listed my pipeline below. Hopefully, it can help some people.
# My task: liftover from mm9 to mm10 for a big wig file.
# All tools used below can be found @ https://genome.ucsc.edu/util.html
# 0) If you start with the wiggle file, you will need "wigToBigWig" to convert wig to bigwig;
e.g. wigToBigWig in.wig chrom.sizes out.bw
# 1) Convert bigwig to bedGraph
bigWigToBedGraph H3K27ac.mm9.bw H3K27ac.mm9.bedGraph
# 2) Liftover from mm9 to mm10
liftOver H3K27ac.mm9.bedGraph mm9ToMm10.over.chain H3K27ac.mm10.bedGraph unMapped
# 3) Sort the bed file
sort -k1,1 -k2,2n H3K27ac.mm10.bedGraph > H3K27ac.mm10.sort.bedGraph
# 4) Fix the overlapping intervals
# The bed file from liftover might have overlapping intervals. You will hit error if directly using bedGraphToBigWig for file conversion. In this case, you need to split the overlapping intervals and assign mean signal to a new bed file.
awk -vOFS="\t" '{ print $1, $2, $3, ".", $4 }' H3K27ac.mm10.sort.bedGraph > tmp.bed
bedops --partition tmp.bed | bedmap --echo --mean --delim '\t' - tmp.bed > H3K27ac.mm10.split.bedGraph
# 5) Convert bedGraph to bigwig
bedGraphToBigWig H3K27ac.mm10.split.bedGraph mm10.sizes.genome H3K27ac.mm10.bw
Done! Have fun!
hg38bwTohg19bw.pl
use strict;
use Cwd;
use POSIX;
my $dir = getcwd;
my @file=glob("*.hg38.bw");
foreach my $file(@file){
open OUT,">$file.job";
my ($fn)=split/.hg38.bw/,$file;
print OUT "#PBS -N $fn\n";
print OUT "#PBS -l nodes=1:ppn=1\n";
print OUT "cd /gpfs/home/run/blueprint\n";
#print OUT "bigWigToBedGraph $file $fn.hg38.bedgraph\n";
#print OUT "liftOver $fn.hg38.bedgraph hg38ToHg19.over.chain.gz $fn.hg19.bedgraph unmap\n";
print OUT "bedtools sort -i $fn.hg19.bedgraph > $fn.hg19.bedgraph.sort\n";
print OUT "bedGraphToBigWig $fn.hg19.bedgraph.sort hg19.chrom.sizes $fn.hg19.bw\n";
}
close OUT;
Possible problem:
- repeat loci might be come out when transfer bw to bedgraph
- might need sort -u before bedtools sort
- unique regions in raw file might have duplicated and overlapped new regions.
- and therefore you need unqiue and interact operation
This is an old question, but if you're using UCSC liftOver, you may want to do a lift-over (map) operation in both directions, to get those intervals that map between genomes in a consistent manner:
- Lift-over intervals from genome A to genome B (e.g., hg18 to hg19).
- Lift-over genome B intervals back to genome A.
- Use
bedmap --exactto filter for intervals that started in genome A and mapped back to the same location in genome A. - Lift-over those unambiguous intervals back to genome B (or use IDs or other hash table or dictionary-based approaches to keep a mapping of genome A to genome B, to avoid the third lift-over).
The wig2bed tool can be used to convert wiggle files to BED format.
For the record Cistrome.org have tool for doing this via a GALAXY like interface. However, their site is not working at the time of writing this.
Log in to answer this question.
it's called LiftOver btw, much less dramatic than LifeOver ;)