Skip to content

How DiMA measures diversity

DiMA (sequence Diversity dynamics analyser for viruses) describes how variable a viral protein or gene is along its length (Tharanga et al. 2025). It continues a line of work that measured the diversity of dengue, HIV-1 and influenza A proteomes position by position (Khan et al. 2008; Hu et al. 2013; Abd Raman et al. 2020). This page introduces the quantities every result is built from; the following pages derive each measure in detail.

DiMA reads a multiple sequence alignment: N seq sequences of the same length L (the alignment columns), protein or nucleotide, in FASTA format. Column j of every sequence holds the residue that the aligner placed at that column, or a gap. How DiMA reads the file — case, gaps, ambiguity codes, white space, compression — is described in Reading alignments.

DiMA slides a window of k columns along the alignment, one column at a time. The window that starts at column p covers columns p , p + 1 , … , p + k − 1 , so there are

P = L − k + 1

positions, numbered from 1. In each sequence, the k characters inside the window form that sequence’s k-mer at position p .

The default k follows the alphabet: 9 for proteins, the length of the peptides presented by HLA class I molecules (Falk et al. 1991; Rammensee 1993; Tharanga et al. 2025), and 27 for nucleotides, the codons of a 9-mer. Any k from 1 to L can be chosen with -k.

A k-mer is valid when all its k characters are residues. A gap, a missing-data symbol, an ambiguity code, a stop or frameshift symbol (see the symbol tables) anywhere in the window makes the k-mer invalid, and that sequence does not contribute at that position.

The support N of a position is the number of sequences with a valid k-mer there. The distinct valid k-mers are the position’s variants; if variant i occurs c i times, then c 1 + c 2 + ⋯ + c D = N , where D is the number of distinct variants. Every other measure of a position is computed from these counts alone.

The support threshold and the low-support labels

Section titled “The support threshold and the low-support labels”

Estimates from few sequences are unreliable, so DiMA compares each position’s support with a support threshold T (-s). Its default is the paper’s, 100 (“default is 100 sequences, arbitrarily defined”), which the paper also uses for HIV-1 (Tharanga et al. 2025); the paper’s Fig. 2 shows 30, the default of DiMA v5.0.9:

LabelSupportMeaning
NS N = 0 no support: no sequence has a valid k-mer
LS 0 < N < T low support
ELS N = T support equal to the threshold
eligible (no label) N > T enough support

Only eligible positions receive the paper’s sample-size correction of the entropy, and only they enter the summary statistics (mean, lowest and highest entropy). LS and ELS positions are still reported, with their observed values; NS positions have no entropy at all, because there is nothing to measure — where the paper assigns them a pseudo-entropy of 0 (see why DiMA departs from it). The low_support_count of a run is the number of NS, LS and ELS positions, as in DiMA v5.0.9.

  • Shannon entropy of the variant distribution, corrected for sample size, and the observed (plug-in) value; the estimated sample coverage (Entropy and its correction).
  • Diversity motifs: each variant is classified as Index, Major, Minor or Unique, with its incidence; the incidence of all non-Index (total) variants and of the distinct non-Index variants (Diversity motifs and summaries).
  • Optionally, the count of every variant per value of chosen FASTA header fields such as host, country or year (Stratify by header metadata).
  • Across positions: historically conserved sequences, stretches whose most common k-mer is (almost) invariant (Historically conserved sequences).

A worked example: MERS-CoV spike position 25

Section titled “A worked example: MERS-CoV spike position 25”

The paper’s Fig. 1C dataset ships with DiMA as samples/mers_spike_aa.fasta: 191 MERS-CoV spike protein sequences, 1,353 columns, so P = 1,353 − 9 + 1 = 1,345 positions of 9-mers. Position 25 covers columns 25–33:

VariantCountIncidenceMotif
SVKSACIEV12975.88%Index
SFKSACIEV148.24%Major
SVKPACIEV95.29%Minor
SAKSACIEV63.53%Minor
SLKSACIEV42.35%Minor
SVKSACIAV42.35%Minor
SAKSVCIEV, SIKSACIEV, SVKSACIKV, SVKSVCIEV1 each0.59% eachUnique

The support is N = 170 : 21 of the 191 sequences have a gap or an ambiguity code somewhere in columns 25–33. With the default T = 100 the position is eligible. Its observed entropy is 1.4224 bits and its corrected entropy 1.4617 bits; 41 sequences (24.12%) carry a non-Index variant, and those 41 sequences carry 9 distinct variants (21.95%, the paper’s 22.0%). The following pages show how each of these numbers is obtained.

Every quantity above is computed exactly from the counts: DiMA uses no random numbers, so the same alignment and options always give the same results, on every operating system and with any number of threads (see Make results reproducible). Where the paper’s procedure is random — the entropy correction — DiMA computes the exact expected value of its regression intercept instead of one random draw (see The exact expectation).

  • Abd Raman HS, Tan S, August JT, Khan AM. Dynamics of Influenza A (H5N1) virus protein sequence diversity. PeerJ. 2020;7:e7954. doi:10.7717/peerj.7954 ↩︎
  • Falk K, Rötzschke O, Stevanović S, Jung G, Rammensee HG. Allele-specific motifs revealed by sequencing of self-peptides eluted from MHC molecules. Nature. 1991;351(6324):290-296. doi:10.1038/351290a0 ↩︎
  • Hu Y, Tan PT, Tan TW, August JT, Khan AM. Dissecting the Dynamics of HIV-1 Protein Sequence Diversity. PLoS ONE. 2013;8(4):e59994. doi:10.1371/journal.pone.0059994 ↩︎
  • Khan AM, Miotto O, Nascimento EJM, Srinivasan KN, Heiny AT, Zhang GL, Marques ET, Tan TW, Brusic V, Salmon J, August JT. Conservation and Variability of Dengue Virus Proteins: Implications for Vaccine Design. PLoS Neglected Tropical Diseases. 2008;2(8):e272. doi:10.1371/journal.pntd.0000272 ↩︎
  • Rammensee H. Peptides Naturally Presented by MHC Class I Molecules. Annual Review of Immunology. 1993;11(1):213-244. doi:10.1146/annurev.immunol.11.1.213 ↩︎
  • Tharanga S, Ünlü ES, Hu Y, Sjaugi MF, Çelik MA, Hekimoğlu H, Miotto O, Öncel MM, Khan AM. DiMA: sequence diversity dynamics analyser for viruses. Briefings in Bioinformatics. 2025;26(1):bbae607. doi:10.1093/bib/bbae607 ↩︎ 1 2 3