Tree diet: reducing the treewidth to unlock FPT algorithms in RNA bioinformatics

Hard graph problems are ubiquitous in Bioinformatics, inspiring the design of specialized Fixed-Parameter Tractable algorithms, many of which rely on a combination of tree-decomposition and dynamic programming. The time/space complexities of such approaches hinge critically on low values for the treewidth tw of the input graph. In order to extend their scope of applicability, we introduce the Tree-Diet problem, i.e. the removal of a minimal set of edges such that a given tree-decomposition can be slimmed down to a prescribed treewidth \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$tw'$$\end{document}tw′. Our rationale is that the time gained thanks to a smaller treewidth in a parameterized algorithm compensates the extra post-processing needed to take deleted edges into account. Our core result is an FPT dynamic programming algorithm for Tree-Diet, using \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$2^{O(tw)}n$$\end{document}2O(tw)n time and space. We complement this result with parameterized complexity lower-bounds for stronger variants (e.g., NP-hardness when \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$tw'$$\end{document}tw′ or \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$tw-tw'$$\end{document}tw-tw′ is constant). We propose a prototype implementation for our approach which we apply on difficult instances of selected RNA-based problems: RNA design, sequence-structure alignment, and search of pseudoknotted RNAs in genomes, revealing very encouraging results. This work paves the way for a wider adoption of tree-decomposition-based algorithms in Bioinformatics. Supplementary Information The online version contains supplementary material available at 10.1186/s13015-022-00213-z.


Introduction
Graph models and parameterized algorithms are found at the core of a sizable proportion of algorithmic methods in bioinformatics addressing a wide array of subfields, spanning sequence processing [1], structural bioinformatics [2], comparative genomics [3], phylogenetics [4], and further examples that can be found in a review by Bulteau and Weller [5]. RNA bioinformatics is no exception, with the prevalence of the secondary structure, an outer planar graph [6], as an abstraction of RNA conformations, and the notable utilization of graph models to represent complex topological motifs called pseudoknots [7], inducing the hardness of several tasks, such as structure prediction [8][9][10], structure alignment [11], or structure/sequence alignment [12]. Such motifs are functionally important and conserved, as witnessed by their presence in the consensus structure of 336 RNA families in the 14.5 edition of the RFAM database [13]. Moreover, methods in RNA bioinformatics [14] are increasingly considering non-canonical base pairs and modules [15,16], further increasing the density of RNA structural graphs and outlining the need for scalable algorithms.
A parameterized complexity approach can be used to circumvent the frequent NP-hardness of relevant problems. It generally considers one or several parameters, whose values are naturally bounded (or much smaller than the input size) within real-life instances. Once relevant parameters have been identified, one aims to design a Fixed Parameter Tractable (FPT) algorithm, having polynomial complexity for any fixed value of the parameter, and reasonable dependency on the parameter value. The treewidth is a classic parameter for FPT algorithms, and intuitively captures a notion of distance of the input to a tree. It is popular in bioinformatics due to the existence of efficient heuristics [17,18] for computing tree-decompositions of reasonable treewidth. Given a tree-decomposition, many combinatorial optimization tasks can be solved using dynamic programming (DP), in time/space complexities that remain polynomial for any fixed treewidth value. Resulting algorithms remain correct upon (almost) arbitrary modifications of the objective function parameters, and can be adapted to study statistical properties of search spaces through changes of algebra. Unfortunately, the existence of a parameterized (or FPT) algorithm does not necessarily imply that of a practically-efficient implementation, even when the parameter takes low typical values. Indeed, the dependency of the complexity on the treewidth may be prohibitive, both in terms of time and memory requirements. This limitation is particularly obvious while searching and aligning structured RNAs, giving rise to an algorithmic problem called RNA structure-sequence alignment [12,19,20], for which the best known exact algorithm is in �(n.m tw+1 ) , with n the structure length, m the sequence/ window length, and tw the treewidth of the structure (inc. backbone). Such a complexity becomes impractical for structures having a treewidth higher than ∼ 4 , which represent 50 to 70% of known RNA structures, as shown by Fig. 1, based on a broad analysis of structures found in the PDB database. Similar complexities hold for problems that can be expressed as (weighted) constraint satisfaction problems, with m representing the cardinality of the variable domains. Such frameworks are frequently used for molecular design, both in proteins [21] and RNA [22], and may require the consideration of tree-widths as high as 20 or more [23].
In this paper, we investigate a pragmatic strategy to increase the practicality of parameterized algorithms based on the treewidth parameter [27]. We put our instance graphs on a diet, i.e. we introduce a preprocessing that reduces their treewidth to a prescribed value by removing a minimal cardinality set of edges. As discussed previously, the practical complexity of many algorithms greatly benefits from the consideration of simplified instances, having lower treewidth. Moreover, specific countermeasures for errors introduced by the simplification can sometimes be used to preserve the correctness of the algorithm. For instance, for searching structured RNAs using RNA structure-sequence alignment [19], an iterated filtering strategy could use instances of increasing treewidth to restrict potential hits, weeding them early so that a-costly-full structure is reserved to (quasi-)hits. This strategy could remain exact while saving substantial time. Alternative countermeasures could be envisioned for other problems, such as a rejection approach to correct a bias introduced by simplified instances in RNA design. An overview of our approach is sketched on Fig. 2 After stating our problem(s) in Sect. 2, we study in Sect. 3 the parameterized complexity of the Graph-Diet problem, the removal of edges to reach a prescribed treewidth. We propose, in Sect. 4, a practical Dynamic Programing FPT algorithm for Tree-Diet, along with possible further optimizations for Path-Diet,  [24]. The data consists of 5 760 non-redundant graphs, each corresponding to a "chain" of a PDB entity. The nucleotide chains and their base pairs were extracted using the DSSR tool [25]. On each of these graphs, 4 standard treewidth heuristics from the LibTW library [26] (min-degree, min-fill-in, lex-BFS, max-cardinality-search) were launched, and the best width result was selected. Even if these heuristics reputedly tend to yield results close to the optimal, these results are still upper bounds. For each individual structure, the actual treewidth value may be lower. Depending on whether non-canonical base pairs are taken into account (right) or not (left), the proportion of structures having a width ≥ 4 ranges from 50 to 70% . For such values, the complexity of structure-sequence alignment ( O(n · m tw+1 ) ) becomes prohibitive. It is also worth noting that only pseudo-knotted structures may have a treewidth ≥ 3

Statement of the problem(s) and results
A tree-decomposition T (over a set V of vertices) is a tree whose nodes are subsets of V, known as bags. The bags containing any v ∈ V induce a (connected) subtree of T . A path-decomposition is a tree-decomposition whose underlying tree T is a path. The width of T (denoted w(T ) ) is the size of its largest bag minus 1. An edge {u, v} is visible in T if some bag contains both u and v, otherwise it is lost. T is a tree-decomposition of G if all edges of G are visible in T . The treewidth of a graph G is the minimum width over all tree-decompositions of G.
Problem (Graph-Diet) Given a graph G = (V , E) of treewidth tw, and an integer tw ′ < tw , find a tree-decomposition over V of width at most tw ′ losing a minimum number of edges from G.
A tree-diet of T is any tree-decomposition T ′ obtained by removing vertices from the bags of T .
Problem (Tree-Diet) Given a graph G, a tree-decomposition T of G of width tw, and an integer tw ′ < tw , find a (tw − tw ′ )-tree-diet of T losing a minimum number of edges.
Note that for Tree-Diet, T does not have to be optimal, so the width tw of the input tree decomposition might be larger than the actual treewidth of G, thus Tree-Diet can be used to reduce the width of any input decomposition. We define Binary-Tree-Diet and Path-Diet analogously, where T is restricted to be a binary tree (respectively, a path). An example of an instance of Graph-Diet and of Tree-Diet are given in Fig. 3.

Parameterized complexity in a nutshell
The basics of parameterized complexity can be loosely defined as follows (see [28] for the formal background). A parameter k for a problem is an integer associated with each instance which is expected to remain small in practical instances (especially when compared to the input size n). An exact algorithm, or the problem it solves, is FPT if it takes time f (k)poly(n) , and XP if it takes time n g(k) (for some functions f, g). Under commonly accepted conjectures (see for instance [29] for details), W[1]-hard problems may not be FPT, and Para-NP-hard problems (NP-hard even for some fixed value of k) are not FPT nor XP.

Our results
Our results are summarized in Table 1. Although the Graph-Diet problem would give the most interesting General description of our approach and rationale. Starting from a structured instance, e.g. an RNA structure with pseudoknots, our tree-diet/path-diet algorithms extract simplified tree/path decompositions, having prescribed target width tw ′ . Those can be used within existing parameterized algorithms to yield efficient heuristics, a posteriori approximations or even exact solutions tree-decompositions in theory, it seems unlikely to admit efficient algorithms in practice (see Sect. 3). Thus we focus on the Tree-Diet relaxation, where an input tree-decomposition is given, which we use as a guide/ restriction towards a thinner tree-decomposition. Seen as an additional constraint, it makes the problem harder (the case tw ′ = 1 becomes NP-hard, Theorem 3, although for Graph-Diet it corresponds to the Spanning Tree problem and is polynomial). With parameter tw however, it does help reduce the search space. In Theorem 7 we give an O((6�) tw � 2 n) Dynamic Programming algorithm, where is the maximum number of children of any bag in the treedecomposition. This algorithm can thus be seen as XP in general, but FPT on bounded-degree tree-decompositions (e.g. binary trees and paths). This is not a strong restriction, since the input tree may safely and efficiently be transformed into a binary one (see Supplementary Section A for more details). Moreover, the duplications of bags which are used in the conversion may only decease the number of lost edges incurred by Tree-Diet.
We also consider the case where the treewidth needs to be reduced by d = 1 only, this without constraining the source treewidth. We give a polynomial-time algorithm for Path-Diet in this setting (Theorem 8) which generalizes into an XP algorithm for larger values of d, noting that an FPT algorithm for d is out of reach by Theorem 5. We also show that the problem is Para-NP-hard if the tree degree is unbounded (Theorem 4).  , an optimal solution for Graph-DieT, with target treewidth 2, yields the tree-decomposition in the middle (edge ah is lost). On the other hand, any 1-tree-diet for the tree-decomposition on the right loses at least 3 edges Table 1 Parameterized results for our problems. Algorithm complexities are given up to polynomial time factors ( O * notation), denotes the maximum number of children in the input tree-decomposition a See Theorem 2 statement for a more precise formulation

Parameter
Source treewidth Target treewidth Difference

Algorithmic limits: parameterized complexity considerations
Graph-Diet can be seen as a special case of the Edge Deletion Problem (EDP) for the family of graphs H of treewidth tw ′ or less: given a graph G, remove as few edges as possible to obtain a graph in H . Such edge modification problems are more often parameterized by the number k of edited edges (see [31] for a complete survey). Given our focus on increasing the practicality of treewdith-based algorithms in bioinformatics, we restrict our focus to treewidth related parameters tw, tw ′ and d = tw − tw ′ . Considering the target treewidth tw ′ , we note that EDP is NP-hard when H is the family of treewidth-2 graphs [30], namely K 4 -free graphs, hence the notation EDP(K 4 ). It follows that Graph-Diet is Para-NP-hard for the target treewidth parameter tw ′ .

Graph-diet: practical solutions seem unlikely
For a combination of the parameters tw ′ and k, we could imagine graph minor theorems yielding parameterized algorithms "for free", as it is often the case with treewidth-based problems. In this respect, Graph-Diet corresponds to deciding if a graph G belongs to the family of graphs having treewidth tw ′ , augmented by k additional edges, denoted as Treewidth-tw ′ +k e since its introduction by Cai [32]. If this family were minor-closed, polynomial minor-free-testing [33,34] would yield an FPT algorithm. However, this is not the case: for some graphs in the family, an edge contraction yields a graph G ′ not in Treewidth-tw ′ +k e, as illustrated by Fig. 4.
Regarding the source graph treewidth tw, the vertex deletion equivalent of Graph-Diet, where one asks for a minimum subset of vertices to remove to obtain a given treewidth, is known as a Treewidth Modulator. This problem has been better-studied than its edge-deletion counterpart [35], and has been shown to be FPT for the treewidth [36]. For the edge-deletion version (Graph-Diet), we can use an optimization variant of Courcelle's Theorem [29,Thm. 7.12] to show that the problem is FPT for tw. However, this is a purely theoretical result as the running-time of such "black-box" algorithms typically involve towers of exponentials on the treewidth parameter.

Theorem 1 Graph Diet is FPT for the treewidth.
Proof We formulate Graph Diet as a Monadic Second-Order Logic (MSO) forumula as follows: given a graph G = (V , E) , an integer tw ′ and a set X of edges, let φ tw ′ (G, X) be true iff G[E \ X] has treewidth tw ′ . Clearly φ tw ′ can be expressed as an MSO formula, since both G[E \ X] and "being of treewidth tw ′ " can be expressed in MSO [37]. Thus, by Arnborg et al. [38], there exists an algorithm that, given G of treewidth tw, finds a set X of minimum size satisfying φ tw ′ (G, X) in time f tw ′ (tw) · n . Writing g(tw) = max tw ′ ≤tw f tw ′ (tw) , this yields an algorithm for Graph Diet running in time at most g(tw) · n .
Overall, even though Graph Diet is FPT for the treewidth, "practical" exact algorithms seem out of reach. Indeed, any algorithm for Graph-Diet can be used to compute the Treewidth of an arbitrary graph, for which current state-of-the-art exact algorithms require time in tw O(tw 3 ) [27]. We thus have the following conjecture, which motivates the Tree-Diet relaxation of the problem.

Conjecture 1 Graph-Diet does not admit algorithms with single-exponential running time for the treewidth.
On a related note, it is worth noting that Edge Deletion to other graph classes (interval, permutation, ...) does admit efficient algorithms when parameterized by the treewidth alone [39], painting a contrasted picture.
Finally, for parameter d, any polynomial-time algorithm for constant d would allow to compute the treewidth of any graph in polynomial time. Since treewidth is NP-hard we have the following result.

Theorem 2 There is no XP algorithm for Graph-Diet with parameter d unless P= NP.
Proof We consider the decision version of Graph-Diet where a bound k on the number of deleted edges is given. We build a Turing reduction from Treewidth: more precisely, assuming an oracle for Graph-Diet with d = 1 is available, we build a polynomial-time algorithm to compute the treewidth of a graph G. This is achieved by computing Graph-Diet(G, tw, d = 1, c' e f Fig. 4 A graph G (left) with treewidth 3. Deleting edge cd gives treewidth 2, implying that G ∈ Treewidth2 + 1e . However, if one contracts edge cd, then the resulting graph (right) has treewidth 3, and deleting any single edge does not decrease the treewidth. This example shows that the graph family Treewidth 2+1e is not minor-closed decreasing values of tw (starting with tw = |V | ): the first value of tw for which this call returns no solution is the treewidth of G. Note that this is not a many-one reduction, since several calls to Graph-Diet may be necessary (so this does not precisely qualify as an NP-hardness reduction, even though a polynomial-time algorithm for Graph-Diet(G, tw, d = 1, k = 0) would imply P=NP).

Lower bounds for tree-diet
Parameters tw ′ and d would be the most interesting in practice, since parameterized algorithms would be efficient for small diets or small target treewidth. However, we prove strong lower-bounds for Tree-Diet on each of these parameters, leaving very little hope for parameterized algorithms (we thus narrow down the possible algorithms to the combined parameter tw ′ + d , i.e. tw, see Sect. 4). Only XP for parameter d when T has a constant degree remains open (cf. Table 1).

Theorem 3 Tree-Diet and Path-Diet are Para-NPhard for the target treewidth parameter tw
Proof By reduction from the NP-hard problem Spanning Caterpillar Tree [40]: given a graph G, does G have a spanning tree C that is a caterpillar? Given G = (V , E) with n = |V | , we build a tree-decomposition T of G consisting of n − 1 bags containing all vertices (the width of the decomposition is therefore n − 1 ) connected in a path. Then (G, T ) admits a tree-diet to treewidth 1 with n − 1 visible edges if, and only if, G admits a caterpillar spanning tree. Indeed, the subgraph of G with visible edges must be a graph with pathwidth 1, i.e. a caterpillar [41]. With n − 1 visible edges, the caterpillar connects all n vertices together, i.e. it is a spanning tree.

Theorem 4
Tree-Diet is Para-NP -hard for the parameter d. More precisely, it is W[1]-hard for parameter , the degree of T , even when d = 1.
Proof As illustrated in Fig. 5, this can be shown by reduction from Multi-Colored Clique (Given a graph G, an integer k and a partition of the vertices of G into k sets, is there a clique in G containing exactly one vertex from each of the k sets?). Consider a k-partite We assume that G is regular (each vertex has degree δ and that each V i has the same size n (Multi Colored Clique is W[1]-hard under these restrictions [28,29]). Let L := δk − k 2 and N = max{|V |, L + 1} . We now build a graph G ′ and a tree-decomposition T ′ : start with for each i ∈ [k] . Thus, T is a tree-decomposition of G ′ with = k and maximum bag size n + N + 1 (vertices of V induce a size-3 path in T , other vertices appear in a single bag, edges of G appear in T 0 , edges of K i in T 1,i , and finally edges between V i and Z i appear in T 2,i ). The following claim completes the reduction: There are no edges lost by removing x i from T 1,i (since x i is not connected to K i ), and the edges lost in T 0 are all edges of G adjacent to any x i . Since X forms a clique and each x i has degree δ , there are L = kδ − k 2 such edges.
⇒ Consider a 1-tree-diet T ′ of T losing L edges.
Since each bag T 1,i has maximum size, T ′ must remove at least one vertex Proof By reduction from Clique. Given a δ-regular graph G with n vertices and m edges and an integer k, consider the trivial tree-decomposition T of G with a single bag containing all vertices of G (it has width n − 1 ). Then (T , G) has a k-tree-diet losing δk − k 2 edges if and only if G has a k-clique. Indeed, such a tree-diet T ′ would remove a set X of k vertices from G and losing δk − k 2 edges, so X induces k 2 edges and is a k-clique of G. Any instance G, with parameter k, of clique can therefore be transformed into an equivalent instance (T , G) of Path-diet, with parameter d = k . Since it qualifies as a parameterized reduction, Path-Diet is W[1]-hard.

For general tree-decompositions
We describe here a O(3 tw n)-space, O(� tw+2 · 6 tw n)-time dynamic programming algorithm for the Tree-Diet problem, with and tw being respectively the maximum number of children of a bag in the input tree-decomposition and its width. On binary tree-decompositions T has a 1-tree-diet losing at most L edges from (where each bag has at most 2 children), it yields a O(3 tw n)-space O(12 tw n)-time FPT algorithm.

Coloring formulation
We aim at solving the following problem: given a treedecomposition T of width tw of a graph G, we want to remove vertices from the bags of T to reach a target width tw ′ while losing as few edges from G as possible. We tackle the problem through an equivalent coloring formulation: our algorithm will assign a color to each occurrence of a vertex in the tree decomposition. We work with three colors: red (r), orange (o), and green (g). Green means that the vertex is kept in the bag, while orange and red means removal of the vertex. An edge is thus visible within a bag when both its ends are green. It is lost if there is no bag where it is visible. To ensure equivalence with the original problem, the colors will be assigned following local rules, which we now describe.
Definition 1 A coloring of vertices in the bags of the decomposition is said to be valid if it follows the following rules: • A vertex of a bag not present in its parent may be green or orange (R1) • A green vertex in a bag may be either green or red in its children (R2) • A red vertex in a bag must stay red in its children (R3) • An orange vertex in a bag has to be either orange or green in exactly one child (unless there is no child with this vertex), and must be red in the other children (R4) These rules are summarized in Fig. 6a. When going down the tree, a green vertex may only stay green or permanently become red. As for orange vertices, they are locally absent but "may potentially be found further down the tree", while red vertices are removed from both the current bag and its entire subtree. An immediate consequence of these rules is therefore that the green occurences of a given vertex form a (possibly empty) connected subtree. (R4) in particular is crucial to this connectivity: if an orange vertex could become orange in several children, it would be able to turn green in several disconnected subtrees. Figure 6b shows an example sketch for a valid coloring of the occurrences of a given vertex in the tree-decomposition. A vertex may only be orange along a path starting form its highest occurrence in the tree, with any part branching off that path entirely red. It ends at the top of a (potentially empty) green subtree, whose vertices may also be parents to entirely red subtrees.
We will now more formally prove the equivalence of the coloring formulation to the original problem. Let us first introduce two definitions. Given a valid coloring C of a tree-decomposition of G, an edge (u, v) of G is said to be realizable if there exists a bag in which both u and v are green per C . Given an integer d, a coloring C of T is said to be d−diet-valid if removing red/orange vertices reduces the width of T from w(T) to w(T ) − d.

Proposition 1 Given a graph G, a tree-decomposition
T of width tw, and a target width tw ′ < tw , The Tree-Diet problem is equivalent to finding a (tw − tw ′ )-dietvalid coloring C of T allowing for a number of realizable edges in G as large as possible.
Proof Given a (tw − tw ′ )-tree-diet of T specifying which vertices are removed from which bags, we first show how to obtain a valid coloring C for T incurring the same number of lost (unrealizable) edges. Let us denote by T ′ the tree decomposition of width tw ′ obtained by applying the diet to T . To start with, a vertex u is colored green in the bags where it is not removed. By the validity of T ′ as a decomposition, this set of bags forms a connected subtree, that we denote T g u . We also write T u for the subtree of bags containing u in the original decomposition T . If T g u and T u do not have the same root, then u is colored orange on the the path in T from the root of T u (included) and the root of T g u (excluded). Vertex u is colored red in any other bag of T u not covered by these two cases. The resulting coloring follows rules (R1-4) and induces the same set of lost/non-realizable edges as the original (tw − tw ′ )-tree-diet. Conversely, an equivalent (tw − tw ′ )-tree-diet is obtained from a (tw − tw ′ )-dietvalid coloring by removing red/orange vertices and keeping green ones. If a given vertex has no green occurences, it is entirely removed from the tree decomposition and all its edges are lost (it becomes an isolated vertex). We may add it back to the tree decomposition by introducing a new bag containing only this vertex, which we connect arbitrarily to the tree decomposition.

Decomposition of the search space and sub-problems
Based on this coloring formulation, we now describe a dynamic programming scheme for the Tree-Diet problem. We work with sub-problems indexed by tuples (X i , f ) , with X i a bag of the input tree decomposition and f a coloring of the vertices of X i in green, orange or red (in particular, f −1 (g) denotes the green vertices of X i , and similarly for o and r).
Let us introduce some notations before giving the definition of our dynamic programming table. Given an edge (u, v) of G, realizable when coloring a tree-decomposition T of G with C , we write T g uv the subtree of T in which both u and v are green. We denote by T i the subtree of the decomposition rooted at X i , and C(i, f) the d-diet-valid colorings of T i agreeing with f on i, with d = tw − tw ′ . Our dynamic programming table is then defined as: The cell c(X i , f ) therefore aggregates all edges realizable strictly below X i . As we shall see through the recurrence relation below and its proof, edges with both ends green in X i will be accounted for above X i in T . We assume w.l.o.g that the tree-decomposition is rooted at an empty bag R. Given the definition of the table, the maximum number of realizable edges, compatible with a tree-diet of (tw − tw ′ ) to T , can be found in c(R, ∅).
The following theorem presents a recurrence relation obeyed by c(X i , f ) : • m: a map from the orange vertices in X i to the children of X i . It decides for each orange vertex u, which child, among those which contain u, will color u orange or green; If there are no orange vertices in X i , only the trivial empty map is considered. • compatible(Y j , f , m) : the set of colorings of Y j compatible with f on X i and m; • count(f , f ′ j ) : set of edges of G involving two vertices of Y j green by f ′ j , but such that one of them is either not in X i or not green by f.
Note that compatible(Y j , f , m) may contain colorings f ′ j that colour too many vertices in Y j in green to reach target width tw ′ . In that case c(Y j , f ′ j ) = −∞. Theorem 6 relies on the following separation lemma for realizable edges under a valid coloring of a tree-decomposition. Recall that we suppose w.l.o.g that the treedecomposition is rooted at an empty bag.

Lemma 1 An edge (u, v) of G, realizable in T under C ,
is contained in exactly one set of the form count(C |P , C |X ) with X a bag of T and P its parent, C |P , C |X the restrictions of C to P and X, respectively, and "count" defined as above.
In addition, X is the root of the subtree of T in which both u and v are green.
Proof Given, in a tree-decomposition, a bag P colored with f, with a child X colored with h, a more precise definition for count(f, h) is: Now, given a realizable edge (u, v), in a tree-decomposition T colored with C , the set of bags in which both u and v are green forms a connected subtree of T . This subtree has a root, or lowest common ancestor, that we denote R (u,v) . Since we assumed T to be rooted at an empty bag, is not the root of T , and has a parent. We call this parent P (u,v) . Clearly, (u, v) belongs to the "count set" associated to the edge (P (u,v) ) → (R (u,v) ) of T , while for any other edge X → Y of T , the colors of u and v cannot verify the conditions to belong to the associated "count set".
Proof of Theorem 6 ≤ Let us more concisely use RE ↓ (T i , C, G) to denote the set of edges (u, v) of G, realizable under the (tw − tw ′ )-diet-valid coloring C of T i , such that T g uv is entirely contained strictly below X i . We have, if f contains enough red/orange vertices to reduce the size of X i to target size: By definition, c(X i , f ) is the maximum number of realizable edges in the subtree-decomposition rooted at X i , such that all green-green occurences . Therefore: and, a fortiori ≥ Conversely, given f, let m be an assignation map for orange vertices and f ′ 1 . . . f ′ � colorings of Y 1 . . . Y � compatible with f and m, and let C ′ . The union of C ′ 1 . . . C ′ � and f is a coloring C for T i , the subtree-decomposition rooted at X i , which can not be better than optimal ( |RE ↓ (T i , C, G)| ≤ c(X i , f ) ). As before, an edge (u, v) either belongs to ∪ j count(f , f ′ j ) or to ∪ j RE ↓ (T ′ j , C ′ j , G) but not both. In any case, it belongs to RE ↓ (T i , C, G) . Therefore: This is true for any choice of m, f ′ 1 . . . f ′ � , therefore: which concludes the proof. Dynamic programming algorithm The recurrence relation of Theorem 6 naturally yields a dynamic programming algorithm for the Tree-Diet problem, as stated below: Theorem 7 There exists a O(� tw+2 · 6 tw · n)-time, O(3 tw · n)-space algorithm for the Tree-Diet problem, with the maximum number of children of a bag in the input tree-decomposition, and tw its width.

Proof (Proof of Theorem 7)
Given the coloring formulation and Proposition 1, and given the sub-problems and c(X i , f )-table definitions, with R the (empty) root of the tree-decomposition, c(R, ∅) is indeed the maximum possible number of realizable edges when imposing a (tw − tw ′ )-diet to T . The recurrence relation of Theorem 6 therefore lends itself to a dynamic programming approach, over the tree-decomposition T following leafto-root order, for the problem.
It is reasonable to assume the number of bags in a tree decomposition to be linear in n (this is for instance the case for a nice tree decomposition [29,42], or for a tree decomposition obtained from an elimination ordering, see [17,43] Overall, as there are at most children, tw + 1 vertices in each child, and 2 possibilities (see enumeration of cases above) of color for each vertex in a child, yielding a total number of compatible colorings bounded by O(� · 2 tw+1 ) . Multiplying these contributions, the overall time complexity of our algorithm is therefore O(� tw+2 · 6 tw · n) . Corollary 1 Binary-Tree-Diet ( = 2 ) admits an FPT algorithm for the tw parameter.
A pseudo-code implementation of the algorithm, using memoization, is included in Additional file 1: Section B

For path decompositions
In the context of path decompositions, we note that the number of removed vertices per bag can be limited to at most 2d without losing the optimality. More precisely, we say that a coloring C is d-simple if any bag has at most d orange and d red vertices. We obtain the following result, using transformations given in Fig. 7.

Proposition 2 Given a graph G and a path-decomposition T , if C is a d-diet-valid coloring of T losing k edges, then T has a d-diet-valid coloring that is d-simple, and loses at most k edges.
Proof of Proposition 2 Consider such a coloring C with a maximal number of green vertices. We show that it is d-simple. Assume the path-decomposition T is rooted in bag X 1 and each X i is the parent of X i+1 . Pick i to be the smallest index so that at least d + 1 vertices in X i are colored red by C , assume any such i exists. Then one of these vertices, say u, is not colored red in X i−1 (either because i = 1 , or it is not in X i−1 , or it is orange or green in X i−1 ). Consider C ′ obtained by C and coloring u green in X i . Then C ′ satisfies local rules R1 through R4 (a green vertex may be absent, green or orange in the parent bag, and a red vertex may be green in the parent bag). Furthermore, it is d-diet-valid since it still removes at least d (red) vertices in X i . Overall C ′ is another d-diet-valid coloring with more green vertices: a contradiction, so no such i exist (and no bag has d + 1 red vertices). The same argument works symmetrically for orange vertices. Overall, C is d-simple.
Together with Proposition 1, this shows that it is sufficient to restrict our algorithm to d-simple colorings. (See also Fig. 7). In particular, for any set X i , choosing which ≤ d vertices are orange and which ≤ d are red, among the total of n vertices, is enough to fix a coloring. The number of such colorings is therefore bounded by O(tw 2d ) . Applying this remark to our algorithm presented in Sect. 4.1 yields the following result:

Proofs of concept
We now illustrate the relevance of our approach, and the practicality of our algorithm for Tree-Diet, by using it in conjunction with FPT algorithms for three problems in RNA bioinformatics. We implemented in C++ the dynamic programming scheme described in Theorem 7 and Additional file 1: Section B. Its main primitives are made available for Python scripting through pybind11 [44]. It actually allows to solve a generalized weighted version of Tree Diet, as explained in Additional file 1: Section B. This feature allows to favour the conservation of important edges (e.g. RNA backbone) during simplification, by assigning them a much larger weight compared to other edges. Our implementation is freely available at https:// gitlab. inria. fr/ amibio/ tree-diet.
The execution time of this implementation on elements of the data set used for Fig. 1 (all RNA-only structures of the PDB database) is represented on Figure 8, for input treewidth values of up to 7. It shows that our tree-diet method is applicable with reasonable run-times ( 1 h) for all structures of width ≤ 7 . The proofs-of-concepts presented in this section involve however instances with treewidth of up to 9, in the case of RNA design, for which the run-time also stays reasonable.

Memory-parsimonious unbiased sampling of RNA designs
As a first use case for our simplification algorithm, we strive to ease the sampling phase of a recent method, called RNAPond [22], addressing RNA negative design. The method targets a set of base pairs S, representing a secondary structure of length n, and infers a set D of m disruptive base pairs (DBPs) that must be avoided. It relies on a �(k · (n + m)) time algorithm for sampling k random sequences (see Additional file 1: Section C for details) after a preprocessing in �(n · m · 4 tw ) time and �(n · 4 tw ) space. Here, the input consists of a graph G = ([1, n], S ∪ D) and a tree decomposition T of G, having width tw. In practice, the preprocessing largely dominates the overall runtime, even for large values of k, and its large memory consumption represents the main bottleneck.
This discrepancy in the complexities/runtimes of the preprocessing and sampling suggests an alternative strategy: relaxing the set of constraints to (S ′ , D ′ ) , with (S ′ ∪ D ′ ) ⊂ (S ∪ D) , and compensating it through a rejection of sequences violating constraints in (S, D) \ (S ′ , D ′ ) . The relaxed algorithm would remain unbiased, while the average-case time complexity of the rejection algorithm would be in �(k · q · (n + m)) time, where q represents the relative increase of the partition function ( ≈ the sequence space) induced by the relaxation. The preprocessing step would retain the same complexity, but based on a (reduced) treewidth tw ′ ≤ tw for the relaxed graph G ′ = ([1, n], S ′ ∪ D ′ ).
These complexities enable a tradeoff between the rejection (time), and the preprocessing (space), which may be critical to unlock future applications of RNA design. Indeed, the treewidth can be decreased by removing relatively few base pairs, as demonstrated below using our algorithm on pairs inferred for hard design instances.
We considered sets of DBPs inferred by RNAPond over two puzzles in the EteRNA benchmark. The EteRNA22 puzzle is an empty secondary structure spanning 400 nts, for which RNAPond obtains a valid design after inferring 465 DBPs. A tree decomposition of the graph formed by these 465 DPBs is then obtained with the standard min-fill-ordering heuritic [18], giving a width of 6. The EteRNA77 puzzle is 105 nts long, and consists in a collection of helices interspersed with destabilizing internal loops. RNApond failed to produce a solution, and its final set of DBPs consists of 183 pairs, for which the same heuristic yields a tree decomposition of width 9. We further make both tree decompositions binary through bag duplications (see Supplementary Section A), giving an FPT runtime to our algorithm, while potentially lowering the number of lost edges.
Executing the tree-diet algorithm (Theorem 7) on both graphs and their tree decompositions, we obtained simplified graphs, having lower treewidth while typically losing few edges, as illustrated and reported in Fig. 9. Remarkably, the treewidth of the DBPs inferred for EteRNA22 can be decreased to tw ′ = 5 by only removing 5 DBPs/edges (460/465 retained), and to tw ′ = 4 by removing 4 further DBPs (456/465). For EteRNA77, our algorithm reduces the treewidth from 9 to 6 by only removing 7 DBPs.
Rough estimates can be provided for the tradeoff between the rejection and preprocessing complexities, by assuming that removing a DBP homogeneously increases the value of Z by a factor α := 16/10 (#pairs/#incomp. Given the large typical asymmetry in runtimes and implementation constants between the computation-heavy preprocessing and, relatively light, generation phases, the availability of an algorithm for the tree-diet problem provides new options, especially to circumvent memory limitations.

Structural alignment of complex RNAs
Structural homology is often posited within functional families of non-coding RNAs, and is foundational to algorithmic methods for multiple RNA alignments [13], considering RNA base pairs while aligning distant homologs.
In the presence of complex structural features (pseudoknots, base triplets), the sequence-structure alignment problem becomes hard, yet admits XP solutions based on the treewidth of the base pair + backbone graph. In particular, Rinaudo et al. [12] describe a �(n.m tw+1 ) algorithm for optimally aligning a structured RNA of length n onto a genomic region of length m. It optimizes an alignment score that includes: (i) substitution costs for matches/mismatches of individual nucleotides and base pairs (including arc-breaking) based on the RIBOSUM matrices [45]; and (ii) an affine gap cost model [46]. We used the implementation of the Rinaudo et al. algorithm, implemented in the LicoRNA software package [47,48].

Impact of treewidth on the structural alignment of a riboswitch
In this case study, we used our tree-diet algorithm to modulate the treewidth of complex RNA structures, and investigate the effect of the simplification on the quality and runtimes of structure-sequence alignments. We considered the Cyclic di-GMP-II riboswitch, a regulatory motif found in bacteria that is involved in signal transduction, and undergoes conformational change upon binding the second messenger c-di-GMP-II [49,50]. A 2.5Å resolution 3D model of the c-di-GMP-II riboswitch in C. acetobutylicum, proposed by Smith et al. [51] based on X-ray crystallography, was retrieved from the PDB [24] (PDBID: 3Q3Z). We annotated its base pairs geometrically using the DSSR method [52]. The canonical base pairs, supplemented with the backbone connections, were then accumulated in a graph, for which we heuristically computed an initial tree decomposition T 4 , having treewidth tw = 4. We simplified our the initial tree decomposition T 4 , and obtained simplified models T 3 , and T 2 , having width tw ′ = 3 and 2 respectively. As controls, we included tree decompositions based on the secondary structure (max. non-crossing set of BPs; T 2D ) and sequence ( T 1D ). We used LicoRNA to predict an alignment a T ,w of each original/simplified tree decomposition T onto each sequence w of the c-di-GMP-II riboswitch family in the RFAM database [13] (RF01786). Finally, we reported the LicoRNA runtime, and computed the Sum of Pairs Score (SPS) [53] as a measure of the accuracy of a T ,w against a reference alignment a ⋆ w : the alignment a ⋆ w between the 3Q3Z sequence and w induced by the manually-curated RFAM alignment of the RF01786 family.
The results, presented in Fig. 10, show a limited impact of the simplification on the quality of the predicted alignment, as measured by the SPS in comparison with the RFAM alignment. The best average SPS (77.3%) is achieved by the initial model, having treewidth of 4, but the average difference with simplified models appears very limited (e.g. 76.5% for T 3 ), especially when considering the median. Meanwhile, the runtimes mainly depend on the treewidth, ranging from 1h for T 4 to 300ms for T 1D . Overall, T 2D seems to represent the best compromise between runtime and SPS, although its SPS may be artificially inflated by our election of RF01786 as our reference (built from a covariance model, i.e. essentially a 2D structure). Finally, the difference in number of edges (and induced SPS) between T 2D and T 2 , both having tw = 2 , exemplifies the difference between the Tree-Diet and Graph-Diet problems, and motivates further work on the latter.

Exact iterative strategy for the genomic search of ncRNAs
In this final case study, we consider an exact filtering strategy to search new occurrences of a structured RNA within a given genomic context. In this setting, one attempts to find all ε-admissible (cost ≤ ε ) occurrences/hits of a structured RNA S of length n within a given genome of length g ≫ n , broken down in windows of length κ.n, κ > 1 . Classically, one would align S against individual windows, and report those , associated with an ǫ−admissible alignment cost. This strategy would have an overall �(g · n tw+2 ) time Fig. 10 Impact on alignment quality (SPS; Left) and runtime (Right) of simplified instances for the RNA sequence-structure alignment of the pseudoknotted c-di-GMP-II riboswitch. The impact of simplifications on the quality of predicted alignments, using RFAM RF01786 as a reference, appears limited while the runtime improvement is substantial complexity, applying for instance the algorithm of [12]. Our instance simplification framework enables an alternative strategy, that incrementally filters out unsuitable windows based on models of increasing granularity. Indeed, for any given target sequence, the min alignment cost c δ obtained for a simplified instance of treewidth tw − δ can be corrected (cf Additional file 1: Section D) into a lower bound c ⋆ δ for the min alignment cost c ⋆ 0 of the full-treewidth instance tw. Any window such that c ⋆ δ > ε thus also obeys c ⋆ 0 > ε , and can be safely discarded from the list of putative ε-admissible windows, without having to perform a full-treewidth alignment. Given the exponential growth of the alignment runtime for increasing treewidth values (see Fig. 10, right) this strategy is expected to yield substantial runtime savings.
We used this strategy to search occurrences of the Twister ribozyme (PDBID 4OJI), a highly-structured ( tw = 5 ) 54nts RNA initially found in O. sativa (Asian rice) [54]. We targeted the S. bicolor genome (sorghum), focusing on a 10kb region centered on the 2,485,140 position of the 5th chromosome, where an instance of the ribozyme was suspected within an uncharacterized transcript (LOC110435504). The 4OJI sequence and structure were extracted from the 3D model as above, and included into a tree decomposition T 5 (73 edges), simplified into T 4 (71 edges), T 3 (68 edges) and T 2 (61 edges) using the treediet algorithm.
We aligned all tree decompositions against all windows of size 58nts using a 13nts offset, and measured the score and runtime of the iterative filtering strategy using a cost cutoff ε = −5 . The search recovers the suspected occurrence of twister as its best result (Fig. 11C), but produced hits (cf Fig. 11D) with comparable sequence conservation that could be the object of further studies. Regarding the filtering strategy, while T 2 only allows to rule out 3 windows out of 769, T 3 allows to eliminate an important proportion of putative targets, retaining only 109 windows, further reduced to 15 windows by T 4 , 6 of which end up as final hits for the full model T 5 (cf Fig. 11A). The search remains exact, but greatly reduces the overall runtime from 24 h to 34 min (42 fold!).

Conclusion and discussion
We have established the parameterized complexity of three treewidth reduction problems, motivated by applications in Bioinformatics, as well as proposed practical algorithms for instances of reasonable treewidths. The reduced widths obtained by our proposed algorithm can be used to obtain: (i) sensitive heuristics, owing to the consideration of a maximal amount of edges/information in the thinned graphs; (ii) a posteriori approximation ratios, by comparing the potential contribution of removed edges to the optimal score obtained of the thinned instance by a downstream FPT/XP algorithm; (iii) substantial practical speedups without loss of correctness, e.g. when partial filtering can be safely achieved based on simplified input graphs.

Open questions
Regarding the parameterized complexity of Graph-Diet and Tree-Diet, some questions remain open (see Table 1): an FPT algorithm for Tree-Diet (ideally, with 2 O(tw) · n running time), would be the most desirable, if possible satisfying the backbone constraints. The existence of such an algorithm is not trivial. In particular, it is perhaps worth noting that it is not implied by the existence of an FPT algorithm for graph-diet with the input treewidth as a parameter (1). Indeed, in comparison to the latter, tree-diet subtly restricts the search space to tree decompositions that are subsets of the input tree decomposition. It follows that the result of graph diet for a graph G may substantially differ from the result of tree-diet given a tree decomposition T of G as input.
We also aim at trying to give efficient exact algorithms for graph diet in the context of RNA (we conjecture this is impossible in the general case). Finally, we did not include the number of deleted edges in our multivariate analysis: even though in practice it is more difficult a priori to guarantee their small number, we expect it can be used to improve the running time in many cases.

Backbone preservation
In two of our applications, the RNA secondary structure graph contains two types of edges: those representing the backbone of the sequence (i.e., between consecutive bases) and those representing base pair bonds. In practice, we want all backbone edges to be visible in the resulting tree-decomposition, and only base pairs may be lost. This can be integrated to the Tree-Diet model (and to our algorithms) using weighted edges, using the total weight rather than the count of deleted edges for the objective function. Note that some instances might be unrealizable (with no tree-diet preserving the backbone, especially for low tw ′ ). In most cases, ad-hoc bag duplications can help avoid this issue. The design of preprocessing methods, involving bag duplications or other Fig. 11 Corrected costs associated with the search for structured homologs of the Twister ribozyme in chromosome 5 of S. bicolor, using simplified instances of various treewidth (A). Gray areas represent scores which, upon correction, remain below the cutoff, and have to be considered for further steps of the iterated filtering. Canonical base pairs of the ribozyme (PDBID 4OJI; B, mapped onto to the best hit (C) and second best hit (D) found along the search colored depending on their support in the target sequence (Red: incompatible; Purple: unstable G-U; Blue: stable)