Operation on BigWig Files
Some operations on BigWig files.
Extract/subset bigwig file for a given genomic region
This is a solution in python version (3.0+) using a package called pyBigWig to extract a given genomic region from a whole genome bigwig file.
Prepare your input bigwig file:
import pyBigWig
# First open bigwig file
bwIn = pyBigWig.open('input.bw')
# check bigwig file header
print(bwIn.header())
Prepare output, since your output doesn’t have a header, you need to add the header using the chosen chromosome size, here I’m using a region from chr18 as an example.
bwOutput = pyBigWig.open('output.bw','w')
bwOutput.addHeader([('chr18',80373285)]) # chromosome size
for x in bwIn.intervals('chr18',62926563,63516911):
bwOutput.addEntries(['chr18'],[x[0]],ends=[x[1]],values=[x[2]])
bwOutput.close()
Merge bigwig files using average value
Software preparation
# install fetchChromSizes
wget https://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/fetchChromSizes
# install wigToBigWig
wget http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/wigToBigWig
# install wiggletools
conda install -c bioconda wiggletools
fetchChromSizes hg38 > hg38.genome
wiggletools mean sample1.bw sample2.bw ... sampleN.bw | wigToBigWig stdin hg38.genome mean.bw
References
Enjoy Reading This Article?
Here are some more articles you might like to read next:
- From Bench to Bedside: A Practical Guide to Using Large Language Models in Medical Research
- Rethinking Bioinformatics Expertise in the Era of AI: A Newbie's Journey as a Custodian
- Mapping the Global Landscape of Cancer Research: Key Trends from the Nature Index
- Shattered Chromosomes: Understanding Chromothripsis and Genome Rearrangement Models
- Diffusion LLMs
- Nanopore raw data visualization using squigualiser
- Nanopore direct RNA data analysis using Dorado
- Modern commnad line tools powered by Rust
- Nanopore direct cDNA data analysis
- Hi-C data analysis