Codon-Aware DNA Alignment in MEGA: Why It Matters for Protein-Coding Genes

When we align a protein-coding gene, should we treat it like any other nucleotide sequence?

Not necessarily.

Protein-coding DNA has an important biological structure: nucleotides are organized into three-base codons, and each codon corresponds to an amino acid or a translation signal. A ordinary nucleotide alignment compares individual bases without explicitly accounting for the coding reading frame.

In contrast, a codon-aware alignment takes the protein-coding structure of the sequence into account.

In the accompanying video tutorial on Janecka Genomics, I use nuclear RAG1 sequences to compare an ordinary nucleotide alignment with a codon-aware nucleotide alignment in MEGA using the MUSCLE aligner. At the end, I also compare the maximum-likelihood trees generated from the two alignments. As I walk through the process in MEGA, I provide practical tips, point out potential problems to watch for, and discuss other considerations when working with protein-coding sequences.

The results illustrate an important point: codon-aware alignment does not necessarily produce a dramatically different tree. Its real advantage is that it preserves biologically meaningful structure in protein-coding sequences and prepares the alignment for downstream analyses that depend on the reading frame and homology across codon positions.

What Does “Codon-Aware” Alignment Mean?

In a normal nucleotide alignment, the program compares individual nucleotides:

A T G G C T A A A ...

The alignment algorithm does not inherently know that positions 1–3 represent one codon, positions 4–6 another, and so forth.

For a protein-coding sequence, however, each group of three have biological meaning. For example:

ATG | GCT | AAA

might translate to:

Met | Ala | Lys

A codon-aware approach uses the translated protein sequence to help maintain this structure during alignment. Insertions and deletions can therefore be positioned in ways that better preserve codon and amino acid homology.

This becomes particularly important when sequences are divergent or contain many insertions and deletions.

For a highly conserved, readily alignable gene such as RAG1, an ordinary nucleotide alignment may already produce a very similar result. Codon-aware alignment is still preferable because it explicitly preserves the biological structure of the coding sequence.

Start With Clean Sequence Names

Before aligning sequences, I recommend shortening long database identifiers, such as those in GenBank's fasta files.

GenBank sequence descriptions can become cumbersome when they are carried into alignments and phylogenetic trees. Long labels can compress the displayed branches and make trees unnecessarily difficult to interpret.

For this RAG1 dataset, I use simple identifiers such as:

lion_RAG1
tiger_RAG1
Sunda_pangolin_RAG1

These names are short, unique, and contain underscores rather than spaces.

I also keep a separate table connecting each shortened identifier with its scientific name, gene symbol, full gene or protein name, and GenBank accession number. This keeps the analysis readable without sacrificing traceability.

It is also important to use these identifiers consistently. If sequence names in an alignment and a saved tree do not match, programs such as MEGA can generate errors during downstream analyses that require both files.

Verify the Genetic Code

Before translating a coding sequence, make sure you are using the appropriate genetic code. The genetic code is nearly universal, but not completely universal. RAG1 is a nuclear vertebrate gene, so the appropriate choice in MEGA is theStandard’ genetic code.

A vertebrate mitochondrial gene would instead require the ‘Vertebrate Mitochondrial’ genetic code. Other organisms and organelles may require still other genetic codes.

The key is to choose the genetic code based on both the organism and where the gene is encoded. A sequence should be assigned the vertebrate mitochondrial code only if it came from a vertebrate’s mitochondrion.

Check the Reading Frame

Your sequences also need to be in the correct reading frame.

For the codon-alignment workflow demonstrated here, I prepare each unaligned coding sequence so that its first nucleotide represents the first position of a complete codon.

Importantly, this does not necessarily mean that the sequence must begin at the start of the gene or with an ATG start codon. A partial sequence may begin somewhere in the middle of a coding region. What matters is knowing where that sequence begins relative to the codon structure.

If necessary, the frame can be confirmed using the GenBank CDS annotation, translation using an online tool such as Expasy, or by comparing it directly against a trusted RefSeq reference protein sequence with Blastx. 

If you make any edits to the sequence identifiers or the sequences themselves, make those in a copy of the original fasta file. Always retain the original sequence data and document any trimming or other modifications.

Don't Ignore Unexpected Stop Codons

One of the most useful quality-control steps when working with coding sequences is simply translating them. In MEGA you can toggle between nucleotides and the amino acid translation.

When you align the sequences by codon, if MEGA pauses and reports internal stop codons, don't automatically click Ignore and continue.

Stop and investigate. Scan through the translated sequence and look for where the stop codons occur; in MEGA, they are represented by an asterisk (*). You can locate them quickly using the Search for Motif function.

An expected terminal stop at the end of a complete coding sequence is fine. Unexpected internal stop codons, especially multiple ones within the same sequence, should raise a red flag.

Possible causes include:

  • an incorrect reading frame

  • the wrong genetic code

  • a reverse-complemented sequence

  • a one- or two-base frameshift insertion or deletion

  • sequencing or base-calling errors in the sequence you are using (yes, even sequences from GenBank!)

  • assembly artifacts

  • incorrect CDS annotation

  • a genuine nonsense mutation

  • a pseudogene

Database sequences are extraordinarily useful, but they are not error-free.

If one sequence contains numerous internal stop codons while the others do not, first check simple explanations such as sequence orientation, genetic code, reading frame, and frameshifting indels. If you identify an error, correct it if possible or replace the problematic sequence with a reliable one.

At this point, however, you need to use your best judgment. Some unexpected stop codons may represent legitimate biological variation, including nonsense mutations or pseudogenes. These cases require closer examination to interpret correctly, and the explanation may not always be straightforward.

Once you have investigated the sequence and corrected any obvious errors, you can restart the alignment and select Ignore if MEGA again warns you about stop codons. However, be aware that clicking Ignore does not correct the underlying issue, even if you decide to proceed with the alignment. A sequence containing an internal stop may still fall near its close homologs in a phylogenetic tree because the vast majority of the sequence remains informative. However, depending on the cause of the internal stop, the sequence may or may not be appropriate to retain for downstream analyses such as fitting codon models, making protein comparisons, or performing tests of selection.

Ordinary vs. Codon-Aware Alignment

In the tutorial, I generate two alignments from the same RAG1 dataset.

The first is an ordinary nucleotide MUSCLE alignment. Nucleotides are aligned without explicitly considering the reading frame.

The second is a MUSCLE codon alignment in MEGA. In this workflow, the protein-coding structure is used during alignment and the resulting alignment is represented as nucleotides.

Both alignments retain synonymous and nonsynonymous nucleotide variation.

The important distinction is how positional homology is established during alignment. In the codon-aware alignment, gaps and homologous positions are established in a way that attempts to preserve codon and amino-acid homology.

Why Does This Matter Downstream?

Codon-aware alignment has another major advantage: it prepares the dataset for analyses that explicitly depend on the reading frame.

These can include:

  • comparing synonymous and nonsynonymous substitutions

  • estimating dN/dS

  • testing for selection among sites or evolutionary branches

  • investigating amino-acid changes and potential functional effects

  • applying codon substitution models

  • partitioning nucleotide models by codon position

  • predicting functional changes

For these reasons, I would not simply describe codon-aware alignment as producing a universally “better” alignment.

A more precise description is that it preserves the reading frame and enables biologically meaningful codon-based and codon-partitioned analyses and interpretation.

Does Codon-Aware Alignment Change the Phylogenetic Tree?

Sometimes. But not necessarily.

In this RAG1 example, the ordinary nucleotide alignment and codon-aware nucleotide alignment produced the same maximum-likelihood tree topology. Bootstrap support for a few nodes was slightly higher in the codon-aware alignment tree, but that doesn’t mean that the ordinary alignment is as good as the codon aware one for RAG1. In fact, it demonstrates a more subtle but very important principle.

RAG1 is relatively conserved, and the sequences in this dataset are readily alignable. The ordinary nucleotide alignment therefore did not introduce enough alignment error to change the inferred topology. With more divergent proteins, difficult-to-align regions, or homologous sequences containing more insertions and deletions, maintaining the reading frame may become considerably more important.

For downstream analyses that depend on the reading frame and correct homology across codon positions, a codon-aware alignment becomes critical. Analyses such as dN/dS estimation, codon models, tests of selection, or comparisons of synonymous and nonsynonymous substitutions can produce misleading or biologically meaningless results if the underlying alignment does not correctly preserve codon homology.

The Take-Home Message

Protein-coding sequences contain biological structure that should be considered when we align them.

Before performing a codon-aware alignment:

  1. Use short, consistent sequence identifiers.

  2. Verify the appropriate genetic code.

  3. Confirm sequence orientation and reading frame.

  4. Begin each sequence at the first position of a complete codon for the workflow used here.

  5. Translate the sequences and investigate unexpected internal stop codons.

  6. Keep the original sequence data and document any changes.

Codon-aware alignment does not guarantee a different phylogenetic tree or higher bootstrap support. For conserved genes such as RAG1, ordinary and codon-aware alignments may produce essentially the same phylogenetic result.

The reason for the advantage is more fundamental: codon-aware alignment maintains the biological structure of protein-coding DNA, reduces the risk of frame-disrupting homology errors, and prepares the data for downstream analyses that explicitly use codon structure.

Watch the Tutorial

In the accompanying Janecka Genomics video tutorial, I walk through this process in MEGA using a real RAG1 dataset, including reading-frame check Janecka Genomics s, genetic-code selection, stop-codon troubleshooting, ordinary and codon-aware MUSCLE alignments, and comparison of the resulting maximum-likelihood trees.

Tutorial resources: The sequence files and other materials used in the tutorial are available through the Janecka Genomics GitHub repository.

By Jan E. Janecka, PhD - August 12, 2026

Back to blog