Python bindings to the UCSC Big Binary (bigWig/bigBed) file library.
Project description
pybbi
Python interface to Jim Kent's Big Binary Indexed file (BBI) [1] library from the UCSC Genome Browser source tree using 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.
Installation
Wheels for pybbi
are available on PyPI for Python 3.6, 3.7, 3.8, 3.9, 3.10 on Linux and Mac OSX platforms under x86-64 architecture.
$ pip install pybbi
API
The bbi.open
function returns a BBIFile
object.
bbi.open(path) -> BBIFile
path
can be a local file path (bigWig or bigBed) or a URL. BBIFile
objects are context managers and can be used in a with
statement to clean up resources without calling BBIFile.close()
.
>>> with bbi.open('bigWigExample.bw') as f:
... x = f.fetch('chr21', 1000000, 2000000, bins=40)
Introspection
BBIFile.is_bigwig -> bool
BBIFile.is_bigbed -> bool
BBIFile.chromsizes -> OrderedDict
BBIFile.zooms -> list
BBIFile.info -> dict
BBIFile.schema -> dict
BBIFile.read_autosql() -> str
Note: BBIFile.schema['dtypes']
provides numpy data types for the fields in a bigWig or bigBed (matched from the autoSql definition).
Interval output
The 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 iterator
Array output
Retrieve 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 array
For a list of equal-length segments (i.e. to produce a stacked heatmap):
BBIFile.stackup(chroms, starts, ends, [bins [, missing [, oob, [, summary]]]]) -> 2D numpy array
-
Summary querying is supported by specifying the number of
bins
for coarsening. Thesummary
statistic can be one of: 'mean', 'min', 'max', 'cov', 'std', 'or 'sum'. (default = 'mean'). -
Missing data can be filled with a custom fill value,
missing
(default = 0). -
Out-of-bounds ranges (i.e.
start
less than zero orend
greater 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,oob
can be provided for out-of-bounds positions (default = NaN).
Function API
The original function-based API is still available:
bbi.is_bbi(path) -> bool
bbi.is_bigwig(path) -> bool
bbi.is_bigbed(path) -> bool
bbi.chromsizes(path) -> OrderedDict
bbi.zooms(path) -> list
bbi.info(path) -> dict
bbi.fetch_intervals(path, chrom, start, end, iterator) -> interval iterator or pandas.DataFrame
bbi.fetch(path, chrom, start, end, [bins [, missing [, oob, [, summary]]]]) -> 1D array
bbi.stackup(path, chroms, starts, ends, [bins [, missing [, oob, [, summary]]]]) -> 2D array
See the docstrings for complete documentation.
Related projects
- libBigWig: Alternative C library for bigWig and bigBed files by Devon Ryan
- pyBigWig: Python bindings for
libBigWig
by the same author - bw-python: Alternative Python wrapper to
libBigWig
by Brent Pederson - bx-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's libBigWig for 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.full
From source
If wheels for your platform or Python version aren't available or you want to develop, you'll need to install pybbi
from source. The source distribution on PyPI ships with (slightly modified) kent utils source, which will compile before the extension module is built.
Requires
- Linux/MacOS
- C compiler, zlib, pthreads, libpng, openssl, make
- Python 3.4+
numpy
andcython
On fresh Ubuntu instance, you'll need build-essential
, make
, zlib1g-dev
, libssl-dev
, libpng16-dev
. It seems to work on the Windows Subsystem for Linux too.
On a Centos/RedHat (rpm) system you'll need gcc
, make
, zlib-devel
, openssl-devel
, libpng-devel
.
For development, clone the repo and install in editable mode:
$ git clone https://github.com/nvictus/pybbi.git
$ cd pybbi
$ pip install -e .
Troubleshooting
On OSX, you may get errors about missing header files (e.g., png.h
, openssl/sha.h
), which even if installed may not be located in standard include locations. Either create the required symlinks or update the C_INCLUDE_PATH
environment variable accordingly before installing pybbi.
export C_INCLUDE_PATH="/usr/local/include/libpng:/usr/local/opt/openssl/include:$C_INCLUDE_PATH"
Notes
Unfortunately, Kent's C source is not well-behaved library code, as it is littered with error calls that call exit()
. pybbi
will catch and pre-empt common input errors, but if somehow an internal error does get raised, it will terminate your interpreter instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pybbi-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ce803066acd72d0f9c36a54af310f870c63bd6b94d0fc755c363dbcb567703 |
|
MD5 | 13b3700804da9a386087741058d6d043 |
|
BLAKE2b-256 | 4b78d9bee071cbc3f698f2c0d647e4fa3eb840eb23fe13d758d5951842c0dd58 |
Hashes for pybbi-0.3.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1cfbf345888223351e19e47cba1ba762162f1718d4685d7b40184da79dbedb7 |
|
MD5 | ae21699e18c8bcf356c2259f6b7352a4 |
|
BLAKE2b-256 | 4f0fa6f2ff85df345e861db70d2b343df5a61aac33bfc5c2fffd569401f44cd8 |
Hashes for pybbi-0.3.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0e17bc5eb880fdcf86312194c24d9b8269f4b022bcfde6435d94d7e7847e0d6 |
|
MD5 | a24614806bb3160d2c52adb26d0d0808 |
|
BLAKE2b-256 | 1aca8a30c8fbbec9e00a8a5327679c1bc6185c8e1ca9b8e18337bf1c4f665ffa |
Hashes for pybbi-0.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00592bf6a4bebc5776168b86f715b1507275b017ab94088d23d1175b61124099 |
|
MD5 | 35dda5a2e1bcac146c17418d63a84345 |
|
BLAKE2b-256 | fe774c745f9f305cbc90eed65919ed63fb782104661d32f3babfce0ae4075e08 |
Hashes for pybbi-0.3.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6348155235aca1059f03d31211c0f114ffa1b88e8f5ba4cc91fe05c4df1736db |
|
MD5 | ca6998c6d781fda829391cf5eb356c24 |
|
BLAKE2b-256 | b0e8f9fbbcf736d51af8a377487d74c129ac692720a947eaea16caa2a39b7940 |
Hashes for pybbi-0.3.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 738cfbd9c3ee234bedf7576bd66db86dda591618473d672536b2beefd397d1c3 |
|
MD5 | 26ef51e0444fa7e7fe2351e6ddb3433c |
|
BLAKE2b-256 | be2bf89d09b59e89e88df6ca06b3165b98b1203c7d80e2aafe22c3ecdabc593a |
Hashes for pybbi-0.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14b9219f0fe33edb730d5247b6425f57cd7664fdaaab307d89eeb1902fb65c68 |
|
MD5 | f8d6d8a5d91b1f50be873decdfb209a1 |
|
BLAKE2b-256 | 1d221fb56aa9ff2275790a9aeac42c85331aa3d0ddf5e5afee5bced5815a586a |
Hashes for pybbi-0.3.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7668c475d21a9e0eb760a179d550eddc3646a2d735236cb36793f50fea204280 |
|
MD5 | a8472af1718cff5d1171079b1e34960d |
|
BLAKE2b-256 | 29bf05cd5b6fc0b2ccd2a1ea804f7364a72287d8535718cfe7299f1b95a92248 |
Hashes for pybbi-0.3.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81ab8d485f6f6bca021bb355a53e2424e0419b5743ea69be331f239af413552b |
|
MD5 | c9732e7c26badd091f9672923f57746b |
|
BLAKE2b-256 | 6f1a39ab825beb997cd45a310e64830bd3c07393d1ee4b6bb5baab545a99b24a |
Hashes for pybbi-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5e38e177cfada756e108944392037703ec1ceb34f0d68a2572d92f92262244b |
|
MD5 | 3bf3ec49c87c92d892bdcff30b0f3d5a |
|
BLAKE2b-256 | c2dcae0e9b14ac006f7f2e08d3bc3254a71bb508ec421555b8f25b3d23d931fc |
Hashes for pybbi-0.3.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf76b35a6b52bfaa6aba53f72afbb1e41c3e33e43d21e8c40aac6ba43c47d5c8 |
|
MD5 | 871d503f378f99a920cbd2326659404f |
|
BLAKE2b-256 | 0b6476a088064b1887a45827b45cd500928dd834824f883160a9f60d08e4e621 |
Hashes for pybbi-0.3.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef0e4b177683a1acbe3d77f7befc8bfe1bf3c1cfb459bc82d3fa065820f79921 |
|
MD5 | 42e0fa3772aa507aed16f0768ed620b4 |
|
BLAKE2b-256 | b1dd8743b32b62ef51688e63821898224e2ce30da242f209842e1ae2f7c63421 |