Skip to main content

Python bindings to the UCSC Big Binary (bigWig/bigBed) file library.

Project description

pybbi

Build Status

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.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 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. The summary 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 or end 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: str) -> bool
bbi.is_bigwig(path: str) -> bool
bbi.is_bigbed(path:str) -> bool
bbi.chromsizes(path: str) -> OrderedDict
bbi.zooms(path: str) -> list
bbi.info(path: str) -> dict
bbi.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 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

  • Platform: Linux or Darwin (Windows Subsystem for Linux seems to work too)
  • pthreads, zlib, libpng, openssl, make, pkg-config
  • Python 3.6+
  • numpy and cython

For example, on a fresh Ubuntu instance, you'll need build-essential, make, pkg-config, zlib1g-dev, libssl-dev, libpng16-dev.

On a Centos/RedHat (rpm) system you'll need gcc, make, pkg-config, zlib-devel, openssl-devel, libpng-devel.

On a Mac, you'll need Xcode and to brew 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 the ARCH environment variable to specify a target architecture or ARCHFLAGS on a Mac.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybbi-0.3.5.tar.gz (34.7 MB view details)

Uploaded Source

Built Distributions

pybbi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pybbi-0.3.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pybbi-0.3.5-cp311-cp311-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pybbi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pybbi-0.3.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pybbi-0.3.5-cp310-cp310-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pybbi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pybbi-0.3.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pybbi-0.3.5-cp39-cp39-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pybbi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pybbi-0.3.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pybbi-0.3.5-cp38-cp38-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file pybbi-0.3.5.tar.gz.

File metadata

  • Download URL: pybbi-0.3.5.tar.gz
  • Upload date:
  • Size: 34.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pybbi-0.3.5.tar.gz
Algorithm Hash digest
SHA256 75b6888ff95bb99811321068213d9ce5618daaea2438cb3c370265186249257a
MD5 580a4b345108c2e88c536345e00ff855
BLAKE2b-256 1d1727e46f0500483389a50e0edf3658342b3359735461c2228f738f5d0c650b

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b3d6f8c446576d8bfce1f05b91f5b5d8124e9664a673b3d47575d0b9e19dc2a
MD5 c8a39a5648e5e2cd4932e5009524479d
BLAKE2b-256 840d14a5e99628416c2cfd0e12fb8c77d2439fd7ceecb9d01e786db4c30784e1

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c8dc54b054557d21578bd34360d0c53e51ffd6775648fc88c506c98e87ba3273
MD5 6ef063203067347fecbece2e0e06046b
BLAKE2b-256 f0fbbdb9ff1d1d562db64ee84376ffa49d6953b38d43c69936c996b26cc607d0

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 58dcd22186666c2c98559f4ef4f51a2eab35c8916a7767df9231b70b1cc82a31
MD5 48bd0c25cafd2478fb8252d94689bd1f
BLAKE2b-256 1952285530cb9540d094181103b20d4f06ed5c74eebefa046c90cb941829defb

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a067a87648ed21a17811c5439ab2c86a309938d973ee0438ce4173b02d86899
MD5 d02b7876da7f2c9e02684158460ef186
BLAKE2b-256 ae5dc72ab2119bdca2c90612ea2f254b4622ca4875a5f0d113d056919c81343a

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 073f527f316a9856f4c47812d4f2e6fad70ad4fc1e229ee388238cfb3ae32911
MD5 4174df213e7938c1ddffde758d977e90
BLAKE2b-256 b5fba109ac74931b0cade2486a0f63f7435a3ba2cef75b4f691b0d67594a4b32

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 39c55f086286eb1d1289af053ee00f5639b7a72f42313fb7e0befc66b466469c
MD5 c8f2572e159e002061dcc68022c07a7c
BLAKE2b-256 ad722341aa06a23a15e7e108344f16a836c24b4a01c5a54b67b5421807ff6cf2

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5186a95b850fce374297c6d4319faa037dd5c77028a572228ece7b4eb99eca7f
MD5 f76c8dd73716609ee93fb035f2d6206d
BLAKE2b-256 c88fca8c616225f05a0d7e1043050a76a8228bf6d68fd1c8a4836ecc1fb05ee0

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f85ab46e21269028c131e208fa804accdabec7f0435cfa5a0c448aa9821254b7
MD5 10160c4bd0d97cdca75d548cb576ca8c
BLAKE2b-256 a47741aa2964e4b619173d2b7614ca25783926327ad4cf366090a65cd99c0222

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6288069d16f8773a4df450c7090b7c71126792c8f29416739a6ee2d1e16142b5
MD5 2b0e937502498303ec05a14245f4cba4
BLAKE2b-256 1925b7edeefbc5c6bab529c4c6c743f59a12834fbc78963386441ff185584e2f

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 614f8644d2d26c7a3d2976017433f0862ed7f09c5a675f950f69bc67dc0035c8
MD5 80f63ac7cca2d7012d0363d6dade55e0
BLAKE2b-256 7fe2a137f292c3bef086133b47330572488dcdcaddbaa9cc42eaf4fb1985ab8c

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c3402b38f015ccdbd276ecdc30b4be20c9aacf5a80ba8f728fbf80a93446c467
MD5 16283e2defa99963b0fca4c05ae2f9bc
BLAKE2b-256 9507c87cd9db2b3d110687f1e5b883f1b358062ceb1f37c2087af7024512e31e

See more details on using hashes here.

File details

Details for the file pybbi-0.3.5-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6e61322cb8b28c18f4c2c0e182c73b1cae552118fbdb1331eb62e94ebebff444
MD5 1e9cdbd27b404919d74038a33079d1bb
BLAKE2b-256 093e0238b6a2ad18b4052c8b139da6c299473ecb26f51674cfc713f425152edb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page