Erratum to: A representation of a compressed de Bruijn graph for pan-genome analysis that enables search

[This corrects the article DOI: 10.1186/s13015-016-0083-7.].


Introduction
Today, next generation sequencers produce vast amounts of DNA sequence information and it is often the case that multiple genomes of the same or closely related species are available. An example is the 1000 Genomes Project, which started in 2008. Its goal was to sequence the genomes of at least 1000 humans from all over the world and to produce a catalog of all variations (SNPs, indels, etc.) in the human population. The genomic sequences together with this catalog is called the "pan-genome" of the population. There are several approaches that try to capture variations between many individuals/strains in a population graph; see e.g. [24,13,22,7]. These works all require a multi-alignment as input. By contrast, Marcus et al. [16] use a compressed de Bruijn graph of maximal exact matches (MEMs) as a graphical representation of the relationship between genomes; see Section 3 for a definition of de Bruijn graphs. They describe an O(n log g) time algorithm that directly computes the compressed de Bruijn graph on a suffix tree, where n is the total length of the genomes and g is the length of the longest genome. Marcus et al. write in [16,Section 4]: "Future work remains to improve splitMEM and further unify the family of sequence indices. Although ..., most desired are techniques to reduce the space consumption ..." In this article, we present such a technique. To be more precise, we will develop an O(n log σ) time algorithm that constructs the compressed de Bruijn graph directly on an FM-index of the genomes, where σ is the size of the underlying alphabet. This algorithm is faster than the algorithms described in a preliminary version of this article [3]. Moreover, we propose a new space-efficient representation of the compressed de Bruijn graph that adds the possibility to search for a pattern (e.g. an allele-a variant form of a gene) within the pan-genome. More precisely, one can use the FM-index to search for the pattern and, if the pattern occurs in the pan-genome, one can start the exploration of the compressed de Bruijn graph at the nodes that correspond to the pattern.
The contracted de Bruijn graph introduced by Cazaux et al. [6] is closely related but not identical to the compressed de Bruijn graph. A node in the contracted de Bruijn graph is not necessarily a substring of one of the genomic sequences (see the remark following Definition 3 in [6]). Thus the contracted de Bruijn graph, which can be constructed in linear time from the suffix tree [6], is not useful for our purposes.

Preliminaries
Let Σ be an ordered alphabet of size σ whose smallest element is the sentinel character $. In the following, S is a string of length n on Σ having the sentinel character at the end (and nowhere else). In pan-genome analysis, S is the concatenation of multiple genomic sequences, where the different sequences are separated by special symbols (in practice, we use one separator symbol and treat the different occurrences of it as if they were different characters; see Section 4.1). For 1 ≤ i ≤ n, S[i] denotes the character at position i in S. For i ≤ j, S[i..j] denotes the substring of S starting with the character at position i and ending with the character at position j. Furthermore, S i denotes the i-th suffix S[i..n] of S. The suffix array SA of the string S is an array of integers in the range 1 to n specifying the lexicographic ordering of the n suffixes of S, that is, it satisfies S SA [1] < S SA [2] < · · · < S SA[n] ; see Fig. 1 for an example. A suffix array can be constructed in linear time; see e.g. the overview article [21]. For every substring ω of S, the ω-interval is the suffix array interval [i..j] so that ω is a prefix of S SA [k] if and only if i ≤ k ≤ j.
The wavelet tree [12] of the BWT supports one backward search step in O(log σ) time [9]: Given the ω-interval [lb..rb] and a character c ∈ Σ, backwardSearch(c, [lb..rb]) re- -1  0  0  10  5  G  $  2  12  0  1  0  13  6  T  ACG$  3  8  3  0  0  14  7  T  ACGTACG$  4  4  7  1  0  15  8  T  ACGTACGTACG$  5  1  2  0  0  1  9  $  ACTACGTACGTACG$  6  13  0  0  0  2  10  A  CG$  7  9  2  0  0  3  11  A  CGTACG$  8  5  6  0  0  4  12  A  CGTACGTACG$  9  2  1  0  1  5  15  A  CTACGTACGTACG$  10  14  0  0  0  6  1  C  G$  11  10  1  0  0  7  13  C  GTACG$  12  6  5  0  1  8 . In other words, if the i-th entry in the suffix array is the suffix S q , then LF(i) "points" to the entry at which the suffix S q−1 can be found; see Fig. 1. The function Ψ is the inverse of the LF-mapping. Using the wavelet tree of the BWT, a value LF(i) or Ψ(i) can be calculated in O(log σ) time. For later purposes, we recall how the LF-mapping can be computed from the BWT. First, the C-array is calculated, where for each c ∈ Σ, C[c] is the overall number of occurrences of characters in BWT that are strictly smaller than c. Second, if in a left-to-right scan of the BWT, where the loop-variable i varies from 1 to n, C[c] is incremented by one for c = BWT[i], then LF The suffix array SA is often enhanced with the so-called LCP-array containing the lengths of longest common prefixes between consecutive suffixes in SA; see Fig. 1. Formally, the LCP-array is an array so that LCP [1] where lcp(u, v) denotes the longest common prefix between two strings u and v. The LCP-array can be computed in linear time from the suffix array and its inverse, but it is also possible to construct it directly from the wavelet tree of the BWT in O(n log σ) time with the help of the procedure getIntervals [2].
A substring ω of S is a repeat if it occurs at least twice in S. Let ω be a repeat of length ℓ and let [i.
A left-and rightmaximal repeat is called maximal repeat. (Note that [16] use the term "maximal exact match" instead of the more common term "maximal repeat". We will not use the term "maximal exact match" here.) A detailed explanation of the techniques used here can be found in [18].

Compressed de Bruijn graph
Given a string S of length n and a natural number k, the de Bruijn graph of S contains a node for each distinct length k substring of S, called a k-mer. Two nodes u and v are connected by a directed edge (u, v) if u and v occur consecutively in S, i.e., Fig. 2 shows an example. Clearly, the graph contains at most n nodes and n edges. By construction, adjacent nodes will overlap by k − 1 characters, and the graph can include multiple edges connecting the same pair of nodes or self-loops representing overlapping repeats. For every node, except for the start node (containing the first k characters of S) and the stop node (containing the last k characters of S), the in-degree coincides with the out-degree. A de Bruijn graph can be "compressed" by merging non-branching chains of nodes into a single node with a longer string. More precisely, if node u is the only predecessor of node v and v is the only successor of u (but there may be multiple edges (u, v)), then u and v can be merged into a single node that has the predecessors of u and the successors of v. After maximally compressing the graph, every node (apart from possibly the start node) has at least two different predecessors or its single predecessor has at least two different successors and every node (apart from the stop node) has at least two different successors or its single successor has at least two different predecessors; see Fig. 2. Of course, the compressed de Bruijn graph can be built from its uncompressed counterpart (a much larger graph), but this is disadvantageous because of the huge space consumption. That is why we will build it directly.   3 shows how splitMEM represents the compressed de Bruijn graph G for k = 3 and the string S = ACTACGTACGTACG$. Each node corresponds to a substring ω of S and consists of the components (id, len, posList, adjList), where id is a natural number that uniquely identifies the node, len is the length |ω| of ω, posList is the list of positions at which ω occurs in S (sorted in ascending order), and adjList is the list of the successors of the node (sorted in such a way that the walk through G that gives S is induced by the adjacency lists: if node G[id] is visited for the i-th time, then its successor is the node that can be found at position i in the adjacency list of G  The nodes in the compressed de Bruijn graph of a pan-genome can be categorized as follows: • a uniqueNode represents a unique substring in the pan-genome and has a single start position (i.e., posList contains just one element) • a repeatNode represents a substring that occurs at least twice in the pan-genome, either as a repeat in a single genome or as a segment shared by multiple genomes.
In pan-genome analysis, S is the concatenation of multiple genomic sequences, where the different sequences are separated by a special symbol #. (In theory, one could use pairwise different symbols to separate the sequences, but in practice this would blow up the alphabet.) This has the effect that # may be part of a repeat. In contrast to splitMEM, our algorithm treats the different occurrences of # as if they were different characters. Consequently, # will not be a part of a repeat. In our approach, each occurrence of # will be the end of a stop node (i.e., there is a stop node for each sequence). According to [16], the compressed de Bruijn graph is most suitable for pan-genome analysis: "This way the complete pan-genome will be represented in a compact graphical representation such that the shared/strain-specific status of any substring is immediately identifiable, along with the context of the flanking sequences. This strategy also enables powerful topological analysis of the pan-genome not possible from a linear representation." It has one defect though: it is not possible to search efficiently for certain nodes and then to explore the graph in the vicinity of these nodes. A user might, for example, want to search for a certain allele in the pan-genome and-if it is present-to examine the neighborhood of that allele in the graph. Here, we propose a new space-efficient representation of the compressed de Bruijn graph that adds exactly this functionality.
We store the graph in an array G of length N , where N is the number of nodes in the compressed de Bruijn graph. Moreover, we assign to each node a unique identifier id ∈ {1, . . . , N }. A node G[id] now has the form (len, lb, size, suffix_lb), where There is one exception though: the sentinel $ and each occurrence of the separator # will be the end of a stop node. Clearly, the suffix $ of S appears at index 1 in the suffix array because $ is the smallest character in the alphabet. The suffix array interval of $ is [1.
.1], so we set suffix _lb = 1. Analogously, a suffix of S that starts with # appears at an index j ∈ {2, . . . , d} in the suffix array (where d is the number of sequences in S) because # is the second smallest character in the alphabet, so we set suffix _lb = j. Fig. 4 shows an example. Henceforth this representation will be called implicit representation, while the representation from Fig. 3 will be called explicit representation. It is clear that in the implicit representation the list of all positions at which ω occurs in S can be computed as follows: . It will be explained later, how the graph can be traversed and how a pattern can be searched for. We shall see that this can be done efficiently by means of the fourth component suffix _lb.

Construction algorithm
We will build the implicit representation of the compressed de Bruijn graph directly from an FM-index (the wavelet tree of the BWT) of S, using Lemma 1 (the simple proof is omitted).

Lemma 1.
Let v be a node in the compressed de Bruijn graph and let ω be the string corresponding to v. If v is not the start node, then it has at least two different predecessors if and only if the length k prefix of ω is a left-maximal repeat. It has at least two different successors if and only if the length k suffix of ω is a right-maximal repeat.
c ω right-maximal k-mer split c ω left-maximal k-mer split Figure 5: The string ω must be split if the length k prefix of cω is a right-maximal repeat or the length k prefix of ω is a left-maximal repeat.
The general idea behind our algorithm is as follows. Compute the suffix array intervals of all right-maximal k-mers. For each such k-mer v, compute all cv-intervals, where c ∈ Σ. Then, for each u = cv, compute all bu-intervals, where b ∈ Σ, etc. In other words, we start with all right-maximal k-mers and extend them as long as possible (and in all possible ways with the procedure getIntervals), character by character, to the left. According to Lemma 1, the left-extension of a string ω must stop if (i) the length k prefix of ω is a left-maximal repeat (this is the case if the procedure getIntervals applied to the ω-interval returns a non-singleton list). It must also stop if (ii) the length k prefix v of cω is a right-maximal repeat for some c ∈ Σ; see Fig. 5. This is because by Lemma 1 there is a node uv, u ∈ Σ * , in the compressed de Bruijn graph with at least two different successors (the length k suffix v of uv is a right-maximal repeat). Consequently, there must be a directed edge (uv, ω) in the compressed de Bruijn graph. In the following, we will explain the different phases of the algorithm in detail.

Computation of right-maximal k-mers and node identifiers
The construction algorithm uses two bit vectors B r and B l . To obtain the bit vector B r , we must compute all right-maximal k-mers and their suffix array intervals. Let u be a right-maximal k-mer and consider the u-interval [lb..rb] in the suffix array. Note that (1) LCP[lb] < k and (2) LCP[rb + 1] < k. Since u is right-maximal, u is the longest common prefix of all suffixes in the interval [lb..rb]. This implies (3) LCP[j] ≥ k for all j with lb + 1 ≤ j ≤ rb and (4) LCP[j] = k for at least one j with lb + 1 ≤ j ≤ rb (in the terminology of [1], [lb..rb] is an lcp-interval of lcp-value k). It follows as a consequence that the bit vector B r can be calculated with the help of the LCP-array. Using the algorithm of [2], Algorithm 1 constructs the LCP-array directly from the BWT in O(n log σ) time, where σ is the size of the alphabet. It is not difficult to verify that lines 8 to 16 of Algorithm 1 compute all suffix array intervals of right-maximal k-mers. Furthermore, on lines 15 and 16 the boundaries lb and rb = i − 1 of the k-mer intervals are marked by setting the entries of B r at these positions to 1. On line 17, the node (lb, k, i − lb, lb) having the current value of the variable counter as identifier is added to the graph G. In contrast to the last two components, the first two components of a node may change later (they will change when a left-extension is possible). On line 18, the node identifier is added to the queue Q and then counter is incremented by one. compute the array C of size σ 4: initialize two bit vectors B r and B l of length n with zeros 5: open ← true 10: if if open then 14: if kIndex > lb then 15: enqueue(Q, counter) 19: counter ← counter + 1 20: if lastdiff > lb then 21: We would like to stress that all right-maximal k-mers can be determined without the entire LCP-array. In order to verify whether or not an interval satisfies properties (1)-(4), it is sufficient to compute all entries ≤ k in the LCP-array (the others have a value > k). Since the algorithm of [2] calculates entries in the LCP-array in ascending order, it is ideal for our purposes. We initialize an array L with values 2 and set L[1] = 0 and L[n + 1] = 0. Two bits are enough to encode the case "< k" by 0, the case "= k" by 1, and the case "> k" by 2 (so initially all entries in the LCP-array are marked as being > k, except for L [1] and L[n + 1], which are marked as being < k). Then, for ℓ from 0 to k − 1, the algorithm of [2] calculates all indices p with entries LCP[p] = ℓ and sets L[p] = 0. Furthermore, it continues to calculates all indices q with entries LCP[q] = k and sets L[q] = 1. Now the array L contains all the information that is needed to compute right-maximal k-mers.
As already mentioned, in pan-genome analysis S = S 1 #S 2 # . . . S d−1 #S d $ is the concatenation of multiple genomic sequences S 1 , . . . , S d , separated by a special symbol #. Our algorithm treats the different occurrences of # as if they were different characters. Assuming that # is the second smallest character, this can be achieved as follows. As explained above, all right-maximal k-mers can be determined without the entire LCP-array if the algorithm in [2]  .rb] and LF is the last-to-first mapping. How this is done by means of the C-array will be explained below. So a one in B l marks a k-mer that precedes a left-maximal k-mer. Since we are only interested in those k-mers that are not right-maximal (right-maximal k-mers are already covered by bit vector B r ), lines 29 to 37 of Algorithm 1 reset those one-bits in B l to zero that mark a right-maximal k-mer.
It remains for us to explain the computation of the B l vector with the C-array. After the computation of the C-array on line 3 of Algorithm 1, for each c ∈ Σ, C[c] is the overall number of occurrences of characters in S that are strictly smaller than c. Moreover, after line 7 of Algorithm 1 was executed, we have (to see this, recall from Section 2 how the LF-mapping can be computed from the BWT). Thus, when the for-loop on lines 6 to 28 of Algorithm 1 is executed for a certain value of i, we have Apart from the direct construction of the LCP-array from the BWT, which takes O(n log σ) time, Algorithm 1 has a linear run-time. The overall run-time is therefore O(n log σ).

Construction of the space-efficient representation
Algorithm 2 constructs the implicit representation of the compressed de Bruijn graph. It calls Algorithm 1, which computes-besides the two bit vectors B r and B l -the suffix array interval [lb..lb + size − 1] of each right-maximal k-mer ω, stores the quadruple (k, lb, size, lb) at G[id], where id = (rank 1 (B r , lb) + 1)/2 (this is because Algorithm 1 computes right-maximal k-mer intervals in lexicographical order), and adds id to the (initially empty) queue Q. The attributes G[id].size and G[id].suffix _lb will never change, but the attributes G[id].len and G[id].lb will change when a left-extension is possible.
Algorithm 2 Construction of the implicit compressed de Bruijn graph.   Now, the algorithm proceeds by case analysis. If the length k prefix of cω is a rightmaximal repeat, there must be a node v that ends with the length k prefix of cω (note that cω[1..k] and ω have a suffix-prefix-overlap of k − 1 characters), and this node v will be detected by a computation that starts with the k-mer cω[1..k]. Consequently, the computation stops here. If the length k prefix of cω is not a right-maximal repeat, one of the following two cases occurs: 2. Otherwise, ω is left-maximal. In this case, a split occurs (so the attributes of G[id] will not change any more) and Algorithm 2 must continue with the k-mer prefix x = cω[1.
.k] of cω. For the correctness of the algorithm, it is important to note that the interval [i..j] is the x-interval; see Lemma 3. We use the bit vector B l to assign the unique identifier newId = rightM ax+rank 1 (B l , i−1)+1 to the next node, which corresponds to (or ends with) x (recall that rightM ax is the number of all right-maximal k-mers and that x is not a right-maximal k-mer).
and newId is added to Q. .q] that has a prefix cub so that cu is a proper prefix of cω and b = cω[ℓ + 1]. Consequently, cu is a right-maximal repeat. Clearly, this implies that u is a right-maximal repeat as well. We consider two cases: 1. ℓ = k: In this case, Algorithm 2 stops (the length k prefix cu of cω is a rightmaximal repeat), so it cannot execute Case 2; a contradiction.
2. ℓ > k: Note that u has length ℓ − 1 ≥ k. Since u is a right-maximal repeat, it is impossible that the procedure getIntervals is applied to the ω-interval [lb.
We claim that Algorithm 2 has a worst-case time complexity of O(n log σ) and use an amortized analysis to prove this. Since the compressed de Bruijn graph has at most n nodes, it is an immediate consequence that at most n identifiers enter and leave the queue Q (this covers Case 2). Case 1 can occur at most n times because there are at most n left-extensions; so at most n intervals generated by the procedure getIntervals belong to this category. Each left-extension eventually ends; so at most n intervals generated by the procedure getIntervals belong to this category because there are at most n left-extensions. In summary, at most 2n intervals are generated by the procedure getIntervals. Since this procedure takes O(log σ) time for each generated interval, the claim follows.

Construction of the explicit compressed de Bruijn graph
In this section, we show how the explicit compressed de Bruijn graph can be constructed efficiently from the implicit representation. If the pan-genome consists of d sequences, then S = S 1 #S 2 # . . . S d−1 #S d $ and there are d stop nodes. Since the implicit representation allows for an efficient backward traversal, there is no need for start nodes. By contrast, the explicit graph must provide them. That is why Algorithm 3 stores them in an array StartN odes of size d.
Algorithm 3 starts with the stop node of the last sequence S d , which has identifier id = rightM ax + lef tM ax + 1. Let ω be the string corresponding to node id. . To find the predecessor of node newId in the same fashion, we must find the index idx at which the suffix S newP os can be found in the suffix array. According to Lemma 4, this is G[newId].lb + (i − G[newId].suffix _lb). The while-loop repeats the search for a predecessor node until a separator symbol is found. In this case, a start node has been reached and its identifier is stored in an array StartN odes of size d. Since there are d separator symbols, the whole process is executed d times. i ← LF (idx) Algorithm 3 has a worst-case time complexity of O(N log σ), where N is the number of edges in the compressed de Bruijn graph. This is because in each execution of the while-loop an edge is added to the graph and a value LF(idx) is computed in O(log σ) time (all other operations take only constant time). Since the uncompressed de Bruijn graph has at most n edges, so does the compressed graph. Hence N ≤ n. In fact, N is much smaller than n in virtually all cases. It follows from the preceding section that N can be characterized in terms of left-and right-maximal k-mer repeats. We have seen that the number of nodes in the compressed de Bruijn graph equals |V 1 | + |V 2 | + d = rightM ax + lef tM ax + d, where V 1 = {ω | ω is a right-maximal k-mer repeat in S} and V 2 = {ω | ∃i ∈ {1, . . . , n − k} : .i+k] is a left-maximal k-mer repeat in S}; the stop nodes are taken into account by adding d. The number N of edges in the compressed de Bruijn graph therefore is |{i

Operations on the compressed de Bruijn graph
It is our next goal to show how the combination of the implicit graph and the FM-index can be used to search for a pattern P of length m ≥ k. This is important, for example, if one wants to search for a certain allele in the pan-genome and-if it is present-to examine the neighborhood of that allele in the graph. Algorithm 4 shows pseudo-code for such a search. The main difficulty is to find the node of the k-length suffix of P in the implicit graph. Once we have found this node, we can use the method introduced in the previous section to continue the search (where backward search replaces the LF-mapping). The key observation is that [i..j] is the suffix array interval of u. Moreover, u can be written as c 1 c 2 . . . c ℓ x, where c q ∈ Σ for q ∈ {1, . . . , ℓ} and x is the k-mer suffix of u. Note that the value of ℓ is unknown. Since c 2 . . . c ℓ x is not left-maximal, it follows that [Ψ(i)..Ψ(j)] is its suffix array interval (this can be proven by similar arguments as in the proof of Lemma 4). Algorithm 4 iterates this process until either on line 18 the identifier of a stop node or on lines 9-13 the identifier of a non-stop-node is found. In the latter case, there are ℓ characters before the k-mer suffix x of u; so |u| = ℓ + k and therefore G[id].len − ℓ − k characters precede u in ω (see line 21). In the former case, u = c 1 c 2 . . . c ℓ # has length ℓ + 1 and thus G[id].len − ℓ − 1 characters precede u in ω. To obtain this value on line 21, k is subtracted from ℓ + 1 on line 20. if i > j then 4: return an empty list ⊲ k-length suffix of P does not occur in the input id ← rightM ax + rank 1 (B l , i − 1) + 1 14: else 15: i ← Ψ(i) ⊲ Ψ is the inverse of LF 16: j ← Ψ(j) 17: ℓ ← ℓ + 1 18: if i ≤ d then ⊲ stop node 19: id ← rightM ax + lef tM ax + i 20: return resList To summarize, after ℓ is set to its new value on line 21 of Algorithm 4, we know that id is the identifier of the node whose corresponding string ω contains P [m−k+1..m] and that there are ℓ characters preceding P [m − k + 1..m] in ω. On line 22 the list resList, which will eventually contain the nodes corresponding to pattern P , is initialized with the element id. Of course, ℓ is bounded by the length of the longest string corresponding to a node, but this can be proportional to n. As a matter of fact, the worst case occurs when the algorithm gets a de Bruijn sequence of order k on the alphabet Σ as input: this is a cyclic string of length n = σ k containing every length k string over Σ exactly once as a substring. For example, the string aacagatccgctggtt is a de Bruijn sequence of order k = 2 on the alphabet Σ = {a, c, g, t}. The compressed de Bruijn graph for such a sequence has just one node and the corresponding string is the de Bruijn sequence itself. In practice, however, ℓ is rather small; see end of Section 6.
Algorithm 4 finds the nodes in the compressed de Bruijn graph that correspond to a pattern P . In this context, the following (and similar) questions arise: • In which sequences (or genomes) does pattern P (or node v) occur?
• In how many sequences (or genomes) does pattern P (or node v) occur?
• How often does pattern P (or node v) occur in a specific sequence (or genome)?
To answer these questions efficiently, we employ the document array D of size n = |S|. An entry D[i] = j means that the suffix S SA[i] belongs to (or starts within) the sequence S j , where j ∈ {1, . . . , d}. The document array can be constructed in linear time from the suffix array or the BWT; see e.g. [18, p. 347]. If we store the document array in a wavelet tree, then the above-mentioned questions can be answered as follows: Given the suffix array interval [lb..rb] of pattern P (or node v), the procedure call getIntervals([lb..rb]) on the wavelet tree of the document array returns a list consisting of all sequence numbers j in which P occurs plus the number of occurrences of P in S j . The worst-case time complexity of the procedure getIntervals is O(z + z log(d/z)), where z is the number of elements in the output list; see Section 1.

Experimental results
The experiments were conducted on a 64 bit Ubuntu 14.04.1 LTS (Kernel 3.13) system equipped with two ten-core Intel Xeon processors E5-2680v2 with 2.8 GHz and 128GB of RAM (but no parallelism was used). All programs were compiled with g++ (version 4.8.2) using the provided makefile. As test files we used the E.coli genomes listed in the supplementary material of [16]. Additionally, we used 5 different assemblies of the human reference genome (UCSC Genome Browser assembly IDs: hg16, hg17, hg18, hg19, and hg38) as well as the maternal and paternal haplotype of individual NA12878 (Utah female) of the 1000 Genomes Project; see [23]. Our software and test data are available at https://www.uni-ulm.de/in/theo/research/seqana.html; splitMEM can be obtained from http://sourceforge.net/projects/splitmem/.
We implemented the three algorithms A1-A3 described in the preliminary version of this article [3] and our new algorithm A4 using Simon Gog's library sdsl [11]. Both A1 and A2 require at least n log n bits because the suffix array must be kept in main memory. Hence Yuta Mori's fast algorithm divsufsort can be used to construct the suffix array without increasing the memory requirements. By contrast, A3 and A4 use a variant of the semi-external algorithm described in [4] to construct the BWT. Both A3 and A4 store the BWT in a wavelet tree and use additional bit vectors; see Section 4.1. The variants of the algorithms that appear in Table 1 are as follows: A3compr1 and A4compr1 compress only the additional bit vectors, A3compr2 and A4compr2 also compress the (bit vectors in the) wavelet tree, whereas A3 and A4 do not use these compression options at all. In contrast to the other algorithms, A4 (and its variants) constructs the implicit graph (instead of the explicit graph) and the wavelet tree of the document array. For a comparison with the other algorithms, we also measured (called A4+explicit) the construction of the implicit and the explicit graph (i.e., the combination of Algorithms 2 and 3).
The first part of Table 1 (in which the k column has the entries init) shows how much time (in seconds) an algorithm needs to construct the index data structure and its maximum main memory usage in bytes per base pair. In the experiments, we built compressed de Bruijn graphs for the 62 E. coli genomes (containing 310 million base pairs) using the k-mer lengths 50, 100, and 500. Table 1 shows the results of these experiments. The run-times include the construction of the index, but similar to splitMEM it is unnecessary to rebuild the index for a fixed data set and varying values of k. The peak memory usage reported in Table 1 includes the size of the index and the size of the compressed de Bruijn graph. Due to its large memory requirements, splitMEM was not able to build a compressed de Bruijn graph for all 62 strains of E. coli on our machine equipped with 128 GB of RAM. That is why we included a comparison based on the first 40 E. coli genomes (containing 199 million base pairs) of the data set.  Table 1: The first column shows the k-mer size (an entry init means that only the index data structure is constructed) and the second column specifies the algorithm used in the experiment. The remaining columns show the run-times in seconds and, in parentheses, the maximum main memory usage in bytes per base pair (including the construction) for the data sets described in the text. A minus indicates that the respective algorithm was not able to solve its task on our machine equipped with 128 GB of RAM.
The experimental results show that our algorithms are more than an order of magnitude faster than splitMEM while using significantly less space (two orders of magnitude). To show the scalability of the new algorithms, we applied them to different assemblies of the human genome (consisting of 23 chromosomes: the 22 autosomes and the X-chromosome). The compressed de Bruijn graphs of their first chromosomes (7xChr1, containing 1,736 million base pairs) and the complete seven genomes (7xHG, containing 21,201 million base pairs) were built for the k-mer lengths 50, 100, and 500. One can see from Table 1 that algorithms A1 and A2 are very fast, but 128 GB of RAM was not enough for them to successfully build the graph for the seven human genomes (note that at least 5 bytes per base pair are required). So let us compare algorithms A3 and A4 (and their variants). The construction of the explicit graph with A4+explicit is faster than with A3, but A4+explicit seems to use much more space for this task. The space comparison, however, is not fair because A4 also constructs the wavelet tree of the document array and two select data structures for the wavelet tree of the BWT to calculate Ψ values. These data structures are important for searches on the graph, but they are superfluous in the construction of the explicit graph. So in fact A4+explicit uses only a little more space for this task because the implicit representation of the graph, which must be kept in main memory, is rather small. Table 2 contains a detailed breakdown of the space usage of the variants of algorithm A4. As the explicit compressed de Bruijn graph, the combination of the implicit graph and the FM-index supports a graph traversal (albeit in backward direction). For this task the implicit graph and the FM-index use much less space than the explicit graph. In contrast to the explicit graph, our new data structure allows to search for a pattern P in the graph and to answer questions like: In how many sequences does P occur? It is this new functionality (notably the document array) that increases the memory usage again; cf. Table 2. Despite this new functionality, the overall space consumption of A4 is in most cases less than that of A3; see Table 1.
In our next experiment, we measured how long it takes to find the nodes in the graph that correspond to a pattern P . Since the median protein length in E. coli is 278 and a single amino acid is coded by three nucleotides, we decided to use a pattern length of 900. Table 3 shows the results for 10, 000 patterns that occur in the pangenome (if patterns do not occur in the pan-genome, the search will be even faster; data not shown). Furthermore, we measured how long it takes to determine to which sequences each node belongs (using the procedure getIntervals on the wavelet tree of the document array as described at the end of Section 5). Table 4 shows the results for the nodes corresponding to 10, 000 patterns that occur in the pan-genome.
Finally, we determined the length of the longest string corresponding to a node in the compressed de Bruijn graph. This is important because the worst-case search time depends on this length; see end of Section 4.3. The results can be found in Table 5 Table 2: The first column shows the algorithm used in the experiment (the k-mer size is 50). The second column specifies the different data structures used: wt-bwt stands for the wavelet tree of the BWT (including rank and select support), nodes stands for the array of nodes (the implicit graph representation), B r and B l are the bit vectors described in Section 4.1 (including rank support), and wt-doc stands for the wavelet tree of the document array. The remaining columns show the memory usage in bytes per base pair and, in parentheses, their percentage. Table 3: The first column shows the k-mer size and the second column specifies the algorithm used in the experiment. The remaining columns show the run-times in seconds for finding the nodes corresponding to 10, 000 patterns of length 900 (that occur in the pan-genome) and, in parentheses, the maximum main memory usage in bytes per base pair for the data sets described in the text. Table 4: The first column shows the k-mer size and the second column specifies the algorithm used in the experiment. The remaining columns show the runtimes in seconds for finding out to which sequences each of the nodes belongs (where the nodes correspond to 10, 000 patterns of length 900 that occur in the pan-genome) and, in parentheses, the maximum main memory usage in bytes per base pair for the data sets described in the text.

Conclusions
We have presented a space-efficient method to build the compressed de Bruijn graph from scratch. An experimental comparison with splitMEM showed that our algorithm is more than an order of magnitude faster than splitMEM while using significantly less space (two orders of magnitude). To demonstrate its scalability, we successfully applied it to seven complete human genomes. Consequently, it is now possible to use the compressed de Bruijn graph for much larger pan-genomes than before (consisting e.g. of hundreds or even thousands of different strains of bacteria). Moreover, the combination of the implicit graph and the FM-index can be used to search for a pattern P in the graph (and to traverse the graph). Future work includes a parallel implementation of the construction algorithm. Moreover, it should be worthwhile to investigate the time-space trade-off if one uses data structures that are optimized for highly repetitive texts; see [17] and the references therein.