Problem statement.

Given the alignments of RNA-seq reads to a reference genome, we first cluster reads into gene loci, and then assemble the expressed transcripts within each gene locus independently (see Fig. 2 for the method overview). For each gene locus, we construct the splice graph G = (V, E), edge weights w, and phasing paths H (see Supplementary Note 6 for the procedure to build G, w and H). Based on G, w and H, we compute a set P of s-t paths of G and associate a real-value f(p) for every path p∈P. Each path p∈P implies an expressed transcript, and f(p) estimates the expression abundance of the corresponding transcript. We now design three objectives to guide reconstructing P and f. First, since each phasing path is constructed from a single read or paired-end reads, which must be sampled from a single transcript, we expect that each phasing path appears as a whole in some reconstructed transcript. Formally, we say a phasing path h∈H is covered by P, if there exists an s-t path p∈P such that h is a consecutive subset of edges of p. We do not require all phasing paths in H be covered by P because of the existence of false-positive phasing paths introduced by alignment errors or sequencing errors. Our algorithm tries to identify and remove false-positive phasing paths both in building the splice graph and in reconstructing paths from the splice graph. Except for these predicted false-positive phasing paths, we do require that all other phasing paths in H be covered by P. Second, for each edge e∈E, we expect that the total of the abundances of the inferred s-t paths passing through e, i.e., ∑ p∈P:e∈p f(p), is as close to its observed read coverage w(e) as possible. Therefore, the second objective is to minimize the deviation between these two quantities, defined as

Third, following the principle of parsimony, we expect to use a smaller set of s-t paths to explain G, w and H. That is, the third objective is to minimize |P|.

Combining all three objectives, we informally describe the task of transcript assembly as follows.

Problem 1 (Transcript Assembly). Given G, w and H, compute a set of s-t paths P of G and abundance f(p) for each p∈P, such that P covers all phasing paths in H (except predicted false-positive ones), and that both d(P, f, w) and |P| are as small as possible.

We do not explicitly combine d(P, f, w) and |P| into a single objective function. The trade-off between these two items is implicitly determined by the phasing paths in H and automatically detected by our algorithm. Specifically, when we have sufficient phasing paths around certain vertices, our algorithm will follow them to locally decompose the splice graph to reconstruct the s-t paths, and in this case our algorithm only minimizes d(P, f, w). On the other hand, when the phasing information is missing for some vertices, then our algorithm emphasizes minimizing |P| to produce a more parsimonious solution.

Algorithm.

Our algorithm employs an iterative strategy to gradually decompose the splice graph into s-t paths while achieving the three objectives above (Fig. 2). Specifically, we divide all vertices into three types based on the influence of the phasing paths on each vertex, and design different subroutines to decompose each type of vertices. In each iteration, our algorithm decomposes a single vertex so as to either locally minimize the deviation d(P, f, w) or minimize the number of reconstructed paths |P|, while preserving all phasing paths in H. Our algorithm can guarantee that all phasing paths (except predicted false-positive ones) can be covered by the final set of s-t paths. This property is achieved by enforcing that all three subroutines keep the invariant that, after each iteration, every phasing path can be covered by some s-t path in the current splice graph.

We say a vertex v ∈ V\{s,t} is trivial, if its in-degree is 1, or its out-degree is 1; otherwise we say v is nontrivial. Intuitively, there is a unique way to decompose a trivial vertex, while there might be multiple ways to decompose a nontrivial vertex. For those nontrivial vertices, we introduce a data structure to further classify them into two types based on the influence of phasing paths on them. For any nontrivial vertex v, we build a bipartite graph G v = (S v ⊂T v , E v ), in which its vertices (S v ⊂T v ) correspond to edges in G, while its edges (E v ) describe whether the corresponding two edges in G are connected by some phasing path in H. Formally, let S v be the set of edges that point to v, and let T v be the set of edges that leave v, i.e., S v := {e∈E|e = (u,v)} and T v := {e∈E|e = (v,w)}. For each pair of edges e∈S v and e′∈T v , we add an edge (e,e′) to E v if there exists a phasing path h∈H such that (e,e′) is a consecutive pair in h. We say a nontrivial vertex v is unsplittable if all elements of S v , or all elements of T v , are in the same connected component of G v (Supplementary Fig. 14a,b); otherwise we say v is splittable. In the following, we design different subroutines to decompose unsplittable vertices, splittable vertices, and trivial vertices.

Decomposing unsplittable vertices.

We now describe the subroutine to decompose an unsplittable vertex v (Supplementary Fig. 14). The aim of this subroutine is to replace v with a set of trivial vertices so as to locally minimize d(P,f,w) and also preserve all phasing paths.

The first step is to balance v by computing new weights for adjacent edges of v (i.e., (S v ⊂T v )). Specifically, for any subset E 1 ⊂E, we define . Let . Then we set for any edge e∈S v , and set for any edge e∈T v . Similarly, we define for any subset E 1 ⊂E. Clearly, we have that , i.e., after balancing the sum of weights of all in-edges of v equal that of all out-edges of v.

The second step of the subroutine is to build the extended bipartite graph . The goal of this extension is to connect edges with no phasing paths to the most likely preceding or succeeding edge. Specifically, let and be the edges that have the largest balanced weights in S v and T v , respectively. Let and be the set of edges that have total degree of 0 in G v . We then set . See Supplementary Figure 14b for an example.

The third step of the subroutine is to assign weights for all edges in the extended bipartite graph so as to locally minimize the deviation w.r.t. , i.e., . We formulate this as a linear programming problem. For each edge (recall that each edge in corresponds to a pair of edges in the splice graph G), we have a variable x e,e′ to indicate the desired weight of edge (e, e′). For each vertex e∈S v ∪ T v (recall that each vertex in corresponds to an edge in G) we add a variable y e to indicate the deviation between its balanced weight and the sum of the weights of all edges that are adjacent to vertex e in . Formally, we have the following constraints:

The objective of the linear programming instance is taken to be:

Solving the above linear programming instance gives us the optimal deviation w.r.t. , and one optimal solution for all variables. However, when contains a cycle there might be multiple optimal solutions that achieve the same optimal deviation (Supplementary Fig. 15). We use the abundance of the phasing paths stored in g(·) to reassign weights while keeping the optimal deviation. For each edge , we denote by g(e, e′) the number of reads or paired-end reads that continuously go through e and e′, which can be computed as . Our goal is then to reassign the weights for edges in so as to keep the above minimal deviation w.r.t. but to minimize the deviation w.r.t. .

We formulate this problem as another linear programming instance. Specifically, let and , e∈S v and e′∈T v , be the optimal solution obtained by solving the first linear programming instance (thus, and are constants rather than variables in the second linear programming problem). We use variables to indicate the weight of edge (e,e′) in . We use the following constraints to guarantee that the optimal weights achieve the same optimal deviation w.r.t. as in the first linear programming instance:

The objective of this linear programming instance is then taken to minimize the sum of the deviation of weights w.r.t. :

We assign the weights for edges in to be the optimal value of in the second linear programming instance. Note that if the first linear programming instance has the unique optimal solution, then both instances will have the same optimal solution. Since linear programming can be solved very efficiently (in polynomial-time), using two such instances for each unsplittable vertex has little influence on the speed of the entire algorithm.

Finally, we update splice graph G by replacing v with (Supplementary Fig. 14c); we denote by G′ the updated splice graph. For the edges in that are added to G′, we maintain the information that they are artificially added edges and thus do not correspond to any edge in G. This information will be used after decomposing all vertices to backtrace the paths with respect to the original splice graph (see line 6 of Algorithm 1, below). For example, if , then the path in G′ corresponds to the path in G. We then update H; we denote by H′ the updated set of phasing paths. For any phasing path h∈H, if h contains a pair of continuous edges e and e′ in G such that , i.e., , then h will become

This subroutine to decompose an unsplittable vertex preserves all phasing paths in H, i.e., every phasing path h∈H is still covered by some s-t path p′ of G′ (if we transform p′ of G′ into the corresponding path p of G through removing the artificially added edges in p′ (if any), then p covers h). This is true because according to our construction of G′ and H′ there is a one-to-one correspondence between H and H′ and every phasing path in H′ is covered by some path in G′.

To choose which unsplittable vertex v to apply the above subroutine to, we define

and select a vertex v that minimizes z (v) to decompose (see line 3 of Algorithm 1, below).

Decomposing splittable vertices.

We now describe the subroutine to decompose a splittable vertex v (Supplementary Fig. 16). The aim of this subroutine is to reduce |P| while preserving all phasing paths. Since P is not explicitly available until we have decomposed all vertices, we use to approximate |P|. It has been proved that U is an upper bound of |P| in the flow decomposition scenario: for a given flow, at most U paths are required to decompose this flow21,22. Following this approximation, in order to reduce |P|, our subroutine will increase the number of vertices or decrease the number of edges, while at the same time preserving all phasing paths. Typically, a splittable vertex will be replaced by two new vertices.

The first step of this subroutine is also to balance v by computing for edges in following the same procedure as decomposing unsplittable vertices. The second step is to split v into two vertices so as to keep all phasing paths and to minimize the balanced weight discrepancy (i.e., to make each of the two new vertices as balanced as possible). Formally, we seek and , and such that for each either and , or and , and that is minimized. Intuitively, this formulation requires that two edges in some phasing path be adjacent after splitting, and thus all phasing paths can be preserved; meanwhile, under such constraints we aim to minimize the discrepancy of each new vertex (the discrepancies of the two new vertices are identical).

The above problem can be equivalently transformed into the subset-sum problem. Let C be the set of all connected components of G v . We define for any . Then the above problem is equivalent to computing a nonempty and strict subset of such that the sum of all elements of this subset is closest to 0. In our implementation, we use the existing pseudo-polynomial time dynamic programming algorithm to solve it.

Let and be the optimal subsets returned by the above algorithm. We then update splice graph G through performing the following procedure to decompose v (Supplementary Fig. 16). We denote the updated splice graph as G′. Vertex v will be split into two vertices by adding another vertex v′ to G′. Edges in will be detached from v and attached to v′. Notice that the weights for edges in are kept unchanged as , i.e., the balanced weight is only used to compute and .

It could be the case that (or symmetrically, , i.e., the new vertex v′ will have either in-degree of 0 and out-degree of 1, or out-degree of 0 and in-degree of 1. In this case, the above procedure of decomposing v will degenerate into removing this edge from G, instead of splitting v into two vertices. If this is the case, it indicates that this particular edge is more likely to be a false-positive edge. (An edge in the current splice graph might correspond to a path in the original splice graph, as we proceed decomposing vertices, an edge might become the concatenation of two adjacent edges.) For this case, we also remove the appearance of this false-positive edge for all phasing paths in H. In other words, this procedure can be used to naturally remove false-positive edges and false-positive phasing paths.

In either the general case of splitting v into two vertices, or in the degenerate case of removing one edge from G, after decomposing splittable vertex v, we have that U will be reduced by 1.

For the degenerate case of removing one edge from G, these phasing paths that contain this edge will be not covered by G′. For the usual case of splitting vertex v into two vertices, this subroutine keeps all phasing paths H unchanged.

Finally, we define

as the measurement to decide which splittable vertex to decompose (see line 4 of Algorithm 1, below).

We identify false-positive edges and false-positive phasing paths when decomposing splittable vertices while we do not do so for unsplittable vertices. This is because edges that are adjacent to an unsplittable vertex v are supported by phasing paths that span v, i.e., such edges can be extended by following phasing paths. Our subroutine to decompose v thus realizes all such extensions. The extended edges could be identified as false-positive edges in the following iterations if they happen to be adjacent to splittable vertices and reported as false-positive edges by the algorithm. In other words, once edges can be elongated through phasing paths, then they are temporarily exempted from being removed as false-positive edges.

Decomposing trivial vertices.

Although there is a unique way to decompose a trivial vertex, decomposing them is necessary to simplify the splice graph so as to explicitly raise up nontrivial vertices for further decomposition using the previous two subroutines (Supplementary Fig. 17). Let v∈V be a trivial vertex. Again, let S v be the set of edges that point to v, and let T v be the set of edges that leave v. Without loss of generality, we assume that the in-degree of v is 1; let e = (u,v) be the only in-edge of v, i.e., . We denote by G′ the updated splice graph after decomposing v. The construction of G′ from G is to remove edge e from G, and merge u and v as a single vertex v (Supplementary Fig. 17). For each edge in e′∈T v , we maintain the information that e′ is preceded by an extra edge e, i.e., for e′ in G we label it as ee′ in G′. When we retrieve the paths w.r.t. the original splice graph (line 6 of Algorithm 1, below), ee′ in G′ will be expanded as a pair of edges (e,e′) in G. We then update the phasing paths H; we denote by H′ the updated set of phasing paths. Consider two cases of a phasing path h∈H that contains e. If e is the last edge of h, i.e., , then we simply remove e from h, i.e., it becomes . Otherwise, if e is not the last element of h, i.e., , we replace e and e 1 with the edge ee 1 in G′, i.e., it becomes .

In Algorithm 1, we first decompose all nontrivial vertices before decomposing any trivial vertex, i.e., when we decompose a trivial vertex, all vertices in the current splice graph are trivial vertices. We now prove that, when the splice graph contains only trivial vertices, this subroutine to decompose a trivial vertex preserves all phasing paths. Again, consider the two cases of a phasing path h∈H that contains e. If , then we have , and h′ is covered by G′. Since ee 1 is essentially the concatenation of e and e 1 , we have that G′ covers h. For the other case that , we have that . (Although G′ covers h′, this alone does not necessarily imply that G′ covers h any more.) Let e 1 = (w, u) and e = (u, v) in G. Since we assume all vertices in G are trivial vertices, in particular u is a trivial vertex, we have that in G′ all the succeeding edges of e 1 are in the type of ee′, where e′ ∈ T v (Supplementary Fig. 17). In other words, for any path in G′ that contains h′, the next edge of e 1 in this path must be a concatenated edge with preceding edge of e. Hence, we have that G′ covers h.

We emphasize that if the splice graph contains a nontrivial vertex, then decomposing a trivial vertex might not preserve all phasing paths. Supplementary Figure 18 gives such an example. Thus, it is essential to decompose all nontrivial vertices before decomposing any trivial vertex.

Complete algorithm.

Our complete algorithm (Algorithm 1; Fig. 2) for Problem 1 is to iteratively decompose vertices by applying the above three subroutines (lines 1–5), and then recover the transcripts (line 6). In Supplementary Note 7 and Supplementary Figures 19–21 we prove that Algorithm 1 can always reach line 6, i.e., our algorithm always terminates. Among nontrivial vertices, we give priority to unsplittable ones, since their decomposition is fully determined by phasing paths (line 3 and line 4). When Algorithm 1 reaches line 5, all vertices must be trivial vertices. When Algorithm 1 reaches line 6, s and t are the only two vertices in the splice graph (since all other vertices, either trivial or nontrivial, have been decomposed), thus every edge must point from s to t (called s-t edges). Each s-t edge in the final splice graph corresponds to an s-t path in the original splice graph, and we can reconstruct such s-t paths through tracing back the information we maintained in each individual decomposition step. The weight of each s-t edge in the final splice graph will become the abundance f (p) of the corresponding s-t path p of the original splice graph.

Algorithm 1: Heuristic for Problem 1

Input: G, w, H and g

Output: P and f

1. Let be the set of unsplittable vertices.

2. Let be the set of splittable vertices.

3. If , compute , decompose v by updating G, w and H, and goto step1.

4. If , compute , decompose v by updating G, and goto step1.

5. Arbitrarily choose a (trivial) vertex , decompose v by updating G and H, and goto step1.

6. For all the s-t edges of G, recover the original s-t paths as P; set f as the corresponding weights of the edges.

After collecting transcripts from all gene loci, we further filter very short and those expressed at extremely low levels, since they are more likely false-positive transcripts. Specifically, we filter a transcript if its length is less than L 0 + N e ·L 1 , where N e is the number of exons in this transcript, and L 0 and L 1 are two parameters (by default they are 150 and 50, respectively). A transcript is also removed if its predicted abundance f(p) is less than a small value (by default this value is 1.0 and 20 for multi-exon transcripts and single-exon transcripts, respectively).

Statistics.

All error bars represent the s.d. See Life Sciences Reporting Summary.

Data availability.

Scallop is freely available as open source (Supplementary Code) and at http://www.github.com/Kingsford-Group/scallop. The scripts and links to the data sets used to compare Scallop with other transcript assemblers and to generate the results presented here are available at http://www.github.com/Kingsford-Group/scalloptest.