Ambivalent covariance models

Background Evolutionary variations let us define a set of similar nucleic acid sequences as a family if these different molecules execute a common function. Capturing their sequence variation by using e. g. position specific scoring matrices significantly improves sensitivity of detection tools. Members of a functional (non‐coding) RNA family are affected by these variations not only on the sequence, but also on the structural level. For example, some transfer‐RNAs exhibit a fifth helix in addition to the typical cloverleaf structure. Current covariance models – the unrivaled homology search approach for structured RNA – do not benefit from structural variation within a family, but rather penalize it. This leads to artificial subdivision of families and loss of information in the Rfam database. Results We propose an extension to the fundamental architecture of covariance models to allow for several, compatible consensus structures. The resulting models are called ambivalent covariance models. Evaluation on several Rfam families shows that coalescence of structural variation within a family by using ambivalent consensus models is superior to subdividing the family into multiple classical covariance models. Conclusion A prototype and source code is available at http://bibiserv.cebitec.uni‐bielefeld.de/acms. Electronic supplementary material The online version of this article (doi:10.1186/s12859-015-0569-1) contains supplementary material, which is available to authorized users.


RNA family modeling in RFAM
The dominating source of information on non-coding RNA families is the RFAM database [1]. The grouping criterion of RFAM is a follows [2]: The ideal basis for a new family is an RNA element that has some known functional classification, is evolutionary conserved, and has evidence for a secondary structure.
For many RNA families, this secondary structure is conserved and varies only to a limited degree, such as insertion of unstructured sequence or loss of some base pairs present in the secondary structure. For these families, present-day modeling techniques work well. But note that by the above definition, RFAM does not strictly insist on a single common structure, strongly conserved in the above sense. There are well known examples with larger structural variations within a family. The most prominent example is probably the tRNA family (RF00005, RFAM release 10.1). It is known that a minority of the tRNA molecules form a stabilizing "variable loop" in addition to the classical cloverleaf structure. The WIKIPEDIA article on tRNA, which RFAM uses to explain the family, does not fail to point to this fact. The tRNA family comprises 967 members in total, of which a minority of 147 members hold the variable loop. But this "loop" is not just inserted, unstructured sequence, which could be accommodated by present-day techniques. In contrast to its name, nucleotides of the variable loop form base-pairs, creating an extra helix which adds stability. A plausible consensus structure for the 147 variable loop members can be constructed by aligning those individual predictions, e. g. with RNAFORESTER [3]. The extra helix is a bona fide feature of the tRNA family.

Limitations of present family modeling
In the presence of structural variation like the one described above, present-day techniques reach a limit. Family models in RFAM are implemented as covariance models (CMs), constructed by the tool INFERNAL [4]. RFAM constitutes the most important use-case for covariance models, and in fact, curators of RFAM and developers of INFERNAL do closely cooperate. By construction, INFERNAL's CMs require all family member sequences to fold into a single, shared secondary consensus structure (SS cons ) with only small deviations such as indels.
An optional structural feature such as the "variable loop" cannot be accommodated. Replacing in our tRNA example the original SS cons with the variable loop enriched version will have no effect on the CM actually built, because the majority of 820 members has gaps at the variable loop positions and therefore INFERNAL will model those positions as insertions. In effect, the introduced variable loop sub-structure is taken out off SS cons , and informative covariance from base-pairs of this extra helix (where present) cannot be captured.
One might also consider enforcing a five-helix SS cons by increasing the allowed gap ratio. Base pairs in the minority structures could now contribute. But this idea would impose large deletion costs on the 820 majority members when aligning to the new model. In either case, an improvement can not be reached by providing an alternative alignment and a single SS cons .

Allowing for structural variation in RNA families
The architecture of CMs has been remarkably stable for 20 years, serving its purpose very effectively. But for accommodating multiple structures, as shown above, one must extend the classical definition and construction of CMs. With the introduction of ambivalent Covariance Models (aCMs), we provide such a generalization.
An aCM is a CM constructed from several consensus structures, allowing sequences to fold into a set of predefined alternatives without penalty, and exploiting sequence conservation and covariance at all points.
The organization of this contribution is as follows: We briefly recapitulate the technical background of CMs and their INFERNAL implementation in Section 'Introduction: classical covariance models'. The classical architecture is hard-wired in INFERNAL's CMs. To be able to modify it, we first re-create classical CMs in a rapid prototyping framework in Section 'Recreating the core of INFERNAL', where the model generation process can be described on the abstraction level of context-free grammars. Extending these grammars by extra rules that branch between alternative consensus structures, we arrive at aCMs in Section 'Ambivalent covariance models'. Section 'Evaluation' is devoted to their evaluation, comparing ambivalent models to classical models in the presence of structural variation.

Recent alternative approaches to structural variability in RNA
While our work is firmly based on the classical work on CMs, there are other interesting approaches, not based on CMs, which address structural variation in related RNA sequences. Both approaches are very recent and have appeared while this manuscript was in preparation.
Saffarian et al. suggest a combinatorial approach to search for a predefined set of alternative structures, called multi-structures, in RNA sequences [5]. They describe this set as a formal grammar, on the granularity of a predefined set of stable helices. This can be used to describe RNA families with structural variation, but also interesting suboptimal structures from the search space of the same type of RNA. We will refer to an aspect of this work in Section 'Ambivalent covariance models'.
Reinkensmeier and Giegerich elaborate the approach of thermodynamic machters to define the "cuckoo" RNA family [6]. The characteristic cuckoo motif consists of 2 -4 hairpins with no sequence conservation in the helices, but exhibiting a conserved loop motif. Their approach is based on the theromodynamic energy model, but in principle, the energy rules can be replaced by stochastic scoring, taking the approach closer to (extended) CMs. Although also based on formal grammars, the approach is semi-automatic, allowing the model designer careful tuning of the generated matchers, which can be considered a blessing as well as a burden.

Introduction: classical covariance models
A covariance model (CM) is a stochastic approach to quantify homology of an RNA sequence to a family of sequences. The family consists of an aligned set of RNA sequences (MSA), which are believed to share the same functionality, shape or other grouping properties, together with one (pseudoknot free) consensus secondary structure (SS cons ). The machinery follows the Bayesian interpretation of probabilities, by updating family independent expert knowledge (priors) with those frequencies observed in the given family (posteriors). Amalgamation of priors and posteriors is called "training" and has to be done just once. Result of the training is a stochastic context free grammar (SCFG), whose production rules are augmented with transition and emission-probabilities. The architecture of CMs can be described by an architecture grammar, which is a grammar that can parse any RNA secondary structure. The family model grammar is generated from the architecture grammar by specializing it to SS cons (for a tutorial exposition of this view see [7]), and its parameters are trained from the multiple alignment.
Covariance models follow the principles of Hidden Markov Models (HMMs) [8], but are more powerful in order to account for distant but coupled positions, which represent the base-pairs of SS cons . While an HMM runs through a linear sequence of states, the transition graph of the CM "automaton" has a tree-like branching structure that mimics SS cons . For historical reasons, the classical description of this technique [4] uses a mixture of HMM ("state transition") and grammar terminology ("bifurcation rule"); here we try to stick to the latter, providing translation of terminology where appropriate.
The parses constructed by the family model grammar for any sequence are very similar. Abstracting away insertions and deletions, they all indicate the same structure, namely the given SS cons . This unique abstract parse tree is called a "guide tree" in INFERNAL terminology. When we apply the CM to an RNA sequence, we can obtain the probability of the most likely parse of the given sequence. Since this probability tends to be very small, it is scaled to a background model. This is done in terms of a log odds ratio, which provides a bit-score, which finally expresses homology between sequence and family. It is up to the user to decide if the bit-score suffices to accept the input sequence as a new family member.

Reference implementation
The INFERNAL software package [9], a product of 20 years of careful software engineering, is the reference implementation of CMs. It does not only provide programs for the above described tasks of training (CMBUILD) and searching (CMSEARCH), but e. g. also tools to "calibrate" the CM -basically to provide E-and P-values for the bit-scores -or to align the new member to the existing family.
Scoring a sequence s of length n to a family model of length m takes O(n * m 3 ) time and O(n * m 2 ) space. Such high computational cost arises from parsing with a context free grammar which itself has a size proportional to the length of the input. Much of the efforts spent in the past twenty years aimed to lower these high computational demands. In 2002, Eddy introduced a memoryefficient divide-and-conquer variant of the CYK (Cocke-Younger-Kasami) algorithm [8,10]. An HMM pre-filtering strategy was pioneered by Weinberg and Ruzzo in 2006 [11]. Since 2007, remaining candidate sequences of s are scored with a heuristics, called "query dependent banding" [12], which tightly restricts the search space while hopefully retaining the most likely candidate. Wherever possible, INFERNAL uses parallelization to further speed up the run-time. For all these improvements, the basic architecture of CMs remained untouched. Furthermore, statistics are enhanced for training by sequence weighting and expectation maximization. Sequence weighting is to adjust for potential sub-grouping of the family members. Expectation maximization should compensate for overfitting, by finding a suitable trade-off between priors and posteriors. CMSEARCH can be run in glocal (aka "small in large" or "free shift") or local mode. The reported bit-score might be either the probability of the most likely statepath (the CYK algorithm, which is the analogue to the "Viterbi" algorithm in HMMs), or probability sum of all possible state paths ("inside" algorithm; HMM analogue is called "forward") [8].

Model construction
We review the model construction process in some detail, as we are going to re-implement it from scratch before extending it.
Before a query RNA sequence can be assessed for homology to a family of interest, a covariance model (CM) must first be built from the given family information, namely the multiple sequence alignment (MSA of k sequences) and the single consensus secondary structure (SS cons ). This construction task is carried out by the program CMBUILD of the INFERNAL package (see the reddish box in Figure 1). CMBUILD takes MSA and SS cons as its inputs and finally produces a CM encoded as a table in a flat-file. This table encodes the parser for the family model grammar, while the underlying family model grammar is not constructed explicitly. (However, it can be extracted from the file by upward compilation [13]).
The complete procedure can be divided into the following seven sub-processes: 1. Break pseudoknots: CMs cannot cope with pseudoknots due to the restriction to context free grammars. However, some RFAM families (89 of 2,208 in release 11.0) contain annotations for crossing base-pairs. One of the crossing pairs is annotated by standard brackets in SS cons , the other with upper-and lower-case letters for the opening and closing partner, respectively. All bracket annotated pairs must either be nested or adjacent to all other bracket annotated pairs. To obtain a pseudoknot free structure, all letters are simply converted into unpaired bases. 2. Gap column masking: Integrating a further sequence into a MSA with an insertion inevitably causes new columns which hold gaps for the majority of sequences. To counteract this effect, INFERNAL tells apart "matching"-columns with a gap-ratio below a certain threshold (50% by default) and "insertion"-columns above this threshold. Only the first column-type is reflected in the final architecture of the CM. The structure SS match is SS cons , where "insertion"-positions are removed. If both columns of a base-pair fall into different column-types, the pair must be broken and only the partner below the threshold appears in SS match as an unpaired base. 3. G 1 -parsing: To generate the family model SCFG, SS match is parsed with the architecture grammar G 1 to gain a guide-tree (gt) as an intermediate step.
In grammar terminology, this guide tree is the only parse tree which the family model grammar can generate without using rules for insertion or deletion. The architecture grammar G 1 is shown in Figure 2.
(Since the architecture grammar G 1 to parse the structure is syntactically ambiguous [14], the result is not unique. One of the parses must be chosen as the guide tree according to a specific set of objectives. The online Additional file 1 informs about these objectives in detail.) 4. Construction: The family model grammar is now extended with productions providing for insertions in the query sequence. These are always considered unpaired bases. And it is extended by productions providing for deletions from SS cons , where unpaired bases as well as paired bases can disappear.
The result of at this point is a the family model grammar, which reflects the unknotted, "insertion"-column masked consensus structure SS match . To turn this grammar into a CM, all transitions and emissions must be associated with probabilities, which are inferred from the MSA via the following processes: 5. Sequence weighting: The MSA might be subdivided into several sub-groups. Due to different biological interests, different levels of experimental difficulties or other reasons, the MSA might have many representatives for one sub-group, but only a few for the other. Since the CM should be able to detect both sub-groups with equal strength, INFERNAL uses different weights for training with the MSA sequences of both sub-groups. Version 1.0.2 of INFERNAL uses the "Gerstein / Sonnhammer / Chothia tree weights" [15] to turn a MSA into a weighted alignment (wMSA ). 6. Expectation maximization: In order to avoid overfitting, INFERNAL uses a rudimentary expectation maximization process to balance the influence of priors and posteriors. The theoretical background is given in [16] and its application in INFERNAL in [17].

Figure 2
Architecture grammar G 1 to parse SS match to generate INFERNAL style CMs. The axiom is A. Terminal symbols are colored blue, algebra functions green and filters magenta. Terminal is the empty word; < and > denotes the opening and closing bases of a pair and * is the unpaired base. The magenta subscript ≥ 1 requires the affected non-terminals to parse at least one character from the input, i. e. the branches of a bifurcation cannot be empty.
Taking only the "matching"-columns of wMSA into account, given by SS match , sequence weights are re-normalized to a value k eff ≤ k to form nwMSA. The value k eff is the result of an optimization problem, where the alignment entropy shall approximate a pre-defined "target" value. 7. Training: Finally, the MSA is used to count how often which production rules of the family model grammar are used in parsing the data and which nucleotide are produced by the terminal symbols in the grammar. The occurrences do not contribute equally, but are weighted according to nwMSA. Priors for emissions p emit and transitions in a G 1 model p trans G 1 are added to the counts before probabilities are computed. Furthermore, emission probabilities are contrasted with a simple background model bg 0 , where unpaired and paired emissions are equally distributed. There is no background model for the transitions. The resulting SCFG is saved in a CM-file, which encodes the parser for the stochastic family model grammar in a tabular form.
The program CMSEARCH of INFERNAL reads the model from the CM-file, takes a query RNA sequence as second input and computes the CYK bit-score for matching the sequence against the model: Process matching CYK in Figure 1.
Our generalization of CMs to aCMs touches the core aspects of this construction process. In particular, we will have to change model architecture and family model grammar. Presently, they are concepts which explain the approach, but are not constituents of the INFERNAL software or its output that we can get our hands on, take out and change. Hence, we re-create INFERNAL in a more flexible framework, in order to venture on to our extension.

Overview
As the first step to our extension towards aCMs, we will produce a software named ALTERNAL, which reimplements the INFERNAL approach, but with a different architecture and an explicit construction of the family model grammars. As the construction of the family model grammar entails parsing SS cons with the architecture grammar, and running the family model means dynamic programming, a programming system that combines both techniques on a high level of abstraction is highly useful for our effort.
In this section, we first review the technique of algebraic dynamic programming, and use it to reconstruct INFERNAL in a way that we can extend towards aCMs in Section 'Ambivalent covariance models'. Asymptotic run-times in ALTERNAL remain the same as reported for Infernal, e.g. scoring a sequence s of length n to a family

ADP and the BELLMAN'S GAP system
Algebraic Dynamic Programming (ADP) [18] is a discipline to formulate algorithms for sequential problems. Its high level of abstraction allows for a clear separation of concerns. (i) A combinatorial search space is generated by a regular tree grammar G. (ii) Each candidate of the search space is evaluated by an evaluation algebra A. (iii) The "best" candidate is determined by an objective function.
Evaluating a search space described by grammar G and input sequence x, using evaluation algebra A, is simply denoted by Normally, this will return the optimal candidate in the search space. When G is the family model grammar, A the stochastic scoring algebra, and x the query sequence, we obtain the best alignment of the query to the model. But the search space may be small and the "score" need not be a number: When G is the architecture grammar, x is some SS match , and the scoring functions in A compute grammar rules, the resulting "score" will be the family model grammar. Wait and see.
In ADP, components of a problem specification can be easily replaced or even combined in algebra products [19] to tackle new challenges without low-level reprogramming. For a detailed exposition of the formal concepts of ADP see [18]. In our experience, when one has to modify a nontrivial dynamic programming algorithm, it is often easier to re-implement it in ADP rather than to tinker with the existing source code.
The BELLMAN'S GAP system is a recent implementation of ADP, which we rely on for the present project [20]. Covariance model generation as well as application are formulated in the language GAP-L, and translated into C++ code by the GAP-C compiler.
The software ALTERNAL (blue box in Figure 1) is our re-implementation of INFERNAL with BELLMAN'S GAP, where many processes are replaced by ADP versions (blue font/borders). It mimics INFERNAL as described in Section 'Model construction', but comes with two fundamental modifications: First, the replacement of the architecture grammar and second the way to obtain the counts for training. Notably, the search spaces of CMs, either created by INFERNAL or by ALTERNAL, are identical. Both implementations will consider the same possible alignments of a query sequence to the model. In principle, this should be true for the bit-scores of the search process as well. The processes break pseudoknots, gap column masking, sequence weighting and expectation maximization remain untouched for the moment.

Change 1: replacing the architecture grammar
The architecture grammar of INFERNAL is G 1 , depicted in Figure 2. For ALTERNAL, we replace the architecture grammar by G 5 , see Figure 3. The advantage is three fold: First, it is guaranteed that the G 5 -parsing process of SS match will exactly yield one parse (guide tree in INFER-NAL terminology). Selecting a specific one from several alternatives by ad-hoc criteria is avoided. Second, the construction-process in ALTERNAL can be described by evaluating SS cons with the evaluation algebra A CFG (see Figure 4). The "scoring" functions of this algebra A CFG do not compute scores. Rather, they compute the productions that make up the family model grammar. And third, compared to a G 1 architecture CM, the number of production rules is roughly reduced four-fold in a G 5 architecture (see Additional file 1 for details), while exactly keeping the same search space. Thus, the training has to infer fewer parameters. The result of the A CFG -evaluation is another grammar -the family model grammar G CM which captures the family specific architecture of the CFG: An example is given in Figure 5. Panel A) shows the MSA with k = 5 sequences. The consensus structure SS cons is given as the top row. The third column is shaded, because it holds more gaps than bases and will be modeled as an insertion. Due to this gap, SS match is << * ><>>, which is different from the initial SS cons . The single guidetree which results from parsing SS match with the architecture grammar G 5 is given in Panel B) of Figure 5. Panel C) presents the final CM grammar, which is the result of evaluating the guide-tree with A CFG . See the online Additional file 1 for further details.

Change 2: gaining posteriors
Once the architecture of a CM is fixed, posteriors from the MSA can be inferred. Aligning a query sequence to a model becomes an optimization problem over many different derivations, because we do not know the best situation relative to the consensus structure for each nucleotide in advance (This is the best scoring parse, called state path in HMM terminology). But we do know the single correct derivation for training, because the training sequences are already aligned. And thus, we have only one candidate in the search space if we force a (training) sequence into a concrete derivation. We can do so by providing this derivation as a second input, besides the nucleotide sequence itself. We need a third, family specific ADP grammar G train to simultaneously parse one MSA row and a secondary structure. This grammar is created by evaluating gt again, but this time with the evaluation algebra A train (see Figure 4): To gain the desired counts in the training process, every MSA row must be parsed together with SS train k which is a slightly modified version of SS cons : If according columns are marked as "insertion-columns", unpaired positions become gaps, and partnering positions become unpaired bases. Mapping a single row of MSA to SS train k might produce columns consisting of a gap in sequence and model: -. These columns must be removed from both inputs. This mapping shall be indicated by the ⊕-operator in Figure 1.
An enumeration algebra A enum is a generic representation of candidates of the search space, which can automatically be produced by the BELLMAN'S GAP compiler. It records which algebra functions were called with which parts of the inputs, but gives no hint about the used nonterminals, i. e. the grammar production rules. The trace of the algebra functions is exactly what we need for training, because they give rise to the derivation through the CM and the sub-words of the nucleotide input, i. e. single bases inform us about the concrete emissions. By creating enum-representations for all training pairs, consisting of the MSA rows and SS train k , and accumulating the occurrence count of each algebra function, we simply get the desired counts. As in INFERNAL, counts do not equally contribute, but are weighted according to nwMSA. The resulting probabilities of this training process will be used to generate a family specific CYK algebra A CYK .
Due to our shift to a G 5 architecture in ALTERNAL, we cannot re-use the priors of INFERNAL for the G 1 transitions p trans G 1 . Instead, we once need to derive a set of  transition priors p trans G 5 from a trusted set of families. We do so with the same set as used for INFERNAL, which is described in [12].
Finally, for the search process, a query RNA sequence x can now be parsed by G CM . With G CM and A CYK coded in GAP-L, BELLMAN'S GAP will compile this into a program instance for the call of G CM (A CYK , x) for any x. All candidates of the search space will be evaluated by A CYK and the maximal score will be reported.

Approving faithful re-implementation
To approve that ALTERNAL is a faithful remake of INFER-NAL, we must show that it considers the same search space and scores candidates in a similar way.
To verify our statement that the search spaces of INFER-NAL and ALTERNAL are identical, we performed the following experiment: The CM flat files, as the product of CMBUILD from the INFERNAL package, contain the models G 1 -architecture as well as all transition and emission probabilities. The upward compiler described in [13] can parse these files and construct an equivalent ADP grammar. We use the same idea to produce grammars G G 1 CM coded in GAP-L. Again, a counting algebra A count can automatically be generated by BELLMAN'S GAP. Thus, we can easily determine and compare the search spaces sizes of G G 1 CM (A count , r) and G CM (A count , r). In fact, they are in all test cases identical (data not shown). To proof that the upward compiled versions are identical to INFER-NAL, we measured a shift of bitscores and found that the median shift is 0.000 for "original" and "shuffled" sequences.
To access the capability of ALTERNAL to reproduce the scoring results of INFERNAL, we set-up the following experiment for each of the 2,208 families in the RFAM 11.0 release: First, a traditional CM is generated from the RFAM seed alignment MSA which includes the consensus structure SS cons with the CMBUILD software (version 1.0.2) using default parameters. Next, a single "original" row from MSA is randomly chosen, gaps are removed and the thus gap-freed sequence is globally aligned to the previously built CM with the program CMALIGN (version 1.0.2) from the INFERNAL package with parameters set to -no-null3 -1 -cyk -nonbanded. The resulting bit-score constitutes our base-line. We prefer CMALIGN over CMSEARCH at this step, because only the first one is able to compute global alignments. Another baseline score for negative test cases is computed by aligning a di-nucleotide "shuffled" (by the program USHUF-FLE [21]) version of the previously used sequence to the same CM. Second, we compile a G CM (A CYK , r) instance with ALTERNAL for the family and run this instance with the exact same two sequences r (original and shuffled) as used before. By subtracting the baseline value from the bit-score computed by G CM (A CYK , r) we obtain the bit-shift between INFERNAL and ALTER-NAL. The bit-shifts for all 2,208 families are depicted as boxplots in Figure 6. Except for those seven families where SS match exceeds 750 bases which causes memory overflows.
We observe small but significant shifts of bit-scores between the two programs, which cannot be explained by rounding errors. Positive test cases show a median shift of −2.2 bits, negative ones a shift of −9.4 bits. If we force both programs to separately report bit-scores originating from emissions and transitions, we see that these differences only stem from shifts in the transitions and not from emissions (data not shown). The reason is the change of the underlying architecture from G 1 to G 5 . In consequence, building two CMs from the same family leads to two fundamentally different grammars, which still have the same semantic meaning. Emissions are not affected by this change, they are only associated at different non-terminals. But there is no possible mapping for the transitions between those two models, which causes divergent posteriors at training and different numbers and values of single transitions for parses of those models at the alignment step. Figure 7 shows an illustrative example. The same tiny family with three sequences in a four-column alignment and a simple hairpin as consensus structure is translated into a G 1 model (on the left) and a G 5 model (on the right). Let us assume that the highest scoring alignment for both models would be UaAA <- * > . The corresponding parses are coloured blue in both models. While G 1 requires only four transitions, the parse of G 5 needs twice as many, also with different values. Thus, the alignment with the exact same meaning gains −1.585 bits from G 1 and only −2.415 bits from G 5 . The tendency of G 5 for more single transitions results in lower bit-scores as shown in Figure 6. Fortunately, this trend hits negative cases harder than positive ones, which means that G 5 models have a stronger discriminative power.
Thus, we conclude that ALTERNAL is a faithful reimplementation of INFERNAL, close enough such that the improvements achieved by our pending generalization can also be expected from analog extensions to INFERNAL.

Ambivalent covariance models
We must define aCMs, specify the input for aCM construction, and describe the generation process. The evaluation of the new approach will be given in Section 'Evaluation' .

Problem definition and input format
aCMs extend classical CMs by modeling for RNA sequence families that fold into a predefined set of consensus structures. Mathematically, aCMs are stochastic context free grammars, generated from a G 5 architecture grammar, and with parameters trained as with classical CMs.
The input to aCM construction is a multiple RNA sequence alignment in Stockholm format, which indicates several consensus structures. The creator arranges the alignment rows according to different structural features and supplies one consensus structure for each sub-family. To distinguish the n different sub-families in the input file, one must prefix the sequence names and the multiple SS_cons lines for the consensus structures with an arbitrary sub-family name, followed by an "@" delimiter character. Here, for the purpose of exposition, we use colours instead.
Let us re-use the previous example alignment of Figure 5, which is here sub-divided into the red sub-family of the first two sequences and a purple sub-family holding the remaining three sequences (n = 2), see Panel A) in Figure 8. The consensus structure for the red sub-family SS red cons remains unchanged. To honor the mutations in column 7 for the purple sub-family, the consensus structure SS purple cons is slightly different, i. e. the base-pair is converted into two unpaired bases.
The SS cons rows in the alignment must represent a correct multiple structure alignment. This condition is not easily checked by a human curator, and our approach applies such a check to the input.

Overview of the aCM generation process
The construction of an aCM (greenish box in Figure 1) follows the ideas of constructing a classical CM with ALTERNAL. The task becomes more difficult, because we not only have to deal with several consensus structures SS i cons yielding different guide trees gt i (indicated by the white box in Figure 1), but we also have to combine all n of them into one ambivalent guide forest F. Once F is found, generation of the topology defining grammar is done by evaluating F with a corresponding generating algebra A aCFG . In the following sections, we give explanations about processes in aCM that have to be modified compared to ALTERNAL:   For simplicity, we omit terminal symbols for bases and skip-nodes -described below -in the trees. That is why subscript 3, pointing to the "insertion"-column, does not appear in the guide trees. The G 5 -style CFG of the ambivalent model is shown in C.

Check for compatibility of consensus structures
Two requirements are imposed on the structures in the input alignment: a) base-pair persistence and b) global nesting. Taking the two requirements together, we call this compatibility of consensus structures. The base-pair persistence property demands that if MSA columns k and l are paired in consensus structure i those two positions must either be paired with each other in all other consensus structures, or may be unpaired, or maybe deleted. But neither k nor l are allowed to form pairs with other alignment columns than each other. For example, we think that the two consensus structures <<- * > * * > <<- * >--> can explain a common evolution up to the point where two additional unpaired bases are inserted into the upper consensus. The double gapped column --is allowed to enable inclusion of rare sequences into MSA, which holds insertions relative to both consensus structures. But we disallow alternative base-pair partners, like << * * >> < * < * >> .
Base-pair slippage in this example must be modeled via insertions.
The global nesting property ensures that the multiple consensus structures do not exhibit crossing base pairs. To exclude pseudoknots in a singe secondary structure, every two base-pairs of the structure must either be adjacent to each other or be nested within each other. With several structures, it is not sufficient that each structure satisfies this criterion. We transfer this property as global nesting to the alignment of n consensus structures by demanding that the union of all base-pairs from all n consensus structures must be either adjacent or nested.
To check if all n consensus structures satisfy base-pair persistence and global nesting, we parse every n 2 pairs of two consensus structures with the two-track ADP grammar G ali_SS , see Figure 9. Parsing one pair of consensus structures of length m with G ali_SS requires a run-time of O(m 3 ). Thus, checking all n 2 pairs needs O(m 3 · n 2 ) time. Should one consensus structure pair be un-parsable by G ali_SS , an error message is issued and the construction task is aborted.

Parsing individual guide trees
As in classical CMs, a guide tree rules the topology of the aCM to be built. For aCMs, we individually infer one guide tree for each consensus structures. First, columns containing a majority of gaps are removed. This insertion masking process operates individually on each subfamily, the resulting SS i match can have different lengths. For example, SS purple match is one position shorter than SS red match , due to a majority of gaps in column 7 for the three purple sequences. The remedy to remain the same alignment coordinates in the different consensus structures is the introduction of gaps in SS i match . This is accomplished by parsing SS i match with a gapped version of G 5s , see Figure 10. The resulting guide trees for both consensus structures of the example are depicted in Panel B) of Figure 8.

Ambivalent guide forest
The ambivalent guide forest is a tree that encodes several guide trees. Common parts of the guide trees are shared. Where the guide trees diverge, the ambivalent guide forest contains an extra fork node, which has the diverging substructures from different guide trees as its subtrees. We need to merge all individual guide trees gt i from the G 5s -parsing process in a progressive fashion into one ambivalent guide forest F. The progressive merge process operates top-town.
Two guide trees for compatible consensus structures like <> * * can differ directly at their root nodes, immediately requiring a fork node. In general, the ambivalent guide forest places the fork nodes as low as possible, to keep the aCM -and thus run-time of the aCM -as small as possible. During construction, we also have to make sure that no unseen combinations become possible, e. g. << * > * --> <--- * <>> shall not not allow for model structure The overall idea when merging two guide trees is to overlay them and identify identical parts. When both guide trees start to diverge, a fork for both alternatives is be introduced in F. Identical parts are identified by simultaneously traversing both guide trees top-down. The coupled traversal starts at both root nodes, e. g. at the red pair 1 and the purple pair 1 of Panel B in Figure 8. If the current nodes of both guide trees are of the same type (nil, pair, open or skip) and refer to the same alignment positions, a new node of this type is introduced in F (right hand side pair 1 in Figure 8) and the coupled traversal is simultaneously applied to all children. If either the types or the alignment positions of the nodes under consideration differ (e. g. red pair 6 and purple open 6 ), the complete sub-trees, which are rooted by these nodes, are added to F under a fork node.
An aCM should be able to hold more than two consensus structures. Thus, it is necessary to progressively add further guide trees to F. The coupled traversal must be modified in the sense that a node of the guide tree is compared not to a single node in F, but to all guide trees already encoded in F, only inducing a fork if it brings in a new subtree.
The ambivalent guide forest for the red and purple guide trees of the example is depicted on the right hand side of Panel B) in Figure 8. Nodes shared by both guide trees are colored in black. The right child of pair 2 is not a Figure 10 Grammar G 5s to parse a gapped consensus structure. It is identical to G 5 (Figure 3), but has a forth alternative production rule to parse gap characters _. single tree, but a forest for the divergent red and purple sub-trees.
The more similar a set of guide trees are, the larger are those parts of the trees that can be jointly represented in the F. In the worst case, there are no common parts in all gt at all. This means that n individual guide trees, each with a number of leaves that is linearly proportional to m, will cause a F with n·m nodes. Depth-first traversal of such F requires O(n · m) time and has to be repeated during the progressive construction of F itself n-times. Thus, the worst-case overall run-time for merging n guide trees into one ambivalent guide forest is O(n 2 · m).
The construction of the ambivalent guide forest leaves room for improvement by recognizing shared substructures. The multi-structure parsing of Saffarian et al. [5] makes use of shared subgrammars for shared substructures. This keeps the grammar smaller and avoids extra tables in the CYK-type parser. Such sharing works for combinatorial matching as well as for energy minimization, as all instances of a shared subgrammar undergo the same scoring. At first glance, it appears not to be applicable with stochastic models, because shared subgrammars have their parameters trained from different sub-families. Scoring shared substructures in different ways, of course, requires separate dynamic programming tables. However, in practice parameters may be tied together in the training phase anyway, or may come out of the training quite similar. In this situation, subgrammar sharing may be a good pragmatic decision. We leave this topic for future research.

Provide indices in the ambivalent guide forest
We have two objectives for the design of aCM topologies: On the one hand, we want to enable alternative parses through the aCM, reflecting the ambivalent consensus structures. We have to take care that transitions are forbidden that are not indicated by the set of consensus structures: << * > * --> <--- * <>> shall not impose model structure <--- * -->. We do so by using ambivalent guide forests, which introduce branches as soon as two subtrees differ. This effects the allowed transitions within the model, i. e. the grammar. On the other hand, an aCM should capture as much shared alignment parts as possible: The ambivalent guide forest for * * <-> * * << * >> branches into two independent sub-trees for * <-> * and << * >>. However, the base-pair from position 3 to 5 is shared between both consensus structures. Counting the emitted nucleotides should be in a sub-family combined fashion for those positions, which are torn apart by the ambivalent guide forest. To combine both objectives, we use two types of indices: One for the non-terminals of the grammar, affirming correct transitions and another one for the CYK algebra to share common emission probabilities. The grammar indices are given as superscripts left of the nodes for the example in Panel B) for Figure 8, while algebra indices are subscripts right of the nodes. Please note that grammar indices are unique. Algebra indices can be shared, e. g. O 6 and P 6 . By construction and using common alignment coordinates the algebra index is directly inherited from the individual guide trees. To obtain grammar indices, we need to distribute a new set of successive numbers to the ambivalent guide forest in a depth-first like strategy. The indexing of a list of ambivalent guide forests starts with depth-first indexing of the complete first tree and then continues with the rest of the list.

Generate aCM grammar
The final step to obtain the aCM grammar is to evaluate the ambivalent guide forest with the function gen, given in Figure 11. A simple structural recursion on F performs this evaluation and returns the family model grammar. An example grammar is illustrated in Panel C) of Figure 8.

Evaluation
We now evaluate aCMs by considering several RNA families whose structural variation can only be expressed unsatisfactorily in RFAM. We take a look at the tRNA, U5 spliceosomal RNA, RNAse-P, and IRES families. The tRNA application is discussed in detail, where we also compare to implementing families as two separate models with classical CMs. For the others, we mainly report the results.

The tRNA family as an aCM
Let us come back to the initial example of the tRNA family from RFAM (ID: RF00005, release 10.1). We subdivide the 967 sequences of the seed alignment with respect to the presence or absence of the variable fifth helix. Thus, we obtain the "cloverleaf " sub-family with 820 members and the famous cloverleaf as its consensus structure SS cloverleaf , as stored in RFAM, as well as the sub-family "varloop", which holds the remaining 147 sequences. The consensus structure of "varloop" is better described by SS varloop , which contains the additional helix.

Figure 11
Algebra like function gen that evaluates a list of ambivalent guide forests into a set of grammar rules. Rules with identical indexed non-terminals will be combined as alternative right hand sides. The function g(x) returns the grammar index of the root node of an ambivalent guide forest x. Index tuple (a, g) holds algebra and grammar index, respectively. Remember that xs and ys are lists of ambivalent guide forests.
The performance of these models is shown in Figure 12. The four blue shaded columns present the results when matching all 967 members of the family to the four different CMs via the CYK algorithm. The lower part of the figure informs about the input for the model creation. The box depicts the input alignment, the curve represents the consensus structure. "cloverleaf " sequences or consensus structures are addressed in green. "varloop" components are red. There are three box-plots in each column: The green box-plot corresponds to those bit-scores that stem from sequences of the sub-family "cloverleaf " and the red box-plot is exclusively for the "varloop" sequences. The blue box-plot is the union of the two sub-families and represents all bit-scores.
The median bit-score (brown horizontal line) for all tRNAs with the original model (leftmost blue shaded column: "all cloverleaf ") is ≈ 52.0. When we differentiate between both sub-families, we see that in fact the "varloop" sequences (red box-plot) get penalized for the additional bases of the variable loop. Their median (≈ 40.1) is significantly lower than the median of the green "cloverleaf " group (≈ 55.2). Our second CM ("all varloop") was constructed from a different consensus structure input (SS varloop instead of SS cloverleaf ), but due to the gap column masking process it gives an identical guide-tree when compared to the original "all cloverleaf " model. And indeed, we do not observe any changes in the bit-scores.
Different SS match and guide-trees can only be achieved by also using different parts of the MSA, as done for the last two models "only cloverleaf " and "only varloop". Training only with the cloverleaf sub-family results in no significant shift of the overall bit-scores (blue box-plot); median is reduced by ≈ 0.3 bits. A closer look reveals that the "varloop" sequences, which are now left out for training, perform even worse (median decreases by ≈ 4.3 bits), while the "cloverleaf " sequences get a tiny bonus of ≈ 0.2 bits for their median. Good scores for "varloop" sequences can be obtained if we use the "only varloop" model. Their median is now at ≈ 53.3 bits. As to be expected, performance for the "cloverleaf " majority of the sequences nosedives (median at ≈ 17.0 bits).
Should we be able to a priori use the correct sub-model for each sequence, or run both models in every case and cherry-picking the better score, we would gain the theoretical median score of ≈ 55.0 bits (magenta horizontal line), which is ≈ 3.0 bits better than the original model. Splitting the family into two separate sub-families seems to be worth it. This summarizes what can be achieved with tRNA by using classical CMs.
Applying our aCM approach relieves the creator to artificially decompose her data into two or more sub-families in order to suit the underlying scoring algorithm. The relationship of all sequences can be kept in one alignment, now enriched by sub-family annotations and additional consensus structures. With this evaluation setup, we expect a properly built aCM at best to return the same bit-scores for the sequences of the various sub-families as a cherry picking of the results from several sub-family specific CMs would do.
The right green shaded column in Figure 12 shows the results for such an aCM for the tRNA example. It is built from both consensus structures (SS cloverleaf and SS varloop ) and trained with the total alignment (all 967 sequences). A rough inspection attests the targeted effect: A single model can both lift the "varloop" sequences to a niveau close to the overall median and simultaneously keep the good scores for the "cloverleaf " group.
Surprisingly, the aCM is doing even better than the theoretical cherry picking. As one can see by examination of the red and green box-plots in the green shaded column of Figure 1, not only the scores for the "varloop" sequences are lifted to a reasonable amount, also the "cloverleaf " sequences benefit from this information enrichment. The median score of the aCM is ≈ 55.9 bits (purple horizontal line) and thus ≈ 0.9 bits better than the theoretical optimum. The explanation is that aCMs contain more information than a set of sub-family specific CMs. Common sub-structures stronger deviate from the background model and predetermined sub-structures do not get penalized. The median score of negative sequences between the original CM and the aCM raises by +1.7 bits (data not shown). Thus, the discriminatory power (as the difference between median bit score of positive and negative test cases) can be increased by 2.1 bits, which means that even those true candidates can get positive scores, which fall below the threshold of an individual CM.

U5 spliceosomal RNA as an aCM
An aCM can also be constructed for more than two subfamilies: The U5 spliceosomal RNA is a widespread family. Its concrete secondary structure changes over the different taxa. We used the original alignment from [23,24] identified six taxa, grouped the sequences, and defined according consensus structures. Figure 13 is the result of the same kind of analysis as shown in Figure 12; negative, i. e. di-nucleotide shuffled sequences, are included here. In conclusion, the mean bit-score could be increased by 27%, compared to the original CM, while bit-scores for negative sequences remain low, thus improving discriminatory power.
The tRNA and U5 RNA families illustrate that the concept of aCMs can protect real families of being artificially torn apart and thus preserve existing relations. We might even render already conducted break-ups unnecessary and merge separate families of an RFAM clan.

Merging RNAse-P RNA families
RNAse-P RNA is a difficult family. Despite sharing a significant structural core, some RNAs may differ locally   to such a degree that their representation as one multiple sequence alignment would lead to an unmanageable "horizontal expansion", i. e. a large proportion of gaps, as reported in [25]), and has led the curators of RFAM to construct sub-alignments, organized in clans. One example is the RNAse-P clan, which is represented in RFAM by six individual families. The success of a joint aCM for RNAse-P heavily depends on the quality of an unifying alignment, which must capture similar regions and allowing for local structural alternatives. For a preliminary evaluation, we resort to the expertise of the authors of [26], who provide an semi-automatically generated RNAse-P alignment for a subset of current RFAM sequences in the clan. The sequences are organized in four sub-groups, each with its own consensus structure. From this alignment, the aCM is generated. The results are shown in Figure 14.
While the median bit-score of aCMs is below the theoretical optimum for cherry-picking from individual CMs, it is much better than median bit-scores for any combined traditional CM. The discriminatory power is improved by ≈ 58 bits.
There is much space for further improvement for RNAse-P, since the used alignment has large horizontal expansions. Of the 1,669 alignment columns in total, 979 columns are masked as gap-columns in all four subgroups and there are only 91 positions where all subgroups agree in having a match-column.

Merging IRES families
A second use-case for the merging capabilities of aCM can be the 27 internal ribosome entry site (IRES) families of RFAM. We determined RF00061 and RF00209 as the two closest IRES families, by computing their link-score with CMCOMPARE [27]. We then structurally aligned their consensus structure and sequence with RNAFORESTER and finally mapped the individual alignment columns to a unifying alignment with two sub-groups. The results of our evaluation setup are given in Figure 15.
Despite the poor quality of the completely automatically created alignment, the according aCM performs as well as a theoretical cherry picking of both single families.

Conclusion
The RFAM database contains several families that cross the limitations of a single consensus structure. The new concept of an RFAM "clan" is a set of closely related families. It seems to be a workaround to cope with several consensus structures within one former family, which is now torn apart. Our evaluation shows that a segmentation of a family impedes homology analysis. Based on our implementatio and evaluation of aCMs, we suggest to extend present practice of RNA family modeling to hold multiple consensus structures to keep up with biologically motivated family definitions.

Additional file
Additional file 1: Supplementary material.

Competing interests
The authors declare that they have no competing interests.