Bloom Filter Trie: an alignment-free and reference-free data structure for pan-genome storage

Background High throughput sequencing technologies have become fast and cheap in the past years. As a result, large-scale projects started to sequence tens to several thousands of genomes per species, producing a high number of sequences sampled from each genome. Such a highly redundant collection of very similar sequences is called a pan-genome. It can be transformed into a set of sequences “colored” by the genomes to which they belong. A colored de Bruijn graph (C-DBG) extracts from the sequences all colored k-mers, strings of length k, and stores them in vertices. Results In this paper, we present an alignment-free, reference-free and incremental data structure for storing a pan-genome as a C-DBG: the bloom filter trie (BFT). The data structure allows to store and compress a set of colored k-mers, and also to efficiently traverse the graph. Bloom filter trie was used to index and query different pangenome datasets. Compared to another state-of-the-art data structure, BFT was up to two times faster to build while using about the same amount of main memory. For querying k-mers, BFT was about 52–66 times faster while using about 5.5–14.3 times less memory. Conclusion We present a novel succinct data structure called the Bloom Filter Trie for indexing a pan-genome as a colored de Bruijn graph. The trie stores k-mers and their colors based on a new representation of vertices that compress and index shared substrings. Vertices use basic data structures for lightweight substrings storage as well as Bloom filters for efficient trie and graph traversals. Experimental results prove better performance compared to another state-of-the-art data structure. Availability https://www.github.com/GuillaumeHolley/BloomFilterTrie.


Background
A string x is a sequence of characters drawn from a finite, non-empty set, called the alphabet A. Its length is denoted by |x|. The character at position i is denoted by x[i], the substring starting at position i and ending at position j by x[i..j]. Strings are concatenated by juxtaposition. If x = ps for (potentially empty) strings p and s, then p is a prefix and s is a suffix of x.
A genome is the collection of all inheritable material of a cell. Ideally it can be represented as a single string over the DNA alphabet A = {a, c, g, t} (or as a few strings in case of species with multiple chromosomes). In practice, however, genomes in databases are often less perfect, either left unchanged in form of the raw data as produced by sequencing machines (millions of short sequences called reads), or after some incomplete assembly procedure in form of contiguous chromosome regions (hundreds of contigs of various lengths). We are interested in the problem of storing and compressing a set of multiple highly similar genomes, e.g. the pangenome of a bacterial species, comprising hundreds, or

Open Access
Algorithms for Molecular Biology *Correspondence: gholley@cebitec.uni-bielefeld.de even thousands of strains that share large sequence parts, but differ by individual mutations from one another. An abstract structure that has been proposed for this task is the colored de Bruijn graph (C-DBG) [1]. It is a directed graph G = (V G , E G ) in which each vertex v ∈ V G represents a k-mer, a string of length k over A, associated with a set of colors representing the genomes in which the k-mer occurs. A directed edge e ∈ E G from vertex v to vertex v ′ , respectively from k-mer x to k-mer x ′ , exists if x [2..k] = x ′ [1..k − 1]. Each k-mer x has |A| possible successors x [2..k] c and |A| possible predecessors cx [1..k − 1] with c ∈ A. An implementation of such a graph does not have to store edges since they are implicitly given by vertices overlapping on k − 1 characters.
In this paper, we propose a new data structure for indexing and compressing a pan-genome as a C-DBG, the Bloom Filter Trie (BFT). It is alignment-free, reference-free and incremental, i.e., it does not need to be entirely rebuilt when a new genome is inserted. BFTs provide insertion and look-up operations for strings of fixed length associated with an annotation. This paper is an extended version of the preliminary work presented in [2].
In the next section, existing data structures and software for pan-genome representation are reviewed. The BFT and the operations it supports are then described, followed by the traversal method of a C-DBG stored as a BFT. Finally, experimental results showing the performance of the data structure are provided.

Existing approaches
The BFT, as well as existing tools for pan-genome storage, uses a variety of basic data structures reviewed in the following. Existing tools for pan-genome storage will then be discussed.

Data structures
One common way to index and compress a set of strings is the Burrows-Wheeler Transform (BWT) [3] that rearranges the input data to enable better compression by aggregating characters with similar context. For multiple sets of strings, a disk-based approach [4] or different terminator characters must be used. The FM-Index [5] [7] is a binary tree with BFs as vertices. An internal vertex is the union of its two children BFs, i.e., a BF where a slot is set to 1 if the slot at the same position in at least one of the two children is 1.
A trie [8] is a rooted edge-labeled tree T = (V T , E T ) storing a set of strings. Each edge e ∈ E T is labeled with a character and no two edges starting at the same vertex can have the same character. A path from the root to a leaf represents the string obtained by concatenating all the characters on this path. The depth of a vertex v in T is denoted by depth(v, T) and is the number of edges between the root of T and v. The height of T, denoted by height(T), is the number of edges on the longest path from the root of T to a leaf. The burst trie [9] is an efficient implementation of a trie which reduces its number of branches by compressing sub-tries into leaves. Its internal vertices are labeled with multiple prefixes of length 1, linked to children. The leaves are labeled with multiple suffixes of arbitrary length. A leaf has a limited capacity of suffixes and is burst when this capacity is exceeded. A burst splits suffixes of a leaf into prefixes of length 1, linked to new leaves representing the remaining suffixes.

Software for pan-genome storage
Existing tools for pan-genome storage are mostly alignment-based or reference-based and take a set of assembled genomes as input. Alignments naturally exhibit shared and unique regions of the pan-genome but are computationally expensive to obtain. In addition, misalignments can lead to an inaccurate estimation of the pan-genome regions [10]. PanCake [11] is an extension of string graphs, known from genome assembly [12], which achieves compression based on pairwise alignments. Experiments showed compression ratios of 3:1 to 5:1. Nguyen et al. [13] formulated the pangenome construction problem as an optimization problem of arranging alignment blocks for a set of genomes partitioned by homology. The complexity of the problem has been shown to be NP-hard, and a heuristic using Cactus graphs [14] was provided. However, a multiple sequence alignment is required for creating the blocks, another NPhard problem.
Among the reference-based tools, Huang et al. [15] proposed to build a pan-genome by annotating a reference genome with all the variants detected between a set of genomes and the reference. The BWT of the augmented reference is then computed and can be used by an aligner based on the FM-Index. While being more accurate with the augmented reference genome than BWA [16] with the reference alone, the aligner is between 10 to 100 times slower, uses significantly more memory and can introduce false positive alignments. RCSI [17] (Referentially Compressed Search Index) uses referential compression with a compressed suffix tree to store a pan-genome and to search for exact or inexact matches. The inexact matching allows a limited number of edit distance operations. 1092 human genomes totaling 3.09 TB of data were compressed into an index of 115 GB, offering a compression ratio of about 28:1. Yet, the index is built for a maximum length query and a maximum number of edit operations. MRCSI [18] improves on RCSI by proposing a compressed search index based on multiple references.
Closer to our approach is SplitMEM [19], which uses a C-DBG to build a pan-genome from assembled genomes and extract the shared regions. The C-DBG is directly constructed in a compressed way, where a non-branching path is stored in a single vertex, using an augmented suffix tree. Baier et al. [20] improved SplitMEM in theory and practice with two algorithms that use the BWT and a compressed suffix tree. Unfortunately, both tools use more memory than the original size of the input sequences.
The tool Khmer [21] provides a lightweight representation of de Bruijn graphs [22] based on Bloom filters and a graph labeling method based on graph partitioning. Unfortunately, the graph labeling method does not offer yet enough flexibility to reproduce the experiments presented in this paper.
The SBT data structure has been implemented in an alignment-free, reference-free and incremental software [7] to label raw sequences with their colors. The proposed tool is designed to index and compress data from sequencing experiments for effective query of full-length genes or transcripts by separation into k-mers. A leaf of an SBT is used to represent a sequencing experiment by extracting all its k-mers and storing them in the BF of the leaf. The SBT software does not represent exactly the set of k-mers of the sequencing experiments they contain, though, due to the inexact nature of BFs.

The Bloom Filter Trie
The Bloom Filter Trie (BFT) that we propose in this paper is an implementation of a C-DBG. It is based on a burst trie and is used to store k-mers associated with a set of colors. For the moment we may assume that colors are represented by a bit array color initialized with 0s. Each color has an index i color such that color x [i color ] = 1 records that k-mer x has color i color . Sets of colors will later be compressed. All arrays in a BFT are dynamic: An insertion at position pos in an array A reallocates it and shifts every slot having an index ≥ pos by one position in O(|A|) time.
In the following, let t = (V t , E t ) be a BFT created for a certain value of k where we assume that k is a multiple of an integer l such that k-mers can be split into k l equal-length substrings. The maximum height of t is height max (t) = k l − 1. The alphabet we consider is the DNA alphabet A = {a, c, g, t}, and because |A| = 4, each character can be stored using two bits. A vertex in a BFT is a list of containers, zero or more of which are compressed, plus zero or one uncompressed container. In the following, we will explain how the containers are represented and how an uncompressed container is burst when its capacity is exceeded.

Uncompressed container
An uncompressed container of a vertex v in a BFT is a limited capacity set of tuples <s, color ps > where s is a suffix and p is the prefix represented by the path from the root to v such that |p| + |s| = k. Tuples are lexicographically ordered in the set according to their suffixes. Uncompressed containers are burst when the number of suffixes stored exceeds their capacity c > 0. Then, each suffix s of the uncompressed container is split into a prefix s pref of length l and a suffix s suf of length |s| − l such that s = s pref s suf . Prefixes are stored in a new compressed Fig. 1 Insertion of six suffixes (that are here complete k-mers) with different colors (boxes with diagonal lines) into a BFT with k = 12, l = 4 and c = 5. In a, the first five suffixes are inserted at the root into an uncompressed container. When a sixth suffix gcgccaggaatc is inserted, the uncompressed container exceeds its capacity and is burst, resulting in the BFT structure shown in b container. Suffixes, attached with their colors, are stored in new uncompressed containers, themselves stored in the children of the compressed container. An example of a BFT and a bursting is given in Fig. 1.

Compressed container
A bursting replaces an uncompressed container by a compressed one, used to: • store q ≤ c suffix prefixes in compressed form (in Fig. 1b, q = 4), • store links to children containing the suffixes, and • reconstruct suffix prefixes and find the corresponding children.
To store a suffix prefix s pref efficiently, it is split into a prefix a and a suffix b with respective binary representations α and β of length and µ bits. A compressed container is composed of four structures quer, pref, suf and clust, where: • quer is a BF represented as a bit array of length m and f hash functions, used to record and filter for the presence of q suffix prefixes; • pref is a bit array of 2 bits initialized with 0s and used to record prefix presence exactly. Here the binary representation α of a prefix a is interpreted as an integer such that pref [α] set to 1 records the presence of a; • suf is an array of q suffixes b sorted in ascending lexicographic order of the original suffix prefixes they belong to; • clust is an array of q bits, one per suffix of array suf, that represents cluster starting points. A cluster is a list of consecutive suffixes in array suf that share the same prefix. It has an index i cluster with 1 ≤ i cluster ≤ 2 and a start position pos cluster in the array suf with i cluster ≤ pos cluster ≤ q. Position pos in array clust is set to 1 to indicate that the suffix in suf[pos] starts a cluster because it is the lexicographically smallest suffix of its cluster. A cluster contains n ≥ 1 suffixes and, therefore, position i in array clust is set to 0 for pos < i < pos + n. The end of a cluster is indicated by the beginning of the next cluster or if pos ≥ q.
• For example, the internal representation of the compressed container shown in Fig. 1b with |a| = 2 and |b| = 2 would be: The size of q substrings in a compressed container is m + 2 + q · (µ + 1) bits. A bursting minimizes this size by choosing a prefix length |a| and a BF size m such that the set of substrings stored in a compressed container does not occupy more memory than their original representation in an uncompressed container, i.e., m + 2 ≤ q · ( − 1). Each suffix prefix inserted after a bursting costs only µ + 1 bits. When the average size per suffix prefix stored is close to µ + 1 bits, arrays pref, suf and clust can be recomputed by increasing |a| and decreasing |b|, such that 2 ′ + q · µ ′ < 2 + q · µ, where ′ and µ ′ are the values of and µ, respectively, after resizing.

Operations supported by the Bloom Filter Trie
The BFT supports all operations necessary for storing, traversing and searching a pan-genome, as well as to extract the relevant information of the contained genomes and subsets thereof. Here we describe the most basic ones of them, Look-up and Insertion, as well as how the sets of colors are compressed. The traversal of the graph is discussed in the next section.
The algorithms use three auxiliary functions. HammingWeight(α, pref ) counts the number of 1s in pref [1.
.α] and corresponds to how many prefixes represented in array pref are lexicographically smaller than or equal to an inserted prefix a with binary representation α of length bits. This requires O(2 ) time. The second function, Rank(i, clust), iterates over array clust from its first position until the ith entry 1 is found and returns the position of this entry. It corresponds to the start position of cluster i in array clust. If the entry is not found, the function returns |clust| + 1 as a position. While Rank could be implemented in O(1) time [5], we use a more naive but space efficient O(q) time implementation, where q is the number of suffix prefixes in a compressed container. Finally, BinarySearch(uc, s) searches for the suffix s in the uncompressed container uc in O(log 2 c) time, where c is the capacity of uc.

Look-up
The function that tests whether a suffix prefix s pref = ab with binary representation αβ is stored in a compressed container cc is given in Algorithm 1.

Insertion
Prior to any k-mer insertion into a BFT t, a look-up verifies if the k-mer is already present. If it is, only its set of colors is modified. Otherwise, the look-up stops the trie traversal on a container cont of a vertex v where the searched suffix prefix or k-mer suffix is not present. If cont is uncompressed, the insertion of the k-mer suffix and its color is a simple O(log 2 c) time process. If cont is compressed, the insertion of suffix prefix s pref = ab is a bit more intricate. In fact, it will only be triggered if cont is the first compressed container of v to have s pref as a false positive (MayContain(s pref , cont.quer) = true and Contains(s pref , cont) = false). False positives are therefore "recycled", which is a nice property of BFTs: The BF quer remains unchanged, and only pref, suf and clust need to be updated in a way similar to Algorithm 1. The presence of prefix a must be first verified by testing the value of pref The function that tests whether a k-mer x is present in a BFT t = (V t , E t ) is given in Algorithm 2. Each vertex v ∈ V t represents k-mer suffixes possibly stored in its uncompressed container or rooted from its compressed containers. The look-up traverses t from the root and, for a vertex v, queries its containers one after the other for suffix .l] cannot be in another container of v because of the insertion process explained later in this paper. If the container is uncompressed, the presence of x suf is detected using the function BinarySearch . As an uncompressed container has no children, a match indicates the presence of the k-mer. Algorithm 2 is initially called as TreeContains(x, 1, l, root). In the worst case, all vertices on a traversed path represent all possible suffix prefixes and the BFs quer have a false positive ratio of 0. In such case, each traversed vertex contains |A| l c containers. The longest path of a BFT has k l vertices. Therefore, the worst case time of k-mer is O(d + 2 + 2q) with d being the worst case time look-up. The internal representation of the compressed container shown in Fig. 1b after insertion of the suffix prefix gtat is given below (inserted parts are highlighted). The presence of prefix gt is recorded in pref [12]. Then, its cluster index and start position are computed as 4 and 5, respectively. Consequently, after reallocation of arrays suf and clust, suffix at is inserted in suf [5] and clust [5] is set to 1 to indicate that suf [5] starts a new cluster. Lemma 1 Let G be a C-DBG represented by a BFT t, x a k-mer in t and v a vertex of t that terminates the shared subpath of the k-mers in succ(x, G). If depth(v, t) = height max (t), succ(x, t) suffixes may be stored in any container of v. If not, they are stored in the uncompressed container of v.
Proof A vertex v is the root of a sub-trie storing k-mer suffixes of length l · (height max (t) − depth(v, t) + 1) with l = k height max (t)+1 . Let s be a k-mer suffix of succ(x, t)

Color compression
Remember from the BFT description that color sets associated with k-mers in a C-DBG are initially stored as bit arrays in BFTs. However, these can be compressed by storing sets of colors that are identical for multiple k-mers once. To this end, a list of all color sets occurring in the BFT is built and sorted in decreasing order of total size, i.e., the number of k-mers sharing a color set multiplied by its size. Then, by iterating over the list, each color set is added incrementally to an external array if the integer encoding its position in the array uses less space than the size of the color set itself. Finally, each color set present in the external array is replaced in the BFT by its position in the external array.

Traversing successors and predecessors
Let t be a BFT that represents a C-DBG G. For a k-mer x, visiting all its predecessors or successors in G, denoted pred(x, G) and succ(x, G), respectively, implies the look-up of |A| different k-mers in t. Such a look-up would visit in the worst case |A| · (height max (t) + 1) vertices in t. This section describes how to reduce the number of vertices and containers visited in t during the traversal of a vertex in G.
Observation 1 Let G be a C-DBG represented by a BFT t and x a k-mer corresponding to a vertex of G. All k-mers of succ(x, G) share x [2..k] as a common prefix and therefore share a common subpath in t starting at the root. On the other hand, k-mers of pred(x, G) have different first characters and, therefore, except for the root of t do not share a common subpath. Hence, the maximum number of visited vertices in t for all k-mers of succ(x, G) is 1 + height max (t) and for all k-mers of pred(x, G) is 1 + |A| · height max (t).
rooted at a vertex v ∈ V t . If depth(v, t) � = height max (t) but s is rooted at a compressed container in v, then this compressed container stores s [1..l], and s[l + 1..|s|] is rooted in one of its children. As the divergent character between the k-mer suffixes of succ(x) is in position |s| − 1 , this character is in s[l + 1..|s|], rooted at one child of this compressed container. Therefore v does not terminate the common subpath shared by succ(x, t) k-mers. Restricting the hash functions used in the compressed containers to take only positions 2 through l − 1 into account, allows to limit the search space. Proof Assume a k-mer suffix s inserted in a vertex v of t. A look-up for s analyzes the containers of v from the head to the tail of the container list. In the worst case, s can be rooted, according to BFs quer, in all compressed containers as a true positive or as a false positive. However, a look-up stops either on the first compressed container claiming to contain the suffix prefix s pref = s[1..l] , or on the uncompressed container. As the hash functions of quer consider only s pref [2..l − 1], a look-up will therefore stop on the same container for any substring s ′ pref = c 1 s pref [2..l − 1]c 2 .
As a consequence of Lemma 2, each suffix prefix s pref stored or to store in arrays pref, suf and clust is modified such that s ′ pref = s pref [2.
.l]s pref [1], which guarantees that all s ′′ pref = s ′ pref [1..l − 2]c 2 c 1 are in the same container. Furthermore, suffixes stored in array suf are required to have a minimum length of two characters to ensure that characters c 1 and c 2 , the variable parts between the different s ′′ pref , are stored in array suf. Hence, as all s ′′ pref share s ′ pref [1..l − 2] as a prefix, they share the same cluster in arrays suf and clust. Suffix prefixes s ′′ pref = s ′ pref [1..l − 1]c 1 also have consecutive suffixes in their cluser.

Evaluation
We compared BFT, version 0.5, to SBT [7], version 0.3.5, on a mid-class laptop with an SSD hard drive and an Intel Core i5-4300M processor cadenced at 2.6 GHz, using a single thread. It was not possible to include Khmer in this evaluation as it does not support k > 32 and building a labeled de Bruijn graph with it requires concatenated raw sequence files as input, where it is not possible to specify a minimum number of occurences per k-mer. Results provided in this section can differ from those reported in the preliminary version of this paper [2] as evaluated software versions are different and computational cost of k-mer counting is now excluded. Also main memory usage is now provided in addition to the disk space usage. BFT and SBT were used to represent one real and one simulated pan-genome dataset. The real dataset consists of raw sequencing data from 473 clinical isolates of Pseudomonas aeruginosa sampled from 34 patients (NCBI BioProject PRJEB5438), resulting in 820.76 GB of FASTQ files. The simulated dataset corresponds to 154 isolates generated from 19 strains of Yersinia pestis. For each isolate, we used Wgsim [23] to create 6,000,000 reads of length 100 with a substitution sequencing error rate of 0.5 %, resulting in 233.84 GB of FASTQ files. We first used KmerGenie [24] on a subsample of the files for each dataset to estimate the best k-mer length and the minimum number of occurrences for considering a k-mer valid (not resulting from a sequencing error). A length of k = 63 with a minimum number of 3 occurrences was selected for the real and a length of k = 54 with a minimum of 15 occurrences for the simulated data set. The capacity c influences the compression ratio as well as the time for insertion and look-up. We chose a value of c = 248, as it showed a good compromise in practice. The prefix length l determines the size of several internal structures of the BFT and how efficiently they can be stored. We selected l = 9, as this limits the internal fragmentation of the memory. As the size of BFs used by the SBT software must be specified prior to the k-mer insertion and should be the same for all vertices, the authors of SBT suggested to estimate the number of unique k-mers in each dataset to design the size of BFs, at the price of an extra computation time (personal communication). Since we knew the exact number of unique k-mers from the BFT construction, we used this instead: 93,201,551 63-mers for the real dataset and 37,334,323 54-mers for the simulated dataset, resulting in BF sizes of 11.11 MB and 4.45 MB, respectively. We also reused unique k-mer counts computed by the BFT to estimate the number of hash functions to use in SBT: One hash function for the real dataset and two hash functions for the simulated dataset. Insertion time and memory usage are shown in Table 1. Insertion time and peaks of memory include the compression steps proposed by both tools, i.e., color compression and RRR compression [25], respectively. The SBT disk sizes are given for the leaves first, since the internal vertices can be reconstructed from them, and then for the complete tree. The compressed disk size corresponds to the size of both data structures on disk, compressed using 7z [26] with the highest compression level and LZMA2 [26] as compression method.
We suspect that 7z delivers such a high compression ratio for the BFT because it takes advantage of the data redundancy among the uncompressed containers, particularly among the sets of colors. Indeed, the color compression step used by the BFT is rather simple but keeps the sets of colors fully indexed and, therefore, does not penalize insertion time. In contrast, SBT uses a more advanced compression method, RRR, which explains the lower compression ratio offered by 7z. The final size of the BFT in main memory and on disk for all pangenomes made of one up to all isolates for the real and simulated dataset is shown in Figs. 2 and 3, respectively. As shown, the memory growth of the BFT is largely sublinear with respect to the size of the input data.
For each dataset, a set of randomly selected k-mers of the BFT was written to disk and reused as a batch query for both data structures. Real and simulated dataset batch queries contain ten million 63-mers and 54-mers, respectively. Query times are shown in Table 2.