October 2026
alignment-distances - Compare alignments of the same sequences.
alignment-distances [OPTIONS] score REFERENCE SAMPLE...
alignment-distances [OPTIONS] AxA SAMPLE...
alignment-distances [OPTIONS] NxN REFERENCE SAMPLE
alignment-distances [OPTIONS] compare [REPORT-OPTIONS] SAMPLE1 SAMPLE2
alignment-distances [OPTIONS] median SAMPLE
alignment-distances [OPTIONS] distances [REPORT-OPTIONS] SAMPLE
Compare alternative alignments of the same sequences, summarize an alignment sample, or choose one representative alignment. Comparisons concern which residues are aligned together, rather than similarity between their nucleotide or amino-acid values.
A sample file contains FASTA alignments separated by empty lines. A
reference file contains exactly one alignment. Use - for
standard input. Sequence names must be unique and match across
alignments; each sequence must have the same ungapped length. Sequence
order may differ. BAli-Phy internal-node placeholders and empty columns
are removed before comparison.
Exactly one command is required. Filenames are positional arguments.
Shared options may appear before or after the command; reporting options
must follow compare or distances. Use
alignment-distances COMMAND --help for command-specific
help.
splits:splits2:nonrecall:inaccuracy.
(i,j) compares alignment i with alignment
j. Default measure: splits.
N is the number of sequences, not alignments. A header
lists sequence names in the order used for both rows and columns; rows
have no labels. Accepts pairwise, nonrecall,
or inaccuracy. Default measure: pairwise.
splits.
splits, splits2,
pairwise, nonrecall, or
inaccuracy. Default measure: splits.
splits.
A residue pair means two residues from different sequences
placed in the same column. Residues are identified by their positions in
their sequences. For a comparison D(A,B), let
H(A) and H(B) be the numbers of residue pairs
in the two alignments, and S the number shared by both.
recall = S/H(A) and
accuracy = S/H(B). Higher values mean greater agreement. In
score, these measure the fraction of reference pairs
recovered and the fraction of sampled pairs supported by the reference,
respectively.
1 - recall and 1 - accuracy. Lower values mean
greater agreement; zero means no missing or unsupported pairs,
respectively. These measures depend on argument order:
nonrecall(A,B) = inaccuracy(B,A).
A occupy k columns in B, that
column contributes k-1 to splits or
k*(k-1)/2 to splits2. Sum over columns in both
directions. Thus splits2 gives more weight to columns
broken into many pieces.
splits, splits2, and pairwise
are symmetric: exchanging alignments gives the same value. The four
fractional measures can be asymmetric. Only score accepts
multiple measures; median excludes recall and
accuracy because it minimizes distance.
For NxN, measures apply separately to each pair of
sequences. Its pairwise score is the fraction of residues
whose aligned partner differs, normalized by the sum of the two sequence
lengths. Values range from zero (agreement) to one (complete
disagreement).
A fraction with a zero denominator is undefined. score,
AxA, and NxN can report NaN;
median, compare, and distances
report an error if a required comparison is undefined.
distances treats its input as sample 1;
compare numbers its inputs 1 and 2. D11 and
D22 describe distances within samples 1 and 2, excluding
self-comparisons. Symmetric measures count each pair once; asymmetric
measures count both directions. D12 describes comparisons
from sample 1 to sample 2. Asymmetric measures also produce
D21, with the arguments reversed.
D1(1) describes the distribution of individual
alignments' mean distances to the others in sample 1; D2(2)
does the same for sample 2. D1(2) contains one mean per
alignment in sample 1, comparing it with all alignments in sample 2.
D2(1) reverses the sample roles. In every mean, the
individual alignment is the first argument of the distance function.
By default, each distribution is summarized by its median and central
95% interval. --mean reports its mean and standard
deviation; --minmax reports its range. The interval
describes variation in distances, not uncertainty in an estimated mean.
Report flags can be combined.
compare also prints comparisons such as
P(D12 > D11): the fraction of cross-distribution value
pairs for which the first value is larger, counting ties as one half.
These are descriptive comparisons, not significance-test p-values. For
recall and accuracy, larger means greater
agreement. A sample containing only one alignment has no within-sample
summary.
median writes FASTA to standard output. Its
standard-error diagnostics list up to five candidates by increasing mean
distance (E D), with ranks starting at zero, followed by
mean distances among the best candidates and among all retained
alignments. A one-alignment sample returns that alignment without
pairwise diagnostics.
--help--skip
N--max
N-1 retains all alignments after
skipping. Does not affect the reference.
--verbose--alphabet ALPHABET--distances MEASURESscore, separate multiple names with
colons, for example --distances=recall:accuracy. Defaults
are listed under COMMANDS.
These options follow compare or
distances.
--CI P--mean--median--minmaxMeasure recovery of reference residue pairs:
alignment-distances score reference.fasta sample.fastas --distances=recall:accuracy
Write an alignment-distance matrix:
alignment-distances AxA sample.fastas > distances.tsv
Locate disagreement by sequence pair:
alignment-distances NxN reference.fasta sample.fastas > sequence-distances.tsv
Select a representative alignment after discarding 100 sampled alignments:
alignment-distances median --skip=100 sample.fastas > representative.fasta
Compare two samples using a directional distance:
alignment-distances compare --mean --distances=nonrecall sample1.fastas sample2.fastas
Summarize an entire sample, without thinning:
alignment-distances distances --max=-1 --median --minmax sample.fastas
BAli-Phy online help: http://www.bali-phy.org/docs.php.
Please send bug reports to bali-phy-users@googlegroups.com.