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

Uploaded Source

Built Distributions

pybbi-0.3.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64

pybbi-0.3.2-cp310-cp310-macosx_10_9_universal2.whl (2.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

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

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pybbi-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pybbi-0.3.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pybbi-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pybbi-0.3.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.4 MB view details)

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

pybbi-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pybbi-0.3.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.4 MB view details)

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

File details

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

File metadata

  • Download URL: pybbi-0.3.2.tar.gz
  • Upload date:
  • Size: 34.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pybbi-0.3.2.tar.gz
Algorithm Hash digest
SHA256 857805f47e27ffecd742e60c35256ec623cebba7c0eb388905ad8090c1db0fd7
MD5 176ce19b6aa2621eceb96f81b0acca8d
BLAKE2b-256 0adb26654d0509cb4f92f5d6a0509fd33b6a6579c17e2b911102e3948994cba2

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4311668b8bf3c95a81878a91a1dcbfa48b03b88808068a393ce12cc0a6f4e6b0
MD5 05bc2ba91a6ee2f3dcfe5e944f8bdcfc
BLAKE2b-256 e5195fded4f441729a4086558d82192d89b9ade3f046e9e3e38a050b12286cc8

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

  • Download URL: pybbi-0.3.2-cp310-cp310-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pybbi-0.3.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f8fe3c87a29e7d06a57127b78c8766560c2b9c52036c9b45f051543f2e415b9f
MD5 448c7d97cf30b61033f66a0b82a0f757
BLAKE2b-256 a4fe6ba2022cee8993ef9aabda75e3cc38f9f57edcbe0a4a08e2ebf00fd4cbce

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 709592ce344a770ae00510632c4d27913b563c5da031a9236527ea46313ed668
MD5 755d724731a6a76bf4872f8c66581ba4
BLAKE2b-256 c40142ce8fee9adc2a3808d21e0191f3137f785ab3bf5f6d6431b6aea2369c5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybbi-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pybbi-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1c4082a8cc5c871b77a2e3619eb06fb286213f81f9968fcb436cce964e1f6ad0
MD5 71602ec2ade60909f0b4e1d310a585f0
BLAKE2b-256 9aacdf97f27edf84f38a17e949642939db6f86e8085a7ec92a3bc815ccbfb2dd

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 866a1ccddb6252d2ffe4e4b6b5211aaa0e95c9c22901572b7a8ffa76d55e4939
MD5 a9ae8e690d525286031f969a17704b81
BLAKE2b-256 1c3ed47d546611dd879549dca866b48320aaf5f23cdb8ec1e46f0600d5942de4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybbi-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pybbi-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fd15ae1e4e0e77822d361fd55f22ccfe72fd63ef4ca952bb669ae375b7302685
MD5 1a0f6c8089bd597a6daa17f5ce8751d5
BLAKE2b-256 632dfaa4bd47e9247146c77a130d220876554251c07e7d16e2964b19117528ed

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b897597361c9003e99871356b3ba28fc323f8e73ccde488e65215f0e182e9742
MD5 5fae7624aea44dad8513fd885cfb1298
BLAKE2b-256 3b6ec2110f6b11a06e2bac9d0afd6a9372eb70acbf9eb9150ed54afe5815753c

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pybbi-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pybbi-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fab80fbcf55109fc350e2e4845dbf2215b34d8f9b85e6df22bbf3f0f9cb32e83
MD5 bf0fc9b809b987e48d3b792316dd45fd
BLAKE2b-256 30d461ee979b1b2ed425a3f3a89c99ebcaf69b49aa82d4838c4684c7b985be75

See more details on using hashes here.

File details

Details for the file pybbi-0.3.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for pybbi-0.3.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 27eeec5110af70916493454a3ce21efaac2438be62457676e0b71937253c400c
MD5 136119f013291e6b410499a30f7c590c
BLAKE2b-256 1609196be584420550e2dfe74328a8386b41d95e5826c96a33f2a1d6474100ec

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