Skip to main content

Python bindings for bio-rs core

Project description

biors-python

Python bindings for bio-rs via PyO3.

Installation

pip install biors

Requires Python 3.9+.

Quickstart

import json

import biors

fasta_text = (
    ">seq1\nACDEFGHIKLMNPQRSTVWY\n"
    ">seq2\nMKWVTFISLLFLFSSAYSRGVFRRDAHKSEVAHRFKDLGEENFKALVLIAFAQYLQQCP\n"
)

# Parse FASTA text
records = biors.parse_fasta_records(fasta_text)

# Validate
report = biors.validate_fasta_input(fasta_text)
rna_report = biors.validate_fasta_input_with_kind(">rna\nACGUN\n", "rna")
print(f"Valid records: {report.valid_records}/{report.records}")
for record in report.sequences:
    for issue in record.warnings:
        print(f"{record.id}: ambiguous residue {issue.residue} at {issue.position}")
    for issue in record.errors:
        print(f"{record.id}: invalid residue {issue.residue} at {issue.position}")

# Tokenize
tokenized = biors.tokenize_fasta_records(fasta_text)
for t in tokenized:
    print(t.id, t.alphabet, t.valid, t.tokens)
    for issue in t.warnings + t.errors:
        print(issue.residue, issue.position)

# Tokenize one in-memory sequence with a caller-provided ID
single = biors.tokenize_protein("ACDEFG", id="sample-001")
print(single.id, single.tokens)

# DNA/RNA use explicit tokenizer profiles.
dna = biors.tokenize_fasta_records(">dna\nACGT\n", profile="dna-iupac")
rna_workflow = biors.prepare_workflow_from_fasta(
    ">rna\nACGU\n",
    max_length=8,
    profile="rna-iupac",
)

# Build model input
model_input = biors.build_model_inputs_checked(
    tokenized,
    max_length=512,
    pad_token_id=0,
    padding="fixed_length",
)
for r in model_input.records:
    print(r.id, r.input_ids, r.attention_mask)

# End-to-end workflow
output = biors.prepare_workflow_from_fasta(
    fasta_text,
    max_length=512,
    pad_token_id=0,
    padding="fixed_length",
)
print(f"Model ready: {output.model_ready}")
print(output.report_json)

# Validate a package on disk, including artifact paths and checksums.
package_report = json.loads(
    biors.validate_package_manifest_file("./protein-package/manifest.json")
)
print(package_report["valid"])

validate_package_manifest(manifest_json) is field-only validation for an in-memory manifest. Use validate_package_manifest_artifacts(manifest_json, base_dir) or validate_package_manifest_file(manifest_path) when package files, checksums, and layout placement must be verified.

Errors raised by core parsing, model-input, and package helpers are BioRsError values with stable code, message, and optional location attributes, while still subclassing ValueError.

Development

Build locally with maturin:

cd packages/rust/biors-python
maturin develop
pytest

License

MIT OR Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biors-0.48.0.tar.gz (132.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

biors-0.48.0-cp39-abi3-win_amd64.whl (446.1 kB view details)

Uploaded CPython 3.9+Windows x86-64

biors-0.48.0-cp39-abi3-manylinux_2_34_x86_64.whl (627.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

biors-0.48.0-cp39-abi3-macosx_11_0_arm64.whl (561.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file biors-0.48.0.tar.gz.

File metadata

  • Download URL: biors-0.48.0.tar.gz
  • Upload date:
  • Size: 132.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for biors-0.48.0.tar.gz
Algorithm Hash digest
SHA256 402eb2d54e854a4aee0d36cb4a8ec5e8479038989c64da6757ec8cdb63f72ccc
MD5 ff06cd8021f08142699f2b398c575f36
BLAKE2b-256 4976fd4bf0995b3d24a5ca34dbaed054480fada7438cf1ac4c0ab68e796d93f1

See more details on using hashes here.

File details

Details for the file biors-0.48.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: biors-0.48.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 446.1 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for biors-0.48.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7bb22f1d98f3c31a30eca61f969ca2bf6a0bfd1375d90da95583ae1dce8c774c
MD5 c09641c3365d681c644d4ade8a9cce06
BLAKE2b-256 2f13bf598c16a529d29382c7cffe628f68e91217683c6247859bc07509087ff5

See more details on using hashes here.

File details

Details for the file biors-0.48.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for biors-0.48.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 db5a6516da3ee5aab6c4cd71bd54af3b8b21e3afbaee5d0eadf12fbe1d9d95a7
MD5 7499532930ba0a262e0e1965edd65a41
BLAKE2b-256 4ae02f220b633f72fe722ba6a0799a3e35b0d1268272d5e8ac8ee3a6e0a20143

See more details on using hashes here.

File details

Details for the file biors-0.48.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for biors-0.48.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2531f59531183f40cd94d41892643a329dd89cd95da2c20e85482a526c078a44
MD5 593ccc6653475dc7bebfdddcf794fb58
BLAKE2b-256 06fb7d795ca75fc0f1f1da4f077fc51ae5b33b6f86a2496e0e6522b7e115cfc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page