Python implementation of the [**IRanges**](https://bioconductor.org/packages/IRanges) Bioconductor package.
Project description
Integer ranges in Python
Python implementation of the IRanges Bioconductor package.
To get started, install the package from PyPI
pip install iranges
# To install optional dependencies
pip install iranges[optional]
IRanges
An IRanges
holds a start position and a width, and is most typically used to represent coordinates along some genomic sequence. The interpretation of the start position depends on the application; for sequences, the start is usually a 1-based position, but other use cases may allow zero or even negative values.
from iranges import IRanges
starts = [1, 2, 3, 4]
widths = [4, 5, 6, 7]
x = IRanges(starts, widths)
print(x)
## output
IRanges object with 4 ranges and 0 metadata columns
start end width
<ndarray[int32]> <ndarray[int32]> <ndarray[int32]>
[0] 1 5 4
[1] 2 7 5
[2] 3 9 6
[3] 4 11 7
Interval Operations
IRanges
supports most interval based operations. For example to compute gaps
x = IRanges([-2, 6, 9, -4, 1, 0, -6, 10], [5, 0, 6, 1, 4, 3, 2, 3])
gaps = x.gaps()
print(gaps)
## output
IRanges object with 2 ranges and 0 metadata columns
start end width
<ndarray[int32]> <ndarray[int32]> <ndarray[int32]>
[0] -3 -2 1
[1] 5 9 4
Or Perform interval set operations
x = IRanges([1, 5, -2, 0, 14], [10, 5, 6, 12, 4])
y = IRanges([14, 0, -5, 6, 18], [7, 3, 8, 3, 3])
intersection = x.intersect(y)
print(intersection)
## output
IRanges object with 3 ranges and 0 metadata columns
start end width
<ndarray[int32]> <ndarray[int32]> <ndarray[int32]>
[0] -2 3 5
[1] 6 9 3
[2] 14 18 4
Overlap operations
IRanges uses nested containment lists under the hood to perform fast overlap and search based operations. These methods typically return a list of indices that map to each interval in query.
subject = IRanges([2, 2, 10], [1, 2, 3])
query = IRanges([1, 4, 9], [5, 4, 2])
overlap = subject.find_overlaps(query)
print(overlap)
## output
[[1, 0], [], [2]]
Similarly one can perform search operations like follow, precede or nearest.
query = IRanges([1, 3, 9], [2, 5, 2])
subject = IRanges([3, 5, 12], [1, 2, 1])
nearest = subject.nearest(query, select="all")
print(nearest)
## output
[[0], [0, 1], [2]]
Further Information
Note
This project has been set up using PyScaffold 4.5. For details and usage information on PyScaffold see https://pyscaffold.org/.
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 Distribution
File details
Details for the file iranges-0.2.12.tar.gz
.
File metadata
- Download URL: iranges-0.2.12.tar.gz
- Upload date:
- Size: 41.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbae0ced0007959f83452e6cc01e50ac2830280c727ab15ec43ce9d89701ca52 |
|
MD5 | 56ea3ec805292f89b0e03eda155351fe |
|
BLAKE2b-256 | a3fb06840fbb7b84d7a9c02d0a31aa8636fd8164ea571557bf5e7d030dd1ab8d |
File details
Details for the file IRanges-0.2.12-py3-none-any.whl
.
File metadata
- Download URL: IRanges-0.2.12-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b3d73ffc21aaf8bf1636d00001b96ced282eb2ea1e28e842c9d69d91a3a8a1 |
|
MD5 | 70b12a3f4ce165e90bee7c3d4279c3db |
|
BLAKE2b-256 | aea8a909df84f387450f3e8fc0f9324367d44cc6d5ac217eab777ade0e926964 |