huseyinmsa
A Python library for Multiple Sequence Alignment (MSA) implemented from scratch using Dynamic Programming.
Installation
pip install huseyinmsa
Quick start
from huseyinmsa import MSA, print_alignment
sequences = {
"Seq1": "ACGTACGT",
"Seq2": "ACGACGT",
"Seq3": "ACGT",
}
msa = MSA()
alignment = msa.align(sequences)
print_alignment(alignment)
print("SP Score:", msa.sp_score(alignment))
Reading / writing FASTA files
from huseyinmsa import MSA, read_fasta, write_fasta, print_alignment
sequences = read_fasta("sequences.fasta")
msa = MSA(match=1, mismatch=-1, gap=-2)
alignment = msa.align(sequences)
print_alignment(alignment)
write_fasta(alignment, "aligned.fasta")
Algorithm
The library implements progressive multiple sequence alignment driven entirely by dynamic programming.
Stage 1 — Pairwise distances (Needleman-Wunsch)
Every pair of input sequences is globally aligned using the classic Needleman-Wunsch O(n·m) DP algorithm.
dp[0][j] = j × gap
dp[i][0] = i × gap
dp[i][j] = max(
dp[i-1][j-1] + sub(seq1[i], seq2[j]), # match or mismatch
dp[i-1][j] + gap, # delete from seq1
dp[i][j-1] + gap, # insert into seq1
)
After alignment, sequence identity (identical columns / total columns)
is used to convert the score into a distance: distance = 1 − identity.
Stage 2 — Guide tree (UPGMA)
The n×n distance matrix is clustered with UPGMA:
- Each sequence starts as its own cluster.
- The two closest clusters are merged; their distance to every other cluster is recalculated as the size-weighted average.
- Repeat until a single root cluster remains.
The result is a binary tree (e.g. (('A','B'),'C')) that tells the aligner
which sequences to merge first — always the most similar ones.
Stage 3 — Progressive alignment (profile–profile DP)
Sequences are merged bottom-up along the guide tree. At each merge step, two blocks of already-aligned sequences (profiles) are aligned with a second DP pass. The score between two columns is the average substitution score over all non-gap character pairs; gap penalties are scaled by the fraction of real characters in a column.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
match |
1 |
Score for identical characters |
mismatch |
-1 |
Penalty for mismatched characters |
gap |
-2 |
Linear gap penalty |
Scoring
After alignment, the Sum-of-Pairs (SP) score is available:
score = msa.sp_score(alignment)
It sums the pairwise substitution / gap score across every aligned column for every pair of sequences. Higher values indicate a better alignment.
License
MIT
Metadata
Release files for Huseyin-Cakir 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| huseyin_cakir-0.1.0.tar.gz | 9.9 kB | Without provenance | Details for huseyin_cakir-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| huseyin_cakir-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for huseyin_cakir-0.1.0-py3-none-any.whl |
Total release size: 20.4 kB
Release files / huseyin_cakir-0.1.0.tar.gz
| Download URL | huseyin_cakir-0.1.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e71c6fd5dbc137f4c9209f725e10c6109a522fff04239a478009aab26957093e
|
|
BLAKE2b-256 checksum How to use checksums |
9017e2ae39db29748dfc629484405a7819b179e92d72c94cb877a70c33246006
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / huseyin_cakir-0.1.0-py3-none-any.whl
| Download URL | huseyin_cakir-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8935e82451d7bffbe34e080ae5aceaa660c1b11b6e0d040bb4c8f616916c43c
|
|
BLAKE2b-256 checksum How to use checksums |
b1eed83dc37dae0fe4800021ec0c33eae0f90cc296843a8c8164ddd0fca3b672
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for Huseyin-Cakir 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.