Phylogenetics & Evolution

Lesson 3 of 13 · 11 min

Multiple Sequence Alignment and Why It Matters

Before you can build a tree you must line up your sequences so that each column holds sites descended from one ancestral position. That is what a multiple sequence alignment does, and it is the silent assumption underneath every tree you will ever infer. Get the columns wrong and every method downstream inherits the mistake.

Homology lives in columns

Distance methods, maximum likelihood, and Bayesian inference all read the alignment one column at a time and treat each column as a set of homologous characters. A substitution model estimates rates from the changes it sees within columns, so a column that mixes non-homologous residues invents substitutions that never happened. Positional homology across columns is the contract, and the aligner's only job is to honor it.

Run the aligners

bash
# Fast and size-adaptive: MAFFT picks a strategy for you
mafft --auto seqs.fasta > seqs.auto.fasta

# Accurate for divergent sequences: L-INS-i (local pairs + iterative refinement)
mafft --localpair --maxiterate 1000 seqs.fasta > seqs.linsi.fasta
# linsi seqs.fasta > seqs.linsi.fasta   # identical shortcut

# A second aligner to cross-check (MUSCLE v5 syntax)
muscle -align seqs.fasta -output seqs.muscle.fasta
nthread = 0
generating a scoring matrix for amino acid (dist=200) ... done
Gap Penalty = -1.53, +0.00, +0.00

Making a distance matrix ..
   26 / 26
done.

Constructing a UPGMA tree (efffree=0) ...
   20 / 26
done.

Progressive alignment 1/2...
STEP    25 / 25
done.

Making a distance matrix from msa..
   20 / 26
done.

Progressive alignment 2/2...
STEP    25 / 25
done.

Segment   1/  1    1- 402
STEP 002-024-1  identical.
Converged.

done.

Strategy:
 L-INS-i (probably most accurate, very slow)
 Iterative refinement method (<16) with LOCAL pairwise alignment information

The --auto flag inspects how many sequences you have and how long they are, then chooses a strategy: for a few hundred short sequences it usually lands on L-INS-i, but for thousands it drops to the fast progressive FFT-NS-2. When accuracy matters, call L-INS-i explicitly instead of leaving it to chance. Running MUSCLE on the same input gives you a second opinion, since columns both tools agree on are trustworthy and blocks where they disagree flag regions that are genuinely hard to align.

Tip: Match the strategy to the data. For divergent sequences with one alignable core flanked by unalignable ends, L-INS-i (--localpair --maxiterate 1000) is the safest default. For closely related, easy-to-align sequences or datasets in the thousands, --auto or FFT-NS-2 (mafft --retree 2) is far faster with little accuracy cost. Reach for E-INS-i (--genafpair --maxiterate 1000) when several conserved domains sit inside long unalignable stretches.

Never trust an alignment you have not looked at. Open the result in AliView or Jalview, scroll the full width, and hunt for tell-tale problems: ragged ends where only one or two sequences carry data, isolated residues stranded in a sea of gaps, and blocks that look like a random column of colors. These ambiguous regions carry little homology signal and a lot of noise, so trimming them before tree inference usually helps.

bash
# Eyeball the alignment first (AliView or Jalview)
aliview seqs.linsi.fasta

# Remove gap-heavy columns with an automatic gap threshold
trimal -in seqs.linsi.fasta -out seqs.gappyout.fasta -gappyout

# Let trimAl choose gappyout vs a stricter method, tuned for ML trees
trimal -in seqs.linsi.fasta -out seqs.automated1.fasta -automated1

# Optional: write an HTML report highlighting which columns were kept
trimal -in seqs.linsi.fasta -out seqs.automated1.fasta -automated1 -htmlout trim_report.html

Warning: Alignment error does not average out, it propagates. A handful of misaligned columns can pull two unrelated taxa together, inflate branch lengths, or hand a nonexistent clade high bootstrap support. Over-trimming is just as dangerous, because stripping too many columns throws away the very signal the tree needs. Aim for the smallest, cleanest set of confidently homologous columns.

Try it yourself: Grab a FASTA of 20 to 40 homologous protein sequences (for example a gene family from OrthoDB). Align it three ways: mafft --auto, mafft --localpair --maxiterate 1000, and muscle -align. Open all three in AliView side by side and find one block where they disagree. Then trim the L-INS-i alignment with both -gappyout and -automated1, note how many columns each removes, build a quick tree from the raw and the trimmed versions, and compare the two topologies.