https://github.com/brentp/bw-python
python wrapper to dpryan79's bigwig library using cffi
https://github.com/brentp/bw-python
Last synced: 2 months ago
JSON representation
python wrapper to dpryan79's bigwig library using cffi
- Host: GitHub
- URL: https://github.com/brentp/bw-python
- Owner: brentp
- License: mit
- Created: 2015-10-19T19:38:07.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-13T13:46:38.000Z (over 9 years ago)
- Last Synced: 2025-09-09T19:43:36.280Z (4 months ago)
- Language: C
- Size: 83 KB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
python wrapper to [Devon Ryan's bigwig library](https://github.com/dpryan79/libBigWig) using cffi
```Python
>>> from bw import BigWig
>>> b = BigWig("libBigWig/test/test.bw")
>>> b
BigWig('libBigWig/test/test.bw')
>>> for interval in b("1", 0, 99):
... interval
Interval(chrom='1', start=0, end=1, value=0.10000000149011612)
Interval(chrom='1', start=1, end=2, value=0.20000000298023224)
Interval(chrom='1', start=2, end=3, value=0.30000001192092896)
# get an array.array() for large numbers of values.
# default is to return nan's for missing values
>>> b.values("1", 0, 9)
array('f', [0.10000000149011612, 0.20000000298023224, 0.30000001192092896, nan, nan, nan, nan, nan, nan])
# we can also get missing, but won't know the base it's associated with.
>>> b.values("1", 0, 9, False)
array('f', [0.10000000149011612, 0.20000000298023224, 0.30000001192092896])
# stats are ("mean", "std", "max", "min", "coverage")
>>> b.stats("1", 0, 9, stat="mean")
0.2000000054637591
>>> b.stats("1", 0, 9, stat="std")
0.10000000521540645
>>> b.stats("1", 0, 4, stat="coverage")
0.75
>>> b.stats("1", 0, 4, stat="coverage", nBins=2)
array('d', [1.0, 0.5])
# get the chromosomes and lengths as a list of tuples:
>>> b.chroms
[('1', 195471971), ('10', 130694993)]
>>> b.close()
```
An array.array can be turned into a numpy array with `np.frombuffer(a, dtype='f')`