Tutorial 2: Evaluating the accuracy of a multiple sequence alignment

Objectives

Align the same protein sequences with three MAFFT strategies and compare each result with a BAliBASE reference using sum-of-pairs and column scores.

Prerequisites and working directory

Install PhyKIT. Install MAFFT to generate the query alignments. Download the sample archive into an empty working directory. Unpack it and run the remaining commands inside the extracted directory.

tar -xzf msa_accuracy.tar.gz
cd msa_accuracy

Workflow

Evaluating the accuracy of multiple sequence alignments is an appropriate way to benchmark multiple sequence alignment strategies. Two popular methods to assess multiple sequence alignment accuracy are sum-of-pairs score and column score, which were introduced by Thompson et al., Nucleic Acids Research (1999), doi: 10.1093/nar/27.13.2682. Sum-of-pairs is calculated by summing the correctly aligned residue pairs over all pairs of sequences. Column score is calculated by summing the correctly aligned columns over all columns in an alignment. Both metrics range from 0 to 1 and higher values indicate more accurate alignments. Correctly aligned pairs or columns require knowing some ground truth of what the correct alignment is. Thus, a reference alignment that is perfectly (or near-perfectly) aligned is required. A reference alignment can be generated using simulations or be obtained from publicly available databases such as BAliBASE 4 (http://www.lbgi.fr/balibase/). For this tutorial we will use a reference alignment from BAliBASE.

Step 0: Generate query alignments

In the msa_accuracy directory, there are two fasta files: BBA0001_query.faa, an unaligned set of sequences and BBA0001_reference.faa, the reference alignment. We will align BBA0001_query.faa using three different strategies implemented in MAFFT (https://mafft.cbrc.jp/alignment/software/), and evaluate the accuracy of each strategy.

To do so, please ensure MAFFT is installed and then execute the following commands:

# first alignment
mafft --localpair BBA0001_query.faa > BBA0001_query.localpair.faa

# second alignment
mafft --genafpair BBA0001_query.faa > BBA0001_query.genafpair.faa

# third alignment
mafft --globalpair BBA0001_query.faa > BBA0001_query.globalpair.faa

To gain some initial insight as to whether the alignments differ, we can look at the length of each alignment using the aln_len function

for alignment in BBA0001_query.*pair.faa; do
    phykit aln_len "$alignment"
done
1560
1464
1497

However, alignment length is not a measurement of accuracy. Thus, we will score each alignment using the sum_of_pairs_score and column_score functions.


Step 1: Score each alignment

For both functions, the first argument is the query alignment and the -r/--reference argument specifies the reference alignment. We will programmatically score each alignment using the same for loop that was used to calculate alignment length.

printf "alignment\tsop\tcs\n"
for alignment in BBA0001_query.*pair.faa; do
    sop=$(phykit sum_of_pairs_score "$alignment" -r BBA0001_reference.faa)
    cs=$(phykit column_score "$alignment" -r BBA0001_reference.faa)
    printf "%s\t%s\t%s\n" "$alignment" "$sop" "$cs"
done
alignment    sop     cs
BBA0001_query.genafpair.faa  0.2119  0.1237
BBA0001_query.globalpair.faa 0.2362  0.1441
BBA0001_query.localpair.faa  0.2314  0.1376

With MAFFT 7.526, --globalpair produces the highest score by both measures on this dataset. The scores are reference-relative. Column score requires a whole column to agree with the reference, while sum-of-pairs credits individual residue pairs. MAFFT version or settings can change the alignments and their scores.


Expected artifacts

MAFFT writes three BBA0001_query.*pair.faa files. The final table reports one sum-of-pairs score and one column score for each query alignment.

Troubleshooting

  • Run phykit <command> --help to compare an invocation with the live interface.

  • Confirm that downloaded files are in the current working directory and retain the filenames shown in the tutorial.

  • For parsing errors, compare taxon names exactly across alignments, trees, and trait tables, including capitalization and underscores.

  • See Troubleshooting for installation, format, and error-reporting guidance.