Codon-aware pairwise alignment
Aligns two coding sequences as protein, then projects the alignment back onto their codons.
Aligns two coding sequences as protein, then projects the alignment back onto their codons.
Coding DNA carries two signals at once: the bases and the protein they spell. A codon-aware alignment keeps both. Each sequence is split into codons and translated, the two proteins are aligned with Needleman–Wunsch under BLOSUM62 and affine gap penalties, and the resulting protein alignment is written back onto the original codons. Every gap is therefore a whole number of codons, three bases wide, and the reading frame survives the alignment.
Both sequences must begin at the first base of a codon. Trailing bases that cannot make up a full codon are left out and reported.
The alignment length is every column of the codon alignment, gap columns included, which is three times the number of codon columns. This is the denominator used by BLAST and by theidentity and similarity calculator on this site, so the numbers agree. Because a gapped codon contributes three non-identical nucleotide columns and one non-identical amino acid column, gaps lower both percentages.
Codon columns where both sequences have a codon are sorted into three groups: the codons areidentical; the codons differ but translate to the same amino acid, a synonymous difference; or the amino acid changes, a non-synonymous difference. The counts are per codon, so a codon with two substitutions is counted once. A large excess of synonymous differences is the usual signature of purifying selection, but turning that impression into a dN/dS ratio also needs the number of synonymous and non-synonymous sites in each codon, which this tool does not estimate.
The example loads two variants of a fluorescent protein coding sequence, 87 and 84 bases, that is 29 and 28 codons. The alignment has 29 codon columns, 87 nucleotide columns, with one codon of sequence 1 aligned against a gap.
Protein identity is much the higher of the two because most differences sit in third positions. Aligning the same pair as plain DNA would not show that split at all.
Gap open is paid once per gap and gap extend for every further codon in it, so one gap of four codons costs 10 + 3 × 1 = 13 at the defaults, far less than four separate codon gaps at 40. The penalties are in protein units: they are paid per codon, not per base. The defaults of 10 and 1 with BLOSUM62 are what BLAST uses for proteins and match thepairwise protein alignment tool.
It is an alignment of coding DNA in which every gap is a whole number of codons, so the reading frame is never broken. The two sequences are translated, the proteins are aligned, and the protein alignment is projected back onto the original codons. A plain nucleotide aligner has no reason to respect the frame and will happily open a one-base gap in the middle of a codon.
Because selection acts on the protein. Two coding sequences that have diverged carry many silent third-position changes, which a nucleotide aligner scores as mismatches and may try to fix with frame-breaking gaps. Aligning the translations puts homologous codons in the same column even when their third bases differ, which is why codon-aware alignment is the standard preparation for dN/dS analysis.
Per codon, not per site. A codon pair in which both codons are present and differ is synonymous when the two codons still translate to the same amino acid, and non-synonymous when the amino acid changes. A codon with two substitutions counts once. This is a description of the alignment, not a dN/dS ratio, which needs the number of synonymous and non-synonymous sites per codon as well.
The trailing one or two bases cannot form a codon, so they are left out of the alignment and a note says how many were dropped. If that happens unexpectedly, the sequence probably does not start at the first base of a codon; trim it to the start of the reading frame first.
The standard code. Stop codons are translated as an asterisk and aligned like any other symbol, scoring +1 against another stop and −4 against an amino acid, the values in the NCBI BLOSUM62 file. A codon holding an ambiguity code such as N is translated as X and scores −1 against everything.