This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Kalign is a fast multiple sequence alignment (MSA) program for biological sequences (protein, DNA, RNA) written in C. The project uses CMake as the primary build system with Zig as an alternative for cross-compilation.
mkdir build
cd build
cmake ..
make
make test
make installmkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
makemkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=ASAN ..
makemkdir build
cd build
cmake -DUSE_OPENMP=OFF ..
makezig buildmake test
# or
ctestctest -R <test_name>kalign_io_test- I/O functionality testskalign_lib_test- Library API testskalign_cmp_test- Comparison testskaligncpp- C++ API testsdssim- Distance similarity tests
lib/- Core library implementationsrc/- Library source files (alignment algorithms, I/O, utilities)include/kalign/- Public API headers
src/- Main executable (command-line interface)tests/- Test suite with biological sequence data
aln_seqseq.c- Sequence-to-sequence alignmentaln_seqprofile.c- Sequence-to-profile alignmentaln_profileprofile.c- Profile-to-profile alignmentaln_controller.c- Alignment orchestrationbpm.c- Bit-parallel matching (Myers' algorithm)
msa_io.c- Multi-format sequence reading/writing (FASTA, MSF, Clustal)msa_alloc.c- Memory management for sequence datamsa_op.c- Sequence operations and manipulations
sequence_distance.c- Sequence distance metricseuclidean_dist.c- Euclidean distance calculationsbisectingKmeans.c- K-means clustering for guide tree construction
tldevel.c- Development utilities and debuggingtlmisc.c- Miscellaneous helper functionsalphabet.c- Sequence alphabet handling (DNA, RNA, protein)task.c- Task scheduling and threading support
- Multi-threading: OpenMP parallelization
- SIMD: SSE4.1, AVX, AVX2 optimizations (enabled by default)
- Bit-parallel algorithms: Myers' algorithm for efficient alignment
- Memory optimization: Custom allocation strategies
The library provides a C API (kalign.h) with C++ compatibility. Key functions:
- Reading sequences from files
- Running alignments with different parameters
- Writing results in various formats
- Memory management helpers
- C11 standard required
- OpenMP support (can be disabled with
-DUSE_OPENMP=OFF) - SIMD instruction support with runtime detection
- Multiple build types: Release, Debug, ASAN (Address Sanitizer)
- Cross-compilation support via Zig build system
- Unit tests for core components (BPM, distance calculations, I/O)
- Integration tests using Balibase sequence datasets
- C++ API compatibility tests
- Performance benchmarks
- Format conversion tests (FASTA, MSF, Clustal)
The repository includes a Python package that provides Python bindings for the Kalign library. The Python package is configured at the root level using modern Python packaging standards.
uv pip install -e .uv run python -m buildmkdir build
cd build
cmake -DBUILD_PYTHON_MODULE=ON ..
makeuv run python -c "import kalign; print(kalign.__version__); seqs=['ATCG','ATCGG']; print(kalign.align(seqs))"uv run pytest tests/python/ -vuv run python -m cibuildwheel --output-dir wheelhousepython-kalign/__init__.py- High-level Python APIpython-kalign/_core.cpp- pybind11 C++ bindingspyproject.toml- Modern Python build configuration (at root level)README-python.md- Python-specific documentationtests/python/- Python test suite
- Simple interface:
kalign.align(sequences, seq_type="auto") - File support:
kalign.align_from_file("file.fasta") - Parameter control: Gap penalties, threading, sequence types
- Error handling: Python exceptions for C library errors
- Memory safety: Automatic memory management through pybind11
The .github/workflows/wheels.yml workflow:
- Builds wheels for Linux, macOS, Windows
- Tests multiple Python versions (3.9-3.13)
- Uses cibuildwheel for cross-platform compatibility
- Publishes to PyPI on tagged releases