njswalig
Needleman–Wunsch (global) and Smith–Waterman (local) pairwise sequence alignment in plain Python, with no dependencies. It prints the alignment and, if you ask, the filled-in dynamic-programming score table.
pip install njswalig
Usage
from njswalig import njalign # Needleman-Wunsch (global)
from njswalig import swalign # Smith-Waterman (local)
seqs = ["ATCG", "TTTA"] # any number of sequences, any lengths
scores = [2, -1, -2] # [match, mismatch, gap] -- always this order
alignment = njalign.sequences(seqs, scores) # or njalign.sequence(...) -- same thing
alignment.show()
Needleman-Wunsch (global): Seq1 vs Seq2, score = -1
Seq1 ATCG
.|..
Seq2 TTTA
| marks a match, . a mismatch and a space a gap.
Smith–Waterman
swalign.sequences(["TGTTACGG", "GGTTGACTA"], [3, -3, -2]).show()
Smith-Waterman (local): Seq1 vs Seq2, score = 13
Seq1 2 GTT-AC 6
||| ||
Seq2 2 GTTGAC 7
The numbers show where the aligned region starts and ends in each sequence (1-based).
More than two sequences
Every pair is aligned. Sequences are named Seq1, Seq2, … in list order, or pass your own:
njalign.sequences(["GATTACA", "GCATGCU", "GATCA"], [1, -1, -1], names=["a", "b", "c"]).show()
The DP score table
swalign.sequences(["ATCG", "TTTA"], [2, -1, -2]).show(matrix=True)
- T T T A
- 0 0 0 0 0
A 0 0 0 0 2
T 0 2 2 2 0
C 0 0 1 1 1
G 0 0 0 0 0
Using the results in code
sequences(...) returns a list of pair alignments. Each has score, aligned1, aligned2,
match_line, name1, name2, seq1, seq2, matrix (the DP table as a list of lists) and
1-based start1, end1, start2, end2.
best = njalign.sequences(["GATTACA", "GCATGCU"], [1, -1, -1])[0]
print(best.score, best.aligned1, best.aligned2) # 0 G-ATTACA GCA-TGCU
Details
- Scoring is linear: every gap position costs
gap.scoresmust be a list of exactly three numbers,[match, mismatch, gap]; anything else raisesValueError. - Sequences are stripped of surrounding spaces and upper-cased, so
"acgt "equals"ACGT". - Ties: when several alignments share the best score, one is returned. The traceback prefers a diagonal step (match/mismatch), then a gap in the second sequence, then a gap in the first. Smith–Waterman starts from the first highest cell, scanning row by row.
- No local match: when nothing scores above 0, Smith–Waterman reports an empty alignment with score 0.
License
MIT
Metadata
Release files for njswalig 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 | |
|---|---|---|---|---|
| njswalig-0.1.0.tar.gz | 6.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| njswalig-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / njswalig-0.1.0.tar.gz
| Download URL | njswalig-0.1.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
687ad683e0f4e9b83187fd8f6f0ccf92f8b5805051252a3ec9cfec2c7e7cddba
|
|
BLAKE2b-256 checksum How to use checksums |
265ce9e35e8915d5df8db9b5e7348a7c4d257b57e268f9a91e9c2b540512f2bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / njswalig-0.1.0-py3-none-any.whl
| Download URL | njswalig-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8414c1fdd05cc29fc0eaef5036a0076c1e71b1267d694c7976a206f8e0676136
|
|
BLAKE2b-256 checksum How to use checksums |
13d444e599bd255e8bf0b8fbaf1937cb765791305233ff9dc5b898b32ccfad5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for njswalig 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.