Inverse folding of RNA pseudoknot structures

Background RNA exhibits a variety of structural configurations. Here we consider a structure to be tantamount to the noncrossing Watson-Crick and G-U-base pairings (secondary structure) and additional cross-serial base pairs. These interactions are called pseudoknots and are observed across the whole spectrum of RNA functionalities. In the context of studying natural RNA structures, searching for new ribozymes and designing artificial RNA, it is of interest to find RNA sequences folding into a specific structure and to analyze their induced neutral networks. Since the established inverse folding algorithms, RNAinverse, RNA-SSD as well as INFO-RNA are limited to RNA secondary structures, we present in this paper the inverse folding algorithm Inv which can deal with 3-noncrossing, canonical pseudoknot structures. Results In this paper we present the inverse folding algorithm Inv. We give a detailed analysis of Inv, including pseudocodes. We show that Inv allows to design in particular 3-noncrossing nonplanar RNA pseudoknot 3-noncrossing RNA structures-a class which is difficult to construct via dynamic programming routines. Inv is freely available at http://www.combinatorics.cn/cbpc/inv.html. Conclusions The algorithm Inv extends inverse folding capabilities to RNA pseudoknot structures. In comparison with RNAinverse it uses new ideas, for instance by considering sets of competing structures. As a result, Inv is not only able to find novel sequences even for RNA secondary structures, it does so in the context of competing structures that potentially exhibit cross-serial interactions.


Introduction
Pseudoknots are structural elements of central importance in RNA structures [1], see Figure 1. They represent cross-serial base pairing interactions between RNA nucleotides that are functionally important in tRNAs, RNaseP [2], telomerase RNA [3], and ribosomal RNAs [4]. Pseudoknot structures are being observed in the mimicry of tRNA structures in plant virus RNAs as well as the binding to the HIV-1 reverse transcriptase in in vitro selection experiments [5]. Furthermore basic mechanisms, like ribosomal frame shifting, involve pseudoknots [6].
Despite them playing a key role in a variety of contexts, pseudoknots are excluded from large-scale computational studies. Although the problem has attracted considerable attention in the last decade, pseudoknots are considered a somewhat "exotic" structural concept. For all we know [7], the ab initio prediction of general RNA pseudoknot structures is NP-complete and algorithmic difficulties of pseudoknot folding are confounded by the fact that the thermodynamics of pseudoknots is far from being well understood.
As for the folding of RNA secondary structures, Waterman et al [8,9], Zuker et al [10] and Nussinov [11] established the dynamic programming (DP) folding routines. The first mfe-folding algorithm for RNA secondary structures, however, dates back to the 60's [12][13][14]. For restricted classes of pseudoknots, several algorithms have been designed: Rivas and Eddy [15], Dirks and Pierce [16], Reeder and Giegerich [17] and Ren et al [18]. Recently, a novel ab initio folding algorithm Cross has been introduced [19]. Cross generates minimum free energy (mfe), 3-noncrossing, 3-canonical RNA structures, i.e. structures that do not contain three or more mutually crossing arcs and in which each stack, i.e. sequence of parallel arcs, see eq. (1), has size greater or equal than three. In particular, in a 3-canonical structure there are no isolated arcs, see Figure 2.

k-noncrossing, s-canonical RNA pseudoknot structures
Let us turn back the clock: three decades ago Waterman et al. [25], Nussinov et al. [11] and Kleitman et al. in [26] analyzed RNA secondary structures. Secondary structures are coarse grained RNA contact structures, see Figure 3.
RNA secondary structures as well as RNA pseudoknot structures can be represented as diagrams, i.e. labeled graphs over the vertex set [n] = {1, ..., n} with vertex degrees ≤ 1, represented by drawing its vertices on a horizontal line and its arcs (i, j) (i < j), in the upper half-plane, see Figure 4 and Figure 1. Given an arc (i, j) we refer to (j -i) as its arc-length.
RNA secondary structures exhibit no crossings in their diagram representation, see Figure 3 and Figure 4, and are therefore 2-noncrossing diagrams satisfying some minimum arc-length condition. An RNA pseudoknot structure is therefore a k-noncrossing diagram for some k satisfying some minimum arc-length condition.
A structure in which any stack has at least size s is called s-canonical, where a stack of size s is a sequence of "parallel" arcs of the form .
is called a stem of length r, see Figure 6. As a natural generalization of RNA secondary structures k-noncrossing RNA structures [27][28][29] were introduced. A k-noncrossing RNA structure of length n is k-noncrossing diagram over [n] without arcs of the form (i, i + 1). In the following we assume k = 3, i.e. in the diagram representation there are at most two mutually crossing arcs, a minimum arc-length of four and a minimum stack-size of three base pairs. The notion k-noncrossing stipulates that the complexity of a pseudoknot is related to the maximal number of mutually crossing bonds. Indeed, most natural RNA pseudoknots are 3-noncrossing [30].

Neutral networks
Before considering an inverse folding algorithm into specific RNA structures one has to have at least some rationale as to why there exists one sequence realizing a given target as mfe-configuration. In fact this is, on the level of entire folding maps, guaranteed by the combinatorics of the target structures alone. It has been shown in [31], that the numbers of 3-noncrossing RNA pseudoknot structures, satisfying the biophysical constraints grows asymptotically as c 3 n -5 2.03 n , where c 3 >0 is some explicitly known constant. In view of the central limit theorems of [32], this fact implies the existence of extended (exponentially large) sets of sequences that all fold into one 3-noncrossing RNA pseudoknot structure, S. In other words, the combinatorics of 3-noncrossing RNA structures alone implies that there are many sequences mapping (folding) into a single structure. The set of all such sequences is called the neutral network of the structure S [33,34], see Figure 7. The term "neutral network" as opposed to "neutral set" stems from giant component results of random induced subgraphs of ncubes. That is, neutral networks are typically connected in sequence space.
By construction, all the sequences contained in such a neutral network are all compatible with S. That is, at any two positions paired in S, we find two bases capable of forming a bond (A-U, U-A, G-C, C-G, G-U and U-G), see Figure 8. Let s' be a sequence derived via a point-mutation of s. If s′ is again compatible with S, we call this mutation "compatible". Let where the u h denotes the unpaired nucleotides and the p h = (s i , s j ) denotes base pairs, respectively, see Accordingly, there are two types of compatible neighbors in the sequence space u-and p-neighbors: a uneighbor has Hamming distance one and differs exactly by a point mutation at an unpaired position. Analogously a p-neighbor differs by a compensatory base pair-mutation, see Figure 9.  We display a 4-noncrossing diagram containing the three mutually crossing arcs (1,7), (4,9), (5, 11) (drawn in red).
Note, however, that a p-neighbor has either Hamming distance one (G-C ↦ G-U) or Hamming distance two (G-C ↦ C-G). We call a u-or a p-neighbor, y, a compatible neighbor. In light of the adjacency notion for the set of compatible sequences we call the set of all sequences folding into S the neutral network of S. By construction, the neutral network of S is contained in C [S]. If y is contained in the neutral network we refer to y as a neutral neighbor. This gives rise to consider the compatible and neutral distance of the two sequences, denoted by C(s, s′) and N(s, s′). These are the minimum length of a C[S]-path and path in the neutral network between s and s′, respectively. Note that since each neutral path is in particular a compatible path, the compatible distance is always smaller or equal than the neutral distance.
In this paper we study the inverse folding problem for RNA pseudoknot structures: for a given 3-noncrossing target structure S, we search for sequences from C[S], that have S as mfe configuration.
They all generate via a local search routine iteratively sequences, whose structures have smaller and smaller distances to a given target. Here the distance between Figure 6 Stems. A stem composed by a sequence of three nested stacks. Note that respective stacks only have to be separated by isolated nucleotides on either the left hand side or the right hand side but not necessarily both.

Figure 7
Neutral network in sequence space. We display sequence space (left) and structure space (right) as grids. We depict a set of sequences that all fold into a particular structure. Any two of these sequences are connected by a red path. The neutral network of this fixed structure consists of all sequences folding into it and is typically a connected subgraph of sequence space. two structures is obtained by aligning them as diagrams and counting "0", if a given position is either unpaired or incident to an arc contained in both structures and "1", otherwise, see Figure 10.
One common assumption in these inverse folding algorithms is, that the energies of specific substructures contribute additively to the energy of the entire structure. Let us proceed by analyzing the algorithms.
RNAinverse is the first inverse-folding algorithm that derives sequences that realize given RNA secondary structures as mfe-configuration. In its initialization step, a random compatible sequence s for the target T is  generated. Then RNAinverse proceeds by updating the sequence s to s′, s′′ ... step by step, minimizing the structure distance between the mfe structure of s′ and the target structure T. Based on the observation, that the energy of a substructure contributes additively to the mfe of the molecule, RNAinverse optimizes "small" substructures first, eventually extending these to the entire structure. While optimizing substructures, RNAinverse does an adaptive walk in order to decrease the structure distance. In fact, this walk is based entirely on random compatible mutations.
RNA-SSD inverse folds RNA secondary structures by initializing sequences using three specific subroutines. In the first a particular compatible sequence is generated, where non-complementary nucleotides to bases adjacent to helical regions are assigned. In the second nucleotides located in unpaired positions as well as helical regions are assigned at random, using specific (non-uniform) probabilities. The third routine constitutes a mechanism for minimizing the occurrence of undesired but favourable interactions between specific sequence segments. Following these subroutines, RNA-SSD derives a hierarchical decomposition of the target structure. It recursively splits the structure and thereby derives a binary decomposition tree rooted in T and whose leaves correspond to T-substructures. Each non-leaf node of this tree represents a substructure obtained by merging the two substructures of its respective children. Given this tree, RNA-SSD performs a stochastic local search, starting at the leaves, subsequently working its way up to the root.
INFO-RNA constructs sequences folding into a given secondary structure by employing a dynamic programming method for finding a well suited initial sequence. This sequence has a lowest energy with respect to the T. Since the latter does not necessarily fold into T, (due to potentially existing competing configurations) INFO-RNA then utilizes an improved (relative to the local search routine used in RNAinverse) stochastic local search in order to find a sequence in the neutral network of T. In contrast to RNAinverse, INFO-RNA allows for increasing the distance to the target structure. At the same time, only positions that do not pair correctly and positions adjacent to these are examined.

Cross
Cross is an ab initio folding algorithm that maps RNA sequences into 3-noncrossing RNA structures. It is guaranteed to search all 3-noncrossing, s-canonical structures and derives some (not necessarily unique),  loop-based mfe-configuration. In the following we always assume s ≥ 3. The input of Cross is an arbitrary RNA sequence s and an integer N. Its output is a list of N 3-noncrossing, s-canonical structures, the first of which being the mfe-structure for s. This list of N structures (C 0 , C 1 , ..., C N-1 ) is ordered by the free energy and the first list-element, the mfe-structure, is denoted by Cross(s). If no N is specified, Cross assumes N = 1 as default.
Cross generates a mfe-structure based on specific loop-types of 3-noncrossing RNA structures. For a given structure S, let a be an arc contained in S (S-arc) and denote the set of S-arcs that cross a by A S ( )  . For two arcs a = (i, j) and a' = (i', j'), we next specify the partial order "≺" over the set of arcs: All notions of minimal or maximal elements are understood to be with respect to ≺. An arc a 3-noncrossing diagrams exhibit the following four basic loop-types: where (i, j) is an arc and [i, j] is an interval, i.e. a sequence of consecutive, isolated vertices (i, i + 1, ..., j -1, j).
(2) An interior-loop, is a sequence (3) A multi-loop, see Figure 11 [19], is the closed structure formed by denotes the substructure over the interval [ω h , τ h ], subject to the condition that if all these substructures are simply stems, then there are at least two of them, see Figure 6.
A pseudoknot, see Figure 12[19], consists of the following data: (P1) A set of arcs where i 1 = min{i h } and j t = max{j h }, such that (i) the diagram induced by the arc-set P is irreducible, i.e. the dependency-graph of P (i.e. the graph having P as vertex set and in which a and a′ are adjacent if and only if they cross) is connected and (ii) for each (i h , j h ) P there exists some arc b (not necessarily contained in P) such that (i h , j h ) is minimal b-crossing.
Having discussed the basic loop-types, we are now in position to state Theorem 1 Any 3-noncrossing RNA pseudoknot structure has a unique loop-decomposition [19]. Figure 13 illustrates the loop decomposition of a 3noncrossing structure.
In order to discuss the organization of Cross, we introduce the basic idea behind motifs and skeleta, combinatorial structures used in the folding algorithm.
A motif is a 3-noncrossing structure, having only ≺-maximal stacks of size exactly s, i.e. no stacks nested in other stacks, see Figure 14. Despite that motifs can exhibit complicated crossings, they can be inductively generated. A skeleton, S is a k-noncrossing structure such that • its core, c(S) has no noncrossing arcs and • its L-graph, L(S) is connected.
Here the core of a structure, c(S), is obtained by collapsing its stacks into single arcs (thereby reducing its length) and the graph L(S) is obtained by mapping arcs into vertices and connecting any two if they cross in the diagram representation of S, see Figure 15. A skeleton reflects all cross-serial interactions of a structure.
Having introduced motifs and skeleta we can proceed by discussing the general idea of Cross. The algorithm generates 3-noncrossing RNA structure "from top to bottom" via the following three subroutines: I (SHADOW): In this routine we generate all maximal stacks of the structure. Note that a stack is maximal with respect to ≺ if it is not nested in some other stack. This is derived by "shadowing" the motifs, i.e. their s-stacks are extended "from top to bottom". II (SKELETONBRANCH): Given a shadow, the second step of Cross consists in generating, the skeletatree. The nodes of this tree are particular 3-noncrossing structures, obtained by successive insertions of stacks. Intuitively, a skeleton encapsulates all cross-serial arcs that cannot be recursively computed. Here the tree complexity is controlled via limiting the (total) number of pseudoknots.

III (SATURATION):
In the third subroutine each skeleton is saturated via DP-routines. After the saturation the mfe-3-noncrossing structure is derived. Figure 16 provides an overview on how the three subroutines are combined.

The algorithm
The inverse folding algorithm Inv is based on the ab initio folding algorithm Cross. The input of Inv is the target structure, T. The latter is expressed as a character In Algorithm 7.1, we present the pseudocodes of algorithm Inv. After validation of the target structure (lines 2 to 5 in Algorithm 7.1), similar to INFO-RNA, Inv constructs an initial sequence and then proceeds by a stochastic local search based on the loop decomposition of the target. This sequence is derived via the routine ADJUST-SEQ. We then decompose the target structure into loops and endow these with a linear order.   According to this order we use the routine LOCAL-SEARCH in order to find for each loop a "proper" local solution.

ADJUST-SEQ
In this section we describe Steps 2 and 3 of the pseudocodes presented in Algorithm 7.1. The routine MAKE-START, see line 8, generates a random sequence, start, which is compatible to the target, with uniform probability.
We then initialize the variable seq min via the sequence start and set the variable d = + ∞, where d denotes the structure distance between Cross(seq min ) and T.
Given the sequence start, we construct a set of potential "competitors", C, i.e. a set of structures suited as folding targets for start. In Algorithm 7.2 we show how to adjust the start sequence using the routine ADJUST-SEQ. Lines 3 to 36 of Algorithm 7.2, contain a Forloop, executed at most n / 2 times. Here the looplength n / 2 is heuristically determined.
For all computer experiments setting the Cross-parameter N = 50, the subroutine executed in the loop-body consists of the following three steps.
Step I. Generating C 0 (l i ) via Cross. Suppose we are in the ith step of the For-loop and are given the sequence l i-1 where l 0 = start. We consider Cross(l i-1 , N), i.e. the list of suboptimal structures with respect to l i-1 ,

Cross
Otherwise we do not update seq min and go directly to Step II.
Step II. The competitors. We introduce a specific procedure that "perturbs" arcs of a given RNA pseudoknot structure, S. Let a be an arc of S and let l(a), r(a) denote the start-and end-point of a. A perturbation of a is a procedure which generates a new arc a', such that   Clearly, there are nine perturbations of any given arc a (including a itself), see Figure 17.
We proceed by keeping a, replacing the arc a by a nontrivial perturbation or remove a, arriving at a set of ten structures ν(S, a).
Now we use this method in order to generate the set C 1 (l i-1 ) by perturbing each arc of each structure This construction may result in duplicate, inconsistent or incompatible structures. Here, a structure is inconsistent if there exists at least one position paired with more than one base, and incompatible if there exists at least one arc not compatible with l i-1 , see Figures 18 Figure 15 Skeleton and its L-graph. We display a skeleton (left) and its L-graph (right). Figure 16 An outline of Cross. For illustration purposes we assume here s = 1. The routines SHADOW, SKELETONBRANCH and SATURATION are depicted. Due to space limitations we only represent a few select motifs and for the same reason only one of the motifs displayed in the first row is extended by one arc (drawn in blue). Furthermore note that only motifs with crossings give rise to nontrivial skeleton-trees, all other motifs are considered directly as input for SATURATION. and 19. Here compatibility is understood with respect to the Watson-Crick and G-U base pairing rules. Deleting inconsistent and incompatible structures, as well as those identical to the target, we arrive at the set of competitors, Step III. Mutation. Here we adjust l i-1 with respect to T as well as the set of competitors, C(l i-1 ) derived in the previous step. Suppose   9). The pair G-C retains the compatibility to (5,9), but is incompatible to (5,10)). By Figure 21 we show feasibility of this step. 3. end-point: If 0 <p(T, w) <w, then by construction the nucleotide has already been considered in the previous step. . Note that the above mutation steps heuristically decrease the structure distance. However, the resulting sequence is not necessarily incompatible to all competitors. For instance, consider a competitor C h whose arcs are all contained T. Since l i is compatible with T, l i is compatible with C h . Since competitors are obtained from suboptimal folds such a scenario may arise.
In practice, this situation represents not a problem, since these type of competitors are likely to be ruled out by virtue of the fact that they have a mfe larger than that of the target structure.
Accordingly we have the following situation, competitors are eliminated due to two, equally important criteria: incompatibility as well as minimum free energy considerations.
If the distance of Cross(l i ) to T is less than or equal to d min + 5, we return to Step I (with l i ). Otherwise, we repeat Step III (for at most 5 times) thereby generating   is minimal. The procedure ADJUST-SEQ employs the negative paradigm [16] in order to exclude energetically close conformations. It returns the sequence seq middle which is tailored to realize the target structure as mfe-fold.

DECOMPOSE and LOCAL-SEARCH
In this section we introduce two the routines, DECOM-POSE and LOCAL-SEARCH. The routine DECOM-POSE partitions T into linearly ordered energy independent components, see Figure 13 and Section 2.1. LOCAL-SEARCH constructs iteratively an optimal sequence for T via local solutions, that are optimal to certain substructures of T.
DECOMPOSE: Suppose T is decomposed as follows, where the T w are the loops together with all arcs in the associated stems of the target.
We define a linear order over B as follows: T w <T h if either 1. T w is nested in T h , or 2. the start-point of T w precedes that of T h .
In Figure 22 we display the linear order of the loops of the structure shown in Figure 13.
Next we define the interval projecting the loop T w onto the interval [l(T w ), r(T w )] and b w = [l′, r′] ⊃ a w , being the maximal interval consisting of a w and its adjacent unpaired consecutive nucleotides, see Figure 13. Given two consecutive loops T w <T w + 1 , we have two scenarios: • either b w and b w+1 are adjacent, see b 5 and b 6 in Figure 22, • or b w ⊆ b w + 1 , see b 1 and b 2 in Figure 22.  1 , b 1 , c 1 , ..., a m' , b m' , c m' . If there are no unpaired nucleotides adjacent to a w , then a w = b w and we simply delete all such b w . Thereby we derive the sequence of intervals I 1 , I 2 , ..., I m . In Figure 23 we illustrate how to obtain this interval sequence: here the target decomposes into the loops T 1 , T 2 and we have I 1 = [3,5], I 2 = [3,6], I 3 = [2,9], and I 4 = [1,10].
LOCAL-SEARCH: Given the sequence of intervals I 1 , I 2 , ..., I m . We proceed by performing a local stochastic search on the subsequences seq seq seq … (initialized via seq = seq middle and where s| [x, y] = s x s x + 1 ... s y ). When we perform the local search on seq I w | , only positions that contribute to the distance to the target, see Figure 10, or positions adjacent to the latter, will be altered. We use the arrays U 1 , U 2 to store the unpaired and paired positions of T. In this process, we allow for mutations that increase the structure distance by five with probability 0.1. The latter parameter is heuristically determined. We iterate this routine until the distance is either zero or some halting criterion is met.

Discussion
The main result of this paper is the presentation of the algorithm Inv, freely available at http://www.combinatorics.cn/cbpc/inv.html Its input is a 3-noncrossing RNA structure T, given in terms of its base pairs (i 1 , i 2 ) (where i 1 <i 2 ). The output of Inv is an RNA sequences s = (s 1 s 2 ...s n ), where s h {A, C, G, G} with the property Cross(s) = T, see Figure 24.     The core of Inv is a stochastic local search routine which is based on the fact that each 3-noncrossing RNA structure has a unique loop-decomposition, see Theorem 1 in Section 2.1. Inv generates "optimal" subsequences and eventually arrives at a global solution for T itself. Inv generalizes the existing inverse folding algorithm by considering arbitrary 3-noncrossing canonical pseudoknot structures. Conceptually, Inv differs from INFO-RNA in how the start sequence is being generated and the particulars of the local search itself.
As discussed in the introduction it has to be given an argument as to why the inverse folding of pseudoknot RNA structures works. While folding maps into RNA secondary structures are well understood, the generalization to 3-noncrossing RNA structures is nontrivial. However the combinatorics of RNA pseudoknot structures [27,28,38] implies the existence of large neutral networks, i.e. networks composed by sequences that all fold into a specific pseudoknot structure. Therefore, the fact that it is indeed possible to generate via Inv sequences contained in the neutral networks of targets against competing pseudoknot configurations, see Figure  24 and Figure 25 confirms the predictions of [31].
An interesting class are the 3-noncrossing nonplanar pseudoknot structures. A nonplanar pseudoknot structure is a 3-noncrossing structure which is not a bi-secondary structure in the sense of Stadler [30]. That is, it cannot be represented by noncrossing arcs using the  upper and lower half planes. Since DP-folding paradigms of pseudoknots folding are based on gap-matrices [15], the minimal class of "missed" structures (given the implemented truncations) are exactly these, nonplanar, 3-noncrossing structures. In Figure 26 we showcase a nonplanar RNA pseudoknot structure and 3 sequences of its neutral network, generated by Inv.
As for the complexity of Inv, the determining factor is the subroutine LOCAL-SEARCH. Suppose that the target is decomposed into m intervals with the length ℓ 1 , ...., ℓ m . For each interval, we may assume that line 2 of LOCAL-SEARCH runs for f h times, and that line 14 is executed for g h times. Since LOCAL-SEARCH will stop (line 4) if T start = T (line 3), the remainder of LOCAL-SEARCH, i.e. lines 7 to 41 run for (f h -1) times, each such execution having complexity O(ℓ h ). Therefore we arrive at the complexity where c(ℓ) denotes the complexity of the Cross. The multiplicities f h and g h depend on various factors, such as start, the random order of the elements of U 1 , U 2 (see Algorithm 7.3) and the probability p. According to [32]  In Figure 27 we present the average inverse folding time of several natural RNA structures taken from the PKdatabase [39]. These averages are computed via generating 200 sequences of the target's neutral networks. In addition we present in Table 1 the total time for 100 executions of Inv for an additional set of RNA pseudoknot structures.

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

Authors' contributions
All authors contributed equally to this paper. All authors read and approved the final manuscript.     if ∃ C h (l i-1 ) C(l i-1 ) s.   In all cases all trials generated successfully sequences of the respective neutral networks.