Skip to main content

🔗🐍⏭️ pyfgs Stars

Python bindings to FragGeneScanRs for fast, error-tolerant bacterial ORF prediction

Release License DOI PyPI Wheel Python Versions Source Issues Downloads

For full usage, see the docs

Why pyfgs?

Built for noisy data

Standard ab initio predictors are fantastic for pristine, fully assembled contigs. However, they struggle with raw metagenomic reads or error-prone assemblies because they immediately break the open reading frame at the first sign of an indel. pyfgs uses an error-tolerant Hidden Markov Model trained on specific sequencing profiles (Illumina, 454, Sanger) to power through these sequencing errors, dynamically correct the reading frame, and salvage the translated protein.

Native frameshift tracking

Instead of just silently stitching broken genes together, pyfgs exposes the exact coordinates of every hallucinated or skipped base directly to Python. This allows you to rigorously track structural variants, correctly annotate INSDC-compliant pseudogenes, or export exact frameshift coordinates for downstream quality control.

No subprocess I/O tax

Running standard CLI bioinformatics tools from Python usually requires a heavy I/O penalty: dumping sequences to a temporary FASTA file, firing a subprocess, and parsing the text outputs back into memory. pyfgs binds directly to the underlying Rust engine. The HMM runs entirely in memory and yields native Python objects ready for immediate analysis.

True multithreading and zero-copy memory

pyfgs is designed to process massive datasets efficiently:

  • GIL-Free Inference: The Rust backend completely releases the Python Global Interpreter Lock (GIL) during the heavy HMM math. You can drop the predictor into a standard ThreadPoolExecutor and achieve true parallel processing across all your CPU cores.

  • Zero-Copy Bytes: The engine borrows raw byte slices (&[u8]) directly from Python's memory, bypassing the overhead of copying strings between languages.

  • Lazy Translation: Translating DNA to amino acids is computationally expensive. pyfgs evaluates sequence strings lazily, meaning you only pay the CPU and memory cost of string allocation if you explicitly request the sequence data.

A Pythonic API

Bioinformatics coordinates are notoriously messy. pyfgs outputs standard 0-based, half-open intervals ([start, end)), allowing you to slice sequence arrays immediately without wrestling with 1-based GFF3 coordinate math. When you do need standardized files, it includes heavily optimized, native-Rust context managers to stream perfectly compliant VCF, BED, GFF3, and FASTA files directly to disk without bloating your RAM.

Blazing Fast

Thanks to the memory-safe zero-copy architecture and multi-threading through Rayon, pyfgs can outperform even the fastest SIMD-optimized Gene Finders (e.g. pyrodigal) in Whole Genome mode—especially on highly fragmented assemblies and metagenomes.

🚀 Usage

1. Vectorized Batch Prediction

If you are a power user integrating gene prediction into a larger Python pipeline, pyfgs offers a vectorized, zero-copy NumPy API that sidesteps Python object overhead completely.

import pyfgs

# 1. Initialize the gene finder
# By default, this loads the Illumina HMM model (error-tolerant).
finder = pyfgs.GeneFinder()

# 2. Extract byte strings of sequence
# Notice we pass bytes (b""), not strings, to avoid encoding overhead.
sequences = [
    b"ATGCCCGGGAAATTTTGACCC",
    b"ATGAAAAAA",
]

# 3. Predict genes across all sequences in parallel (releasing the GIL)
batch = finder.find_genes_batch(sequences)

# 4. Access predictions as flat, 1-dimensional NumPy arrays (Structure-of-Arrays)
print(batch.starts)  # array([0, ...])
print(batch.ends)  # array([18, ...])
print(batch.strands)  # array([1, ...])
print(batch.scores)  # array([12.34, ...])

# 5. Fields with variable counts per gene (e.g. insertions/deletions)
# are exposed as flat arrays alongside parallel "offsets" arrays
# defining the slice boundaries (i.e. ragged arrays).
print(batch.insertions_offsets)
print(batch.insertions_flat)

2. High-Performance I/O Pipeline

If your goal is just to read a FASTA file and output standard format files (GFF3, BED, etc), pyfgs provides a pure-Rust IO pipeline that bypasses Python entirely. This is what the pyfgs CLI uses under the hood.

import pyfgs

finder = pyfgs.GeneFinder()

# Stream directly from disk to disk using Rust native threading
finder.run_file(
    input_path="input.fasta",
    is_fastq=False,
    outputs={
        "gff3": "output.gff3",
        "faa": "output.faa",
    },
)

🔧 Installing

This project is supported on Python 3.10 and later.

pyfgs can be installed directly from PyPI:

pip install pyfgs

⚡️ Power users ⚡️ can force your local machine to compile the Rust engine specifically for your own CPU by running:

RUSTFLAGS="-C target-cpu=native" pip install --no-binary pyfgs pyfgs

💭 Feedback

⚠️ Issue Tracker

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

🏗️ Contributing

Contributions are more than welcome! See CONTRIBUTING.md for more details.

📋 Changelog

This project adheres to Semantic Versioning and provides a changelog in the Keep a Changelog format.

⚖️ License

This library is provided under the GNU General Public License v3.0. The FragGeneScanRs code was written by Peter Dawyndt, Bart Mesuere and Felix Van der Jeugt and is distributed under the terms of the GPLv3 as well. See https://github.com/FragGeneScanRs/LICENSE for more information.

This project is in no way affiliated, sponsored, or otherwise endorsed by the original FragGeneScanRs authors Peter Dawyndt, Bart Mesuere and Felix Van der Jeugt. It was developed by Tom Stanton during his Post-doc project at Monash University in the Wryes Lab.

Metadata

Release files for pyfgs 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfgs 0.0.3
File Size Uploaded
pyfgs-0.0.3.tar.gz 124.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyfgs 0.0.3
File Interpreter ABI Platform
pyfgs-0.0.3-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
pyfgs-0.0.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pyfgs-0.0.3-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details

Total release size: 6.4 MB

Release files / pyfgs-0.0.3.tar.gz

Download URL pyfgs-0.0.3.tar.gz
Size 124.8 kB
Tags Source
SHA-256 checksum
How to use checksums
68516f012fa4199ec6873a1584de252239444d39dd56dca41570771d256980b7
BLAKE2b-256 checksum
How to use checksums
38e84e163ea3a5a9948190ddca8a197f808cd4fb4292f1b3e48d80af3d426391
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / pyfgs-0.0.3-cp314-cp314-macosx_11_0_arm64.whl

Download URL pyfgs-0.0.3-cp314-cp314-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1fecbc19fadabde0e6347c1a9b934ff4de155330277d0a8553736fccbfce8cd2
BLAKE2b-256 checksum
How to use checksums
ef238f6db1ee22e63e9b26c14efa2856194da89d1080e5219c30f8dae99c8fbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / pyfgs-0.0.3-cp312-cp312-win_amd64.whl

Download URL pyfgs-0.0.3-cp312-cp312-win_amd64.whl
Size 2.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
89de1ce70cab252d5a88667e5aed64371211edf19ee228020e0c28bd24b2c79f
BLAKE2b-256 checksum
How to use checksums
89df6ebfc99b4e21380c067bec50b51d1ecbf3991e9b5c0af2da7881d43a0abe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / pyfgs-0.0.3-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL pyfgs-0.0.3-cp312-cp312-manylinux_2_34_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
eb4d014a3aead38e1b185a0858a0e010764dbd7000e5c8bd225a92f6b5bbc54a
BLAKE2b-256 checksum
How to use checksums
b4714d234d3c82e8492c24cbf848f34912b5c372321a8f9a8038c93c40214618
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page