Algorithm Search⌘K

Data structurecore

Splice graph

Also called splicing graph.

A DAG of the exon segments of a gene locus, with an edge for each junction seen in the reads. Each transcript is a path, but not every path is a transcript.

A splice graph is a directed acyclic graph that holds all the ways a gene was seen to splice in a sample. Its nodes are the segments of the genome that the reads cover, cut at every splice site, and its edges join a segment to the next one along a read, either directly or across an intron. Every transcript that the reads came from is a path of the graph, and the transcript assembly problem is to pick the right paths and their abundances. Heber, Alekseyev, Sze, Tang and Pevzner (2002) introduced the splicing graph for EST data, and genome-guided assemblers such as StringTie build one from spliced read alignments.

In plain words

Think of a gene as a road with optional parts. Some parts are always used, some are skipped by some copies of the message, and some start a little later than others.

Cut the road at every place where a read jumps away or lands. Each piece between two cuts is a node. Draw an arrow from one piece to the next whenever some read goes from the first to the second, either by running straight on or by jumping over an intron.

Each message that the cell made is now a route through the arrows. The graph also allows routes that mix the choices of different messages, so a route is a candidate, not a proof.

The abstract type

A splice graph of one locus on one strand is a directed acyclic graph G=(V,E)G = (V, E) with an interval of the genome on each node. It supports these operations:

  • BUILD(alignments): make the graph from a set of spliced alignments.
  • PATH-OF(alignment): the list of nodes that an alignment passes through.
  • COUNT-PATHS(): the number of paths from a source (a node with no predecessor) to a sink (a node with no successor).
  • PATHS(): the list of these paths.
  • SPELL(path): the exons of a path, with touching nodes merged.

Weighted versions also store the number of reads on each node and on each edge, which is the input of flow-based assembly and path cover assembly.

Representation

The page uses 1-based closed intervals, as in SAM and GFF; the code uses 0-based half-open intervals, so the page's 201..250201..250 is [200,250)[200, 250) in the code. An alignment is a list of blocks, the parts between the N operations of its CIGAR. The gap between two blocks is an intron: its donor is the last base of the block before it and its acceptor is the first base of the block after it.

The fields are a sorted array of node intervals, a successor and a predecessor list for each node, and the sorted list of introns. The invariants: the node intervals are disjoint and in coordinate order; no donor and no acceptor is strictly inside a node, so a junction always leaves from the end of a node and lands at the start of a node; and every edge goes from a node to a node further right. The last invariant makes the coordinate order a topological order.

Operations

  1. BUILD(alignments)
  2. 1B ← all blocks of all alignments; I ← all introns (donor, acceptor) of all alignments
  3. 2C ← the donors and the acceptors in I
  4. 3U ← the union of B as maximal covered intervals, in coordinate order
  5. 4V ← the intervals of U cut at each point of C strictly inside them, in order
  6. 5for each block in B: add an edge between each pair of consecutive nodes that the block overlaps
  7. 6for each intron (d, a) in I: add an edge from the node that ends at d to the node that starts at a
  8. 7return (V, E)

Line L4 makes the cuts that line L6 needs: every donor ends a node and every acceptor starts one. Line L5 joins the nodes that one block runs through. A covered region that holds no splice site stays one node, however many reads cover it. With the cuts sorted, BUILD costs O((∣B∣+∣I∣)log⁡(∣B∣+∣I∣))O((|B| + |I|) \log(|B| + |I|)) time plus the total length of the paths of the blocks.

  1. PATH-OF(alignment)
  2. P1 P ← empty list
  3. P2 for each block [s..e] of the alignment, in order:
  4. P3 append the nodes that overlap [s..e], in order, by binary search for s in the node starts
  5. P4 return P

PATH-OF costs O(rlog⁡∣V∣+∣P∣)O(r \log |V| + |P|) for an alignment with rr blocks. It is how a read becomes a subpath constraint for the assemblers.

  1. COUNT-PATHS()
  2. C1 for v ← 1 to |V| do
  3. C2 w(v) ← 1 if v has no predecessor, else the sum of w(u) over the edges (u, v)
  4. C3 return the sum of w(v) over the nodes v with no successor

COUNT-PATHS costs O(∣V∣+∣E∣)O(|V| + |E|). PATHS lists the paths by depth-first search from each source, in time proportional to the total length of its output. The count can be exponential: a gene with kk exons that can each be skipped independently has 2k2^k paths.

Example

A gene has the exons E1 = 1..1001..100, E2 = 201..300201..300 and E3 = 401..500401..500, and E2 has a second acceptor at 251. Three transcripts are expressed: t1t_1 = E1, E2, E3; t2t_2 = E1, 251..300251..300, E3; and t3t_3 = E1, E3, which skips E2. Their full-length alignments are the input of BUILD.

step state
L1 introns, as (donor, acceptor): (100, 201), (300, 401), (100, 251), (100, 401)
L2 splice sites: donors 100 and 300, acceptors 201, 251 and 401
L3 covered intervals: 1..1001..100, 201..300201..300, 401..500401..500
L4 nodes: v1=1..100v_1 = 1..100, v2=201..250v_2 = 201..250, v3=251..300v_3 = 251..300, v4=401..500v_4 = 401..500
L5 the block 201..300201..300 of t1t_1 runs through v2v_2 and v3v_3: edge (v2,v3)(v_2, v_3)
L6 junction edges (v1,v2)(v_1, v_2), (v3,v4)(v_3, v_4), (v1,v3)(v_1, v_3), (v1,v4)(v_1, v_4)

COUNT-PATHS gives w(v1)=1w(v_1) = 1, w(v2)=1w(v_2) = 1, w(v3)=w(v1)+w(v2)=2w(v_3) = w(v_1) + w(v_2) = 2, w(v4)=w(v1)+w(v3)=3w(v_4) = w(v_1) + w(v_3) = 3, and the answer 3. The paths are v1v2v3v4v_1 v_2 v_3 v_4, v1v3v4v_1 v_3 v_4 and v1v4v_1 v_4, and SPELL turns them back into t1t_1, t2t_2 and t3t_3.

Now a short read with the CIGAR 20M150N20M at position 81 has the blocks 81..10081..100 and 251..270251..270. PATH-OF gives (v1,v3)(v_1, v_3): the read shows the junction of t2t_2 and nothing about where the transcript starts or ends. Add a fourth transcript E1, 201..300201..300 without E3; it adds no node and no edge, but it makes v3v_3 a possible end, and the graph cannot record that.

Correctness

The proof shows four facts. The nodes partition the covered bases, and the cuts are exactly the splice sites inside covered regions. Every input alignment is a path, PATH-OF returns it, and its exons have the same introns as the alignment. The edge set is exactly the set of consecutive pairs of these paths, so the graph has no edge without a read behind it, and every edge goes to the right, so the graph is acyclic. COUNT-PATHS is right by induction in coordinate order. The proof also gives the two limits: some paths are not transcripts, and a transcript that starts or ends inside a node is not a source-to-sink path.

Proof: The splice graph is a DAG in which every input alignment is a path, every edge comes from an alignment, and the path count is rightfull

We use the BUILD pseudocode of the page and its 0-based, half-open coordinates. An alignment aa is a list of blocks [s1,e1),…,[sr,er)[s_1, e_1), \ldots, [s_r, e_r) with si<eis_i < e_i and ei<si+1e_i < s_{i+1}. Each pair (ei,si+1)(e_i, s_{i+1}) is an intron with donor eie_i and acceptor si+1s_{i+1}. Let BB be the set of all blocks of all alignments, II the set of introns, CC the set of donors and acceptors (line L2), and U=⋃BU = \bigcup B the covered bases.

1. The nodes

Line L3 merges the blocks into the maximal intervals [x,y)[x, y) of UU; blocks that touch or overlap are merged. Line L4 cuts each such interval at the points of CC strictly inside it. So the nodes are disjoint intervals that partition UU, and they are numbered in coordinate order.

Lemma 1. A point pp is the end of one node and the start of the next node if and only if pp is inside a maximal interval of UU and p∈Cp \in C. Every point of CC is a node boundary: each donor is the end of a node and each acceptor is the start of a node.

Proof. The first sentence is the definition of line L4. A donor d=eid = e_i is the end of a block, so d−1∈Ud - 1 \in U. Either dd is the end of a maximal interval of UU, and then the last node of that interval ends at dd, or dd is strictly inside a maximal interval, and then line L4 cuts at dd. In both cases a node ends at dd. An acceptor si+1s_{i+1} is the start of a block, and the same argument gives a node that starts there. □\square

So no node holds a donor or an acceptor strictly inside it, and the nodes are the largest intervals with this property: two nodes that touch are separated by a point of CC, and two nodes that do not touch are separated by uncovered bases. The test file checks this against a position-by-position definition.

2. Every alignment is a path

For a block [s,e)[s, e), let span(s,e)\mathrm{span}(s, e) be the nodes that overlap it, in order. Line L5 adds an edge between each pair of consecutive nodes of each span.

Lemma 2. The nodes of span(s,e)\mathrm{span}(s, e) are consecutive and each one ends where the next starts.

Proof. The block lies inside one maximal interval of UU, because it is covered. Inside that interval the nodes are consecutive and touch, by line L4. The nodes that overlap [s,e)[s, e) form a contiguous run of them. □\square

Theorem 1. For every input alignment aa, the list path(a)\mathrm{path}(a), which is the concatenation of the spans of its blocks, is a path of the graph. Its spelled exons have the same introns as aa.

Proof. Inside one block, consecutive nodes are joined by line L5. Between blocks ii and i+1i + 1, the last node of span(si,ei)\mathrm{span}(s_i, e_i) ends at eie_i, because by Lemma 1 a node ends at eie_i and the bases ei−1e_i - 1 and eie_i are in different nodes. In the same way the first node of the next span starts at si+1s_{i+1}. Line L6 adds exactly the edge from the node that ends at eie_i to the node that starts at si+1s_{i+1}. So every consecutive pair of path(a)\mathrm{path}(a) is an edge. Merging the nodes of each span gives one exon per block, which ends at eie_i and starts at si+1s_{i+1} at each intron. □\square

3. Every edge comes from an alignment, and the graph is acyclic

Theorem 2. The edge set equals the set of consecutive pairs of path(a)\mathrm{path}(a) over all input alignments aa. Every edge (u,v)(u, v) has end(u)≤start(v)\mathrm{end}(u) \le \mathrm{start}(v), so u<vu < v, and the graph is a DAG in which the node order is a topological order.

Proof. Line L5 adds the consecutive pairs inside spans, and line L6 adds the pairs at introns; by the proof of Theorem 1 these are exactly the consecutive pairs of the paths, and the lines add nothing else. An edge of line L5 joins touching nodes, so end(u)=start(v)\mathrm{end}(u) = \mathrm{start}(v). An edge of line L6 goes from a node ending at a donor eie_i to a node starting at si+1>eis_{i+1} > e_i. Node ids follow coordinates, so u<vu < v for every edge, and no cycle exists. □\square

4. Counting and listing paths

COUNT-PATHS sets w(v)=1w(v) = 1 for a source and w(v)=∑(u,v)w(u)w(v) = \sum_{(u, v)} w(u) otherwise, in increasing order of vv, and returns ∑v sinkw(v)\sum_{v \text{ sink}} w(v).

Theorem 3. w(v)w(v) is the number of paths from a source to vv, so the result is the number of source-to-sink paths.

Proof. By induction on vv. All predecessors uu of vv have u<vu < v by Theorem 2, so w(u)w(u) is final when vv is processed. A source has only the one-node path. A path from a source to a non-source vv ends with exactly one edge (u,v)(u, v), and removing it leaves a path from a source to uu; this is a bijection, so the count is ∑uw(u)\sum_u w(u). □\square

The listing of all paths by depth-first search from every source is correct for the same reason: in a DAG every walk is a path, every extension by an edge is explored, and the search stops at sinks. The test file compares both with a brute force over all subsets of nodes.

5. What is not true

A source-to-sink path need not be a transcript: the graph also holds every combination of the splice choices, also those that no input alignment has. And a transcript need not be a source-to-sink path: if two alignments start at different points of the same exon, the node that holds both starts is the same, and the graph forgets which start was used. Both are limits of the model, not errors of the construction. ■\blacksquare

Complexity

∣B∣|B| is the number of blocks, ∣I∣|I| the number of distinct introns, rr the number of blocks of one alignment and ∣P∣|P| the length of its path.

operation time space
BUILD O((∣B∣+∣I∣)log⁡(∣B∣+∣I∣))O((\lvert B \rvert + \lvert I \rvert) \log(\lvert B \rvert + \lvert I \rvert)) plus the total path length O(∣V∣+∣E∣)O(\lvert V \rvert + \lvert E \rvert)
PATH-OF O(rlog⁡∣V∣+∣P∣)O(r \log \lvert V \rvert + \lvert P \rvert) O(∣P∣)O(\lvert P \rvert)
COUNT-PATHS O(∣V∣+∣E∣)O(\lvert V \rvert + \lvert E \rvert) O(∣V∣)O(\lvert V \rvert)
PATHS O(∣V∣+∣E∣)O(\lvert V \rvert + \lvert E \rvert) plus the size of the output O(∣V∣)O(\lvert V \rvert) for the stack, plus the output

The graph is small: $|V| \le 2|I| + $ the number of covered intervals, and ∣E∣≤∣V∣+∣I∣|E| \le |V| + |I|, because line L5 only adds edges between touching nodes and line L6 adds one edge for each intron. The code is a toy and cuts each covered interval by a scan over all splice sites, which costs O(∣U∣⋅∣C∣)O(|U| \cdot |C|) instead of the sorted merge.

Variants

  • A source and a sink. StringTie adds a source node and a sink node to the graph, joined to the nodes where transcripts can start and end, so that every candidate transcript is a path from the source to the sink.
  • Weights. The number of reads on each node and each junction, or the mean coverage per base. These weights are what assemblers use to choose paths.
  • Phasing paths. Scallop keeps, besides the edges, the paths that single reads or read pairs cover, so that the choices at two splice sites stay linked. The general form is a path problem with subpath constraints.
  • Splicing graphs from ESTs. Heber and others built the graph from expressed sequence tags and gene annotations, before short reads.
  • Annotation graphs. Built from known transcripts only, the graph holds the annotated splicing, and the reads only add weights.
  • One graph per strand. With a stranded library, reads give the strand. Without one, the strand of a junction comes from its splice site motif, such as GT-AG.

When to use it

Use a splice graph for genome-guided assembly and for splicing analysis when a reference genome is known: it holds every junction of a locus in a few hundred nodes, and it can be built in one pass over sorted alignments. Without a genome, use a de Bruijn graph of the reads instead, as in de novo transcriptome assembly. For a read mapper that maps only to known transcripts, a transcript index is simpler, and the graph is not needed.

Pitfalls

  • Reading every path as a transcript. The paths combine all choices, and their number can be exponential. Line C3 counts candidates, not isoforms; assemblers pick a few paths with the read evidence.
  • Lost starts and ends. Line L4 cuts only at splice sites. Two transcripts that start at different points of the same first exon share one node. Cut also at read start clusters, or keep the ends in a separate list, if the starts matter.
  • Off by one at junctions. In 1-based closed coordinates the donor of an intron 101..200101..200 is base 100 and the acceptor is base 201. Mixing this with half-open coordinates in line L6 joins the wrong nodes.
  • Spurious junctions. A read that is misaligned by a few bases makes a false intron in line L1, and a false node boundary in line L4. Filter junctions by read count, by anchor length and by splice motif before BUILD.
  • Mixed strands. Antisense genes overlap. Build one graph per strand, or the paths mix the two genes.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

splice_graph.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/splice-graph/. The authors are listed in prov/7RCBRT.jsonl.

"""A splice graph built from spliced alignments on one strand of one locus.

An alignment is a list of blocks (start, end), 0-based and half-open, in
increasing order, with a gap of at least one base between consecutive blocks.
Each gap is an intron: it goes from the donor (the end of the block before
it) to the acceptor (the start of the block after it).

The nodes are the maximal intervals of covered bases that hold no donor and
no acceptor inside them: the covered region is cut at every donor and every
acceptor. The nodes are numbered in coordinate order, which is a topological
order, because every edge goes to the right. There is an edge (u, v) when one
block runs from node u into node v, which then starts where u ends, or when
an intron joins the end of u to the start of v.
"""

from __future__ import annotations

from bisect import bisect_right
from typing import Dict, List, Sequence, Set, Tuple

Block = Tuple[int, int]
Alignment = Sequence[Block]


def _check(alignment: Alignment) -> None:
    if not alignment:
        raise ValueError("an alignment needs at least one block")
    for s, e in alignment:
        if s >= e:
            raise ValueError("a block needs start < end")
    for (_, e1), (s2, _) in zip(alignment, alignment[1:]):
        if s2 <= e1:
            raise ValueError("blocks must be in order with an intron between them")


class SpliceGraph:
    def __init__(self, alignments: Sequence[Alignment]):
        blocks: List[Block] = []
        introns: Set[Tuple[int, int]] = set()
        for a in alignments:  # @line L1
            _check(a)
            blocks.extend(a)
            introns.update((a[i][1], a[i + 1][0]) for i in range(len(a) - 1))
        cuts = {d for d, _ in introns} | {s for _, s in introns}  # @line L2
        covered: List[List[int]] = []  # @line L3
        for s, e in sorted(blocks):
            if covered and s <= covered[-1][1]:
                covered[-1][1] = max(covered[-1][1], e)
            else:
                covered.append([s, e])
        self.nodes: List[Block] = []
        for s, e in covered:  # @line L4
            pts = sorted({s, e} | {c for c in cuts if s < c < e})
            self.nodes.extend(zip(pts, pts[1:]))
        self._starts = [s for s, _ in self.nodes]
        self.edges: Set[Tuple[int, int]] = set()
        for s, e in blocks:  # @line L5
            span = self._overlapping(s, e)
            self.edges.update(zip(span, span[1:]))
        by_end: Dict[int, int] = {e: i for i, (_, e) in enumerate(self.nodes)}
        by_start: Dict[int, int] = {s: i for i, (s, _) in enumerate(self.nodes)}
        for d, a in introns:  # @line L6
            self.edges.add((by_end[d], by_start[a]))
        self.introns = sorted(introns)
        self.succ: List[List[int]] = [[] for _ in self.nodes]
        self.pred: List[List[int]] = [[] for _ in self.nodes]
        for u, v in sorted(self.edges):
            self.succ[u].append(v)
            self.pred[v].append(u)
        return  # @line L7

    def _overlapping(self, s: int, e: int) -> List[int]:
        """The ids of the nodes that overlap [s, e), in order."""
        i = bisect_right(self._starts, s) - 1
        if i < 0 or self.nodes[i][1] <= s:
            i += 1
        out = []
        while i < len(self.nodes) and self.nodes[i][0] < e:
            out.append(i)
            i += 1
        return out

    def path_of(self, alignment: Alignment) -> List[int]:
        """The node path of an alignment that was used to build the graph."""
        out: List[int] = []
        for s, e in alignment:
            out.extend(self._overlapping(s, e))
        return out

    def sources(self) -> List[int]:
        return [v for v in range(len(self.nodes)) if not self.pred[v]]

    def sinks(self) -> List[int]:
        return [v for v in range(len(self.nodes)) if not self.succ[v]]

    def count_paths(self) -> int:
        """The number of source-to-sink paths, by dynamic programming in node order."""
        ways = [0] * len(self.nodes)
        for v in range(len(self.nodes)):
            ways[v] = 1 if not self.pred[v] else sum(ways[u] for u in self.pred[v])
        return sum(ways[v] for v in self.sinks())

    def paths(self) -> List[List[int]]:
        """All source-to-sink paths, in lexicographic order of node ids."""
        out: List[List[int]] = []
        for s in self.sources():
            stack = [[s]]
            while stack:
                p = stack.pop()
                if not self.succ[p[-1]]:
                    out.append(p)
                for v in reversed(self.succ[p[-1]]):
                    stack.append(p + [v])
        return sorted(out)

    def spell(self, path: Sequence[int]) -> List[Block]:
        """The exons of a node path: runs of nodes that touch are merged into one block."""
        out: List[List[int]] = []
        for v in path:
            s, e = self.nodes[v]
            if out and out[-1][1] == s:
                out[-1][1] = e
            else:
                out.append([s, e])
        return [(s, e) for s, e in out]
test_splice_graph.py 137 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/splice-graph/. The authors are listed in prov/7RCBRT.jsonl.

import random
from itertools import combinations

from splice_graph import SpliceGraph


def project(transcript, start, length):
    """The genome blocks of the read transcript[start:start + length], where transcript is a list of exons."""
    blocks, offset = [], 0
    for s, e in transcript:
        lo, hi = max(start, offset), min(start + length, offset + e - s)
        if lo < hi:
            gs, ge = s + lo - offset, s + hi - offset
            if blocks and blocks[-1][1] == gs:
                blocks[-1] = (blocks[-1][0], ge)
            else:
                blocks.append((gs, ge))
        offset += e - s
    return blocks


def random_locus(rng: random.Random):
    """Random exons on a short genome, transcripts as chains of them, and reads from the transcripts."""
    points = sorted(rng.sample(range(1, 80), 2 * rng.randint(2, 4)))
    exons = [(points[i], points[i + 1]) for i in range(0, len(points), 2)]
    transcripts = []
    for _ in range(rng.randint(1, 4)):
        chosen = sorted(rng.sample(exons, rng.randint(1, len(exons))))
        # An alternative donor or acceptor: move one exon end inside the exon.
        if rng.random() < 0.5:
            j = rng.randrange(len(chosen))
            s, e = chosen[j]
            if e - s >= 3:
                chosen[j] = (s, rng.randint(s + 1, e - 1)) if rng.random() < 0.5 else (rng.randint(s + 1, e - 1), e)
        transcripts.append(chosen)
    alignments = []
    for t in transcripts:
        tlen = sum(e - s for s, e in t)
        alignments.append(project(t, 0, tlen))
        for _ in range(rng.randint(0, 6)):
            length = rng.randint(1, tlen)
            alignments.append(project(t, rng.randint(0, tlen - length), length))
    return alignments


def nodes_by_positions(alignments):
    """The nodes from the definition: runs of covered bases with no donor or acceptor inside."""
    covered, cuts = set(), set()
    for a in alignments:
        for s, e in a:
            covered.update(range(s, e))
        for (_, d), (acc, _) in zip(a, a[1:]):
            cuts.update((d, acc))
    nodes, start = [], None
    for p in range(min(covered), max(covered) + 2):
        inside = p in covered
        if start is not None and (not inside or p in cuts):
            nodes.append((start, p))
            start = None
        if inside and start is None:
            start = p
    return nodes


def test_worked_example():
    # E1 [0, 100), E2 [200, 300) with a second acceptor at 250, E3 [400, 500).
    t1 = [(0, 100), (200, 300), (400, 500)]
    t2 = [(0, 100), (250, 300), (400, 500)]
    t3 = [(0, 100), (400, 500)]
    g = SpliceGraph([t1, t2, t3])
    assert g.nodes == [(0, 100), (200, 250), (250, 300), (400, 500)]
    assert sorted(g.edges) == [(0, 1), (0, 2), (0, 3), (1, 2), (2, 3)]
    assert g.paths() == [[0, 1, 2, 3], [0, 2, 3], [0, 3]]
    assert g.count_paths() == 3
    assert [g.spell(p) for p in g.paths()] == [t1, t2, t3]
    assert g.path_of([(80, 100), (250, 270)]) == [0, 2]


def test_nodes_match_the_definition():
    rng = random.Random(1)
    for _ in range(500):
        alignments = random_locus(rng)
        assert SpliceGraph(alignments).nodes == nodes_by_positions(alignments)


def test_edges_are_the_steps_of_the_alignment_paths():
    rng = random.Random(2)
    for _ in range(500):
        alignments = random_locus(rng)
        g = SpliceGraph(alignments)
        steps = set()
        for a in alignments:
            p = g.path_of(a)
            assert p == sorted(set(p))
            steps.update(zip(p, p[1:]))
        assert g.edges == steps
        for u, v in g.edges:
            assert g.nodes[u][1] <= g.nodes[v][0]


def test_every_transcript_is_a_path():
    rng = random.Random(3)
    for _ in range(300):
        alignments = random_locus(rng)
        g = SpliceGraph(alignments)
        for a in alignments:
            p = g.path_of(a)
            assert all((u, v) in g.edges for u, v in zip(p, p[1:]))
            # The path spells the same introns, and each block lies inside its exon.
            exons = g.spell(p)
            assert len(exons) == len(a)
            for (s, e), (xs, xe) in zip(a, exons):
                assert xs <= s < e <= xe
            for i in range(len(a) - 1):
                assert exons[i][1] == a[i][1] and exons[i + 1][0] == a[i + 1][0]


def test_paths_against_brute_force():
    rng = random.Random(4)
    checked = 0
    while checked < 300:
        g = SpliceGraph(random_locus(rng))
        n = len(g.nodes)
        if n > 12:
            continue
        checked += 1
        src, snk = set(g.sources()), set(g.sinks())
        brute = []
        for r in range(1, n + 1):
            for sub in combinations(range(n), r):
                if sub[0] in src and sub[-1] in snk and all((u, v) in g.edges for u, v in zip(sub, sub[1:])):
                    brute.append(list(sub))
        assert g.paths() == sorted(brute)
        assert g.count_paths() == len(brute)

History

Heber, Alekseyev, Sze, Tang and Pevzner (2002) defined the splicing graph and used it to assemble ESTs, with each transcript as a path. With RNA-seq, genome-guided assemblers built graphs of the same kind from spliced alignments: Pertea and others (2015) used an alternative splice graph with a source and a sink in StringTie, and Shao and Kingsford (2017) added phasing paths in Scallop. Mäkinen, Belazzougui, Cunial and Tomescu (2015) give the graph models of transcript assembly, path covers and flows, in a textbook.

References

  1. Steffen Heber, Max Alekseyev, Sing-Hoi Sze, Haixu Tang and Pavel A. Pevzner, Splicing graphs and EST assembly problem, Bioinformatics 18(Suppl 1) (2002), pp. S181 to S188 (the splicing graph; each transcript is a path in it)
  2. Mihaela Pertea, Geo M. Pertea, Corina M. Antonescu, Tsung-Cheng Chang, Joshua T. Mendell and Steven L. Salzberg, StringTie enables improved reconstruction of a transcriptome from RNA-seq reads, Nature Biotechnology 33(3) (2015), pp. 290 to 295, Online Methods (the alternative splice graph with a source and a sink, built from spliced alignments)
  3. Mingfu Shao and Carl Kingsford, Accurate assembly of transcripts through phase-preserving graph decomposition, Nature Biotechnology 35(12) (2017), pp. 1167 to 1169 (a weighted splice graph with phasing paths)
  4. Veli Mäkinen, Djamal Belazzougui, Fabio Cunial and Alexandru I. Tomescu, Genome-Scale Algorithm Design, Cambridge University Press (2015), Part V, the chapter on transcriptomics (splicing graphs, path covers and flows)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/7RCBRT/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/7RCBRT/text.yaml