Pairwise sequence alignment

Compare two sequences directly, preserve the aligned strings and scoring settings, and separate correspondence from similarity scores.

What is pairwise sequence alignment?

Pairwise sequence alignment is the process of arranging exactly two biological sequences so that positions proposed to correspond appear in the same columns. Identical residues or nucleotides appear as matches, different characters appear as substitutions, and inserted gaps represent possible insertion or deletion events. The resulting alignment is a hypothesis about positional correspondence between the sequences, not a direct measurement of function or evolutionary history.

A pairwise alignment algorithm uses a scoring system to choose among many possible arrangements. Global alignment compares the sequences across their complete lengths, while local alignment finds the strongest matching region within them. Needleman–Wunsch is the classic global alignment algorithm, and Smith–Waterman is the classic local alignment algorithm. Both use dynamic programming to find an optimal result under the specified scoring model.

The alignment is only as meaningful as the question, inputs and settings behind it. Two unrelated sequences can always be arranged somehow, and a numerically optimal alignment is not necessarily a biologically valid one.

When to use pairwise sequence alignment

Use a pairwise method when the two records and the region of interest are already defined:

  • A protein variant needs comparison with its reference.
  • Two alleles or constructs need substitution and gap review.
  • A shared domain needs a local rather than full-length comparison.
  • Residue or base positions must be mapped between two records.

Strengths and limitations

An explicit two-sequence alignment makes matches, substitutions, gaps and their positions inspectable. Global and local scopes let the calculation match the biological question, while a defined scoring model makes repeated comparisons reproducible.

An optimal score is conditional on matrix, gap penalties, boundaries and orientation. Similarity can arise by chance or from a short low-complexity segment, and a score-only calculation cannot show where gaps were placed. The alignment is a correspondence hypothesis, not proof of function or ancestry.

Which pairwise alignment should you use?

Choose the alignment scope before choosing a particular sequence alignment tool.

Your questionRecommended approachBest suited forMain limitation
Should these two complete sequences correspond from beginning to end?Global sequence alignmentFull-length homologs, alleles, isoforms with similar architecture, and engineered constructsUnrelated terminal regions or extra domains can distort the result
What is the strongest shared region between these sequences?Local sequence alignmentConserved domains, motifs, fragments, and partial homologyIgnores weaker or unrelated regions outside the best local match
Does a fragment overlap one end of a longer sequence?Overlap or end-gap-aware alignmentAmplicons, reads, trimmed constructs, and partial sequencesEnd-gap treatment differs among tools and must be reported
Which database sequences resemble my query?BLAST or another similarity searchDiscovering possible homologs in a databaseA heuristic search is not the same calculation as an exact pairwise alignment
How do three or more homologous sequences correspond?Multiple sequence alignmentProtein families, conserved motifs, profiles, and phylogenetic preparationThe problem and algorithm differ from aligning only two sequences
Do weakly similar proteins share the same fold?Structure-based sequence alignmentProteins whose structural correspondence is clearer than their sequence similarityRequires compatible experimental or predicted structures

A global alignment is usually appropriate when both sequences represent comparable full-length molecules. A local alignment is safer when only one domain, motif, or subsequence is expected to correspond. Using global alignment merely because the input contains two sequences can force unrelated flanks into an apparently orderly but misleading result.

How to align two sequences online

A reliable online sequence alignment should begin with a scientific choice, not simply with pasting two strings into a form.

  1. Confirm the molecule type. Use two protein or two nucleotide records, with comparable boundaries and the correct DNA orientation.
  2. Prepare exactly two FASTA records. Preserve identifiers and remove copied numbering or unsupported symbols.
  3. Choose the scope. The featured template uses a MAFFT alignment and a separate StringZilla Needleman–Wunsch global score. For a strictly local question, use the local-alignment workflow instead.
  4. Set the score model. Record the substitution or match values and gap penalties before comparing numeric scores.
  5. Run both branches. Inspect MAFFT's aligned strings and gap placement. StringZilla returns a score matrix without traceback or percent identity.
  6. Review biological positions. Check coverage, substitutions, termini and important residues against the original records.
  7. Keep native outputs. Save the FASTA, MAFFT alignment, StringZilla matrix and settings as separate files.

A two-record FASTA input looks like this:

FASTA
>reference_protein
MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQ
>variant_protein
MKTAYIAKQRTISFVKSHFSRQLDERLGLIEVQ

FASTA headers should be unique. The sequence lines should contain only symbols supported for the selected molecule type. Ambiguous amino acids or nucleotides may be accepted by some tools, but the tool-specific treatment of those symbols should remain visible in the result.

Pairwise protein sequence alignment

Pairwise protein sequence alignment compares two amino-acid sequences. It is useful when you need to align two proteins, compare an engineered protein with its parent, inspect amino-acid substitutions, or map corresponding residues between known or suspected homologs.

Unlike a simple character match, a protein alignment can give different scores to different substitutions. Replacing leucine with isoleucine may be treated more favorably than replacing leucine with aspartate because the first pair has more similar physicochemical and evolutionary behavior. Protein alignment tools represent these preferences through substitution matrices such as BLOSUM or PAM. BLOSUM matrices were derived from conserved blocks in related protein families.

There is no universally correct matrix for every protein pair. Matrix choice, gap penalties, sequence length, domain architecture, and expected evolutionary distance all affect the result. Use the same settings when comparing scores between several protein pairs, and preserve the matrix name with every reported alignment.

Pairwise protein alignment helps locate substitutions and indels in variants, verify engineered tags or linkers against a parent construct, and map residues between orthologs or paralogs. For proteins with different architectures, compare the shared domains instead of allowing unrelated regions to determine an end-to-end score.

If two proteins have different domain architectures, an end-to-end alignment may be the wrong model. Align the shared domain locally or compare the relevant subsequences directly. For protein families and alignments of more than two records, see sequence alignment.

Pairwise DNA sequence alignment

Pairwise DNA sequence alignment arranges two nucleotide sequences to reveal exact base matches, substitutions, insertions, deletions, and unaligned ends. A DNA alignment tool is appropriate for comparing two alleles, amplicons, plasmid constructs, coding sequences, transcripts, or homologous genomic regions.

Before aligning two DNA sequences, check their orientation. A sequence and the reverse complement of its homolog can appear unrelated if both are submitted in their original direction. Some alignment software can test orientation automatically, while other tools require you to reverse-complement one sequence first. MAFFT provides direction-adjustment modes for nucleotide alignments, but orientation handling depends on the selected implementation and settings.

Confirm strand orientation and record how ambiguous bases such as N, R, or Y are handled. Compare full-length constructs globally and fragments locally when their boundaries differ. Genomic DNA and mature messenger RNA require spliced alignment across introns; whole assemblies and rearrangements call for whole-genome alignment. For coding sequences, a nucleotide alignment locates base changes, while a translated protein comparison addresses amino-acid conservation.

For a workflow configured specifically for nucleotide input, open the pairwise DNA alignment workflow above or see sequence alignment for DNA families.

How is a sequence alignment score calculated?

A sequence alignment score is the total value assigned to one proposed alignment under a defined scoring system. It normally combines scores for aligned character pairs with penalties or negative scores for gaps.

Conceptually:

Text
alignment score =
  sum of match or substitution scores
  + sum of gap-opening scores
  + sum of gap-extension scores

With a common affine gap model, the score or penalty for a gap of length k depends on one gap-opening term plus k - 1 gap-extension terms:

Text
gap score(k) = gap open + (k - 1) × gap extension

The exact sign convention differs among tools: one program may display positive penalties that are subtracted, while another may report negative gap scores that are added. EMBOSS Needle, for example, reports the comparison matrix, gap-opening penalty, gap-extension penalty, aligned length, identity, similarity, gaps, and final score together.

Score componentWhat it representsEffect of changing it
Match scoreReward for aligning identical residues or basesA larger reward favors alignments containing more exact matches
Substitution or mismatch scoreValue assigned to non-identical aligned charactersProtein matrices distinguish conservative from unfavorable substitutions
Gap-open scoreCost of starting an insertion or deletionA stronger penalty tends to produce fewer separate gaps
Gap-extension scoreAdditional cost for lengthening an existing gapA weaker extension penalty favors fewer, longer gaps over many short gaps
Terminal-gap treatmentWhether unaligned sequence ends are penalizedCan strongly affect fragments, tags, incomplete sequences, and unequal lengths

A raw sequence alignment score has meaning only with its algorithm, substitution matrix or nucleotide scoring scheme, gap settings, sequence lengths, alignment scope, and treatment of terminal gaps and ambiguous symbols. Scores from different settings or from protein and nucleotide alignments cannot be compared directly.

A longer pair of similar sequences will often produce a larger raw score than a shorter pair, even when the shorter pair has a higher percentage identity. BLAST bit scores and E-values apply statistical normalization to local search results, but not every pairwise alignment program reports those statistics.

How to interpret identity, similarity, coverage, and gaps

A pairwise alignment should be interpreted as a collection of related measurements rather than one definitive percentage.

MetricMeaningCommon interpretation error
Aligned lengthNumber of columns in the reported alignmentAssuming it equals both original sequence lengths
Exact matchesColumns containing the same residue or nucleotideIgnoring whether the match covers a meaningful part of each sequence
Percent identityExact matches divided by a stated denominatorReporting the percentage without saying which denominator was used
Protein similarityExact or matrix-favored amino-acid pairsTreating it as a molecule-independent quantity
Query coverageFraction of the first sequence included in the aligned regionConfusing high local identity with full-length correspondence
Target coverageFraction of the second sequence included in the aligned regionReporting only query coverage when the second sequence is much longer
GapsAlignment columns containing an insertion or deletion characterAssuming every gap corresponds to one known historical mutation event
Raw scoreObjective optimized by the selected methodComparing scores from different settings or programs

Percent identity

Percent identity is usually calculated as:

Text
percent identity = exact matches / stated denominator × 100

The denominator may be the complete alignment length, the number of non-gap aligned columns, the query length, the target length, or another explicitly defined value. EMBOSS Needle reports identity over the aligned region using its reported alignment length, including gap-containing columns in that length.

For reproducibility, report the numerator and denominator as well as the percentage, for example, 31/33 identical aligned positions (93.9%).

Protein similarity

Protein similarity includes amino-acid pairs that receive a favorable value in the selected substitution matrix. It is therefore matrix-dependent. Two protein sequences can have the same percent identity but different similarity scores because their non-identical residues differ in how conservatively they substitute.

For DNA, “similarity” is sometimes used loosely as a synonym for identity. State the exact score or matrix definition instead of assuming that the term has one universal meaning.

Coverage

Identity without coverage can be misleading. Two 500-residue proteins may share a 40-residue domain with 90% local identity while the remaining 460 residues do not align. That result answers a different question from 90% identity across both complete proteins.

Report coverage separately for each sequence when their lengths differ.

Homology

Homology means descent from a common ancestor. It is not a percentage. Sequences may be homologous or not homologous; they are not “80% homologous.” Sequence identity, similarity, alignment length, statistical significance, structural correspondence, and biological context provide evidence used to infer homology.

Worked example: compare two protein sequences

Consider these two aligned amino-acid sequences:

Text
reference  MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQ
variant    MKTAYIAKQRTISFVKSHFSRQLDERLGLIEVQ
           ||||||||||.||||||||||||.|||||||||

Across 33 aligned positions, 31 are exact matches and two are substitutions, with no gaps. Identity is 31 / 33 × 100, or 93.9%.

The first substitution is Q → T, while the second is E → D. A protein substitution matrix may score E → D more favorably because both residues are acidic, so matrix-based similarity may be higher than exact identity.

The alignment score still cannot be determined from the displayed strings alone. It also requires the substitution matrix or match/mismatch values and the selected gap model.

Even a 93.9% identity result does not establish that the proteins have identical activity. A substitution at an active site, binding interface, cleavage site, localization signal, or structurally constrained position may matter more than many conserved residues elsewhere. Always inspect biologically important positions directly.

Pairwise alignment versus BLAST and multiple sequence alignment

Several tools can display two sequences in aligned rows, but they do not necessarily perform the same calculation.

MethodTypical resultBest useImportant distinction
Needleman–WunschOptimal global alignment and score under one scoring modelTwo complete sequences expected to correspond end to endEvaluates the full lengths of both sequences
Smith–WatermanOptimal local alignment and score under one scoring modelBest shared domain, motif, or subsequenceCan leave unrelated flanks outside the alignment
BLAST with query and subject sequencesOne or more heuristic local alignments with statistical measuresFast local comparison and significance assessmentBLAST is heuristic and is not guaranteed to return the exact dynamic-programming optimum
MAFFT with two recordsTwo aligned sequences produced by the selected MAFFT strategyConvenient protein or nucleotide alignment with configurable modesMAFFT is a multiple-sequence alignment program; preserve the actual strategy and settings
Clustal Omega with two recordsA two-row alignment produced by a progressive MSA systemCompatibility with Clustal workflows and downstream formatsIt should not automatically be described as an exact Needleman–Wunsch calculation
Multiple sequence alignmentAlignment of three or more homologous sequencesFamilies, conserved columns, profiles, and phylogeneticsAdditional sequences change the optimization problem and may alter column placement

Can Clustal Omega align two sequences?

Yes. Clustal Omega can accept two sequences and return an aligned output, so “Clustal pairwise alignment” is a reasonable description of the resulting two-row file. However, Clustal Omega is designed as a multiple sequence alignment program. Its progressive and profile-based methods should not be confused with a dedicated exact pairwise dynamic-programming implementation.

Use Clustal Omega when you need its formats or expect to expand the analysis to more sequences. Use a dedicated global or local pairwise method when the exact score and algorithmic definition are central to the question.

No. Pairwise alignment directly compares two supplied sequences. A sequence-search tool compares a query with many database records and ranks possible matches. NCBI’s BLAST two-sequence mode allows a query and subject to be compared directly, but it still uses BLAST’s heuristic local-search behavior.

Common mistakes when comparing two sequences

Choosing global alignment for sequences that share only one region

A global method must account for both complete lengths. If one sequence contains an extra domain, long tag, signal peptide, or unrelated flank, the alignment may contain many gaps and weakly supported correspondences. Use local alignment or isolate the shared domain.

Using local identity as though it described both complete sequences

A short local alignment can have very high identity while covering only a small fraction of each input. Always report aligned length and coverage.

Comparing DNA sequences in opposite orientations

A reverse-complemented homolog can appear unrelated to the original strand. Confirm DNA orientation before interpreting a poor alignment.

Comparing the wrong sequence boundaries

Isoforms, precursor proteins, mature chains, transit peptides, tags, and incomplete records can produce terminal differences that are artifacts of sequence selection rather than biological divergence.

Treating every alignment score as comparable

A raw score from one matrix or gap model cannot be ranked directly against a score produced with another configuration. Preserve the complete scoring definition.

Reporting “percent homology”

Report percent identity or a clearly defined similarity metric. Homology is an evolutionary inference, not a continuous percentage.

Ignoring low-complexity or repetitive regions

Repeats may support several alignments with similar scores. The top-scoring path can look precise even when the positional correspondence is ambiguous.

Using generic pairwise alignment for a specialized problem

Genomic DNA versus messenger RNA requires spliced alignment. Complete genomes require genome-scale methods. Very weak protein similarity may require profile or structure-based comparison. Choose the method that represents the biological problem rather than forcing every comparison into the same two-sequence tool.

What should an online sequence alignment tool return?

Useful online sequence alignment software should make the result inspectable and reproducible. Retain the original identifiers and inputs, the gapped aligned strings, algorithm and version, alignment scope, scoring model, gap settings, raw score definition, exact identity count and denominator, aligned length, coverage of each sequence, gap distribution, warnings, and downloadable result files.

Do not accept an unlabeled “sequence match” percentage as a complete result. Without the alignment scope, denominator, score definition, and input coverage, the number may answer a different question from the one you intended to ask.

The featured ProteinIQ workflow below keeps two forms of evidence separate: MAFFT returns the aligned sequence strings, while StringZilla v5 independently calculates a Needleman–Wunsch global score. The score and alignment are related, but they are not interchangeable outputs.

How pairwise sequence alignment works

MAFFT returns aligned sequences while StringZilla independently returns a Needleman–Wunsch global score; the workflow keeps those outputs distinct.

  1. Define scope. Decide whether the full sequences or only a shared region should be compared.
  2. Prepare the pair. Verify molecule type, orientation, headers, boundaries, and ambiguous symbols.
  3. Set scoring. Record the substitution and gap settings rather than relying on an unlabeled score.
  4. Run comparison. Generate aligned strings and, when useful, an independent pairwise score.
  5. Interpret and export. Inspect identity, coverage, gaps, terminal effects, and biologically important positions.

Inputs and outputs

Check formats before running, then inspect and download the result from every workflow step.

Inputs

Alignment input

FASTAPDBmmCIF

Two protein, DNA, or RNA sequences in FASTA format.

Outputs

Alignment outputs

FASTACSVTSVPDBJSON

Aligned FASTA plus method-native score tables and downloadable settings.

Frequently asked questions

AI answers from our docs. No sign-in needed.

Run your first analysis today

Start with 200 free credits and no installs. Upgrade when your project needs more compute.