Untangled

Topic 3

RNA folding: Nussinov, then CYK

Nussinov asks which pairs make the most base pairs. A stochastic grammar asks which parse is most probable. Same table shape, same traceback, different bookkeeping.

Nussinov in one screen

N(i,j) is the best score for the interval i to j. To fill it, look at the four things base j or base i could be doing. Take the max.

N(i,j) = max of
N(i+1, j) i is unpaired
N(i, j−1) j is unpaired
N(i+1, j−1) + 1 i pairs with j (only if A–U, G–C or G–U, and j − i > 3)
maxk N(i,k) + N(k+1,j) split into two independent pieces
  • Fill by interval length.Every cell needs only shorter intervals. Intervals with j − i ≤ 3 are 0 because a hairpin needs a loop of at least 3 bases.
  • Pairing the ends is not automatic.If i and j can pair, that is only one option. A split can beat it. In GAAACGAAAC the best answer uses a split.
  • A saved split means follow both pieces.In the traceback, N(i,k) and N(k+1,j) each get traced. Forgetting the second one loses half the structure.
  • Ties are fine.More than one structure can have the best score. Any optimal one is a correct answer.
  • Cost.O(n³) time, O(n²) space. Pseudoknots (crossing pairs) are not allowed, and allowing them costs O(n⁶) time and O(n⁴) space.

Fold one yourself, step by step

Try the lecture sequence GGGAAAUCC (answer: 3 pairs, (((...)))). Click any cell to see its four options. Switch to the toy weights to see how the winner can change.

Check yourself
  • Why is N(i,j) = 0 when j − i ≤ 3?
  • What does the traceback do when it hits a saved split?
  • Quiz 3: why does GAAAAUCGAAAU score 3 and not 4? (Pairing 1 with 12 uses up both ends and leaves only 2 pairs.)
  • What is the time and space cost, and why?

Same idea, written as a grammar

Each Nussinov option is a grammar rule. A stochastic context-free grammar (SCFG) gives every rule a probability, and CYK finds the most probable parse using the same interval table.

Nussinov optionGrammar ruleMeaning
i unpairedX → a Yemit a base, keep going
j unpairedX → Y bkeep going, emit a base
i pairs with jX → a Y bemit two paired bases around Y
split at kX → Y Ztwo pieces side by side
  • Dv(i,j) is the best probability that state v generates positions i to j. It plays the role of N(i,j), with one table per state.
  • Probabilities multiply, then you take the max.A pair rule gives p × D(inner). A split rule gives p × maxk DY(i,k) × DZ(k+1,j).
  • Each state's rules add to 1.That is what makes it a probability model. In the lecture grammar S has 0.3 + 0.3 + 0.4.
  • Highest-probability parse is not a confidence.It is the best explanation under made-up rule probabilities. In lecture, GAAAC scores 0.24 by pairing the ends and only 0.08 by splitting.

Watch CYK run on the lecture grammar

Fill the unpaired-string states first, then S, which pairs the ends or splits. Click any cell for the arithmetic.

Other folding facts worth knowing

  • Real energy models (Zuker, ViennaRNA) score stacked pairs and loops by free energy instead of counting pairs. Same dynamic programming shape.
  • Covariance models are SCFGs fitted to RNA families and used to search genomes.
  • RNALfold folds local windows of length L in O(nL²). LinearFold prunes to O(nb log b).
  • Toy weights from lecture: G–C 3, A–U 2, G–U 1.