Global Sequence Alignment Calculator
Enter two DNA, RNA, or protein sequences and choose your scoring system to compute a full Needleman-Wunsch global alignment.
What is the Needleman-Wunsch algorithm?
The Needleman-Wunsch algorithm is a classic dynamic programming method for global sequence alignment. It compares two entire sequences from start to end and finds the highest-scoring alignment based on your scoring rules: match reward, mismatch penalty, and gap penalty.
It is widely used in bioinformatics for comparing DNA, RNA, and protein sequences. Unlike local alignment methods, global alignment aims to align both full sequences, which is ideal when the sequences are expected to be similar overall.
How this calculator works
1) Matrix initialization
The calculator builds a scoring matrix with one extra row and column for leading gaps. The first row and column are filled using cumulative gap penalties.
2) Matrix filling (dynamic programming)
For each cell, it computes three candidate scores:
- Diagonal move: match or mismatch from the previous diagonal cell
- Up move: introduce a gap in sequence 2
- Left move: introduce a gap in sequence 1
The highest of these three values becomes the current cell score.
3) Traceback
Starting at the bottom-right cell, the algorithm traces back to the top-left cell to reconstruct an optimal alignment. This calculator also highlights the traceback path in the matrix when sequence lengths are manageable.
How to use this tool
- Paste or type your first sequence in Sequence 1.
- Paste or type your second sequence in Sequence 2.
- Set your scoring system (match, mismatch, and gap values).
- Click Calculate Alignment to view score, aligned strings, and alignment statistics.
Interpreting the output
After calculation, you will see:
- Final Alignment Score — the optimal global alignment score under your scoring system.
- Aligned Sequence Strings — including inserted gap characters (
-). - Identity % — percentage of exact matches in aligned positions.
- Match/Mismatch/Gap counts — useful for understanding alignment quality.
Tips for choosing scoring parameters
DNA/RNA comparisons
A common starter setup is match = +1, mismatch = -1, gap = -1 or -2. If you want to discourage gaps, use a more negative gap penalty.
Protein comparisons
For proteins, full substitution matrices (like BLOSUM62) are typically preferred over a single mismatch penalty. This calculator uses a simplified scoring model, which is still useful for learning and quick checks.
Complexity and practical limits
Needleman-Wunsch runs in O(mn) time and memory, where m and n are sequence lengths. Long sequences can become computationally expensive. This page is optimized for educational and moderate-size inputs.
Frequently asked questions
Does this perform local alignment?
No. This implementation performs global alignment only. For local alignment, you would use the Smith-Waterman algorithm.
Why do I see multiple possible optimal alignments in theory?
Ties can occur in dynamic programming. This calculator uses a deterministic traceback preference so results stay consistent.
What symbols are accepted?
Letters A-Z and * are accepted, and whitespace is ignored automatically.