University Biology — Year 3 · Bachelor Year 3
5Bioinformatics and Sequence Analysis
A biologist who has just sequenced a gene from a deep-sea worm pastes its amino acids into a web form and, three seconds later, learns that the protein is a distant cousin of a human kinase, with identity over residues and a probability of that the resemblance is chance. Behind those three seconds are a dynamic-programming algorithm from 1970, a statistical theory of random alignments, substitution matrices distilled from thousands of protein families, and a database of some hundred billion residues. This chapter is about the reasoning inside the box: how two sequences are aligned so that the alignment is provably the best, how the score is made to mean something, how a match is told from a coincidence, and how patterns are found in a genome that no one has looked at before. The mathematics is elementary — a recurrence, a logarithm, a Poisson distribution — and it is worth knowing, because every conclusion drawn from a sequence comparison rests on it.
5.1 Aligning two sequences
Definition 5.1 (Alignment and score)
An alignment of two sequences writes them one above the other, with gaps (–) inserted so that the columns pair a residue with a residue or a residue with a gap, and no column pairs two gaps. Its score is the sum over columns of a substitution score for each pair of residues and a gap penalty for each gap: a linear penalty per gap position, or, more realistically, an affine penalty for a run of gaps, with the opening cost larger than the extension cost , since one insertion of several residues is a single evolutionary event. A global alignment covers both sequences end to end; a local alignment finds the highest-scoring pair of substrings and ignores the rest, which is what one wants when a shared domain sits in two otherwise unrelated proteins.
Theorem 5.2 (Needleman–Wunsch)
Let and , with linear gap penalty . Define as the best score of a global alignment of the prefixes and . Then , , and for
is the optimal global score, an optimal alignment is recovered by tracing back from the choices that produced each maximum, and the whole computation takes steps. The Smith–Waterman variant for local alignment adds as a fourth option in the maximum, sets the borders to , and reads the answer at the largest entry of the table.
Proof. Consider the last column of any alignment of the two prefixes. It is one of three things: over , over a gap, or a gap over . Removing it leaves an alignment of , of , or of respectively, whose score is at most of that pair; and conversely each of those optimal alignments can be extended by the corresponding last column. So the best score ending in each kind of column is of the shorter pair plus the column’s score, and the optimum is the largest of the three. The borders are forced (only gaps are possible against an empty prefix). Induction on fills the table; the number of cells is . For local alignment the extra option means “start a new alignment here”, which makes the best score of an alignment ending at , and the best local alignment ends somewhere. ∎
Example 5.3 (A four-by-three table)
Align GAT with GCAT, scoring for a match, for a mismatch, . The borders are along the top and down the side. Filling row by row: , , , ; , , , ; , , , . The optimum is , and tracing back — diagonal from (T,T), diagonal from (A,A), then left from (G,C) to (G,G), then diagonal — gives
three matches and one gap: .
Method 5.4 (Aligning two sequences)
(1) Choose the scoring: a substitution matrix suited to the expected divergence (BLOSUM62 for proteins of unknown distance; match/mismatch for DNA), and affine gap penalties (typically open , extend with BLOSUM62). (2) Decide global or local: global for two sequences believed homologous over their whole length, local otherwise. (3) Fill the table by the recurrence, keeping for each cell a pointer to the choice that gave its maximum. (4) Trace back from (global) or from the maximum cell to a zero (local), writing the alignment from right to left. (5) Judge the result not by its raw score but by its statistical significance (below), and look at it: long gaps, low-complexity runs and alignments confined to a repeat are warnings.
5.2 Scoring: what a match is worth
Definition 5.5 (Substitution matrices)
A substitution matrix gives for every pair of amino acids as a log-odds score:
where is the frequency with which and are found aligned in trusted alignments of related proteins, the frequency with which they would be paired by chance, and a scale chosen to make the entries convenient integers. A positive score means the pair occurs more often in homologues than by chance; the identity scores are largest for rare amino acids (tryptophan , cysteine in BLOSUM62) and smallest for common ones (leucine , alanine ), and conservative substitutions (isoleucine–valine ) score positive while radical ones (tryptophan–glycine ) score negative. The PAM matrices (Dayhoff, 1978) were derived from closely related proteins and extrapolated to greater distances by matrix multiplication; the BLOSUM matrices (Henikoff and Henikoff, 1992) were counted directly in blocks of aligned sequences clustered at a given identity — BLOSUM62 from blocks at — and are the default because they were measured, not extrapolated, at the distance where they are used.
Proposition 5.6 (Why log-odds)
For a scoring scheme to be used in local alignment, the expected score of a randomly paired column, , must be negative, and some scores must be positive; otherwise random alignments would grow without bound and the highest-scoring segment would be the whole sequence. Given that, any such scheme is equivalent to a log-odds scheme for some target frequencies — the alignments it will find as optimal are those whose residue pairs are distributed like . Choosing the matrix is therefore choosing the divergence one expects to detect: a matrix for close relatives (BLOSUM80, PAM30) has sharper positives and harsher negatives, one for distant relatives (BLOSUM45, PAM250) is flatter.
Proof. Admitted at this level. ∎
Example 5.7 (Identity, similarity and the twilight zone)
Two random protein sequences aligned optimally with gaps reach about identity by chance. Above identity over a hundred residues two proteins are almost surely homologous; between and is the twilight zone, where identity alone cannot decide and the statistics below must. Homologues can fall far below the zone: haemoglobin and myoglobin subunits share identity, lysozyme and -lactalbumin , and many pairs of proteins with the same fold share less than , detectable only by comparing profiles or structures.
5.3 Searching a database
Definition 5.8 (BLAST)
Aligning a query of residues against a database of by full dynamic programming would take cell updates per search. BLAST (Altschul and colleagues, 1990) trades a little sensitivity for a thousandfold speed by three steps: (1) list the query’s words (three residues for proteins, eleven bases for DNA) and their high-scoring neighbours; (2) scan the database for exact word matches — seeds; (3) extend each seed in both directions without gaps until the score drops a set amount below its best, keeping the high-scoring segment pairs (HSPs), then join nearby HSPs with gapped dynamic programming in a narrow band. A true homologue almost always contains at least one exact three-residue word in common; a chance resemblance rarely does, and is never extended.
Theorem 5.9 (The statistics of a random hit)
For a query of length searched against a database of total length , with a scoring scheme of negative expected score, the number of ungapped local alignments scoring at least that arise by chance is Poisson-distributed with mean
where and depend only on the scoring scheme and the residue frequencies ( is the scale of the log-odds matrix). is the expect value of the score . Writing the score in bits, , the formula becomes , and the probability that at least one chance alignment reaches is , which equals when is small.
Partial proof. The exponential tail is the Karlin–Altschul theorem and is admitted: the maximal segment score of a random walk with negative drift has a distribution whose tail decays as , with the positive root of — which is exactly the equation that makes the log-odds matrix consistent. Given that tail, the rest is counting. High-scoring segments can start at any of the pairs of positions, they are rare, and they are nearly independent; the number of them exceeding is therefore Poisson with a mean proportional to and to the tail probability, . The probability of none is . The bit-score substitution is algebra: . For gapped alignments the same form holds with and estimated by simulation. ∎
Example 5.10 (Reading an E-value)
A query of residues against a database of residues has . A hit with a bit score of has : essentially certainly a homologue. A hit with has : eleven such scores are expected by chance, and the hit means nothing. The same alignment, with the same bit score, searched against a database ten times larger, has an ten times larger — significance is a property of the search, not of the pair. The threshold in common use is for a confident homologue; – deserves a second look with a profile method.
5.4 Profiles, hidden states and motifs
Definition 5.11 (Multiple alignment and profiles)
A multiple sequence alignment arranges a family of sequences in columns of homologous residues. Exact dynamic programming over sequences costs and is impossible beyond three; practical programs align progressively, first the closest pair by a guide tree, then sequences and groups to the growing alignment, with rounds of refinement. A finished alignment is summarised as a profile: for each column, the frequency of each residue and of gaps. A profile hidden Markov model formalises this as a chain of match states, one per conserved column, each emitting residues with its own probabilities, with insert and delete states allowing extra or missing residues at each position; the model of a family (a Pfam entry) scores a new sequence by the probability of the best path through the states, and finds homologues far below the twilight zone of pairwise comparison, because a column that tolerates only hydrophobic residues says so, while a single sequence cannot.
Definition 5.12 (Motifs and information content)
A motif is a short pattern — a transcription-factor site, a splice signal, a phosphorylation site — represented by a position weight matrix of the frequency of each base or residue at each position . The information content of position is bits for DNA, where is its entropy: bits for an invariant base, for a position where all four are equally likely. The total is drawn as a sequence logo, each position a stack of letters whose total height is and whose letters are sized by frequency.
Proposition 5.13 (How much information a site needs)
A site that must be found times in a genome of positions, and nowhere else, needs about bits of information content: the motif must reduce the candidate positions to the true ones, and each bit halves the candidates. Observed motifs of well-studied bacterial regulators match this prediction — E. coli sites for a repressor binding a few dozen places in a genome carry bits; eukaryotic transcription-factor motifs, at bits in a genome, cannot specify their targets alone, which is why they act in combinations and in the open chromatin of Chapter 1.
Proof. A random position matches a motif of information content with probability about (each bit of specificity halves the chance), so the expected number of chance matches in positions is . For the true sites to stand out this must be of order or less: , that is, . ∎
Example 5.14 (Expected chance matches)
A restriction site of six fixed bases has bits and matches a random position with probability : about times in an E. coli genome of read on both strands (the site is palindromic, so once per position), and times in the human genome. A eukaryotic factor whose motif carries bits matches million positions in the human genome, several thousand times more than the genes it regulates. A motif alone is a weak predictor in a large genome; the chromatin state, the neighbouring motifs and the conservation of the site across species are what make a prediction.
5.5 From sequence to function
Method 5.15 (Annotating an unknown protein)
Given a new coding sequence: (1) translate it in the right frame and check for a signal peptide, transmembrane segments and low-complexity regions; (2) search the protein databases with BLAST and read the hits with , noting whether the alignment covers the whole protein (a true orthologue) or a segment (a shared domain); (3) search the domain databases with profile HMMs, which find families that BLAST misses and partition the protein into domains; (4) infer orthology, not merely similarity, by checking that the best hit in the other genome has the query as its best hit (reciprocal best hits) or by placing the protein in a gene tree (Chapter 25); (5) transfer the function of orthologues with caution — a conserved catalytic residue argues for conserved chemistry, a missing one against — and predict the structure; (6) treat every prediction as a hypothesis for the bench.
Proposition 5.16 (Structure from sequence)
A protein’s fold is determined by its sequence (Chapter 7), and computing it from the sequence was for fifty years the central unsolved problem of the field. Three approaches succeeded in turn. Homology modelling builds the structure of a protein on that of a solved homologue, reliably above identity. Coevolution analysis exploits the fact that two residues in contact in the fold tend to mutate together across a deep multiple alignment, so that statistically coupled pairs of columns are predicted contacts, and enough contacts define a fold. Deep-learning methods trained on the hundred thousand solved structures and on such alignments now predict most globular protein structures to near-experimental accuracy (the CASP assessments of 2020), and databases hold a predicted structure for essentially every known protein sequence. What they predict less well is what a single structure does not capture: disordered regions, alternative conformations, the effect of a point mutation, and complexes.
Remark 5.17 (The limits of inference)
Most functional annotations in the databases were never tested; they were transferred from a homologue, which had in turn been annotated by transfer. Errors propagate and multiply, and a wrong annotation on a well-connected protein can infect a whole family. The remedies are the ones above: distinguish orthology from homology, read the alignment, look for the catalytic residues, and remember that “hypothetical protein” is an honest label that a third of the genes in most genomes still deserve.
5.6 Exercises
Exercise 5.1 ★
Define global and local alignment and give one biological situation that calls for each.
Solution
Solution of Exercise 5.1.
Global: both sequences aligned end to end, every residue in a column — for two proteins believed homologous over their whole length, such as orthologues of a housekeeping enzyme. Local: the best-scoring pair of substrings, the rest ignored — for finding a shared domain (an SH2 domain in two otherwise unrelated signalling proteins), or a gene in a long genomic sequence.
Exercise 5.2 ★
Fill the Needleman–Wunsch table for AGC against AAC with match , mismatch , gap , and give the optimal alignment and score.
Solution
Solution of Exercise 5.2.
Borders each way. Row A: . Row G: . Row C: . Optimum : AGC over AAC with no gaps (match, mismatch, match: ).
Exercise 5.3 ★
In BLOSUM62, tryptophan–tryptophan scores and leucine–leucine . Explain from the log-odds formula why the rarer residue’s identity is worth more.
Solution
Solution of Exercise 5.3.
. Tryptophan is rare (), so the chance of two tryptophans aligning at random, , is tiny, and a conserved tryptophan pair is a far stronger sign of homology than a conserved leucine pair (); the log-odds ratio is correspondingly larger.
Exercise 5.4 ★
What is an E-value? A search returns a hit with . What does that number mean, and is the hit a homologue?
Solution
Solution of Exercise 5.4.
The E-value is the number of alignments with a score at least as high that would be expected by chance in a search of this query against a database of this size. means three such scores are expected by chance: the hit is not evidence of homology (it may still be one, but the search cannot tell).
Exercise 5.5 ★★
A query of residues is searched against residues. Compute the E-value of hits with bit scores , and . Which bit score gives ? How does the answer change if the query is residues long?
Solution
Solution of Exercise 5.5.
. ; ; . needs bits. A -residue query has ten times smaller, : bits suffice — but a short query can rarely reach even that.
Exercise 5.6 ★★
Compute the information content of a motif whose four positions have base frequencies (A, C, G, T) of , , and . How many chance matches does it have in a genome?
Solution
Solution of Exercise 5.6.
Information contents: , , , and with , so . Total bits. Chance matches: positions on two strands — the motif is nearly useless alone.
Exercise 5.7 ★★
Explain why affine gap penalties are more realistic than linear ones, and why a very high gap-opening penalty and a very low one both give poor alignments.
Solution
Solution of Exercise 5.7.
An insertion of several residues is one mutational event, so its cost should not grow linearly with its length: an opening cost plus a small extension cost models this. Too high an opening penalty forces mismatches where a gap belongs and misaligns everything after a true insertion; too low a penalty scatters gaps everywhere, matching residues by chance and inflating identity.
Exercise 5.8 ★★
A BLAST search of a human protein against a fly database gives a best hit with covering residues 50–180 of the -residue query. Is the fly protein the orthologue of the human one? What further test would you do?
Solution
Solution of Exercise 5.8.
Not necessarily: the alignment covers a -residue segment, which is the signature of a shared domain rather than of an orthologue aligned over its length. Test: search the fly protein back against the human proteome (is the query its best hit, over the whole length?), identify the domain with a profile HMM, and build a gene tree of the family in several species.
Exercise 5.9 ★★
Why do profile methods detect homologues that pairwise alignment misses? Give an example of a column pattern that a profile captures and a single sequence cannot.
Solution
Solution of Exercise 5.9.
A profile records, column by column, what the family tolerates: a position that is always hydrophobic but never the same residue, an invariant catalytic residue, a position that is always a gap in half the family. A pairwise alignment scores each residue against one other residue and cannot know that a valine at position 40 is “as good as” the isoleucine there in the query. The profile also weights the conserved columns, so weak similarity concentrated where the family is conserved becomes significant.
Exercise 5.10 ★★★
Show that under a scoring scheme with positive expected score, the Smith–Waterman local alignment of two long random sequences has a score growing linearly with their length, and explain why this makes the E-value theory fail. What does this imply for aligning DNA with match and mismatch at GC content?
Solution
Solution of Exercise 5.10.
With positive expected score per column, the cumulative score along the diagonal of two random sequences is a random walk with positive drift: after columns it is about , so the best local alignment is essentially the whole thing and its score grows as rather than as . The Karlin–Altschul theory, which requires a negative drift so that high scores are rare excursions, does not apply and no exists. For DNA at GC the chance of a match is , so the expected score is : still negative, and the statistics hold; but a scheme such as match , mismatch would have expectation and would report the whole genome as one alignment.
Exercise 5.11 ★★★
The Needleman–Wunsch table needs memory cells; for two chromosomes that is . Describe two ideas by which genome aligners avoid it (seeds and chaining; banding), and what each gives up.
Solution
Solution of Exercise 5.11.
Seeds and chaining: find exact or near-exact matches of -mers between the two sequences with a hash table, keep the ones that line up on consistent diagonals, chain them, and run dynamic programming only in the gaps between chained seeds; it gives up alignments in regions with no seed (highly divergent stretches). Banding: if the two sequences are known to be nearly collinear, compute only the cells within a band of width around the diagonal, at cost instead of ; it gives up any alignment with an insertion larger than the band.
Exercise 5.12 ★★★
A gene-finding HMM for bacteria has states for the three codon positions and for non-coding DNA. Explain how the model can tell coding from non-coding sequence with no stop codon information at all (consider codon usage), and why the same approach is much harder in a human genome.
Solution
Solution of Exercise 5.12.
Coding sequence has a period of three: the three codon positions have different base compositions (the third is the most biased), and codon usage is uneven in each species. A model with three coding states in sequence, each emitting bases with the composition of that codon position, assigns coding DNA a higher probability than the non-coding state does, over a window of a few dozen codons, even without stops. In a human genome exons are short (), separated by introns of kilobases, so the coding signal is brief and interrupted; the model must also recognise splice sites, which are weak signals, and the sheer amount of non-coding sequence produces many false coding segments.
5.7 Problem: A Sequence from the Deep Sea
Problem 5.1
Weekend problem — an unknown protein aligned by hand, searched against the databases with its significance computed, its regulatory motif weighed in bits, and its gene checked against the statistics of random open reading frames, ending on the E-value of the best hit, the bits a site needs and the length a reading frame must have to be believed
Data: a -residue protein from a deep-sea annelid. Protein database: residues. Genome of the worm: , GC. Scoring for hand alignments: match , mismatch , gap . Bit score of the best BLAST hit: ; of the tenth hit: .
Part I — By hand.
- Align the peptides KQT and KAQT with the Needleman–Wunsch recurrence: write the table and give the optimal alignment and score.
- Repeat with Smith–Waterman (local) for GATCAT against ACAT: find the best local alignment and its score.
- How many cell updates does a global alignment of the -residue protein against a -residue protein take? Against the whole database?
- If a computer performs updates per second, how long does the full database alignment of question 3 take? Why is BLAST used instead?
- A BLOSUM62 identity score is for alanine () and for tryptophan (). With (half-bit units), compute the target frequency and , and the ratio for each. Interpret.
- Two proteins share identity over residues. Say why identity alone cannot settle homology here and what would.
Part II — The search.
- Compute for the query against the database, and .
- Compute the E-value of the best hit () and of the tenth hit ().
- What bit score corresponds to for this search? To ?
- The same best hit is found when the database has grown to residues. Its E-value?
- The tenth hit aligns residues 200–260 of the query with a identity over residues. Using the E-value, say whether it is evidence of homology, and what a profile search could add.
- The best hit is a human kinase, aligned over residues 10–290. Its best hit in the worm proteome is the query. What does this reciprocal test establish, and what does it not?
Part III — A motif.
- Upstream of the gene lies a candidate transcription-factor site of eight positions with information contents bits. Total ?
- How many chance matches does the motif have in the genome (both strands, positions)?
- The factor regulates about genes. How many bits would a motif need to specify sites alone in this genome?
- How much of the shortfall could a second, adjacent motif of bits supply, if the two must co-occur within a fixed spacing?
- A position with frequencies for (A, C, G, T): compute its entropy and information content.
- Explain, using the information argument, why bacterial transcription factors typically have longer and more conserved sites than eukaryotic ones.
Part IV — The gene itself.
- In random DNA of uniform base composition, what is the probability that a codon is a stop? What is the expected number of codons before a stop appears (a geometric distribution)?
- The worm genome is GC. Recompute the probability that a random codon is a stop (TAA, TAG, TGA) with the actual base frequencies, and the expected reading-frame length. Which way does a low GC content push gene finding?
- What is the probability that a random open reading frame is at least codons long? At least ?
- In the genome, six frames on two strands give about codon starts. How many random open reading frames of at least codons are expected? Of at least ?
- Explain why “open reading frame longer than codons” is a usable gene finder in a bacterium but not in this genome, and what a eukaryotic gene finder uses instead.
- The worm gene has six exons averaging . Explain how RNA sequencing reads resolve the exon structure that genomic sequence alone leaves ambiguous.
- Summarise: the E-value of the best hit (question 8), the bits needed to specify sites (question 15), and the expected number of random reading frames of codons in the genome (question 22).
Solution
Solution of Problem 5.1.
1. Rows K, Q, T; columns K, A, Q, T; borders and . Row K: ; row Q: ; row T: . Optimum : K-QT over KAQT. 2. Best local score : CAT against CAT (residues 4–6 of GATCAT with 2–4 of ACAT); ATCAT against A-CAT also scores . 3. updates; against the database . 4. s, ten hours per query; BLAST’s seeds skip almost all of the table and answer in seconds. 5. . Alanine: , , ratio . Tryptophan: , , ratio . An aligned tryptophan pair is times more frequent in homologues than by chance, an alanine pair only four times; alanine pairs are nevertheless commoner in absolute terms because alanine is common. 6. lies in the twilight zone, where random alignments reach ; the E-value of the alignment, conserved motifs at the right positions, a profile-HMM match to a known family, or a shared fold would settle it. 7. ; . 8. ; . 9. at bits; at bits. 10. Ten times : , still overwhelming. 11. With the tenth hit is what chance produces; a identity over residues is not evidence. A profile search of residues 200–260 against the domain database could show whether that segment is a known domain, with statistics that pairwise comparison lacks. 12. Reciprocal best hits over the full length are consistent with one-to-one orthology; they do not prove it — a duplication in one lineage after the split gives two co-orthologues, and the loss of the true orthologue can leave a paralogue as best hit. A gene tree with several species is the test. 13. bits. 14. chance matches. 15. bits. 16. Co-occurrence at fixed spacing adds the bits: , supplying of the missing; about bits (a factor of in chance matches) must come from elsewhere — chromatin accessibility, further partners. 17. bit; bit. 18. A bacterial factor must find its few sites in a genome with no help from chromatin: it needs some bits, and its sites are long and conserved. A eukaryotic genome is a thousand times larger, needing ten more bits, yet its factors have short sites; they achieve specificity by combination and by the restriction of accessible chromatin, which also makes regulation more evolvable, since a short site is easily gained or lost. 19. ; the expected number of codons before a stop is . 20. , : , ; total , expected frame length codons. AT-rich DNA is full of stops, so random open frames are shorter and long ones stand out more. 21. ; . 22. Each maximal open frame ends at a stop, and codon starts contain stops: about random frames of at least codons, and of at least . 23. A bacterium of has some stops and hence about chance frames of codons but almost none of ; its genes average codons and of the DNA is coding, so a long open frame is nearly always a gene. In the worm, of the DNA codes, exons average codons — shorter than the chance threshold — and a million random frames of codons swamp them. Eukaryotic gene finders use splice-site signals, codon bias in a hidden Markov model, homology to known proteins and, above all, sequenced transcripts. 24. A read from a spliced messenger aligns to the genome in two pieces separated by an intron: the split marks both splice sites to the base; read coverage delineates the exons and paired reads link successive exons into one transcript, resolving which of several candidate splice sites is used. 25. for the best hit; about bits to specify sites in the genome; some chance reading frames of codons in the whole genome.