This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\journaltitle

TBD \DOITBD \accessAdvance Access Publication Date: Day Month Year \appnotesPreprint

\corresp

[\ast]Corresponding author. hli@ds.dfci.harvard.edu

BWT construction and search at the terabase scale

Heng Li\ORCID0000-0003-4874-2874 Department of Data Science, Dana-Farber Cancer Institute, 450 Brookline Ave, Boston, MA 02215, USA Department of Biomedical Informatics, Harvard Medical School, 10 Shattuck St, Boston, MA 02215, USA Broad Insitute of MIT and Harvard, 415 Main St, Cambridge, MA 02142, USA
(2024; 2024)
Abstract

Motivation: Burrows-Wheeler Transform (BWT) is a common component in full-text indices. Initially developed for data compression, it is particularly powerful for encoding redundant sequences such as pangenome data. However, BWT construction is resource intensive and hard to be parallelized, and many methods for querying large full-text indices only report exact matches or their simple extensions. These limitations have hampered the biological applications of full-text indices.
Results: We developed ropebwt3 for efficient BWT construction and query. Ropebwt3 indexed 320 assembled human genomes in 65 hours and indexed 7.3 terabases of commonly studied bacterial assemblies in 26 days. This was achieved using up to 170 gigabytes of memory at the peak without working disk space. Ropebwt3 can find maximal exact matches and inexact alignments under affine-gap penalties, and can retrieve similar local haplotypes matching a query sequence. It demonstrates the feasibility of full-text indexing at the terabase scale.
Availability and implementation: https://github.com/lh3/ropebwt3

1 Introduction

Although millions of genomes have been sequenced, the majority of them were sequenced from a small number of species such as human, E. coli and M. tuberculosis. As a result, existing genome sequences are highly redundant. This is how Hunt et al., (2024) compressed 7.86 terabases (Tb) of bacterial assemblies, also known as AllTheBacteria, into 78.5 gigabytes (GB) after grouping phylogenetically related genomes (Břinda et al., , 2024). The resultant compressed files losslessly keep all the sequences but are not directly searchable. Indexing is necessary to enable fast sequence search.

K-mer data structures are a popular choice for sequence indexing (Marchet et al., , 2021). They can be classified into three categories. The first category does not associate k-mers with their positions in the database sequences. These data structures support membership query or pseudoalignment (Bray et al., , 2016), but cannot reconstruct input sequences or report base alignment. Sequence search at petabase scale use all such methods (Edgar et al., , 2022; Karasikov et al., , 2024; Shiryev and Agarwala, , 2024). The second category associates a subset of k-mers with their positions. Upon finding k-mer matches, algorithms in this category go back to the database sequences and perform base alignment. Most aligners work this way. However, because the database sequences are not compressed well, these algorithms may require large space to store them. The last category keeps all k-mers and their positions. Algorithms in this category can reconstruct all the database sequences without explicitly storing them. Nonetheless, although positions of k-mers can be compressed efficiently (Karasikov et al., , 2020), they still take large space. The largest lossless k-mer index consists of a few terabases (Karasikov et al., , 2024).

Compressed full-text indices, such as FM-index (Ferragina and Manzini, , 2000) r-index (Gagie et al., , 2018; Bannai et al., , 2020; Gagie et al., , 2020) and move index (Nishimoto and Tabei, , 2021), provide an alternative way for fast sequence search (Navarro, , 2022). The core component of these data structures is often Burrows-Wheeler Transform (BWT; Burrows and Wheeler, 1994) which is a lossless transformation of strings. The BWT of a highly redundant string tends to group symbols in the original string into long runs and can thus be well compressed. When we supplement BWT with a data structure to efficiently compute the rank of a symbol in BWT, we can in theory count the occurrences of a query string in time linear to its length. FM-index further adds a sampled suffix array to locate substrings, while r-index uses an alternative method that is more efficient for redundant strings. Both of them support compression and sequence search at the same time.

BWT-based indices have been used for read alignment (Langmead et al., , 2009; Li and Durbin, , 2009; Li et al., , 2009), de novo sequence assembly (Simpson and Durbin, , 2012), metagenome profiling (Kim et al., , 2016) and data compression (Cox et al., , 2012). They have also emerged as competent data structures for pangenome data. Existing pangenome-focused tools (Rossi et al., , 2022; Ahmed et al., , 2021; Zakeri et al., , 2024) use prefix-free parsing for BWT construction (Boucher et al., , 2019). They require more memory than input sequences and are impractical for huge datasets. Although ropebwt2 developed by us can construct BWT in memory proportional to its compressed size and is fast for short strings (Li, , 2014), it is inefficient for chromosome-long sequences. OnlineRlbwt (Bannai et al., , 2020) has a similar limitation. grlBWT (Díaz-Domínguez and Navarro, , 2023) is likely the best algorithm for constructing the BWT of similar genomes. It reduces the peak memory at the cost of large working disk space. In its current form, the algorithm does not support update to BWT. We would need to reconstruct the BWT from scratch when new genomes arrive. BWT construction for highly redundant sequences remains an active research area.

With BWT-based data structures, it is trivial to test the presence of string PP in the index, but finding substring matches within PP needs more thought. Learning from bidirectional BWT (Lam et al., , 2009), we found a BWT constructed from both strands of DNA sequences supports the extension of exact matches in both directions (Li, , 2012). This gave us an algorithm to compute maximal exact matches (MEMs), which was later improved by Gagie, (2024) for long MEMs. Bannai et al., (2020) proposed a distinct algorithm to compute MEMs without requiring both strands. Matching statistics (Chang and Lawler, , 1994) and pseudo-matching length (PML; Ahmed et al., 2021) have also been considered. All these algorithms find exact local matches only.

It is also possible to identify inexact matches. Kucherov et al., (2016) invented search schemes to find semi-global alignment. With the BWT-SW algorithm, Lam et al., (2008) simulated a suffix trie, a tree data structure, with BWT and performed sequence-to-trie alignment to find all local matches between a query string and the BWT of a large genome. We went a step further by representing the query string with its direct acyclic word graph (DAWG; Blumer et al., 1983) and performed DAWG-to-trie alignment. This is the BWA-SW algorithm (Li and Durbin, , 2010). Nonetheless, we later realized the formulation of BWA-SW had theoretical flaws and its implementation was closer to DAWG-to-DAWG alignment than to DAWG-to-tree alignment.

In this article, we will explain our solution to BWT construction and to sequence search at the terabase scale. Our contribution includes: a) a reinterpreted BWA-SW algorithm that fixes issues in our earlier work (Li and Durbin, , 2010); b) its application in finding similar haplotypes; c) an incremental in-memory BWT construction implementation that scales to large pangenome datasets; d) a faster algorithm to find alignment positions with a standard FM-index of highly redundant strings.

2 Methods

In a nutshell, ropebwt3 computes the partial multi-string BWT of a subset of sequences with libsais (https://github.com/IlyaGrebnov/libsais) and merges the partial BWT into the existing BWT run-length encoded as a B+-tree (Li, , 2014). It repeats this procedure until all input sequences are processed. The BWT by default includes input sequences on both strands. This enables forward-backward search (Li, , 2012) required by accelerated long MEM finding (Gagie, , 2024). Ropebwt3 also reports local alignment with affine-gap penalty using a revised BWA-SW algorithm (Li and Durbin, , 2010).

Ropebwt3 combines and adapts existing algorithms and data structures. Nonetheless, the notations here differ from our early work (e.g. from 1-based to 0-based coordinates) and from other publications. We will describe our methods in full for completeness.

Table 1: Notations and naming convention
\topruleNotation Description
\midruleΣ\Sigma Alphabet of symbols. {𝙰,𝙲,𝙶,𝚃,𝙽}\{{\tt A},{\tt C},{\tt G},{\tt T},{\tt N}\} for DNA
Σ\Sigma^{\prime} Augmented alphabet: ΣΣ{$}\Sigma^{\prime}\triangleq\Sigma\cup\{\$\}
a,b,ca,b,c Symbols in Σ\Sigma^{\prime}
TT Concatenated reference string including sentinels
S(i)S(i) Suffix array: offset of the ii-th smallest suffix
BB BWT string: B[i]T[S(i)1]B[i]\triangleq T[S(i)-1]
mm Number of sentinels: m|{i:B[i]=$}|m\triangleq|\{i:B[i]=\$\}|
nn Total length: n|T|=|B|n\triangleq|T|=|B|
rr Number of runs: r|{i:B[i]B[i+1]}|+1r\triangleq|\{i:B[i]\not=B[i+1]\}|+1
CB(a)C_{B}(a) Accumulative count: CB(a)|{i:B[i]<a}|C_{B}(a)\triangleq|\{i:B[i]<a\}|
rankB(a,k){\rm rank}_{B}(a,k) Rank: rankB(a,k)|{i<k:B[i]=a}|{\rm rank}_{B}(a,k)\triangleq|\{i<k:B[i]=a\}|
πB(a,k)\pi_{B}(a,k) πB(a,k)CB(a)+rankB(a,k)\pi_{B}(a,k)\triangleq C_{B}(a)+{\rm rank}_{B}(a,k)
π(k)\pi(k) LF-mapping: π(k)S1(S(k)1)=πB(B[k],k)\pi(k)\triangleq S^{-1}(S(k)-1)=\pi_{B}(B[k],k)
\botrule

2.1 Basic concepts

Refer to caption
Figure 1: Examples of BWT and related data structures. (a) The BWT BB, suffix array SS and LF-mapping π\pi of string TT. Subscriptions are equal to the ranks of symbols in BB, which are the same as the ranks among the suffixes (indicated by arrows). (b) The prefix trie simulated with BWT BB. In each node, the pair of integers gives the suffix array interval of the string represented by the path from the node to the root. Double circles indicate nodes that can reach the beginning of TT. (c) The prefix directed acyclic word graph (DAWG) of TT by merging nodes with identical suffix array intervals.

Let Σ\Sigma be an alphabet of symbols (Table 1). Given a string PP over Σ\Sigma, |P||P| is its length and P[i]ΣP[i]\in\Sigma, 0i<|P|0\leq i<|P|, is the ii-th symbol in PP, and P[i,j)P[i,j) is a substring of length jij-i starting at ii. Operator “\circ” concatenates two strings or between strings and symbols. It may be omitted if concatenation is apparent from the context.

Suppose 𝒯=(P0,P1,,Pm1)\mathcal{T}=(P_{0},P_{1},\ldots,P_{m-1}) is an ordered list of mm strings over Σ\Sigma. TP0$0P1$1Pm1$m1T\triangleq P_{0}\$_{0}P_{1}\$_{1}\cdots P_{m-1}\$_{m-1} is the concatenation of the strings in 𝒯\mathcal{T} with sentinels ordered by $0<$1<<$m1\$_{0}<\$_{1}<\cdots<\$_{m-1}. For other ways to define string concatenation on ordered string lists or unordered string sets, see Cenzato and Lipták, (2024).

For convenience, let n|T|n\triangleq|T| and T[1]=T[n1]T[-1]=T[n-1]. The suffix array of TT is an integer array SS such that S(i)S(i), 0i<n0\leq i<n, is the start position of the ii-th smallest suffix among all suffixes of TT (Fig. 1a). The Burrows-Wheeler Transform (BWT) of TT is a string BB computed by B[i]=T[S(i)1]B[i]=T[S(i)-1]. All sentinels in BB are represented by the same symbol “$\$” and are not distinguished from each other. ΣΣ{$}\Sigma^{\prime}\triangleq\Sigma\cup\{\$\} denotes the alphabet including the sentinel.

For aΣa\in\Sigma^{\prime}, let CB(a)|{i:B[i]<a}|C_{B}(a)\triangleq|\{i:B[i]<a\}| be the number of symbols smaller than aa and rankB(a,k)|{i<k:B[i]=a}|{\rm rank}_{B}(a,k)\triangleq|\{i<k:B[i]=a\}| be the number of aa before offset kk in BB. We may omit subscription BB when we are describing one string only. The last-to-first mapping (LF mapping) π\pi is defined by π(i)S1(S(i)1)\pi(i)\triangleq S^{-1}(S(i)-1), where S1S^{-1} is the inverse function of suffix array SS. It can be calculated as π(i)=πB(B[i],i)\pi(i)=\pi_{B}(B[i],i), where πB(a,i)C(B[i])+rank(B[i],i)\pi_{B}(a,i)\triangleq C(B[i])+{\rm rank}(B[i],i). As B[π(i)]B[\pi(i)] immediately proceeds B[i]B[i] on TT, we can use π\pi to decode the ii-th sequence in BB.

2.2 BWT construction

Algorithm 1 Insert BWT B2B_{2} into BWT B1B_{1}
1:procedure AppendBWT(B1,B2B_{1},B_{2})
2:     m1|{k:B1[k]=$}|m_{1}\leftarrow|\{k:B_{1}[k]=\$\}|
3:     m2|{k:B2[k]=$}|m_{2}\leftarrow|\{k:B_{2}[k]=\$\}|
4:     for k0k\leftarrow 0 to |B2|1|B_{2}|-1 do
5:         aB2[k]a\leftarrow B_{2}[k]
6:         R(k)(a,πB2(a,k))R(k)\leftarrow(a,\pi_{B_{2}}(a,k))
7:     end for
8:     for i0i\leftarrow 0 to m21m_{2}-1 do
9:         kik\leftarrow i; lm1l\leftarrow m_{1}
10:         repeat
11:              (a,k)R(k)(a,k^{\prime})\leftarrow R(k)
12:              R(k)(a,k+l)R(k)\leftarrow(a,k+l)\triangleright position in the merged BWT
13:              kkk\leftarrow k^{\prime}; lπB1(a,l)l\leftarrow\pi_{B_{1}}(a,l)
14:         until a=$a=\$
15:     end for
16:     for (a,k)R(a,k)\in R do\triangleright N.B. kk is sorted in array RR
17:         insertB1(a,k){\rm insert}_{B_{1}}(a,k)\triangleright insert aa after kk symbols in B1B_{1}
18:     end for
19:end procedure

Libsais is an efficient library for computing the suffix array of a single string. It does not directly support a list of strings. Nonetheless, we note that TT is a string over alphabet Σ′′={$0,$1,,$m1,𝙰,𝙲,𝙶,𝚃,𝙽}\Sigma^{\prime\prime}=\{\$_{0},\$_{1},\ldots,\$_{m-1},{\tt A},{\tt C},{\tt G},{\tt T},{\tt N}\} with lexicographical order $0<<$m1<𝙰<𝙲<𝙶<𝚃<𝙽\$_{0}<\cdots<\$_{m-1}<{\tt A}<{\tt C}<{\tt G}<{\tt T}<{\tt N}. We can use m+5m+5 non-negative integers to encode TT and apply libsais. The suffix array derived this way will be identical to the suffix array of TT.

For mm that can be represented by a 32-bit integer and nn represented by a 64-bit integer, libsais will need at least 12n12n bytes to construct the suffix array. It is impractical for nn more than tens of billions. To construct BWT for large nn, ropebwt3 uses libsais to build the BWT for a batch (up to 7 Gb by default) and merges it to the BWT of already processed batches (Algorithm 1). The basic idea behind the algorithm is well known (Ferragina et al., , 2010) but implementations vary (Sirén, , 2016; Oliva et al., , 2021). In ropebwt3, we encode BWT with a B+-tree (Fig. 2a). This yields O(logr)O(\log r) rank query (line 13) and insertion (line 17), where rr is the number of runs in the merged BWT. The bottleneck of the algorithm lies in rank calculation (line 8), which can be parallelized if m2>1m_{2}>1.

This online BWT construction algorithm does not use temporary disk space. The overall time complexity is O(nlogr)O(n\log r). The BWT takes O(rlogr)O(r\log r) in space. The memory required for partial BWT construction with libsais depends on the batch size and the longest string. B+-tree is dynamic. Ropebwt3 optionally converts B+-tree to the fermi binary format (Fig. 2b; Li, 2012) which is static but is faster to query and can be memory-mapped.

Ropebwt2 (Li, , 2014) uses the same B+-tree to encode BWT and has the same time complexity. However, it inserts sequences, not partial BWTs, into existing BWT. It cannot be efficiently parallelized for long strings. Note that independent of our earlier work, Ohno et al., (2018) also used a B+-tree to encode BWT. Its implementation (Bannai et al., , 2020) is several times slower than ropebwt2 on 152 bacterial genomes from Li et al., (2024), possibly because ropebwt2 is optimized for the small DNA alphabet.

Refer to caption
Figure 2: Examples of binary BWT encoding. The alphabet is {𝙰,𝙲,𝙶}\{{\tt A},{\tt C},{\tt G}\}. (a) Encoded as a B+-tree. An internal node keeps the marginal counts of symbols in its descendants. An external node keeps the run-length encoded substring in BWT. A run length may be encoded in one, two, four or eight bytes in a scheme inspired by UTF-8. A B+-tree organized this way resembles the rope data structure. (b) Encoded as a bit-packed array. The first two rows store run-length encoded BWT interleaved with marginal counts in each block. The Elias delta encoding is used to represent run lengths. The last row is an index into BWT for fast access.

2.3 Suffix array interval and backward search

For a string PΣP\in\Sigma^{*} (i.e. not including sentinels), let occ(P){\rm occ}(P) be the number of occurrences of PP in TT. Define lo(P){\rm lo}(P) to be the number of suffixes that are lexicographically smaller than PP and hi(P)lo(P)+occ(P){\rm hi}(P)\triangleq{\rm lo}(P)+{\rm occ}(P). [lo(P),hi(P))[{\rm lo}(P),{\rm hi}(P)) is called the suffix array interval of PP, or SA interval in brief. An SA interval is important if there exists PP such that it is the SA interval of PP. The SA interval of the empty string is [0,n)[0,n) where n=|T|n=|T|.

If we know the SA interval of PP, we can calculate the SA interval of aPaP with: lo(aP)=πB(a,lo(P)){\rm lo}(aP)=\pi_{B}(a,{\rm lo}(P)) and hi(aP)=πB(a,hi(P)){\rm hi}(aP)=\pi_{B}(a,{\rm hi}(P)). To calculate occ(P){\rm occ}(P), we start with [0,n)[0,n) and repeatedly apply the equation above from the last symbol in PP to the first. This procedure is called backward search.

2.4 Locating with FM-index

By definition of BWT, if i[lo(P),hi(P))i\in[{\rm lo}(P),{\rm hi}(P)), P=T[S(i),S(i)+|P|)P=T[S(i),S(i)+|P|). We can thus locate an occurrence of PP in the original string TT. However, suffix array SS takes O(nlogn)O(n\log n) in space and may be too large to store explicitly. With an FM-index, we only store S(i)S(i) if and only if ii is a multiple of ss where ss is a positive integer controlling the sample rate. We calculate the rest of S(i)S(i) using LF-mapping π()\pi(\cdot).

A complication with multi-string BWT is that π(i)\pi(i) does not point to the preceeding symbol when B[i]=$B[i]=\$. This is because sentinels are ordered during suffix sorting but are not distinguished from each other in BWT. We will have to store the rank of each string in TT (array RR in Algorithm 2). For convenience, we also keep the index of the string and the offset on the string instead of the offset on the concatenated string TT.

To find the position of i[lo(P),hi(P))i\in[{\rm lo}(P),{\rm hi}(P)) in the original string, we repeatedly apply π()\pi(\cdot) kk times until the position of πk(i)\pi^{k}(i) is stored. With UU, VV and RR precalculated by IndexSSA in Algorithm 2, we can locate ii with

{(R(πk(i)),k)(B[πk(i)]=$)(U(πk(i)),V(πk(i)+k))(otherwise and πk(i)mods=0)\left\{\begin{array}[]{ll}(R(\pi^{k}(i)),k)&(B[\pi^{k}(i)]=\$)\\ (U(\pi^{k}(i)),V(\pi^{k}(i)+k))&(\mbox{otherwise and $\pi^{k}(i)\bmod s=0$})\\ \end{array}\right.

where kk is the smallest non-negative integer such that B[πk(i)]=$B[\pi^{k}(i)]=\$ or πk(i)mods=0\pi^{k}(i)\bmod s=0. On average, ksk\approx s, which means each locate operation triggers ss rank queries.

Function Locate1 in Algorithm 2 provides a faster way to find one position in SA interval [l,h)[l,h). A key observation is that if the interval contains a sentinel or there exists kk such that lks<hl\leq ks<h, we can immediately locate one occurrence; if not, we can apply backward search repeatedly until an SA interval [l,h)[l^{\prime},h^{\prime}) brackets a stored suffix array value. If TT consists of mm^{\prime} identical strings, we apply s/min(hl,m)s/\min(h-l,m^{\prime}) rounds of backward searches on average, usually much faster than the naive algorithm. Ropebwt3 implements a generalized Locate1 function that finds multiple occurrences.

Algorithm 2 Locate one hit given suffix array samples
1:procedure IndexSSA(B,sB,s)
2:     AA\leftarrow\emptyset; m|{i:B[i]=$}|m\leftarrow|\{i:B[i]=\$\}|\triangleright Number of sequences
3:     for t0t\leftarrow 0 to m1m-1 do\triangleright Traverse all sequences
4:         ktk\leftarrow t; l0l\leftarrow 0\triangleright ll will be the length of tt-th sequence
5:         repeat\triangleright Iterate from the end of the sequence
6:              kπ(k)k\leftarrow\pi(k); ll+1l\leftarrow l+1
7:              if B[k]=$B[k]=\$ then
8:                  R(k)tR(k)\leftarrow t\triangleright The rank of tt-th sequence is kk
9:              else if kmods=0k\bmod s=0 then
10:                  AA{k/s}A\leftarrow A\cup\{k/s\}
11:              end if
12:         until B[k]=$B[k]=\$
13:         for kAk\in A do
14:              U(k)=tU(k)=t; V(k)l1kV(k)\leftarrow l-1-k
15:         end for
16:     end for
17:     return (U,V,R)(U,V,R)
18:end procedure
19:procedure Locate1(B,U,V,R,lo,hi,sB,U,V,R,{\rm lo},{\rm hi},s)
20:     I{(lo,hi,0)}I\leftarrow\{({\rm lo},{\rm hi},0)\}
21:     while II\not=\emptyset do
22:         (l,h,o)largest interval in I(l,h,o)\leftarrow\mbox{largest interval in $I$}
23:         II{(l,h,o)}I\leftarrow I\setminus\{(l,h,o)\}
24:         if k\exists k such that ks[l,h)k\cdot s\in[l,h) then
25:              return (U(k),V(k)+o)(U(k),V(k)+o)
26:         else if πB($,l)<πB($,h)\pi_{B}(\$,l)<\pi_{B}(\$,h) then
27:              return (R(πB($,l)),o)(R(\pi_{B}(\$,l)),o)
28:         end if
29:         for aΣa\in\Sigma do
30:              II{(πB(a,l),πB(a,h),o+1)}I\leftarrow I\cup\{(\pi_{B}(a,l),\pi_{B}(a,h),o+1)\}
31:         end for
32:     end while
33:end procedure

2.5 Double-strand BWT

The definitions above are applicable to generic strings. With one BWT, we can only achieve backward search; forward search additionally requires the BWT of the reverse strings (Lam et al., , 2009). Nonetheless, due to the strand symmetry of DNA strings, it is possible to achieve both forward and backward search with one BWT provided that the BWT contains both strands of DNA strings (Li, , 2012).

Formally, a DNA alphabet is Σ={𝙰,𝙲,𝙶,𝚃,𝙽}\Sigma=\{{\tt A},{\tt C},{\tt G},{\tt T},{\tt N}\}. a¯\overline{a} denotes the Watson-Crick complement of symbol aΣa\in\Sigma. The complement of $\$, 𝙰{\tt A}, 𝙲{\tt C}, 𝙶{\tt G}, 𝚃{\tt T} and 𝙽{\tt N} are $\$, 𝚃{\tt T}, 𝙶{\tt G}, 𝙲{\tt C}, 𝙰{\tt A} and 𝙽{\tt N}, respectively.

For string PP, P¯\overline{P} is its reverse complement string. The double-strand concatenation of a DNA string list 𝒯=(P0,P1,,Pm1)\mathcal{T}=(P_{0},P_{1},\ldots,P_{m-1}) is T~=P0$0P¯0$1P1$2P¯1$3Pm1$2m2P¯m1$2m1\tilde{T}=P_{0}\$_{0}\overline{P}_{0}\$_{1}P_{1}\$_{2}\overline{P}_{1}\$_{3}\cdots P_{m-1}\$_{2m-2}\overline{P}_{m-1}\$_{2m-1}. The double-strand BWT (DS-BWT) of 𝒯\mathcal{T} is the BWT of T~\tilde{T}. We note that if PP is a substring of T~\tilde{T}, P¯\overline{P} must be a substring and occ(P)=occ(P¯){\rm occ}(P)={\rm occ}(\overline{P}). The suffix array bidirectional interval (SA bi-interval) of PP is a 3-tuple defined as (lo(P),lo(P¯),occ(P))({\rm lo}(P),{\rm lo}(\overline{P}),{\rm occ}(P)).

Algorithm 3 Backward and forward extensions with DS-BWT
1:procedure BackwardExt(B,(k,k,s),aB,(k,k^{\prime},s),a)
2:     for all b<a¯b<\overline{a} do\triangleright bb can be $\$
3:         kk+[πB(b¯,k+s)πB(b¯,k)]k^{\prime}\leftarrow k^{\prime}+\big{[}\pi_{B}(\overline{b},k+s)-\pi_{B}(\overline{b},k)\big{]}
4:     end for
5:     sπB(a,k+s)πB(a,k)s\leftarrow\pi_{B}(a,k+s)-\pi_{B}(a,k)
6:     kπB(a,k)k\leftarrow\pi_{B}(a,k)
7:     return (k,k,s)(k,k^{\prime},s)
8:end procedure
9:procedure ForwardExt(B,(k,k,s),aB,(k,k^{\prime},s),a)
10:     (k,k,s)(k^{\prime},k,s)\leftarrowBackwardExt(B,(k,k,s),a¯)(B,(k^{\prime},k,s),\overline{a})
11:     return (k,k,s)(k,k^{\prime},s)
12:end procedure

An SA bi-interval can be extended in both backward and forward directions. To calculate the SA bi-interval of aPaP, we can use the standard backward search to compute lo(aP){\rm lo}(aP) and occ(aP){\rm occ}(aP) from lo(P){\rm lo}(P) and occ(P){\rm occ}(P). As to lo(aP¯){\rm lo}(\overline{aP}), we note that [lo(aP¯),hi(aP¯))[lo(P¯),hi(P¯))[{\rm lo}(\overline{aP}),{\rm hi}(\overline{aP}))\subset[{\rm lo}(\overline{P}),{\rm hi}(\overline{P})) because aP¯=P¯a¯\overline{aP}=\overline{P}\circ\overline{a} is prefixed with P¯\overline{P}. We can thus calculate lo(aP¯)=lo(P¯)+b<a¯occ(P¯b)=lo(P¯)+b<a¯occ(b¯P){\rm lo}(\overline{aP})={\rm lo}(\overline{P})+\sum_{b<\overline{a}}{\rm occ}(\overline{P}b)={\rm lo}(\overline{P})+\sum_{b<\overline{a}}{\rm occ}(\overline{b}P).

It is easy to see that if (k,k,s)(k,k^{\prime},s) is the SA bi-interval of PP, (k,k,s)(k^{\prime},k,s) is the SA bi-interval of P¯\overline{P}, and vice versa. Therefore, we can use the backward extension of P¯\overline{P} to achieve the forward extension of PP. Algorithm 3 gives the details. It simplifies the original formulation (Li, , 2012).

2.6 Finding supermaximal exact matches

An exact match between strings TT and PP is a 3-tuple (t,p,l)(t,p,l) such that T[t,t+l)=P[p,p+l)T[t,t+l)=P[p,p+l). A maximal exact match (MEM) is an exact match that cannot be extended in either direction. A MEM may be contained in another MEM on the pattern string PP. For example, suppose T=𝙶𝙰𝙲𝙲𝚃𝙲𝙲𝙶T={\tt GACCTCCG} and P=𝙰𝙲𝙲𝚃P={\tt ACCT}. MEM (5,1,2)(5,1,2) is contained in MEM (1,0,4)(1,0,4) on the pattern string. A supermaximal exact match (SMEM) is a MEM that is not contained in other MEMs on the pattern string. In the example above, only (1,0,4)(1,0,4) is a SMEM. There are usually much fewer SMEMs than MEMs. Gagie, (2024) recently proposed a new algorithm to find long SMEMs (Algorithm 4) that is faster than our earlier algorithm (Li, , 2012) especially when there are many short SMEMs to skip. Both algorithms can also find SMEMs occurring at least smins_{\min} times (Tatarnikov et al., , 2023).

Algorithm 4 Finding SMEMs no shorter than \ell (Gagie, , 2024)
1:procedure FindSMEM1(,smin,B,P,i\ell,s_{\min},B,P,i)
2:     if i+>|P|i+\ell>|P| then return |P||P|\triangleright Reaching the end of |P||P|
3:     (k,k,s)(0,0,|B|)(k,k^{\prime},s)\leftarrow(0,0,|B|)\triangleright SA bi-interval of empty string
4:     for ji+1j\leftarrow i+\ell-1 to ii do\triangleright backward
5:         (k,k,s)(k,k^{\prime},s)\leftarrowBackwardExt(B,(k,k,s),P[j])(B,(k,k^{\prime},s),P[j])
6:         if s<smins<s_{\min} then return j+1j+1
7:     end for
8:     for ji+j\leftarrow i+\ell to |P|1|P|-1 do\triangleright forward
9:         (k,k,s)(k,k^{\prime},s)\leftarrowForwardExt(B,(k,k,s),P[j])(B,(k,k^{\prime},s),P[j])
10:         if s<smins<s_{\min} then break
11:     end for
12:     eje\leftarrow j and output [i,e)[i,e)\triangleright SMEM found
13:     (k,k,s)(0,0,|B|)(k,k^{\prime},s)\leftarrow(0,0,|B|)
14:     for jej\leftarrow e to i+1i+1 do\triangleright backward again
15:         (k,k,s)(k,k^{\prime},s)\leftarrowBackwardExt(B,(k,k,s),P[j])(B,(k,k^{\prime},s),P[j])
16:         if s<smins<s_{\min} then return j+1j+1
17:     end for
18:end procedure
19:procedure FindSMEM(,smin,B,P\ell,s_{\min},B,P)
20:     i0i\leftarrow 0
21:     repeat
22:         ii\leftarrowFindSMEM1(,smin,B,P,i)(\ell,s_{\min},B,P,i)
23:     until i|P|i\geq|P|
24:end procedure

2.7 Finding inexact matches with BWA-SW

The prefix trie of TT is a tree that encodes all the prefixes of TT (Fig. 1b). Each edge in the tree is labeled with a symbol in Σ\Sigma. A path from a node to the root spells a substring of TT. We can label a node with the SA interval of the string from the node to the root. When we know the label of a node, we can find the label of its child using backward search. We can thus simulate the top-down traversal of the prefix trie (Lam et al., , 2008).

As is shown in Fig. 1b, different nodes in the prefix trie may have the same label. If we merge nodes with the same label (Fig. 1c), we will get a prefix DAWG (Blumer et al., , 1983). For |T|>1|T|>1, the DAWG has at most 2|T|12|T|-1 nodes (Blumer et al., , 1984). Each node uniquely corresponds to an important SA interval of TT.

Let GTG_{T} denote the prefix DAWG of TT and V(GT)V(G_{T}) be the set of vertices in GTG_{T}. Given a reference string TT and a pattern string PP, we can align GTG_{T} and GPG_{P} under affine-gap penalty with

{Euv=maxupre(u){max{Huvq,Euv}}eFuv=maxvpre(v){max{Huvq,Fuv}}eGuv=maxupre(u),vpre(v){Huv+s(u,u;v,v)}Huv=max{Guv,Euv,Fuv}\left\{\begin{array}[]{lll}E_{uv}&=&\max_{u^{\prime}\in{\rm pre}(u)}\{\max\{H_{u^{\prime}v}-q,E_{u^{\prime}v}\}\}-e\\ F_{uv}&=&\max_{v^{\prime}\in{\rm pre}(v)}\{\max\{H_{uv^{\prime}}-q,F_{uv^{\prime}}\}\}-e\\ G_{uv}&=&\max_{u^{\prime}\in{\rm pre}(u),v^{\prime}\in{\rm pre}(v)}\{H_{u^{\prime}v^{\prime}}+s(u^{\prime},u;v^{\prime},v)\}\\ H_{uv}&=&\max\{G_{uv},E_{uv},F_{uv}\}\\ \end{array}\right.

where uV(GP)u\in V(G_{P}), vV(GT)v\in V(G_{T}), pre(u){\rm pre}(u) and pre(v){\rm pre}(v) are the sets of predecessors in GPG_{P} and GTG_{T} respectively, qq is the gap open penalty, ee is the gap extension penalty, and s(u,u;v,v)s(u^{\prime},u;v^{\prime},v) is the match/mismatch score between the symbol labeled on edge (u,u)(u^{\prime},u) in GPG_{P} and the symbol on (v,v)(v^{\prime},v) in GTG_{T}. This equation is similar to but not the same as our earlier result (Li and Durbin, , 2010).

On real data, GTG_{T} may be too large to store explicitly. Ropebwt3 instead explicitly stores GPG_{P} only and traverses it in the topological order (Algorithm 5). At a node uV(GP)u\in V(G_{P}), we use a hash table to keep {vV(GT):Huv>0}\{v\in V(G_{T}):H_{uv}>0\}. This algorithm is exact in that it guarantees to find the best alignment. In practice, however, a large number of vV(GT)v\in V(G_{T}) may be aligned to uu with Huv>0H_{uv}>0. It is slow and memory demanding to keep track of all cells (u,v)(u,v) with positive scores when PP is long. Similar to our earlier work, we only store top WW cells (25 by default) at each uu. This heuristic is akin to dynamic banding for linear sequences (Suzuki and Kasahara, , 2018).

Algorithm 5 The revised BWA-SW algorithm
1:procedure BwaSW(GP,GTG_{P},G_{T})
2:     for uV(GP)u\in V(G_{P}) in topological order do
3:         for upre(u)u^{\prime}\in{\rm pre}(u) do\triangleright predecessors of uu
4:              for vV(GT)v^{\prime}\in V(G_{T}) s.t. Huv>0H_{u^{\prime}v^{\prime}}>0 do\triangleright match
5:                  for vchild(v)v\in{\rm child}(v^{\prime}) do\triangleright children of vv^{\prime}
6:                       Huvmax{Huv,Huv+s(u,u;v,v)}H_{uv}\leftarrow\max\{H_{uv},H_{u^{\prime}v^{\prime}}+s(u^{\prime},u;v^{\prime},v)\}
7:                  end for
8:              end for
9:              for vV(GT)v\in V(G_{T}) s.t. Huv>0H_{u^{\prime}v}>0 do\triangleright insertion
10:                  Euvmax{Euv,max{Huvq,Euv}e}E_{uv}\leftarrow\max\{E_{uv},\max\{H_{u^{\prime}v}-q,E_{u^{\prime}v}\}-e\}
11:                  Huvmax{Huv,Euv}H_{uv}\leftarrow\max\{H_{uv},E_{uv}\}
12:              end for
13:         end for
14:         for vV(GT)v^{\prime}\in V(G_{T}) s.t. Huv>0H_{uv^{\prime}}>0 do\triangleright deletion
15:              for vchild(v)v\in{\rm child}(v^{\prime}) do\triangleright children of vv^{\prime}
16:                  Fuvmax{Fuv,max{Huvq,Fuv}e}F_{uv}\leftarrow\max\{F_{uv},\max\{H_{uv^{\prime}}-q,F_{uv^{\prime}}\}-e\}
17:                  Huvmax{Huv,Fuv}H_{uv}\leftarrow\max\{H_{uv},F_{uv}\}
18:              end for
19:         end for
20:     end for
21:end procedure

2.8 Estimating local haplotype diversity

BWA-SW with the banding heuristic may miss the best matching haplotype especially given an index consisting of similar haplotypes. When the suffix on the best full-length alignment has a lot more mismatches than the suffix on suboptimal alignments, the best alignment may have moved out of the band early in the iteration and thus get missed. Nevertheless, a long read sequenced from a new sample may be the recombinant of two genomes in the index. We often do not seek the best alignment of the long read to a single haplotype. We are instead more interested in the collection of haplotypes a query sequence can be aligned to even if they do not lead to the best alignment. This now becomes possible as BWA-SW explores suboptimal alignments to multiple haplotypes.

More exactly, we perform semi-global sequence-to-DAWG alignment (i.e. requiring the query sequence to be aligned from end to end) by applying BWA-SW to the graph representing the linear query sequence PP, from the end to the start. We can find the set of matching haplotypes {vV(GT):Hu0v>0}\mathcal{M}\triangleq\{v\in V(G_{T}):H_{u_{0}v}>0\} where u0u_{0} represents the start of PP. \mathcal{M} may include suboptimal haplotypes caused by small variants as well as the optimal one.

Importantly, PP may be aligned to similar positions on TT with slightly different gap placements. For example, given T=𝙲𝙰𝙰𝙶𝙲𝙰𝙶T={\tt CAAGCAG} and P=𝙰𝙶𝙲𝙶P={\tt AGCG}, the algorithm above may find the following two alignments around the same position but in different SA intervals:

   T: CAAGCAG        CAAGCAG
        ||||    or    | |||
   P:   AGCA          A-GCA

When counting hits, we want to ignore the second suboptimal alignment. In theory, we can identify this case by comparing the position of each alignment. This procedure is slow as the locate operation is costly. We instead leverage the bi-directionality to identify redundancy heuristically. Suppose PP can be aligned to SA bi-intervals (k1,k1,s1)(k_{1},k^{\prime}_{1},s_{1}) and (k2,k2,s2)(k_{2},k^{\prime}_{2},s_{2}) and the alignment score to the first interval is higher. We filter out the second interval if [k2,k2+s2)[k1,k1+s1)[k_{2},k_{2}+s_{2})\subset[k_{1},k_{1}+s_{1}) or [k2,k2+s2)[k1,k1+s1)[k^{\prime}_{2},k^{\prime}_{2}+s_{2})\subset[k^{\prime}_{1},k^{\prime}_{1}+s_{1}). This strategy does not avoid all overcounting but it works well on multiple real examples we have closely inspected.

In practice, we may apply this algorithm to the flanking sequence of a variant or to sliding k-mers of a long query sequence to enumerate possible local haplotypes and estimate their frequencies in the index. It is a new query type that is biologically meaningful.

3 Results

Table 2: Datasets
\topruleName #bases1 #sequences avg run length2
\midrulehuman1003 301.6 Gb 38.6 k 141.6
human3204 963.0 Gb 27.1 k 395.6
CommonBacteria5 7326.6 Gb 278.4 M 828.6
\botrule
{tablenotes}

number of bases in the input sequences on one strand

average run length in BWT constructed from both strands

100 long-read human assemblies; N50 string length: 44.4 Mb

320 long-read human assemblies; N50 string length: 135.3 Mb

AllTheBacteria (Hunt et al., , 2024) excluding “dustbin” and “unknown”

Table 3: Indexing performance
\topruleDataset Algorithm Elapsed1 CPU2 RAM
\midrulehuman100 grlBWT 8.3 h ×3.6\times 3.6 84.8 GB
pfp-thres3 <<51.7 h ×1.0\times 1.0 788.1 GB
ropebwt3 20.5 h ×22.9\times 22.9 83.0 GB
metagraph4 16.9 h ×18.6\times 18.6 251.0 GB
fulgor5 1.2 h ×27.2\times 27.2 165.2 GB
human320 grlBWT6 23.3 h ×4.2\times 4.2 270.4 GB
ropebwt3 81.2 h ×16.5\times 16.5 99.2 GB
ropebwt37 64.9 h ×23.7\times 23.7 170.5 GB
CommonBacteria ropebwt3 25.6 d ×32.4\times 32.4 67.3 GB
\botrule
{tablenotes}

Up to 64 threads specified if multi-threading is supported.

excluding time for format conversion; “h” for hours; “d” for days

number of CPU threads used on average

pfp-thresholds was run on a slower machine with more RAM

k-mer coordinates in the “row_diff_brwt_coord” encoding

without “–meta –diff” as the basic index is smaller; lossy index

using two bytes per run with option ‘-b 2’, which is faster

BWT merge and partial BWT construction with libsais are run together

3.1 Performance on index construction

We evaluated the performance of BWT construction on 100 haplotype-resolved human assemblies collected in Li et al., (2024). As we included both strands (Section 2.5), each BWT construction algorithm took about 600 billion bases as input (Table 2). grlBWT (commit 5b6d26a; Díaz-Domínguez and Navarro, 2023) is the fastest algorithm (Table 3) at the cost of \sim2 terabytes of working disk space including decompressed sequences. Ropebwt3 took 21 hours from input sequences in gzip’d FASTA to the final index, of which 7.7 hours was spent on libsais. It does not use working disk space and can append new sequences to an existing BWT. However, hardcoded for the DNA alphabet, ropebwt3 does not work with more general alphabets. pfp-thresholds (Rossi et al., , 2022) used more memory than the input sequences. It may be impractical with increased sample size.

Both MONI (v0.2.1; Rossi et al., 2022) and Movi (v1.1.0; Zakeri et al., 2024) use pfp-thresholds for building BWT. They generate additional data structures on top of BWT. Time spent on these additional steps were not counted. The tested version of Movi used more than one terabyte of memory to construct the final index. The Movi developer kindly provided the Movi index for the evaluation of query performance in the next section.

We also indexed the same dataset with k-mer based tools. In the lossless mode, metagraph (v0.3.6; Karasikov et al., 2024) indexed the 100 human genomes in 17 hours (Table 3). Fulgor (v3.0.0; Fan et al., 2024) is by far the fastest. However, lossy in nature, it is not directly comparable to the rest of the tools in the table.

To test scalability, we indexed a larger dataset consisting of 320 human genomes recently released by the Human Pangenome Reference Consortium (Liao et al., , 2023). Because these assemblies are more contiguous than human100 (Table 2), m2m_{2} in Algorithm 1 is smaller, which reduces the multi-threading efficiency of ropebwt3. We can alleviate this by executing BWT merge and partial BWT construction at the same time at the cost of higher memory footprint. On human320, grlBWT is 2–4 times as fast but uses more memory (Table 3). On the largest CommonBacteria dataset (Table 2), ropebwt3 took less than a month to construct the double-strand BWT with 14.66 trillion symbols. The final index in the fermi format is 27.6 GB in size. The “dustbin” and “unknown” categories in AllTheBacteria consist of many unique sequences which are not compressed well. Indexing the entire AllTheBacteria with ropebwt3 will probably take 100–200 GB memory at the peak.

Table 4: Query performance
\topruleData Algorithm Type4 Speed5 (kb/s) RAM (GB)
\midruleSR+1+^{1} ropebwt36 MEM31 1758.5 10.6
MEM51 1907.5 10.6
SW10 84.1 15.2
MONI7 MEM- 453.2 68.4
extend 348.2 68.4
Movi PML 5894.0 47.6
metagraph PA++ <<0.1 65.3
fulgor PA 2717.5 5.1
LR+2+^{2} ropebwt3 MEM31 1695.9 10.5
MEM51 1793.9 10.5
SW25 82.7 15.6
MONI MEM- 413.6 68.4
Movi PML 16204.9 47.6
metagraph PA++ <<0.1 65.3
fulgor PA 2491.6 5.1
LR3-^{3} ropebwt3 MEM31 1365.0 10.4
MEM51 3051.6 10.4
SW25 58.2 17.9
MONI MEM- 186.8 68.4
Movi PML 8490.9 47.6
metagraph PA++ 1119.3 65.3
fulgor PA 4240.8 5.1
\botrule
{tablenotes}

first 1 million 125bp human short reads from SRR3099549

first 10,000 human PacBio HiFi reads from SRR26545347

first 10,000 metagenomic PacBio HiFi reads from DRR290133

MEMxx: super-maximal exact matches (SMEMs) of xx bp or longer with counts; MEM-: SMEM without counts; extend: Smith-Waterman extension from the longest SMEM; PML: pseudo-matching length; PA: pseudo-alignment; PA++: pseudo-alignment with contig names; SWyy: BWA-SW with bandwidth yy

kilobases processed per CPU second. Index loading time excluded

index in the binary fermi format

The MONI index includes both strands. We modified MONI such that extension is performed on the forward query strand only

3.2 Query performance

We queried 100–200 Mb human short reads (SR++), human long reads (LR++) and non-human long reads (LR-) against the human pangenome indices constructed above (Table 4). It is important to note that no two tools support exactly the same type of query, but the comparison can still give a hint about the relative performance.

Among the three BWT-based tools, ropebwt3 is slower than Movi but faster than MONI on finding exact matches. Movi finds pseudo-matching length (PML) which is not intended to be the longest exact match. PML corresponds to the longest MEM for only 195 out of one million short reads, and none for long reads. The longest PML of each read is on average 27% shorter than the longest exact match for LR++ and 22% shorter for SR++. Nonetheless, we believe it is possible to implement SMEM finding based on the Movi data structure with minor performance overhead.

MONI and ropebwt3 can also find inexact matches. Implementing r-index, MONI can relatively cheaply locate one SMEM. It leverages this property to extract the genomic sequence around the longest SMEM and performs Smith-Waterman extension. MONI extension is faster than BWA-SW on SR++ because it does not need to inspect suboptimal hits. This feature apparently focuses on short reads only. On LR++, MONI extension fails to extend to the ends of reads and generate incorrect output for the majority of reads.

As to k-mer indices, fulgor outputs the labels of genomes that each read have enough 31-mer matches to. In its current form, such output is not useful for pangenome analysis as we know most of reads can be mapped to all genomes. Metagraph can additionally output the contig name of each match. However, when most k-mers are present in the index, metagraph is impractically slow.

3.3 Identifying novel sequences

As a biological application, we used the pangenome index to identify novel sequences in reads that are absent from other human genomes. For this, we downloaded the PacBio HiFi reads for tumor sample COLO829 (https://downloads.pacbcloud.com/public/revio/2023Q2/COLO829/COLO829/), mapped them to human100 (Table 2), which includes T2T-CHM13 (Nurk et al., , 2022), and extracted \geq1kb regions on reads that are not covered by SMEMs of 51bp or longer. We found 95kb sequences in 43 reads. These sequences could not be assembled. NCBI BLAST suggested multiple weak hits to cow genomes. We could not identify the source of these sequences but there were few of them anyway.

When we mapped the COLO829 reads to T2T-CHM13 only and applied the same procedure, we found 55.9Mb of “novel” sequences in 25,365 reads. The much larger number is caused by regions with dense SNPs that prevented long exact matches. Counterintuitively, mapping these reads to T2T-CHM13 with minimap2 (Li, , 2018) resulted in more “novel” sequences at 78.6Mb, probably because minimap2 ignores seeds occurring thousands of times in T2T-CHM13 and may miss more alignments. Capable of finding SMEMs at the pangenome scale, ropebwt3 is more effective for identifying known sequences. It is also 16% faster and uses less memory than full minimap2 alignment against a single genome.

3.4 Haplotype diversity around C4 genes

Refer to caption
Figure 3: Haplotype diversity around the C4A gene. 101-mers with 50bp overlaps are extracted from the C4A genomic sequence on GRCh38 and aligned to the human pangenome. The Y axis shows the counts of 101-mer matches under different edit-distance thresholds.

The reference human genome GRCh38 has two paralogous C4 genes, C4A and C4B, and they may have copy-number changes (Sekar et al., , 2016). In both cases, the exon 26 harbors the functional domain. We extracted the exon 26 from both genes from GRCh38. They differ at six mismatches over 157bp. We aligned both 157bp segments, one from each gene, to the human pangenome. 105 haplotypes have the same C4A exon 26 sequence, one haplotype has a mismatch at offset 128 and four haplotypes have a mismatch at 54. In case of C4B, 60 haplotypes have the same reference C4B sequence and 23 also have a mismatch at offset 54. This means among the 100 human haplotypes, there are 110 C4A gene copies and 83 C4B copies. If we increase the bandwidth from the default 25 to 200, BWA-SW will be able to align C4A exon 26 to C4B genes and output all five hits for each sequence.

Fig. 3 shows the local haplotype diversity across the entire C4A gene spanning \sim20.6kb on GRCh38. We can see most regions have 193 copies, except a \sim6.4kb HERV insertion that separates long and short forms (Sekar et al., , 2016). The dip around exon 26 is caused by the C4AC4B difference. We could only see these alternative haplotypes with BWA-SW which reports suboptimal hits.

4 Discussions

Ropebwt3 is a fast tool for BWT construction and sequence search for redundant DNA sequences. Generating BWT purely in memory and supporting incremental build, ropebwt3 is convenient and practical for BWT construction at large scale. It is the only algorithm that can construct the BWT of 320 human genomes from a 2.5 GB AGC archive (Deorowicz et al., , 2023) without staging all decompressed data in memory or on disk. It provides the fastest algorithm so far for finding supermaximal exact matches and can report inexact hits as well. Ropebwt3 demonstrates that BWT-based data structures are scalable to terabases of pangenome data.

Ropebwt3 implements an FM-index to locate SMEMs or local hits. Although the standard r-index is faster than an FM-index of the same size, it imposes a fixed sampling rate: two suffix array values per run. The BWT of CommonBacteria has 14.6 trillion bases and 17.6 billion runs. An r-index is likely to take more than 200GB, while an FM-index sampled at one position per 8,192bp takes 17.5GB in ropebwt3. Subsampled r-index (sr-index; Cobas et al., 2024) is probably the better solution, which we will explore in future.

This article has not evaluated several recent BWT-based tools including r-index-f (Brown et al., , 2022), block_RLBWT (Díaz-Domínguez et al., , 2023), Move-r (Bertram et al., , 2024) and b-move (Depuydt et al., , 2024). Although they have not been tested on large datasets like human pangenome and they do not report SMEMs, some of their data structures are probably more efficient than the ones we use. We may integrate these methods into ropebwt3 in future as well.

We often use pangenome graphs to analyze multiple similar genomes (Liao et al., , 2023). These graphs are built from the multiple sequence alignment through complex procedures involving many parameters (Li et al., , 2020; Hickey et al., , 2023; Garrison et al., , 2024). It is challenging to understand if the graph topology is biologically meaningful especially given that we do not know the correct alignment between two genomes, let alone multiple ones. Complement to graph-based data structures, BWT-based algorithms are often exact with no heuristics or parameters but they tend to support limited query types. For example, we cannot project the alignment to a designated reference genome. What additional query types we can achieve will be of great interest to the comprehensive pangenome analysis in future.

Acknowledgments

We are grateful to Travis Gagie for pointing us to his long MEM finding algorithm, to Ilya Grebnov for adding the support of 16-bit alphabet which helps to accelerate ropebwt3, to Mohsen Zakeri for providing the Movi index, to Massimiliano Rossi for explaining the MONI algorithm, and to Giulio Pibiri and Rob Patro for trouble-shooting compilation issues with fulgor.

Author contributions

H.L. conceived the project, implemented the algorithms, analyzed the data and drafted the manuscript.

Conflict of interest

None declared.

Funding

This work is supported by National Institute of Health grant R01HG010040 and U01HG010961 (to H.L.).

Data availability

The ropebwt3 source code is available at https://github.com/lh3/ropebwt3. Prebuilt ropebwt3 indices can be obtained from https://doi.org/10.5281/zenodo.11533210 and https://doi.org/10.5281/zenodo.13955431.

References

  • Ahmed et al., (2021) Ahmed, O., Rossi, M., Kovaka, S., Schatz, M. C., Gagie, T., et al. (2021). Pan-genomic matching statistics for targeted nanopore sequencing. iScience, 24:102696.
  • Bannai et al., (2020) Bannai, H., Gagie, T., and I, T. (2020). Refining the r-index. Theor. Comput. Sci., 812:96–108.
  • Bertram et al., (2024) Bertram, N., Fischer, J., and Nalbach, L. (2024). Move-r: Optimizing the r-index. In Liberti, L., editor, 22nd International Symposium on Experimental Algorithms, SEA 2024, July 23-26, 2024, Vienna, Austria, volume 301 of LIPIcs, pages 1:1–1:19. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Blumer et al., (1983) Blumer, A., Blumer, J., Ehrenfeucht, A., Haussler, D., and McConnell, R. M. (1983). Linear size finite automata for the set of all subwords of a word - an outline of results. Bull. EATCS, 21:12–20.
  • Blumer et al., (1984) Blumer, A., Blumer, J., Ehrenfeucht, A., Haussler, D., and McConnell, R. M. (1984). Building the minimal DFA for the set of all subwords of a word on-line in linear time. In Paredaens, J., editor, Automata, Languages and Programming, 11th Colloquium, Antwerp, Belgium, July 16-20, 1984, Proceedings, volume 172 of Lecture Notes in Computer Science, pages 109–118. Springer.
  • Boucher et al., (2019) Boucher, C., Gagie, T., Kuhnle, A., Langmead, B., Manzini, G., and Mun, T. (2019). Prefix-free parsing for building big BWTs. Algorithms Mol Biol, 14:13.
  • Bray et al., (2016) Bray, N. L., Pimentel, H., Melsted, P., and Pachter, L. (2016). Near-optimal probabilistic RNA-seq quantification. Nat Biotechnol, 34:525–7.
  • Břinda et al., (2024) Břinda, K., Lima, L., Pignotti, S., Quinones-Olvera, N., Salikhov, K., et al. (2024). Efficient and robust search of microbial genomes via phylogenetic compression. bioRxiv.
  • Brown et al., (2022) Brown, N. K., Gagie, T., and Rossi, M. (2022). RLBWT tricks. In Schulz, C. and Uçar, B., editors, 20th International Symposium on Experimental Algorithms, SEA 2022, July 25-27, 2022, Heidelberg, Germany, volume 233 of LIPIcs, pages 16:1–16:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Burrows and Wheeler, (1994) Burrows, M. and Wheeler, D. J. (1994). A block sorting lossless data compression algorithm. Technical report 124, Digital Equipment Corporation.
  • Cenzato and Lipták, (2024) Cenzato, D. and Lipták, Z. (2024). A survey of BWT variants for string collections. Bioinformatics, 40:btae333.
  • Chang and Lawler, (1994) Chang, W. I. and Lawler, E. L. (1994). Sublinear approximate string matching and biological applications. Algorithmica, 12:327–344.
  • Cobas et al., (2024) Cobas, D., Gagie, T., and Navarro, G. (2024). Fast and small subsampled r-indexes. CoRR, abs/2409.14654.
  • Cox et al., (2012) Cox, A. J., Bauer, M. J., Jakobi, T., and Rosone, G. (2012). Large-scale compression of genomic sequence databases with the Burrows-Wheeler transform. Bioinformatics, 28:1415–9.
  • Deorowicz et al., (2023) Deorowicz, S., Danek, A., and Li, H. (2023). AGC: compact representation of assembled genomes with fast queries and updates. Bioinformatics, 39(3):btad097.
  • Depuydt et al., (2024) Depuydt, L., Renders, L., de Vyver, S. V., Veys, L., Gagie, T., and Fostier, J. (2024). b-move: Faster bidirectional character extensions in a run-length compressed index. In Pissis, S. P. and Sung, W., editors, 24th International Workshop on Algorithms in Bioinformatics, WABI 2024, September 2-4, 2024, Royal Holloway, London, United Kingdom, volume 312 of LIPIcs, pages 10:1–10:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Díaz-Domínguez et al., (2023) Díaz-Domínguez, D., Dönges, S., Puglisi, S. J., and Salmela, L. (2023). Simple runs-bounded FM-Index designs are fast. In Georgiadis, L., editor, 21st International Symposium on Experimental Algorithms, SEA 2023, July 24-26, 2023, Barcelona, Spain, volume 265 of LIPIcs, pages 7:1–7:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Díaz-Domínguez and Navarro, (2023) Díaz-Domínguez, D. and Navarro, G. (2023). Efficient construction of the BWT for repetitive text using string compression. Inf. Comput., 294:105088.
  • Edgar et al., (2022) Edgar, R. C., Taylor, B., Lin, V., Altman, T., Barbera, P., et al. (2022). Petabase-scale sequence alignment catalyses viral discovery. Nature, 602:142–147.
  • Fan et al., (2024) Fan, J., Khan, J., Singh, N. P., Pibiri, G. E., and Patro, R. (2024). Fulgor: a fast and compact k-mer index for large-scale matching and color queries. Algorithms Mol Biol, 19:3.
  • Ferragina et al., (2010) Ferragina, P., Gagie, T., and Manzini, G. (2010). Lightweight data indexing and compression in external memory. In López-Ortiz, A., editor, LATIN, volume 6034, pages 697–710. Springer.
  • Ferragina and Manzini, (2000) Ferragina, P. and Manzini, G. (2000). Opportunistic data structures with applications. In FOCS, pages 390–398. IEEE Computer Society.
  • Gagie, (2024) Gagie, T. (2024). How to find long maximal exact matches and ignore short ones. In Day, J. D. and Manea, F., editors, Developments in Language Theory - 28th International Conference, DLT 2024, Göttingen, Germany, August 12-16, 2024, Proceedings, volume 14791 of Lecture Notes in Computer Science, pages 131–140. Springer.
  • Gagie et al., (2018) Gagie, T., Navarro, G., and Prezza, N. (2018). Optimal-time text indexing in bwt-runs bounded space. In Czumaj, A., editor, Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2018, New Orleans, LA, USA, January 7-10, 2018, pages 1459–1477. SIAM.
  • Gagie et al., (2020) Gagie, T., Navarro, G., and Prezza, N. (2020). Fully functional suffix trees and optimal text searching in BWT-runs bounded space. J. ACM, 67:2:1–2:54.
  • Garrison et al., (2024) Garrison, E., Guarracino, A., Heumos, S., Villani, F., Bao, Z., et al. (2024). Building pangenome graphs. Nat Methods.
  • Hickey et al., (2023) Hickey, G., Monlong, J., Ebler, J., et al. (2023). Pangenome graph construction from genome alignments with Minigraph-Cactus. Nat Biotechnol.
  • Hunt et al., (2024) Hunt, M., Lima, L., Shen, W., Lees, J., and Iqbal, Z. (2024). AllTheBacteria - all bacterial genomes assembled, available and searchable. bioRxiv.
  • Karasikov et al., (2024) Karasikov, M., Mustafa, H., Danciu, D., Zimmermann, M., Barber, C., et al. (2024). Indexing all life’s known biological sequences. bioRxiv.
  • Karasikov et al., (2020) Karasikov, M., Mustafa, H., Joudaki, A., Javadzadeh-No, S., Rätsch, G., and Kahles, A. (2020). Sparse binary relation representations for genome graph annotation. J Comput Biol, 27:626–639.
  • Kim et al., (2016) Kim, D., Song, L., Breitwieser, F. P., and Salzberg, S. L. (2016). Centrifuge: rapid and sensitive classification of metagenomic sequences. Genome Res, 26:1721–1729.
  • Kucherov et al., (2016) Kucherov, G., Salikhov, K., and Tsur, D. (2016). Approximate string matching using a bidirectional index. Theor. Comput. Sci., 638:145–158.
  • Lam et al., (2009) Lam, T. W., Li, R., Tam, A., Wong, S. C. K., Wu, E., and Yiu, S. (2009). High throughput short read alignment via bi-directional BWT. In 2009 IEEE International Conference on Bioinformatics and Biomedicine, BIBM 2009, Washington, DC, USA, November 1-4, 2009, Proceedings, pages 31–36. IEEE Computer Society.
  • Lam et al., (2008) Lam, T. W., Sung, W. K., Tam, S. L., Wong, C. K., and Yiu, S. M. (2008). Compressed indexing and local alignment of DNA. Bioinformatics, 24:791–7.
  • Langmead et al., (2009) Langmead, B., Trapnell, C., Pop, M., and Salzberg, S. L. (2009). Ultrafast and memory-efficient alignment of short dna sequences to the human genome. Genome Biol, 10:R25.
  • Li, (2012) Li, H. (2012). Exploring single-sample SNP and INDEL calling with whole-genome de novo assembly. Bioinformatics, 28:1838–44.
  • Li, (2014) Li, H. (2014). Fast construction of FM-index for long sequence reads. Bioinformatics, 30:3274–5.
  • Li, (2018) Li, H. (2018). Minimap2: pairwise alignment for nucleotide sequences. Bioinformatics, 34:3094–3100.
  • Li and Durbin, (2009) Li, H. and Durbin, R. (2009). Fast and accurate short read alignment with Burrows-Wheeler Transform. Bioinformatics, 25:1754–60.
  • Li and Durbin, (2010) Li, H. and Durbin, R. (2010). Fast and accurate long-read alignment with Burrows-Wheeler transform. Bioinformatics, 26:589–95.
  • Li et al., (2020) Li, H. et al. (2020). The design and construction of reference pangenome graphs with minigraph. Genome Biol, 21:265.
  • Li et al., (2024) Li, H., Marin, M., and Farhat, M. R. (2024). Exploring gene content with pangene graphs. Bioinformatics, 40:btae456.
  • Li et al., (2009) Li, R., Yu, C., Li, Y., Lam, T.-W., Yiu, S.-M., et al. (2009). SOAP2: an improved ultrafast tool for short read alignment. Bioinformatics, 25:1966–7.
  • Liao et al., (2023) Liao, W.-W., Asri, M., Ebler, J., Doerr, D., Haukness, M., et al. (2023). A draft human pangenome reference. Nature, 617:312–324.
  • Marchet et al., (2021) Marchet, C., Boucher, C., Puglisi, S. J., Medvedev, P., Salson, M., and Chikhi, R. (2021). Data structures based on k-mers for querying large collections of sequencing data sets. Genome Res, 31:1–12.
  • Navarro, (2022) Navarro, G. (2022). Indexing highly repetitive string collections, part II: compressed indexes. ACM Comput. Surv., 54:26:1–26:32.
  • Nishimoto and Tabei, (2021) Nishimoto, T. and Tabei, Y. (2021). Optimal-time queries on BWT-runs compressed indexes. In Bansal, N., Merelli, E., and Worrell, J., editors, 48th International Colloquium on Automata, Languages, and Programming, ICALP 2021, July 12-16, 2021, Glasgow, Scotland (Virtual Conference), volume 198 of LIPIcs, pages 101:1–101:15. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Nurk et al., (2022) Nurk, S., Koren, S., Rhie, A., Rautiainen, M., Bzikadze, A. V., et al. (2022). The complete sequence of a human genome. Science, 376:44–53.
  • Ohno et al., (2018) Ohno, T., Sakai, K., Takabatake, Y., I, T., and Sakamoto, H. (2018). A faster implementation of online RLBWT and its application to LZ77 parsing. J. Discrete Algorithms, 52-53:18–28.
  • Oliva et al., (2021) Oliva, M., Rossi, M., Sirén, J., Manzini, G., Kahveci, T., et al. (2021). Efficiently merging r-indexes. In Bilgin, A., Marcellin, M. W., Serra-Sagristà, J., and Storer, J. A., editors, 31st Data Compression Conference, DCC 2021, Snowbird, UT, USA, March 23-26, 2021, pages 203–212. IEEE.
  • Rossi et al., (2022) Rossi, M., Oliva, M., Langmead, B., Gagie, T., and Boucher, C. (2022). MONI: A pangenomic index for finding maximal exact matches. J Comput Biol, 29:169–187.
  • Sekar et al., (2016) Sekar, A., Bialas, A. R., de Rivera, H., Davis, A., Hammond, T. R., et al. (2016). Schizophrenia risk from complex variation of complement component 4. Nature, 530:177–83.
  • Shiryev and Agarwala, (2024) Shiryev, S. A. and Agarwala, R. (2024). Indexing and searching petabase-scale nucleotide resources. Nat Methods, 21:994–1002.
  • Simpson and Durbin, (2012) Simpson, J. T. and Durbin, R. (2012). Efficient de novo assembly of large genomes using compressed data structures. Genome Res, 22:549–56.
  • Sirén, (2016) Sirén, J. (2016). Burrows-wheeler transform for terabases. In Bilgin, A., Marcellin, M. W., Serra-Sagristà, J., and Storer, J. A., editors, 2016 Data Compression Conference, DCC 2016, Snowbird, UT, USA, March 30 - April 1, 2016, pages 211–220. IEEE.
  • Suzuki and Kasahara, (2018) Suzuki, H. and Kasahara, M. (2018). Introducing difference recurrence relations for faster semi-global alignment of long sequences. BMC Bioinformatics, 19:45.
  • Tatarnikov et al., (2023) Tatarnikov, I., Farahani, A. S., Kashgouli, S., and Gagie, T. (2023). MONI can find k-MEMs. In Bulteau, L. and Lipták, Z., editors, 34th Annual Symposium on Combinatorial Pattern Matching, CPM 2023, June 26-28, 2023, Marne-la-Vallée, France, volume 259 of LIPIcs, pages 26:1–26:14. Schloss Dagstuhl - Leibniz-Zentrum für Informatik.
  • Zakeri et al., (2024) Zakeri, M., Brown, N. K., Ahmed, O. Y., Gagie, T., and Langmead, B. (2024). Movi: a fast and cache-efficient full-text pangenome index. bioRxiv.