How to convert BAM file to bigWig in Python? I am manipulating some BAM files using pysam package which seems to be very fast and handy. However, I ran into problem when I am trying to generate bigWig files from BAM files in Python. I used bamCoverage from deeptools to do this previously, but it is a standalone tool that cannot be used from within my Python scripts.

Therefore, I am wondering what Python package would allow me to read in BAM files and convert them to bigWig files.

Thanks
deepTools has a (somewhat poorly documented) API, since it's a python package too. The basic code framework is:

from deeptools import writeBedGraph
from deeptools.getScaleFactor import get_scale_factor

wr = writeBedGraph.WriteBedGraph(options and input files)
func_args = {'scaleFactor': get_scale_factor(...options...)}
wr.run(writeBedGraph.scaleCoverage, func_args, output_file_name, ...)