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

Uploaded Source

Built Distributions

pybbi-0.3.4-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.4-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.4-cp311-cp311-macosx_10_9_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pybbi-0.3.4-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.4-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.4-cp310-cp310-macosx_10_9_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pybbi-0.3.4-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.4-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.4-cp39-cp39-macosx_10_9_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pybbi-0.3.4-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.4-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.4-cp38-cp38-macosx_10_9_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pybbi-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 406383981c80481d8aa86499681442a20e68bdc7ef3806cfd6cc4492d3f363e1
MD5 f24472b8bdaf548ccc565df704e1d8c5
BLAKE2b-256 bc34898d457bebf870525c29349ec667f64cc4f621d6356b623b7d4fa5112f6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 383962194f5566fd3a396be4d5d51d5d84324f09e750931523a5332ccb54f8b3
MD5 8a2d7d90e82432d6e99762aeef4dc77d
BLAKE2b-256 7e0df8a19bd28c1612a1c2d9173d62d9a1c30b3e2e8e5f3faed7ca7fa89eed7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 da8316e091f7e4d8c345ed2aeef26a2de85bc2b547821daa58098087f5bc0b9a
MD5 8002ce1dbb688c92aaeecc199c443a56
BLAKE2b-256 9a3eda08c45c4828c5540be1babc64ef34554ec5ff9913dc7aea986c5cbfdcbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 336b545b6fdb8d094ec48bf211ceff84b6b09f423bc74811525b299e666920fd
MD5 67a81f80ccb70b4f89042d4f7b38770e
BLAKE2b-256 9d21a6f549ba1e217d315fa6c2ac3049961bb3c60e62a21a89ec034b8a771a04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0c06e072601d9b3d245452d6d9c025fe511215beafb4121c7b52a69f8e0bffcb
MD5 3563f145e2b6fecbb094c46b52d6b5c5
BLAKE2b-256 4e516c40445f21353438c4bbec9c935445d8a47c567c733f4292fb3a3f823eb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dee0b4550ec374629cdd571cca2f312a9352a8caf512a9a09800ebc0a82f964c
MD5 d6021132d29446d053f76064dc7efe34
BLAKE2b-256 aa5616f10a782105b8151b02133c48e6701445caf8c8601f0c4f091517e731bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8e0ac929b7db99377378fae13c3b11cb4b0bbed06399e94bc0ae15925c9fd009
MD5 a25ed45446ca03ceb6654047b67a81fb
BLAKE2b-256 a4c10f419b207182d2e1b7a277c2840eacd04cade09b0dce14a29a4ebb683778

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2bacf8149b1242f706d0bd2e015e2d82b54a7dce1540426afceda341b810f263
MD5 c93f0773d91e3cd2070c9bb982c48e0b
BLAKE2b-256 19a2a9fedc6e4abc1f10fffe29e76991a32e06bfd619edfb76e54a311aad56a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9e304b364052e3adb8401f776224c235b62bbd4a6903ddf1c954b9e974fdc61e
MD5 1dbf874b4bfbb9c1d57db63cfcc7e117
BLAKE2b-256 b4792a9093f4e66bf75d579badedb43312a940e8656c3e1b9631bd4d39bbc0fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 802b63e69824f2cb92a9a62b8c1dfafdd38e7ec44fee5143d876e25532cf56a8
MD5 4e09847e4bc6eeeafadd53fb6b0cf234
BLAKE2b-256 998754c0ab081acb735e4534478549bf395935bae8f167861ceb36581a80aa33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02a518ca2cf90b166b465c2e22734ed34560dc18090f750214432093fed500a0
MD5 d33eaeed5ab82daf656a7800236b9b49
BLAKE2b-256 b1b744f7417b199834e918889d9609c58852ebe24adaefb9c6944c04e77e7ea2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1d6ce7ed4a9885e11e8b630ca4e6ae6da0098d44917f23e1641db33d6b7124a0
MD5 42333f080a37080f760772c2f5f1d820
BLAKE2b-256 de8aec1a26415cb73fedc01cc5415f53c95cd4ce7a6fd7009d6e07a6e1579487

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pybbi-0.3.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7e0e115bff866f28c67d9c1b4b7a4929eeb5ad89f0b7f574e6157877ba453793
MD5 4ac9b14b77fd152f994ebc8a014c30d0
BLAKE2b-256 00ba684363b08f91fdb63e780ba96e615763ca09e2c4117469170a33694417e5

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