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 crates/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.56.0.tar.gz (181.4 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.56.0-cp39-abi3-win_amd64.whl (449.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

biors-0.56.0-cp39-abi3-manylinux_2_34_x86_64.whl (629.9 kB view details)

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

biors-0.56.0-cp39-abi3-macosx_11_0_arm64.whl (564.7 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for biors-0.56.0.tar.gz
Algorithm Hash digest
SHA256 e8b0a9c7aed1a94d359109cde64171babdc5528d0c2de5b48cc4fca82c33a130
MD5 63eb34994b3752adc152e79a41cf35cf
BLAKE2b-256 dbb9601e369847818e854359f0cb6d5c71332ce611211dadcac3c3219c338932

See more details on using hashes here.

File details

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

File metadata

  • Download URL: biors-0.56.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 449.7 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.56.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cbd0d3d8934136ee6e45edffc0fc0655c3973371c336bfebbf8aadd8396b8f63
MD5 f82e36b4e2713271053fdd9d27462a24
BLAKE2b-256 a953b5ddd60d1e8ada477f8375aaf3071ee4251c0f7d5317fa7dacf4c8427788

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for biors-0.56.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c9274047bcb0a62df8dcb10fa75d0cfe2afa8f8073aec1996e2ab963457bcd94
MD5 7b1e0866e91db2bca3fd8dc2a5b81db6
BLAKE2b-256 9381480fd04267959335cd24c30fee668eef417aa87a54cf5ec0ad0ef2635298

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for biors-0.56.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53dc6cfcbe5b08637977ae1e814fa6ddfc72f898f754dbbcab8c1b6c4cdc092a
MD5 1958169ae2253d46543885cdbbf2b134
BLAKE2b-256 c980f03e14a96e6e94a8e663af6c010127da39403759498afa91a3627c65ab29

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