https://github.com/biocpy/iranges
IRanges in Python
https://github.com/biocpy/iranges
interval-arithmetic iranges
Last synced: 20 days ago
JSON representation
IRanges in Python
- Host: GitHub
- URL: https://github.com/biocpy/iranges
- Owner: BiocPy
- License: mit
- Created: 2023-10-28T00:02:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-21T16:28:34.000Z (22 days ago)
- Last Synced: 2025-04-21T17:35:37.193Z (22 days ago)
- Topics: interval-arithmetic, iranges
- Language: Python
- Homepage: https://biocpy.github.io/IRanges/
- Size: 601 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Authors: AUTHORS.md
Awesome Lists containing this project
README
[](https://pyscaffold.org/)
[](https://pypi.org/project/IRanges/)
# Integer ranges in Python
Python implementation of the [**IRanges**](https://bioconductor.org/packages/IRanges) Bioconductor package.
To get started, install the package from [PyPI](https://pypi.org/project/IRanges/)
```bash
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.
Note: Ends are inclusive.
```python
from iranges import IRangesstarts = [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
[0] 1 4 4
[1] 2 6 5
[2] 3 9 6
[3] 4 10 7## Interval Operations
`IRanges` supports most interval based operations. For example to compute gaps
```python
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
[0] -3 -3 1
[1] 5 8 4Or Perform interval set operations
```python
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
[0] -2 2 5
[1] 6 9 3
[2] 14 17 4### Overlap operations
IRanges uses [nested containment lists](https://github.com/pyranges/ncls) under the hood to perform fast overlap and search based operations. These methods typically return a hits-like BiocFrame.
```python
subject = IRanges([2, 2, 10], [1, 2, 3])
query = IRanges([1, 4, 9], [5, 4, 2])overlap = subject.find_overlaps(query)
print(overlap)
```## output
BiocFrame with 3 rows and 2 columns
self_hits query_hits
[0] 1 0
[1] 0 0
[2] 2 2Similarly one can perform search operations like follow, precede or nearest.
```python
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
BiocFrame with 4 rows and 2 columns
query_hits self_hits
[0] 0 0
[1] 0 1
[2] 1 1
[3] 2 2## Further Information
- [IRanges reference](https://biocpy.github.io/IRanges/api/iranges.html#iranges-package)
- [Bioc/IRanges](https://bioconductor.org/packages/release/bioc/html/IRanges.html)## Note
This project has been set up using PyScaffold 4.5. For details and usage
information on PyScaffold see https://pyscaffold.org/.