Package: pybbi
pybbiPython interface to Jim Kent's Big Binary Indexed file (BBI) [1] library from theUCSC Genome Browser source treeusing Cython.This provides read-level access to local and remote bigWig and bigBed files but no write capabilitites. The main feature is fast retrieval of range queries into numpy arrays.InstallationWheels forpybbiare available on PyPI for Python 3.8, 3.9, 3.10, 3.11 on Linux (x86_64 and aarch64) and Mac OSX (x86_64/Intel). Apple Silicon (arm64) wheels will be made available once M1 runners are available in GitHub Actions.$ pip install pybbiAPIThebbi.openfunction returns aBBIFileobject.bbi.open(path) -> BBIFilepathcan be a local file path (bigWig or bigBed) or a URL.BBIFileobjects are context managers and can be used in awithstatement to clean up resources without callingBBIFile.close().>>>withbbi.open('bigWigExample.bw')asf:...x=f.fetch('chr21',1000000,2000000,bins=40)IntrospectionBBIFile.is_bigwig -> bool
BBIFile.is_bigbed -> bool
BBIFile.chromsizes -> OrderedDict
BBIFile.zooms -> list
BBIFile.info -> dict
BBIFile.schema -> dict
BBIFile.read_autosql() -> strNote:BBIFile.schema['dtypes']provides numpy data types for the fields in a bigWig or bigBed (matched from the autoSql definition).Interval outputThe actual intervals in a bigWig or bigBed can be retrieved as a pandas dataframe or as an iterator over records as tuples. The pandas output is parsed according to the file's schema.BBIFile.fetch_intervals(chrom, start, end) -> pandas.DataFrame
BBIFile.fetch_intervals(chrom, start, end, iterator=True) -> interval iteratorArray outputRetrieve quantitative signal as an array. The signal of a bigWig file is obtained from its "value" field. The signal of a bigBed file is obtained from the genomic coverage of its intervals.For a single range query:BBIFile.fetch(chrom, start, end, [bins [, missing [, oob, [, summary]]]]) -> 1D numpy arrayTo produce a stacked heatmap from a list of (1) equal-length intervals or (2) arbitrary-length intervals withbinsspecified:BBIFile.stackup(chroms, starts, ends, [bins [, missing [, oob, [, summary]]]]) -> 2D numpy arraySummaryquerying is supported by specifying the number ofbinsfor coarsening. Thesummarystatistic can be one of: 'mean', 'min', 'max', 'cov', 'std', 'or 'sum'. (default = 'mean'). Intervals need not have the same length, in which case the data from each interval will be interpolated to the same number of bins (e.g., gene bodies).Missingdata can be filled with a custom fill value,missing(default = 0).Out-of-boundsranges (i.e.startless than zero orendgreater than the chromosome length) are permitted because of their utility e.g., for generating vertical heatmap stacks centered at specific genomic features. A separate custom fill value,oobcan be provided for out-of-bounds positions (default = NaN).Function APIThe original function-based API is still available:bbi.is_bbi(path:str)->boolbbi.is_bigwig(path:str)->boolbbi.is_bigbed(path:str)->boolbbi.chromsizes(path:str)->OrderedDictbbi.zooms(path:str)->listbbi.info(path:str)->dictbbi.fetch_intervals(path:str,chrom:str,start:int,end:int,iterator:bool)->Union[Iterable,pd.DataFrame]bbi.fetch(path:str,chrom:str,start:int,end:int,[bins:int[,missing:float[,oob:float,[,summary:str]]]])->np.array[1,'float64']bbi.stackup(path:str,chroms:np.array,starts:np.array,ends:np.array,[bins:int[,missing:float[,oob:float,[,summary:str]]]])->np.array[2,'float64']See the docstrings for complete documentation.Related projectslibBigWig: Alternative C library for bigWig and bigBed files by Devon RyanpyBigWig: Python bindings forlibBigWigby the same authorbw-python: Alternative Python wrapper tolibBigWigby Brent Pedersonbx-python: Python bioinformatics library from James Taylor's group that includes tools for bbi files.This library provides bindings to the reference UCSC bbi library code. Check out@dpryan79'slibBigWigfor an alternative and dedicated C library for big binary files. pyBigWig also provides numpy-based retrieval and bigBed support.References[1]:http://bioinformatics.oxfordjournals.org/content/26/17/2204.fullFrom sourceIf wheels for your platform or Python version aren't available or you want to develop, you'll need to installpybbifrom source. The source distribution on PyPI ships with (slightly modified) kent utils source, which will compile before the extension module is built.RequiresPlatform: Linux or Darwin (Windows Subsystem for Linux seems to work too)pthreads, zlib, libpng, openssl, make, pkg-configPython 3.6+numpyandcythonFor example, on a fresh Ubuntu instance, you'll needbuild-essential,make,pkg-config,zlib1g-dev,libssl-dev,libpng16-dev.On a Centos/RedHat (rpm) system you'll needgcc,make,pkg-config,zlib-devel,openssl-devel,libpng-devel.On a Mac, you'll need Xcode and tobrew install pkg-config openssl libpng.For development, clone the repo and install in editable mode:$ git clone https://github.com/nvictus/pybbi.git
$ cd pybbi
$ pip install -e .You can use theARCHenvironment variable to specify a target architecture orARCHFLAGSon a Mac.NotesUnfortunately, Kent's C source is not well-behaved library code, as it is littered with error calls that callexit().pybbiwill catch and pre-empt common input errors, but if somehow an internal error does get raised, it will terminate your interpreter instance.