A thermodynamic matcher (TDM) is a specialized RNA folding program. Instead of spanning the complete search space of general RNA folding, a TDM spans only a defined subset of it. This subset might be defined via a graphical description (see Locomotif: From Graphical Motif Description to RNA Motif Search) or via a shape string (see Faster computation of exact RNA shape probabilities).
"Algebras/alg_tdm.gap" is for the later one. Given a shape string of a specific shape level, we have to generate a specialized grammar out of one of the four prototype grammars Grammars/gra_nodangle.gap Grammars/gra_overdangle.gap Grammars/gra_microstate.gap or Grammars/gra_macrostate.gap. This process itself is done with a GAP-L program. So one could say a GAP program generates a GAP program. Due to modularity it only generates the grammar, algebras, signatures and instances could simply be re-used.
After the given shape string has been parsed by one of the grammars from Grammars/gra_tdm.gap, the candidate(s) must be transformed into a GAP-L grammar, which is specialized to enumerate only those RNA structures that fold into the given shape. All 20 (4 grammars * 5 levels) algebras, defined in "Algebras/alg_tdm.gap", are for that transformation. To avoid duplication of rules in the generated grammars, we use the special data type rules. We heavily use "extends" to avoid implementing the same functions several times. E.g. the algebras for the nodangle prototype are identical to overdangle algebras, except the convert
function, which sets the name of the grammar.
For TDMs the rules must be indexed. We do so by using sub-shape strings, but have to convert [
to L
and ]
to J
characters to fit GAP-L's requirements for valid non-terminal identifiers.
Please have a look at the application RapidShapes, to see TDMs in action.