Skip to main content

Cython bindings and Python interface to Opal, a SIMD-accelerated pairwise aligner.

Project description

🐍🌈🪨 PyOpal Stars

Cython bindings and Python interface to Opal, a SIMD-accelerated database search aligner.

Actions Coverage License PyPI Bioconda AUR Wheel Python Versions Python Implementations Source Mirror Issues Docs Changelog Downloads

🗺️ Overview

Opal is a sequence aligner enabling fast sequence similarity search using either of the Smith-Waterman, semi-global or Needleman-Wunsch algorithms.

PyOpal is a Python module that provides bindings to Opal using Cython. It implements a user-friendly, Pythonic interface to query a database of sequences and access the search results. It interacts with the Opal interface rather than with the CLI, which has the following advantages:

  • single dependency: PyOpal is distributed as a Python package, so you can add it as a dependency to your project, and stop worrying about the Opal binary being present on the end-user machine.
  • no intermediate files: Everything happens in memory, in a Python object you control, so you don't have to invoke the Opal CLI using a sub-process and temporary files.
  • better portability: Opal uses SIMD to accelerate alignment scoring, but doesn't support dynamic dispatch, so it has to be compiled on the local machine to be able to use the full capabilities of the local CPU. PyOpal ships several versions of Opal instead, each compiled with different target features, and selects the best one for the local platform at runtime.
  • wider platform support: The Opal code has been backported to work on SSE2 rather than SSE4.1, allowing PyOpal to run on older x86 CPUs (all x86 CPUs support it since 2003). In addition, Armv7 and Aarch64 CPUs are also supported if they implement NEON extensions.

🔧 Installing

PyOpal is available for all modern versions (3.6+), with no external dependencies.

It can be installed directly from PyPI, which hosts some pre-built wheels for the x86-64 architecture (Linux/OSX) and the Aarch64 architecture (Linux only), as well as the code required to compile from source with Cython:

$ pip install pyopal

💡 Example

Create a database from some reference sequences:

import pyopal

database = pyopal.Database([
    "MESILDLQELETSEEESALMAASTVSNNC",                         # goadvionin A
    "MKKAVIVENKGCATCSIGAACLVDGPIPDFEIAGATGLFGLWG",           # subtilosin A
    "MAGFLKVVQILAKYGSKAVQWAWANKGKILDWINAGQAIDWVVEKIKQILGIK", # lacticin Z
    "MTQIKVPTALIASVHGEGQHLFEPMAARCTCTTIISSSSTF",             # plantazolicin
])

Then search it with a query sequence, and show the target sequence with the highest score:

results = database.search("MAGFLKVVQLLAKYGSKAVQWAWANKGKILDWLNAGQAIDWVVSKIKQILGIK")
best = max(results, key=lambda result: result.score)
print(best.score, best.target_index, database[best.target_index])

You can also get the alignment for every target, but this must be enabled when searching the database:

results = database.search("MESVLDLQELETSEEESALMAASTISQNC", mode="full")
for result in results:
    print(result.score, result.identity(), result.cigar())

🧶 Thread-safety

Database objects are thread safe through a C++17 read/write lock that prevents modification while the database is searched. In addition, the Database.search method is re-entrant and can be safely used to query the same database in parallel with different queries across different threads:

import multiprocessing.pool
import pyopal
import Bio.SeqIO

queries = [
    "MEQQIELDVLEISDLIAGAGENDDLAQVMAASCTTSSVSTSSSSSSS",
    "MTQIKVPTALIASVHGEGQHLFEPMAARCTCTTIISSSSTF",
    "MGAIAKLVAKFGWPIVKKYYKQIMQFIGEGWAINKIIDWIKKHI",
    "MGPVVVFDCMTADFLNDDPNNAELSALEMEELESWGAWDGEATS",
]

database = pyopal.Database([
    str(record.seq)
    for record in Bio.SeqIO.parse("vendor/opal/test_data/db/uniprot_sprot12071.fasta", "fasta")
])

with multiprocessing.pool.ThreadPool() as pool:
    hits = dict(pool.map(lambda q: (q, database.search(q)), queries))

💭 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 MIT License. Opal is developed by Martin Šošić and is distributed under the terms of the MIT License as well. See vendor/opal/LICENSE for more information. The cpu_features library was written by Guillaume Chatelet and is licensed under the terms of the Apache License 2.0. See vendor/cpu_features/LICENSE for more information.

This project is in no way not affiliated, sponsored, or otherwise endorsed by the Opal authors. It was developed by Martin Larralde during his PhD project at the European Molecular Biology Laboratory in the Zeller team.

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

pyopal-0.2.0.tar.gz (102.2 kB view hashes)

Uploaded Source

Built Distributions

pyopal-0.2.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (356.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (221.6 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

pyopal-0.2.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (359.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl (221.9 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

pyopal-0.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (360.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-pp37-pypy37_pp73-macosx_10_12_x86_64.whl (222.0 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

pyopal-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyopal-0.2.0-cp310-cp310-macosx_10_15_x86_64.whl (318.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyopal-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyopal-0.2.0-cp39-cp39-macosx_10_15_x86_64.whl (318.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyopal-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyopal-0.2.0-cp38-cp38-macosx_10_15_x86_64.whl (315.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyopal-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pyopal-0.2.0-cp37-cp37m-macosx_10_15_x86_64.whl (313.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

pyopal-0.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

pyopal-0.2.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

pyopal-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl (316.5 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

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