Skip to main content

Python bindings to 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 Pythons 3.5, 3.6, 3.7, 3.8 on Linux and Mac OSX.

$ 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', or 'std'. (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) -> 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 and cython

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


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.0.tar.gz (34.7 MB view details)

Uploaded Source

Built Distributions

pybbi-0.3.0-cp39-cp39-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pybbi-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pybbi-0.3.0-cp38-cp38-manylinux2010_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pybbi-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pybbi-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pybbi-0.3.0-cp37-cp37m-macosx_10_6_intel.whl (1.4 MB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

pybbi-0.3.0-cp36-cp36m-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pybbi-0.3.0-cp36-cp36m-macosx_10_6_intel.whl (1.4 MB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

pybbi-0.3.0-cp35-cp35m-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

pybbi-0.3.0-cp35-cp35m-macosx_10_6_intel.whl (1.4 MB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

File details

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

File metadata

  • Download URL: pybbi-0.3.0.tar.gz
  • Upload date:
  • Size: 34.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 53b76ec07b558e404cf6e8421629b06814b97064bb047c030d64898884137ec3
MD5 d8e9563aae4adf5cd36f7b7c92a48862
BLAKE2b-256 6fe60967621c2bbd9ac9c27ebc7274b08eeb6c03c90f87c693994194dfef6746

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for pybbi-0.3.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a8ca56904f3cf4e7f8a7dfddb317b8e374e46e638e10181fe3c1d235ddb93223
MD5 f2359dbbc40891566bcced5d2740802d
BLAKE2b-256 7f9fc15dede01e66a77668cb900ba17d65c773ea1dc6c03a3aa58fdb7a975990

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybbi-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for pybbi-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c634975fafa15593d5d31dcabbb210728e7a53c01cbba28965c34c250327ef6
MD5 d66884c937b60dab727a9186a6d9cc17
BLAKE2b-256 257170046154b0bbef4c56dc24bd988befc20e99ba2f590c940dca143489d508

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 882f9e221b3f11ad86e6cd0409a5204746310a709521d7abad2c2519070bcfe4
MD5 39a8626808c022705b6a8bb111e6b8f1
BLAKE2b-256 b7414a432d57ef7aa90fef53b1b70d9e8c658db68302b233c71afe2af3b0f17d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybbi-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c89ed1032d33b41549f7483b1bb49f4cc9eed041bae1da6730d6ada533c6c59
MD5 5d9f8df11a40ee891f8f8904d2d93dd9
BLAKE2b-256 9b3c5625c425583f9d5ec4dbcf64b6f37e492ad8cbd39dd24b9067e8e9012a27

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 bba7370868da603daac2d8e0cd07dc9d0ccf0f4d1f1837a36bd273924db16d92
MD5 a0ad47959f6d27b17d438874cfe2d18b
BLAKE2b-256 9a84a81b211e37ae492a16db36d8494a5418e2fbcf331e6bf01f707df20139cf

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 f75ce131d88d5dee2b7cc0148b760d2dc5b465c3410b47f8748250eb0d32a5e0
MD5 92dae9dafbe87c4bb5e1450c5dcbea5f
BLAKE2b-256 f3f5fd56493679ec4bf8d196e3ea0651813f784c530097130bdc4e004f8a1740

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 51e4a393c9b1e06dc423deb532002cb5fc67425d3f5d717449c1f9547a0d8150
MD5 4caf7ac8d1f5f4d911c51996636f8095
BLAKE2b-256 51d787622659f3d44f829ef890107fb1e4cc860643029f57f5c3ca81f83b5885

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 51b17a197b4b1ddbf5feca929b9a1bca0b699364f36be1585d17a9fd7b0464ee
MD5 a973c939f5588709ef7e2b0bd6539f40
BLAKE2b-256 d249d7de2be17bfddc2c19870e97166374e0a2e1d28047f17bccc900786d3af3

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 71e804eadae4b9f65ae2569da8ff0ff806bd6a7a696239bc1ba48698c3eab98e
MD5 b531832719a2bef0a6c3f0ecf1cf2a52
BLAKE2b-256 a1788f68f5042c4621ecab62e2ab76df9e6eb1569d827f7e29dd0ad188d9aae5

See more details on using hashes here.

File details

Details for the file pybbi-0.3.0-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

  • Download URL: pybbi-0.3.0-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.5m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.4

File hashes

Hashes for pybbi-0.3.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 8b493c615283fb8e7efc7cc5aa397f6baecfc1c9ec6c205cad3c98406276f3ee
MD5 9b0c6cb4d193114eaf0294b32c3b37ea
BLAKE2b-256 0b4cd54e2bc792daaaa4ce63f7a62f0266b8bf32fab53857f5c08d99431edf75

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