I am using bx-python to read a bigwig file. However, the current implementation is very slow. A single query in my benchmarks takes about 0.02 seconds in a 2.5Ghz server and I need to run thousands of queries. Through parallelization and other tricks I can read the bigwig faster but I wonder whether anyone knows other library or means to query a bigwig file using python? The perl library to read bigwig files is very fast but I will prefer a python solution.
Update to clarify the problem:
""" usage: %prog bigwig_file.bw < bed_file.bed """ from bx.intervals.io import GenomicIntervalReader from bx.bbi.bigwig_file import BigWigFile import numpy as np import time import sys bw = BigWigFile( open( sys.argv ) ) ll =  for interval in GenomicIntervalReader( sys.stdin ): start = time.time() bw.query(interval.chrom, interval.start, interval.end, 20 ) total = time.time() - start ll.append(total) print np.mean(ll)
This python script will print the average time of each call. For a bed file containing thousands of lines this code may take half an hour while a Perl counterpart using the Bio-BigFile library takes only few seconds.