Skip to main content

Fast approximate string searching using SIMD

Project description

Sassy Python Bindings

🐍 The python bindings for Sassy

Installation

Pip.

pip install sassy-rs

(as sassy was already taken we chose sassy-rs)

From source. In the root of the repository, run:

maturin develop --features python

You need Maturin for this, see maturin:

Usage

A simple usage is as follows:

import sassy
pattern = b"ATCGATCG"
text = b"GGGGATCGATCGTTTT"
# alphabet: ascii, dna, iupac
searcher = sassy.Searcher("dna")
matches = searcher.search(pattern, text, k=1)
for i, match in enumerate(matches):
    print(f"Match {i+1}:")
    print(f"    Start: {match.text_start}")
    print(f"    End: {match.text_end}")
    print(f"    Cost: {match.cost}")
    print(f"    Strand: {match.strand}")
    print(f"    CIGAR: {match.cigar}")

This finds 3 matches:

Match 1:
    Start: 4
    End: 12
    Cost: 0
    Strand: +
    CIGAR: 8=
Match 2:
    Start: 6
    End: 14
    Cost: 1
    Strand: -
    CIGAR: 6=X=
Match 3:
    Start: 2
    End: 10
    Cost: 1
    Strand: -
    CIGAR: X7=

Further options are sassy.Searcher(alpha=0.5) to allow overhang alignments, sassy.Searcher("dna", rc=False) to disable reverse complements for DNA or IUPAC strings, and sassy.Searcher("dna", max_n_frac=0.1) to drop matches whose aligned text region is more than 10% N bases. Here, max_n_frac is a fraction in [0, 1] where omitting it or using 1.0 disables the filter. searcher.search is the simple function to search one pattern in one text, while searcher.search_many takes multiple patterns and multiple texts and searches each pattern in each text, possibly in multiple threads.

See sassy/example.py for a larger example.

Type Hints

This package ships PEP 561 type stubs (sassy/py.typed + sassy/__init__.pyi) so that type checkers and IDEs can provide autocomplete and type checking out of the box.

The .pyi stubs are auto-generated by the PyPI publishing workflow, and are not stored in git. To manually generate stubs for local testing:

# macOS
RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo build --features python
cargo run --features python-stubs --bin gen_stubs -- target/debug/libsassy.dylib

# Linux
cargo build --features python
cargo run --features python-stubs --bin gen_stubs -- target/debug/libsassy.so

Once the stubs have been generated, type-checking for the sassy Python library will be enabled. See sassy/example_typed.py for a typed example that exercises all public APIs.

Running the example requires the sassy package be installed in your environment.

To install maturin and the package in an isolated environment, then run the typed example you can use a single uv command:

uv run \
    --with maturin \
    sh -c 'maturin develop && python python/sassy/example_typed.py'

Running type checking on the type exampled requires mypy be installed in your environment.

To install mypy in an isolated environment then run type checking on the typed example you can use a single uv command:

uv run \
    --with mypy \
    sh -c 'mypy python/sassy/example_typed.py'

Troubleshooting

1. I could install sassy-rc but no modules/functions are found.

When creating an issue please include the output of print(dir(sassy)) if you were able to install sassy-rs but no functions/modules were found.

Your output might look like:

['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

Whereas it should look like:

['Match', 'Searcher', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'features']

2. Other sassy issues.

If you were able to install sassy, but have other issues please also add the output of sassy.features().

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

sassy_rs-0.2.6.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

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

sassy_rs-0.2.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (476.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

sassy_rs-0.2.6-cp38-abi3-macosx_11_0_arm64.whl (422.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file sassy_rs-0.2.6.tar.gz.

File metadata

  • Download URL: sassy_rs-0.2.6.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sassy_rs-0.2.6.tar.gz
Algorithm Hash digest
SHA256 ac0fb941a7a399f25dd0c6a1ffdd40c42fb1953eda851796f573c2c8daa2fea1
MD5 71588b8325e65244117642d28e8cd374
BLAKE2b-256 be07e936786dded5a813f394676ccf0cd9646c807b7470945fbc81a5b23ae715

See more details on using hashes here.

File details

Details for the file sassy_rs-0.2.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sassy_rs-0.2.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdb12d5acf8842136824d2201f8f2873fc5b1a8bd5bfc1bca69273d7407cd42f
MD5 676fd017e80227ee9434d9782a71de26
BLAKE2b-256 4c2ccc60711dcf4fdd0820b1b911ae688da63d3eae33488b5bf07a62092d6adf

See more details on using hashes here.

File details

Details for the file sassy_rs-0.2.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sassy_rs-0.2.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a755b44a076070bb33465a794cc9e14636d1d8dd64c663277f4fd692a3b98e9e
MD5 32f00bfd05662b889741508be449182b
BLAKE2b-256 73007e17cdb3e473582991f21efbc8379c6d865e0055bfa4d18cbad224afca71

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