Alignment trimmer

Removes gappy columns, and ragged sequences, from an aligned FASTA. Nothing is uploaded.

Trimmed alignment

What the trimmer removes

Two filters, applied in this order:

  1. Sequences whose occupancy falls below the minimum are dropped whole. Doing this first matters: one ragged fragment in a set of ten makes every column it misses look 10 % gappy.
  2. Columns are then scored on the sequences that remain, and a column is removed when it has more gaps than the threshold allows, or when its identity is below the minimum.
column gaps % = gap characters in the column ÷ sequences × 100
column identity % = the most common residue in the column ÷ sequences × 100
sequence occupancy % = residues ÷ alignment columns × 100

Gaps count in the denominator of column identity, the same convention as the rest of this site, so a column that is half gaps can never be more than 50 % identical. Both- and . are read as gaps.

Which gap threshold should I use?

The default of 50 % removes only the columns that most of the alignment does not share, which is a safe starting point. Tighter settings are common for phylogenetics:

Max gapstrimAlEffect
0 %-gt 1Only columns present in every sequence survive
20 %-gt 0.8Strict, typical for tree building
50 %-gt 0.5Removes the clearly gappy columns
80 %-gt 0.2Removes only near-empty columns

Keep at least is the counterpart of trimAl's -cons: if the filters would leave less than that share of the original columns, the least gappy of the removed columns are put back until the share is reached. Set it when a threshold must not be allowed to destroy a short alignment.

Worked example

The example is an alignment of 5 coding sequences, 54 columns wide, in which one record is a fragment covering half the alignment and three columns carry an insertion found in only one sequence.

  • At the default 50 % gap threshold, 51 of 54 columns are kept. The three removed, columns 28–30, are 80 % gaps.
  • Set max gaps to 0 % and only 26 columns survive, the ones present in all five records.
  • Set minimum sequence occupancy to 60 % and the fragment, whose occupancy is 50 %, is dropped before the columns are scored.

After trimming

The trimmed alignment is plain FASTA, ready to copy or download, and can be converted to PHYLIP, NEXUS or Clustal with thealignment format converter. To check how much the trimming changed the sequences, run the trimmed file through theidentity and similarity calculator, which reports every pair. To remove gap characters altogether rather than columns, use thegap cleaner, and to join several trimmed alignments into one supermatrix, use merge alignments.

Frequently asked questions

What does trimming a multiple sequence alignment do?

It removes the columns that carry little usable signal, almost always the gappy ones created by a few long insertions or by ragged sequence ends. Every sequence loses the same columns, so the alignment stays an alignment; only its width shrinks. Phylogenetic and selection analyses often improve when those columns go, because a column that is mostly gaps contributes noise to every pair.

How does the gap threshold relate to trimAl?

trimAl -gt takes the smallest fraction of sequences that must have a residue in a column, so -gt 0.8 keeps columns that are at most 20 percent gaps. This page asks for the same number the other way round, as the largest share of gaps a column may have, because that is how the question is usually phrased. Max gaps 20 percent is trimAl -gt 0.8.

Should I trim before building a tree?

It depends on the alignment. Trimming clearly helps when a few sequences are partial or carry long private insertions, which is common in a set pulled from a database. On a well-aligned, complete set, aggressive trimming can remove more signal than noise. Compare trees from the trimmed and untrimmed alignment before deciding, and report the threshold you used.

What does minimum sequence occupancy do?

It drops whole sequences before any column is looked at. Occupancy is the share of alignment columns in which a sequence has a residue rather than a gap, so a fragment that covers a third of the alignment has an occupancy of 33 percent. Removing such fragments first is usually what makes the column statistics meaningful, since one ragged sequence can make many columns look gappy.

Do the sequences have to be the same length?

Yes. An alignment is a rectangle: every record must have the same number of columns once gaps are counted. If the lengths differ, the file is not an alignment, or lines were lost in copying, and the tool says which records are the odd ones out instead of guessing.