polars-bio
High-performance genomic interval operations and bioinformatics file I/O on Polars DataFrames. Overlap, nearest, merge, coverage, complement, subtract for BED/VCF/BAM/GFF intervals. Streaming, cloud-native, faster bioframe alternative.
Author
Category
Development ToolsInstall
Download and extract to your skills directory
Copy command and send to AI Agent for auto-install:
polars-bio - High-Performance Genomic Interval Operations and Bioinformatics File Handling
Skills Overview
polars-bio is a high-performance Python library for genomic interval operations and bioinformatics file handling based on Polars DataFrames. It supports common formats such as BED, VCF, BAM, CRAM, and GFF, and provides streaming processing and cloud storage access capabilities.
Use Cases
scan_* functions) and the DataFusion engine can process data in batches without loading everything into memory at once.Core Features
read_*, scan_*, and write_* interfaces supports 10+ formats including BED, VCF, BAM, CRAM, GFF/GTF, FASTA, FASTQ, and SAM. It automatically handles compression (GZIP, BGZF) and coordinate system conversion. Read operations return a LazyFrame to enable streaming.register_* functions, you can query variant data and interval data using standard SQL. It supports complex queries such as joins across multiple tables, aggregations, and filtering, making it suitable for analysts familiar with SQL.Common Questions
What bioinformatics file formats does polars-bio support?
It supports BED, VCF (including VCF Zarr), BAM, CRAM, GFF, GTF, FASTA, FASTQ, SAM, and Hi-C pairs files. For each format, it provides two functions: read_* (immediate loading) and scan_* (lazy scanning). Some formats also provide write_*/sink_* writing interfaces.
How do I process large genomic files that exceed memory size?
Use scan_* functions (e.g., scan_bam, scan_vcf) together with .collect(engine="streaming") for streaming processing. The DataFusion engine loads data in batches. For cloud storage files, you can pass S3/GCS/Azure URI paths directly and rely on predicate pushdown to read only the required regions.
What is the difference between polars-bio and bioframe?
polars-bio is built on Polars and Apache Arrow and is 6–38× faster than bioframe in real benchmarks. It supports streaming large datasets, direct cloud storage access, and SQL querying, whereas bioframe is based on pandas and is better suited for small in-memory computations. polars-bio uses a default 1-based coordinate system (genomics convention), while bioframe uses 0-based half-open intervals (BED convention), but both can be configured to switch.
Important Limitations: polars-bio requires Python 3.11–3.14, and genomic positions are stored using INT32 (upper limit about 2.1 billion, covering all known genomes). BAM files require a matching .bai index file, and CRAM files must provide a reference sequence path (reference_path parameter). The .pb accessor functionality differs between DataFrame and LazyFrame: interval operations are only available on LazyFrame, while on DataFrame only write methods are available.