Thank you. I knew there had to be a simple solution like this available.
I have a large WIG files which are difficult to run in IGV, due to the size. I am only interested in chromosome M so I would like to extract signal from that chromosome and thus have a smaller file size. I found one solution on Stackoverflow (https://stackoverflow.com/questions/17354962/pcregrep-a-wiggle-file-to-extract-chromosome-multiple-line-regex-search), but that doesn't work at all. Any other ideas? I check UCSC utils and extensively searched online. I am also open to suggestions on bedgraph or similar formats.
3 answers
use one of the tools provided by the UCSC to extract a region of the chromosome : http://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/
for example bigWigToWig :
-chrom=chr1 - if set restrict output to given chromosome
-start=N - if set, restrict output to only that over start
-end=N - if set, restict output to only that under end
-udcDir=/dir/to/cache - place to put cache for remote bigBed/bigWigs
and then convert back to bigwig with wigToBigWig
Here's another solution.
You can convert the wig file to a bedGraph using bedops and manually cutting it:
wig2bed < hg19.sometrack.chr21.wig | cut -f1-3,5 > hg19.sometrack.chr21.bedgraph
Then convert it back to bigWig:
bedGraphToBigWig hg19.sometrack.chr21.bedgraph hg19.sizes hg19.sometrack.chr21.bw
Log in to answer this question.
Please specify what doesn't work.
The
awksolution on stackoverflow looks fine to me.fin swimmer
It produces an empty file. I checked with grep and the chromosome exists in the original file.