Shannon Entropy in Diagnostic Design
In information theory, Shannon entropy quantifies the amount of uncertainty or surprise in a set of possible outcomes. In bioinformatics, we use it to measure sequence variability at individual positions within a multiple sequence alignment (MSA). This page provides the mathematical formulation of Shannon entropy, a step-by-step calculation example, and explains how the pipeline translates entropy into a normalized physical conservation score ().Mathematical Formulation
For a given position (column) in a multiple sequence alignment, the Shannon entropy is calculated as: Where:- is the alphabet of possible states at that position. In our pipeline, we use a 5-letter alphabet: where
$-$represents an alignment gap. - is the observed frequency (proportion) of state in column , such that .
- By definition, if , we define .
Entropy Bounds
- Minimum Entropy (): Occurs when a position is 100% conserved (only one base is present across all sequences). There is zero uncertainty or variation.
- Maximum Entropy (): Occurs when all 5 states in the alphabet are present in equal proportions ( for each state). There is maximum uncertainty.
Normalised Conservation Score ()
To integrate entropy with other signals in the Bridge Builder (M07), we normalise the entropy value to a scale of , where represents maximum conservation and represents maximum randomness.Step-by-Step Calculation Example
Suppose we have an alignment of 10 viral sequences at a specific position , and we observe the following base counts:- Adenine (A): 8 sequences
- Guanine (G): 1 sequence
- Gap (-): 1 sequence
- Thymine (T) / Cytosine (C): 0 sequences
Step 1: Calculate Proportions ()
Step 2: Compute for each active state
- For A:
- For G:
- For -:
Step 3: Sum the terms to find
Step 4: Calculate Normalized Conservation ()
At this position, the conservation score is 0.603. This is well below the pipeline’s strict target threshold (usually ), meaning this position would be avoided when designing primer binding sites.Integrating Gaps in the Alphabet
Many bioinformatics tools exclude gaps from entropy calculations or treat them as missing data. However, treating gaps as a 5th character state is critical for diagnostic design:- A high gap frequency at a position indicates that a subset of circulating strains contains a deletion relative to the reference.
- Designing a primer over a deletion region will cause immediate hybridization failure in those strains.
- By incorporating gaps into the alphabet, any deletion results in a significant increase in entropy, driving the conservation score down and disqualifying the region from primer design.
The Configured Thresholds, in Interpretable Terms
Two different scales are in play, and confusing them causes silent errors:- The conservation score is normalised to and is what the tier grades and reports display.
- The configured thresholds are compared against raw entropy in bits, not against .
!!! warning “Corrected: these thresholds must not be rescaled with the alphabet”
An earlier revision multiplied all three by when the entropy alphabet was widened from 4 symbols to 5, giving 0.023 / 0.116 / 0.58. That was wrong and has been reverted.
The normaliser affects only the display score . The thresholds are compared against raw , and a column containing no gaps has identical raw entropy under both alphabets — the gap frequency is zero, so it contributes nothing to the sum. Multiplying the thresholds therefore rescaled nothing; it simply loosened every criterion by 16% (the exclusion threshold went from MAF 11.0% to 13.8%).
Widening the alphabet was still correct — it is what makes a deletion raise entropy, as described above. Only the thresholds should have stayed put.
A second annotation error was corrected at the same time: the exclusion threshold was documented as “0.50 ~ 30% MAF”. It is ~11%; 30% MAF corresponds to 0.88 bits.
Shannon Entropy vs. Minor Allele Frequency (MAF)
While Minor Allele Frequency (MAF) measures the frequency of the second-most common allele, Shannon entropy provides a more robust signal for multiple-base variation:
In the pipeline:
- Shannon Entropy is used as the continuous signal to calculate the base conservation score.
- MAF is used as a discrete threshold (via
global_params.iupac_threshold) to decide when to introduce degenerate IUPAC bases into the consensus sequence for PrimerLab.
