Skip to main content

Python wrapper for the Kalign multiple sequence alignment engine

Project description

Kalign Python Package

Python bindings for Kalign, a fast multiple sequence alignment program for biological sequences (DNA, RNA, protein).

Installation

pip install kalign-python

Optional dependencies for ecosystem integration:

pip install kalign-python[biopython]    # Biopython integration (fmt="biopython", I/O helpers)
pip install kalign-python[skbio]        # scikit-bio integration (fmt="skbio")
pip install kalign-python[io]           # I/O helpers (requires Biopython)
pip install kalign-python[analysis]     # pandas + matplotlib for downstream analysis
pip install kalign-python[all]          # all of the above

Quick Start

import kalign

sequences = [
    "ATCGATCGATCG",
    "ATCGTCGATCG",
    "ATCGATCATCG"
]

aligned = kalign.align(sequences, seq_type="dna")
for seq in aligned:
    print(seq)

Core API

kalign.align()

aligned = kalign.align(
    sequences,              # list of str
    seq_type="auto",        # "auto", "dna", "rna", "protein", "divergent", "internal"
    gap_open=None,          # positive float, or None for defaults
    gap_extend=None,        # positive float, or None for defaults
    terminal_gap_extend=None,
    n_threads=None,         # int, or None for global default
    fmt="plain",            # "plain", "biopython", "skbio"
    ids=None,               # list of str (for biopython/skbio output)
)

Returns a list of aligned strings (default), a Bio.Align.MultipleSeqAlignment (fmt="biopython"), or a skbio.TabularMSA (fmt="skbio").

kalign.align_from_file()

Align sequences directly from a FASTA, MSF, or Clustal file:

result = kalign.align_from_file("sequences.fasta", seq_type="protein")
for name, seq in zip(result.names, result.sequences):
    print(f"{name}: {seq}")

Returns an AlignedSequences named tuple with .names and .sequences.

kalign.compare()

Score a test alignment against a reference using the Sum-of-Pairs (SP) score:

score = kalign.compare("reference.msf", "test.fasta")
print(f"SP score: {score:.1f}")  # 0 (no match) to 100 (identical)

kalign.write_alignment()

Write aligned sequences to a file:

kalign.write_alignment(aligned, "output.fasta", format="fasta", ids=ids)

Supported formats: fasta, clustal, stockholm, phylip (non-FASTA formats require Biopython).

Threading

import kalign

kalign.set_num_threads(4)        # set global default
n = kalign.get_num_threads()     # query current default

# or override per call
aligned = kalign.align(sequences, n_threads=8)

Thread settings are thread-local, so different threads can use different defaults.

Utilities (kalign.utils)

Requires only NumPy (installed automatically):

import kalign

aligned = kalign.align(sequences)

arr = kalign.utils.to_array(aligned)                          # numpy array
stats = kalign.utils.alignment_stats(aligned)                 # dict with gap_fraction, conservation, identity
consensus = kalign.utils.consensus_sequence(aligned, threshold=0.7)
matrix = kalign.utils.pairwise_identity_matrix(aligned)       # numpy array
trimmed = kalign.utils.remove_gap_columns(aligned)
region = kalign.utils.trim_alignment(aligned, start=2, end=10)

Biopython Integration

Requires pip install kalign-python[biopython].

import kalign

# Return a Biopython MultipleSeqAlignment
aln = kalign.align(sequences, fmt="biopython", ids=["s1", "s2", "s3"])
print(aln.get_alignment_length())

# Write in various formats via Biopython
from Bio import AlignIO
AlignIO.write(aln, "output.clustal", "clustal")

I/O helpers (kalign.io)

sequences = kalign.io.read_fasta("input.fasta")
sequences, ids = kalign.io.read_sequences("input.fasta")

aligned = kalign.align(sequences)
kalign.io.write_fasta(aligned, "output.fasta", ids=ids)
kalign.io.write_clustal(aligned, "output.aln", ids=ids)
kalign.io.write_stockholm(aligned, "output.sto", ids=ids)
kalign.io.write_phylip(aligned, "output.phy", ids=ids)

scikit-bio Integration

Requires pip install kalign-python[skbio].

import kalign

# Returns a TabularMSA of DNA, RNA, or Protein depending on seq_type
aln = kalign.align(sequences, seq_type="dna", fmt="skbio")
print(type(aln))  # <class 'skbio.alignment._tabular_msa.TabularMSA'>

Sequence Types

String Constant Description
"auto" kalign.AUTO Auto-detect (default)
"dna" kalign.DNA DNA sequences
"rna" kalign.RNA RNA sequences
"protein" kalign.PROTEIN Protein sequences
"divergent" kalign.PROTEIN_DIVERGENT Divergent protein sequences
"internal" kalign.DNA_INTERNAL DNA with internal gap preference

Command-line Interface

kalign-py -i sequences.fasta -o aligned.fasta --format fasta --type protein
kalign-py -i sequences.fasta -o - --format clustal   # stdout
cat input.fa | kalign-py -i - -o aligned.fasta        # stdin
kalign-py --version

Development

git clone https://github.com/TimoLassmann/kalign.git
cd kalign
uv pip install -e .
uv run pytest tests/python/ -v

Requirements: Python 3.9+, CMake 3.18+, C++11 compiler, NumPy.

Citation

If you use Kalign in your research, please cite:

Lassmann, T. (2020). Kalign 3: multiple sequence alignment of large data sets. Bioinformatics, 36(6), 1928-1929. doi:10.1093/bioinformatics/btz795

License

GNU General Public License v3.0 or later. See COPYING.

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

kalign_python-3.4.9.tar.gz (1.3 MB view details)

Uploaded Source

Built Distributions

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

kalign_python-3.4.9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (299.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

kalign_python-3.4.9-cp313-cp313-macosx_14_0_x86_64.whl (166.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ x86-64

kalign_python-3.4.9-cp313-cp313-macosx_14_0_arm64.whl (400.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

kalign_python-3.4.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (298.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

kalign_python-3.4.9-cp312-cp312-macosx_14_0_x86_64.whl (166.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

kalign_python-3.4.9-cp312-cp312-macosx_14_0_arm64.whl (400.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

kalign_python-3.4.9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (297.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

kalign_python-3.4.9-cp311-cp311-macosx_14_0_x86_64.whl (165.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

kalign_python-3.4.9-cp311-cp311-macosx_14_0_arm64.whl (399.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

kalign_python-3.4.9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (295.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

kalign_python-3.4.9-cp310-cp310-macosx_14_0_x86_64.whl (163.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ x86-64

kalign_python-3.4.9-cp310-cp310-macosx_14_0_arm64.whl (398.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

kalign_python-3.4.9-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (295.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

kalign_python-3.4.9-cp39-cp39-macosx_14_0_x86_64.whl (164.0 kB view details)

Uploaded CPython 3.9macOS 14.0+ x86-64

kalign_python-3.4.9-cp39-cp39-macosx_14_0_arm64.whl (398.4 kB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file kalign_python-3.4.9.tar.gz.

File metadata

  • Download URL: kalign_python-3.4.9.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kalign_python-3.4.9.tar.gz
Algorithm Hash digest
SHA256 947e55af8d0c3f1042eca9e4408f89f936b6631e3f5a50bf1e762be68772ce6c
MD5 d622fbfcd41d9593bd7f68c734b9200c
BLAKE2b-256 7dd9723af321afac128b4842236aad2012115805db301065cc359e7e8f678852

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9.tar.gz:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c543e994c03661f31680435b5d33f32d52ccf94a20aef78403d3b77b0a71b98
MD5 a5528429deb2993780f742c273879c55
BLAKE2b-256 e85ea03c0bd1cd4a8d83a298427245bae5868c15b95f4d47f7102192ffec9d9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp313-cp313-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp313-cp313-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 251b7c3e9788c6ffb03f5c90b79b129a594f14e894a532cc1615a0ce9bfea76b
MD5 cadcffe887ec25933c00ac58b28247e2
BLAKE2b-256 94c7b0745c52c504ba20191de98bb8ff3e7861d0e4c568fa3a9b0b4728355ca4

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp313-cp313-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5bfbc6300ff5fffbc6b14c969f81fc1b787e7c450435f2d9d10a30d71a20564
MD5 9034002cb9dbd267546bc0e5439d76c2
BLAKE2b-256 2c3f0796d3c8b931adc203ec20b5af62c8682605e463db74414c2c4bcd196a1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e27220d44b13eecb67a7a851c07939e373d13cf1f2ba5734f32a56b3627d1a64
MD5 0150c4fc55bbcd1d722659b7e6b6163e
BLAKE2b-256 96e336c31bab9fcc4ecd5a8e8088388a72a7a69cab9f9423d9bd02349fde02b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 adf3d9bcd527e89b7fb432b902e8b80817a52bc7b3a96401a104fb795ed8ffa2
MD5 8b897aaf1e56f36ca1800ab2b7207ea4
BLAKE2b-256 4e9e8034c665b4865540d6740845e187c71c7523933572f98f23207f031dc7a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp312-cp312-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 875152b1ff38ae33af4a1714172bb8769722832cbe3aa1dee3a9ccf24f2686f9
MD5 f75e0f99f1da2f2cfc66cf39d5342849
BLAKE2b-256 581e7975971e1a9585554a48b04161eab1b4be8c65b7cd15c0184bc9dd783f2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8d4a43a282e299736375cbd0b4c78f3d4fae80c45873bbf74cdb869bc7a9f400
MD5 e642dc9724ad3c1e0dc583e0b66664dd
BLAKE2b-256 fc02c16c3878a3f10de162dfdaec8ba1ac6b5ba33c59a1f72db04ba6d091d7eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 2a68e289806850290180f358609b65211edb390eda9a9056a3124343af582bfc
MD5 dda205572a65ae426b17e98dc37baee0
BLAKE2b-256 342517e4bc4f674f32d8a9db5b5583f9edfffbf1cf65d9324eb46cc2bf051770

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp311-cp311-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 57ddcb19a9efaafd19597e68781c8a2ada6767aa57146ecc9f341e69491db42b
MD5 c59a9bde07eb27236fbe1359c80d379a
BLAKE2b-256 1c7dd15520a03406f460878418c79a883dbef57c3a5a331939e34d13feead50d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 87465d7bdc45ac5342d0f17ca5b7eea8c02f339bf5b614fb695e109a60d70217
MD5 a22af25e31753c46f23db48dbf515043
BLAKE2b-256 18f7ba1ad915426d73a90f2a02b9c30997fbe6c8c5f58eb24d4bc7eeb54c5821

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 ccbb7f02e13856418e31f0180f54cd16c093bd530f0331ee5030a260661463fd
MD5 d470e9ffaa34ae8adbe2b7b3974ab83c
BLAKE2b-256 8479b4afa8e30e2a5aeab2f9b3d5895c7d4a74f0d3fb360ec3c95967df6b9295

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp310-cp310-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b220d971dd52340177a36b56f45f72a36619ee7cd7aa6934e4878946ebff6433
MD5 cc7171ab86efe633f5cc775fbe85ca1d
BLAKE2b-256 77f2d38166feac2dcabd551e971c29411ce1ad81d63c9c93536ef2cd98eb8e7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1f991651dba1f5976997fc563a5b02b697366df45d8168e484dbc31b2d73cafb
MD5 75e9ac1d95cc71b8674705d5ad333651
BLAKE2b-256 df951a4b8570f20bd8bdaed09580ff3e652e30e6ba8e417d5086ad5f74eaa49f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp39-cp39-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp39-cp39-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 187f00cc7fd567f461b3e3f0311e7b2192e2bba9ba930e34cbe1acb415f01a7c
MD5 d3900c4acce1b9a8c71e8b0aaf74a9f8
BLAKE2b-256 898b401fd1ae8abcef4bb3026cda3852541db3da4394d1dd0c54e8cf14ce9e54

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp39-cp39-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kalign_python-3.4.9-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for kalign_python-3.4.9-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0503abf1d42e8bf65982a8cd03a27560851c639d2ef674da2311ea027e23c3ae
MD5 fe9ada0ee3d4ef14aa0c347185b945c6
BLAKE2b-256 ea15dba8bcf3c1084ed044b537b5217242a25787e5af27107867ed82293a69be

See more details on using hashes here.

Provenance

The following attestation bundles were made for kalign_python-3.4.9-cp39-cp39-macosx_14_0_arm64.whl:

Publisher: wheels.yml on TimoLassmann/kalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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