$ show pyranges/pyranges0
PyRanges (version 0, legacy) is a Python library for genomic interval operations, analogous to Bioconductor's GenomicRanges. It provides a comprehensive set of tools for manipulating, comparing, and analyzing genomic intervals and annotations. The library supports reading and writing common bioinformatics file formats (BED, GTF, GFF3, BAM, BigWig), and implements a wide range of operations including merging, intersection, subtraction, join, nearest neighbor, clustering, coverage, and statistical methods like Jaccard and Fisher exact. Internally, PyRanges represents intervals as a dictionary of pandas DataFrames keyed by chromosome and optionally strand. This design enables efficient per-chromosome parallelism and easy integration with the Python data science stack. Operations are implemented as modular functions in separate files under the `methods/` directory, each accepting a DataFrame and keyword arguments from a central dispatcher. The library also provides a parallel execution framework using Ray via `pyrange_apply` and related functions, allowing users to apply custom functions to each chromosome/strand group in parallel. Although primarily a software library, this repository has a strong research character: it includes built-in example datasets (e.g., ChIP-seq peaks, CpG islands, Ensembl annotations), a bookdown tutorial with executable R Markdown, property-based tests that compare results against the bedtools suite, and statistical methods designed for colocalization and annotation enrichment. This makes it equally valuable as a research tool for bioinformatics analysis. Maintenance note: This is the legacy version 0 of PyRanges, superseded by a redesigned version 1 (pyranges1). Despite the deprecation, the codebase is mature, well-tested, and still functional. The design patterns (modular operations, per-chromosome dispatch, property-based testing against a reference tool) are noteworthy and could be reused in other bioinformatics and data engineering projects.
The LLM identified 2 files worth highlighting for reuse:
Provides Hypothesis strategies for generating random PyRanges objects and helper functions to run bedtools for comparison. Enables property-based testing that ensures core operations match the reference implementation. This pattern can be adapted to test other interval manipulation libraries, demonstrating a rigorous approach to validating bioinformatics tools.
Implements a framework to apply arbitrary functions over chromosome/strand groups using Ray for parallel execution. The core functions (pyrange_apply, pyrange_apply_single, pyrange_apply_chunks) form a reusable pattern for parallelized group-wise operations on pandas DataFrames, with automatic Ray cluster management. This can be extracted as a general-purpose parallel group apply utility with minimal changes.