ferroseq
Fast, vectorised biological-sequence analysis for Polars and pandas, written in Rust — plus a seqkit-style command line.
pandas gave Python a table you can compute on column by column. ferroseq does the same for DNA, RNA
and protein sequences: it adds a .seq namespace to Polars and pandas whose methods (GC content,
reverse complement, translation, IUPAC motif search with mismatches, k-mers, quality scores, and more)
run as compiled Rust across every row at once, in parallel, without a Python loop. Files of any size
stream through lazily, and a ferroseq command covers the everyday FASTA/FASTQ jobs.
import polars as pl
import ferroseq as fs # importing registers `.seq`
clean = (
fs.scan_fastq("reads.fastq.gz") # lazy + streaming: any file size
.pipe(fs.quality_trim, 20) # BWA/cutadapt 3' trimming
.with_columns(
gc=pl.col("sequence").seq.gc_content(),
ee=pl.col("quality").seq.expected_errors(),
has_site=pl.col("sequence").seq.contains_motif("GAATTC", max_mismatches=1),
)
.filter(pl.col("ee") <= 1.0)
.collect(engine="streaming")
)
fs.write_fasta(clean, "clean.fa.gz")
fs.stats("reads.fastq.gz") # seqkit-stats-compatible summary
ferroseq stats *.fastq.gz # N50, Q20/Q30, GC, quartiles, ...
ferroseq grep -s GATTACA -m 1 -B reads.fq.gz -o hits.fq.gz
ferroseq trim -q 20 --min-len 50 reads.fq.gz | ferroseq filter --max-ee 1 -o clean.fq.gz
The same methods work on a pandas Series:
import pandas as pd, ferroseq
pd.Series(["ATGGCCTAA", "GGNNATRY"]).seq.reverse_complement() # index preserved
Why another library?
| Need | Use |
|---|---|
| Genomic intervals: overlap, nearest, coverage on BED/VCF/BAM | polars-bio, pyranges1 |
| Per-record sequence computation inside a dataframe, and fast FASTA/FASTQ chores | ferroseq |
| Alignment, phylogenetics, structures, a bit of everything | Biopython, Biotite |
ferroseq complements these: it replaces the slow Python loop ([gc_fraction(s) for s in seqs],
[str(Seq(s).translate()) for s in seqs]) and the shell-out to a CLI for routine read processing.
Install
pip install ferroseq # wheels: Linux, macOS, Windows; Python 3.11+
conda install -c conda-forge -c bioconda ferroseq # once the Bioconda recipe is merged
pip install "ferroseq[pandas]" # with the pandas accessor dependencies
From source (needs a Rust toolchain): pip install maturin && maturin develop --release.
Expression API
Every method is available as pl.col(...).seq.<method>(), polars_series.seq.<method>() and
pandas_series.seq.<method>().
| Method | Returns | Notes |
|---|---|---|
gc_content() |
f64 | (G+C+S)/(G+C+S+A+T+U+W), case-insensitive; = Biopython gc_fraction(ambiguous="remove") |
gc_skew() / entropy() |
f64 | (G−C)/(G+C); Shannon entropy in bits |
is_valid(alphabet="dna", iupac=False, allow_gaps=False) |
bool | "dna", "rna", "protein" |
reverse_complement(rna=False) / complement() / transcribe() / back_transcribe() |
str | IUPAC aware, case preserving |
translate(table=1, to_stop=False) |
str | NCBI tables 1–6, 11; ambiguous codons as Biopython (GCN→A, SAA→Z, else X) |
count_motif(motif, both_strands=False, max_mismatches=0) |
u32 | IUPAC motif, overlapping matches, ≤k substitutions |
contains_motif / find_motif / motif_positions (same arguments) |
bool / u32 / list[u32] | 0-based starts |
kmers(k, canonical=False) |
list[str] | or fs.kmer_counts(frame, k) for a frequency table |
count_bases(letters) |
u32 | e.g. "GCgc", "Nn", "- ." |
hamming(other) / levenshtein(other) |
u32 | other is a column or a string literal |
mean_phred() / mean_error_phred() / expected_errors() |
f64 | arithmetic vs probability-averaged quality; USEARCH maxee |
count_quality_at_least(min_q) |
u32 | bases ≥ Q (Q20/Q30 counts) |
quality_trim_index(threshold=20) |
u32 | length to keep after 3' trimming |
I/O, streaming and helpers
| Function | What it does |
|---|---|
read_fastx / read_fasta / read_fastq(source, columns=None, n_rows=None) |
eager read; source = path, "-" (stdin), bytes or file object; plain or gzip |
scan_fastx / scan_fasta / scan_fastq(source) |
LazyFrame with projection, limit and predicate pushdown; collect(engine="streaming") for files larger than memory |
iter_batches(source, batch_size) |
bounded-memory iteration over DataFrame batches |
write_fasta / write_fastq(frame, path) |
Polars/pandas DataFrame or LazyFrame; "-" = stdout; .gz = gzip; descriptions kept |
stats(*sources) |
one row per input, same definitions as seqkit stats -a |
quality_trim, filter_reads, kmer_counts, show_versions |
common read processing; version report for bug reports |
fs.stats and seqkit. Columns are seqkit stats -a's in snake_case (q20_pct = Q20(%),
n50_num = N50_num, …) with the same definitions; the test suite compares them against the real
seqkit on randomised files. Two things to know: seqkit's table printer sometimes rounds for display
(quartile 12.5 shows as 12), and seqkit before 2.15 computed N50_num (L50) by counting distinct
lengths rather than records — ferroseq uses the corrected definition seqkit adopted in 2.15.
Command line
ferroseq <command> [input] [-o output] — inputs and outputs default to stdin/stdout, .gz outputs
are compressed, FASTQ stays FASTQ unless the output name says FASTA. Every command streams in batches.
| Command | Does | seqkit analogue |
|---|---|---|
stats [-T] [-b] [--seqkit-names] files… |
summary statistics table | stats -a |
grep -s MOTIF [-m K] [-B] [-r ID_REGEX] [-v] |
keep records by IUPAC motif (≤K mismatches, both strands) and/or ID regex | grep -s -m |
filter [--min-len] [--max-len] [--max-ee] [--min-mean-q] [--max-n-frac] [--min-gc] [--max-gc] |
read filtering | seq -m/-M + others |
trim [-q 20] [--min-len 1] |
3' quality trimming | — (cutadapt -q) |
convert [--to fasta|fastq] |
FASTQ→FASTA, gzip ↔ plain | fq2fa, seq |
fx2tab [-l] [-g] [-q] [-H] |
FASTA/FASTQ → TSV with length, GC, mean quality | fx2tab |
python -m ferroseq … works too.
Performance
Python API — 500,000 reads × 150 bp (75 Mbp), single thread (POLARS_MAX_THREADS=1), best of three,
on a 2-vCPU cloud VM (python bench/bench.py). Timings on a shared VM vary by ±30% between runs.
| Task | Alternative | Alternative | ferroseq | Speed-up |
|---|---|---|---|---|
| GC content | Biopython gc_fraction loop |
1.223 s | 0.044 s | 28× |
| GC content | pandas .str.count |
8.335 s | 0.044 s | 191× |
| Reverse complement | Biopython loop | 0.480 s | 0.035 s | 14× |
| Reverse complement | Python str.translate()[::-1] loop |
0.238 s | 0.035 s | 6.8× |
| Translate (table 1) | Biopython Seq.translate loop |
6.651 s | 0.121 s | 55× |
| Expected errors | NumPy (join + reduceat) |
0.415 s | 0.042 s | 10× |
| Read FASTQ → DataFrame | Biopython FastqGeneralIterator → pandas |
1.058 s | 0.137 s | 7.7× |
IUPAC motif RGATCY |
Python re loop |
1.150 s | 0.070 s | 16× |
IUPAC motif RGATCY |
Polars regex [AG]GATC[CT] |
0.043 s | 0.070 s | 0.6× (slower) |
With two threads ferroseq times roughly halve.
Command line vs seqkit 2.13 — same 500,000-read FASTQ (158 MB), wall clock including interpreter
start-up, best of three (python bench/bench_cli.py):
| Task | ferroseq | seqkit | |
|---|---|---|---|
stats (plain FASTQ) |
0.33 s | 0.67 s | 2.0× faster |
stats (gzip FASTQ) |
0.72 s | 0.99 s | 1.4× faster |
grep motif, both strands |
0.44 s | 1.00 s | 2.3× faster |
grep motif, ≤1 mismatch |
0.50 s | 18.13 s | 36× faster |
| FASTQ → FASTA | 0.26 s | 0.16 s | 0.6× (slower) |
Where ferroseq is slower: a plain regex motif in Polars (SIMD prefilter, non-overlapping matches), and FASTQ→FASTA conversion, where Python start-up (~0.14 s) is most of the gap.
Design
python/ferroseq/ Python API: .seq namespaces (Polars + pandas), scan/read/write, stats, CLI
│ Polars expression plugin + IO plugin (FFI, Arrow buffers)
src/ PyO3 bindings: parallel batching, streaming FASTX reader/writer, stats histogram
│
crates/ferroseq-core/ pure-Rust kernels on &[u8]; no Python dependency; usable as a Rust crate
- Expression plugin, not Python callbacks: methods run inside Polars' engine (lazy, streaming,
group_by, no GIL). - Lookup tables and bit-parallel scans: complement, GC and quality use 256-entry tables; motifs up to 64 bp use shift-and (bitap), extended to k substitutions, so search cost doesn't grow with motif length.
- Correctness against references: GC, complements, all 64 codons × 7 tables and all 3,375 IUPAC codons
are checked against Biopython;
statsandgrep -magainst seqkit; motifs, k-mers, distances and quartiles against plain-Python reference implementations (300+ tests).
Development
cargo test -p ferroseq-core
python -m venv .venv && . .venv/bin/activate
pip install maturin polars pytest biopython pandas pyarrow
maturin develop --release
pytest # set SEQKIT=/path/to/seqkit to run the seqkit comparisons
python bench/bench.py 500000 && python bench/bench_cli.py 500000
See CONTRIBUTING.md to add a kernel (about 30 lines across three layers).
Releasing
- Bump the version in
Cargo.tomland date the entry inCHANGELOG.md. - Tag and push, e.g.
git tag v0.2.0 && git push origin v0.2.0. The release workflow builds and tests wheels and uploads them to PyPI via trusted publishing (workflowrelease.yml, environmentpypi). - Bioconda's autobump bot opens the version-update PR for the recipe; see packaging/bioconda/README.md.
License
MIT
Metadata
Release files for ferroseq 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ferroseq-0.1.0.tar.gz | 79.2 kB | Without provenance | Details for ferroseq-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| ferroseq-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for ferroseq-0.1.0-cp311-abi3-win_amd64.whl |
| ferroseq-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for ferroseq-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| ferroseq-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for ferroseq-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| ferroseq-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for ferroseq-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
| ferroseq-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for ferroseq-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 25.1 MB
Release files / ferroseq-0.1.0.tar.gz
| Download URL | ferroseq-0.1.0.tar.gz |
|---|---|
| Size | 79.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
866c2cd419d13aada8d9f6267cd50cfdbdf84f022195179bbb2436fdb86d6ef9
|
|
BLAKE2b-256 checksum How to use checksums |
3801913e94386f0b2b95b8737abc12a4e2538ac44f72c5672ff86bfd56fe6fa4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ferroseq-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | ferroseq-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4a464caf7a7b7a00974d5cac233c17691f051fb6dabeebb930d51dca8faf83ae
|
|
BLAKE2b-256 checksum How to use checksums |
26355241cf46ed169da250229df46e5c003fb77d76c41b8e7bea5bd818f097a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ferroseq-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | ferroseq-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1e5f951304709ced9346df6bf6a5f5bc6261a5a1434ff513530f98d1617557ab
|
|
BLAKE2b-256 checksum How to use checksums |
8c8b9240830a9f8fb8af9b11ad988f554af58de8b5b1b6c725d83c7fa697a437
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ferroseq-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | ferroseq-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
698f355e9527ac5bc4d7428e7e89e78f42b9463566825263a3d24191c03609b1
|
|
BLAKE2b-256 checksum How to use checksums |
37b6cab2d858f6b1e277a0a052522a09408cb2d95bd8d21bba6e6969b6ed341c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ferroseq-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | ferroseq-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
18f0bfe455effe757a603912b1da3dec313af2510b90aa1c76c362e382a1eda4
|
|
BLAKE2b-256 checksum How to use checksums |
6193421fcd06d0468c7db842004ce7ec720d6ec80456c9249646ba8e32857646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ferroseq-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | ferroseq-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
7ef3f178de0133a8ecdbeb26de30e58af12b9771db2319d238b325b40a1b2a2b
|
|
BLAKE2b-256 checksum How to use checksums |
f7f472a72e237d1eeb59fc4c87c1d3a83f4bf8c76ffd10dbf41e4af2d252feb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ferroseq 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.