Python bindings to the UCSC source for Big Binary Indexed (bigWig/bigBed) files.
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.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 interval records 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
Summary bin records at each zoom level are also accessible.
BBIFile.fetch_summaries(chrom, start, end, zoom) -> pandas.DataFrame
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
To produce a stacked heatmap from a list of (1) equal-length intervals or (2) arbitrary-length intervals with bins
specified:
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'). Intervals need not have the same length, in which case the data from each interval will be interpolated to the same number of bins (e.g., gene bodies). -
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: 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
andcython
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
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.4.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2197144d071e17fbbb136508046315b319bbe2fbf88085b356fb02f962b7b704 |
|
MD5 | 51b3638b002dd6e2880bd09da880de89 |
|
BLAKE2b-256 | bd701942a663e32085eba7ec255f1ee873047df1901b2798dd4e57a1db0795b9 |
Hashes for pybbi-0.4.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8dc2ebd0e1d670dbcec02f52978dad910293eb705383318090a7608c142f911 |
|
MD5 | 5dbc1ce825e54243975e1c2964399303 |
|
BLAKE2b-256 | dabbab151ecbe26f1421a8a3ae12bd357471d130387b22b0820456b8749acc69 |
Hashes for pybbi-0.4.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe1c68e0d13489d75b374d4f82bdeeff192241ff3dfffefc59652491ab3d8b42 |
|
MD5 | ea5375029fe3cbc7bddbf39f8df90f9c |
|
BLAKE2b-256 | faffbd13e585560406b1624f68a36b98e74b705cf202ab465f1cd8231efb0522 |
Hashes for pybbi-0.4.1-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b276deb438fa990d9db0947ec8dfa3f6d75728ba43e1d71650a0c24ffc6482af |
|
MD5 | 02c77c1979b900bdd2acd97a80689a9b |
|
BLAKE2b-256 | c3df26a59938de8f092536dcd7287154bd21346f6721b1a6f38c5fa141e35b38 |
Hashes for pybbi-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7d9f22cd18e7b8affc66c42a2c95e542afd8a1652430c0d9bfbabf7d4c11799 |
|
MD5 | 05d704b3309205e145fbb5f053538262 |
|
BLAKE2b-256 | cfbedc05048eb85965bea938caacd3068b62e3fbc00284a8d5b52205f3212685 |
Hashes for pybbi-0.4.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607084a293d1c18915d3a4811c7c81b640601ba18b240f67338b2d97fd793481 |
|
MD5 | d6179025c2a58c8cedeaa80e6b293c75 |
|
BLAKE2b-256 | 37f35ed2a7e188ac9063d3ddf97e0d6fff4f876753222ed7093ea0ff8324cf9c |
Hashes for pybbi-0.4.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68d351ab964d6189a5d3beec7105e679177bc43141a4ec272e89246a6e8d7f72 |
|
MD5 | 7d6fb536e42c58b262cbf566e3436c3a |
|
BLAKE2b-256 | 8dc7ce5b7ad871e9f580fd2cb4c8bf02e8c13708b45657dd17d1dbc33ecf828c |
Hashes for pybbi-0.4.1-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d6c33ded8cf8b5b85f7093cb7ced67059540e80203df31c33c12c2167aa28ad |
|
MD5 | f62d6176a1a8666547f9fbab80c50f72 |
|
BLAKE2b-256 | 3bad0517feaeef73c493604f85de73adb66b1d9fd8d42da2bcbac0702d029dd4 |
Hashes for pybbi-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb94da99b7edbf0eb2111b273f7345ae78fd0ed6ccd098a649a0c4c546a4fc7d |
|
MD5 | 33ffe50c0ae62210f3115379d4b081b7 |
|
BLAKE2b-256 | 679642d795bcd89926d4e24fbe90c7eb875dac0e64c57fe2d15c74df5ab208e4 |
Hashes for pybbi-0.4.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf2dcf60e712b409c2199568159b23ccd39a1273d02e96ceea27a668527e1f2e |
|
MD5 | 5268b0821dfac4be77f5515d75437ad8 |
|
BLAKE2b-256 | 061f530d3fd1420fc9b31ccc5659dbde14744f1c58fff47ed03a6a42abb9b319 |
Hashes for pybbi-0.4.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a2351bfdec49954e9b12df37422ce6815b9d22e219fdc03787b82099c9b005 |
|
MD5 | ace4294bfc813a657348152eee4b4631 |
|
BLAKE2b-256 | 5a7576592a8f2b1a8e1320866ac17d9efae79a83e33864b09a5a7e23edd65268 |
Hashes for pybbi-0.4.1-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da07fd359d49a7aa3d8facc0adc9cd24e10109c7d2bf35e900b7151b45e6b644 |
|
MD5 | 82c3f8ba755f546e165f9110b5c3fd61 |
|
BLAKE2b-256 | cdb2f274c9afdd5e8261dce265deea7c1f098d7a2e16589e15dce00887d6661e |
Hashes for pybbi-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f31c966598af3109085c098ea33f9ba5e48108feb94c0c73692fe125f5daadd |
|
MD5 | 183c7535bb986e61bb32f268e830d243 |
|
BLAKE2b-256 | c7494be3740f7d5586dfdc6b66d649a74f043ec61ff292081631cef2646a8a4f |
Hashes for pybbi-0.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0065c5f52f165df962028299a12016ea4b3af51e3c230d9d02d8df70084976f2 |
|
MD5 | b7b49921e3e618502301328d831cac4a |
|
BLAKE2b-256 | a99bc74cc68eaa9abfdebd5fd6e00c91605a10c56254c2023d23717c45f41b13 |
Hashes for pybbi-0.4.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b4931a389a9dd686305fb1a9a9fb24ccb4aaf2f97ffbef7ab8c5e6366d4328f |
|
MD5 | 42cc94fa5f6f9f4bcab96b7a0c5628e8 |
|
BLAKE2b-256 | 12b0a36607acac77d38261469befe423c37412e4298c0a707a29cb31344654e0 |
Hashes for pybbi-0.4.1-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6add8b3d461aabce5a43f8c2d97e7b69b358ff25f035842ccfbf14098788d973 |
|
MD5 | cdc86d996ebadd5c71045326d049b4f6 |
|
BLAKE2b-256 | d1eed6166c0b7d1c8727526871303c52df38c4d02f8d136faa0151fa02908490 |
Hashes for pybbi-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6726ea3decad71cb17541e6d0d440588ab6a555d2e280cedf4517f2ea011a07c |
|
MD5 | 6eb87841510425c95e2e788b5c51cf3a |
|
BLAKE2b-256 | befe12f528f09015f8d80f8c6307b439cb8f77524509540b765325a4d4f1ae7a |
Hashes for pybbi-0.4.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf44f1cc8bbbdcbf6ecbdada9a00f85a87416a299a7de72462b03f075287a7a |
|
MD5 | 4a44f29178a30a6ae90033f22d97e9cf |
|
BLAKE2b-256 | c6c6e74b133766270ca4bc83f611cf080ad8d890d0c9be4eed5d3096cc75754e |
Hashes for pybbi-0.4.1-cp39-cp39-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e622817ba90fa39efea407deac364201f2ffdfa274311422450fac329078c7b |
|
MD5 | 75e5de651b8650388f943356dce5cc4c |
|
BLAKE2b-256 | 265ea2aa1d3a36fe8209075bf7c029eb88b03d3326665453166fdfcfca2c4871 |
Hashes for pybbi-0.4.1-cp39-cp39-macosx_13_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdcabcd727ea90ec334589a9fb1ad6a3403b551c1fa8dd497beba93c09911d0b |
|
MD5 | 323cd68070c9a54c0d5b801dbba6b5d1 |
|
BLAKE2b-256 | 5178fe1a9aafe2c73c0e848e8bc315a9ee443e6eb4ff675d0cf11f38d6d87b4c |