Optimal-Time Mapping in Run-Length Compressed PBWT
Abstract
The Positional Burrows–Wheeler Transform (PBWT) is a data structure designed for efficiently representing and querying large collections of sequences, such as haplotype panels in genomics. Forward and backward stepping operations – analogues to LF- and FL-mapping in the traditional BWT – are fundamental to the PBWT, underpinning many algorithms based on the PBWT for haplotype matching and related analyses. Although the run-length encoded variant of the PBWT (also known as the -PBWT) achieves -word space usage, where is the total number of runs, no data structure supporting both forward and backward stepping in constant time within this space bound was previously known. In this paper, we consider the multi-allelic PBWT that is extended from its original binary form to a general ordered alphabet . We first establish bounds on the size and then introduce a new -word data structure built over a list of haplotypes , each of length , that supports constant-time forward and backward stepping.
We further revisit two key applications – haplotype retrieval and prefix search – leveraging our efficient forward stepping technique. Specifically, we design an -word space data structure that supports haplotype retrieval in time. For prefix search, we present an -word data structure that answers queries in time, where denotes the length of the longest common prefix returned and occ denotes the number of haplotypes prefixed the longest prefix.
Keywords and phrases:
PBWT, LF-Mapping, prefix searches, run-length encodingCopyright and License:
2012 ACM Subject Classification:
Theory of computation Data structures design and analysisAcknowledgements:
The authors would like to thank Travis Gagie for bringing prefix searches to their attention.Funding:
All authors have received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement PANGAIA No. 872539, as well as from grant MIUR 2022YRB97K (PINC, Pangenome Informatics: From Theory to Applications), funded by the European Union under the NextGenerationEU programme, Mission 4.Editors:
Philip Bille and Nicola PrezzaSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Background and motivation.
The Positional Burrows–Wheeler Transform (PBWT) [5] is a data structure designed for efficiently representing and querying large collections of sequences, such as haplotype panels in genomics. Originally proposed by Durbin [5], the PBWT stores a set of haplotypes across variant sites in a binary matrix, where the rows at each column are arranged in co-lexicographic order according to the prefixes of the haplotypes up to column . This ordering facilitates efficient querying between a given haplotype and the panel, enabling the identification of set-maximal exact matches (SMEMs).
Two fundamental operations are defined on the PBWT: forward stepping and backward stepping. Forward stepping, denoted by , maps the position of a haplotype in the permutation of the PBWT at site to its position in the permutation at site , while backward stepping, denoted by , performs the inverse mapping, tracing a haplotype’s position at site back to its position at site . These operations play an essential role in many PBWT-based algorithms for haplotype matching and analysis.
Although the PBWT enables efficient computations, its memory usage grows rapidly with large haplotype datasets, posing a challenge for population-scale cohorts like the UK Biobank [8]. To address this limitation, the -PBWT [4], also discussed in [2], was introduced as a compressed variant of the PBWT that leverages run-length encoding (RLE) to reduce space usage. A run in a sequence is defined as a maximal contiguous block of identical symbols, and the -PBWT′s storage requirement is words, where denotes the total number of runs in the corresponding PBWT across all sites. This run-length compression reduces the -PBWT’s memory usage to only a fraction of that of the original PBWT, making it feasible to index and query massive haplotype panels such as those in the UK Biobank [8].
Beyond space efficiency, the -PBWT’s structure has proven particularly useful for downstream applications such as computing matching statistics [4, 3], Minimal Positional Substring Covers (MPSC) [3], and SMEMs [4, 3]. Each of these applications relies on repeated forward and backward stepping operations. However, within the -space bound of the -PBWT, no data structure supporting both operations in constant time was known prior to our work. Achieving faster stepping operations would directly improve the performance of all these applications and further enhance the efficiency of run-length compressed PBWT indexing for large-scale genomic analyzes.
Related work.
Durbin [5] noted that, due to the co-lexicographic ordering of the PBWT, the forward (resp, backward) stepping operation is the natural analogue of the LF- (resp, FL-) mapping in the classical Burrows–Wheeler Transform (BWT). Gagie et al. [7, Lemma 2.1] presented a data structure requiring words of space, built over a text of length , that supports LF- and FL-mappings on the BWT in time, where is the number of runs in the BWT of the text and is the number of bits in a machine word. By applying this data structure to each column of the PBWT, we can achieve, for every site , an -word data structure that supports both forward and backward stepping queries in time, where denotes the number of runs at site .
Nishimoto and Tabei [12] recently proposed the move structure to accelerate LF-mapping operations on the BWT. Their approach first divides the runs in the BWT into at most sub-runs, and then constructs an -word data structure over these sub-runs. Given a position in the BWT and the index of the sub-run containing , the structure can compute LF and determine the index of the sub-run containing LF in constant time.
Typically, in applications of the PBWT, forward and backward stepping are performed iteratively. For example, to traverse a haplotype in the PBWT from site to site , the forward stepping procedure is invoked sequentially times. However, efficient (e.g., constant-time) forward and backward stepping in the run-length encoded PBWT cannot be achieved simply by applying the move structure independently at each site. Indeed, the move structure only returns the index of the sub-run at site that contains , whereas continuing the forward step from site to site requires the index of the sub-run at site that contains . See Figure 1 for an example. Hence, new methods are needed to accelerate fore and back queries while maintaining the run-length encoded PBWT.
Two key applications of the back and fore queries on the PBWT are haplotype retrieval and prefix search [6]. In haplotype retrieval, the goal is to extract any haplotype from the PBWT. In prefix search, the objective is to find the longest common prefix between any haplotype and a query pattern , and to list the indices of all haplotypes prefixed by . Using the data structure from [7, Lemma 2.1], built over each column of the PBWT, haplotype retrieval can be performed in time by invoking forward stepping iteratively times, with an overall space usage of words. Gagie et al. [6] present a textbook solution based on the PBWT that uses words of space and supports each prefix query in time, where occ denotes the number of reported indices. They also provide various time-space tradeoffs in the same work. Nishimoto and Tabei [12] propose a data structure for prefix search that combines a BWT built over all haplotypes, a compact trie [10], the move data structure, and at most marked positions. The structure supports computing the longest prefix in time, using words of space, where denotes the number of runs in the BWT of the concatenated sequence.
Our results.
We consider the multi-allelic PBWT as described in [11]. We propose a “move data structure”style solution specifically tailored for the PBWT. Our approach introduces a simple yet effective algorithm that partitions the runs of the PBWT into at most sub-runs across all columns of the PBWT (Section 4). We then design an -word data structure over the sub-runs (Theorem 13) that supports -time computation of both forward and backward stepping operations, allowing to be invoked iteratively (Section 5).
As a first application, we present a PBWT-based solution for prefix searches. Specifically, assuming all haplotypes have the same length, we design an -word data structure that finds the longest common prefix between any haplotype and a query pattern in time. When the haplotypes are sorted lexicographically, we can further reduce the space complexity from to . Note that the problem setting considered by Nishimoto and Tabei [12] allows haplotypes of varying lengths. We also show that our PBWT-based solution can be adapted to this more general case. While our query time is not as efficient as that of Nishimoto and Tabei [12], our approach has the advantage of not requiring a compact trie. As a second application, we design an -word data structure to represent the haplotypes, supporting retrieval of any haplotype () in time (Theorem 17).
Before introducing our “move”-like -word data structure, we complement our results with lower and upper bounds on the measure . We establish a connection between and the number of adjacent haplotype pairs such that . Specifically, we show that and .
Paper organization.
In Section 2, we introduce the notation and preliminary results used throughout the paper. In Section 3, we establish lower and upper bounds on the size . Section 4 defines the three-overlap constraint over two lists of intervals and presents an algorithm that divides intervals in one list into sub-intervals satisfying this constraint. Applying this algorithm, we describe in Section 5 how to divide PBWT runs into sub-runs for back and fore queries. In Section 6, we design data structures over these sub-runs and develop the corresponding algorithms for back and fore queries. Section 7 discusses two applications of back and fore queries: haplotype retrieval and prefix searches. Finally, Section 8 concludes the paper and outlines directions for future work.
2 Preliminaries
All results in this paper are presented under the word RAM (random-access machine) model. We evaluate the space cost of data structures in words. Each word is of bits.
Notations.
We denote by the interval of integers , and define if . Given an interval , we denote its left and right endpoints by and , respectively, so that and . For any matrix , we denote by its -th column and by the entry . Let be the matrix that stores in rows . We note that the input haplotypes might not be pairwise distinct.
Consider an ordered alphabet with . A string over this alphabet is a finite sequence of symbols from , that is, , where denotes the length of , and for all . The empty string is denoted by . For indices , we denote by the substring of spanning positions through (and define if ). The string is referred to as the -th prefix of , and as the -th suffix, for . A proper prefix (respectively, proper suffix) of is a prefix (respectively, suffix) such that .
Given two strings and over the alphabet set , we say that is lexicographically smaller than , denoted by , if and only if one of the following holds: i) there exists an index such that for all , and ; ii) or is a proper prefix of . We say that is co-lexicographically smaller than , denoted by , if and only if one of the following holds: i) There exists an index such that for all , and ; ii) or is a proper suffix of .
Predecessor queries.
Given a sorted list of integers, a predecessor query takes an integer as input and returns and its rightmost position in .
Lemma 1 ([1, Theorem A.1]).
Given an increasingly sorted list of integers, drawn from the universe , there is a data structure that occupies bits of space and answers a predecessor query in time.
Rank and select queries.
Given a sequence over an alphabet , the operation returns the number of occurrences of in , for . The operation returns the position of the -th occurrence of in , for , and returns if .
Lemma 2 ([1]).
There exists a data structure of words built on that supports rank queries in time and select queries in time.
Positional Burrows–Wheeler Transform (PBWT).
Closely related to the PBWT is the Prefix Array (PA), a matrix that records, for each column, the permutation of haplotype indices induced by the PBWT. Formally, the Prefix Array PA built for the matrix is an matrix, in which is simply the list , and , for , stores the permutation of the set induced by the co-lexicographic ordering of prefixes of up to column , that is, if and only if is ranked in the co-lexicographic order of .
Let PBWT be the matrix representing the positional BWT of . Then PBWT is also an matrix in which for all and . We refer to a maximal substring of identical characters in as a run. Throughout the paper, let denote the number of runs for . We define as .
Forward and backward stepping on PBWT.
We define , for and , as the (row) index of in , and , for and , as the (row) index of in .
Previously, the operation could be implemented as follows. Let denote the number of occurrences of symbols in column of the PBWT, that is, in . Then, , where . The backward stepping operation can be implemented in a symmetric manner.
Proposition 3 states the key properties of fore.
Proposition 3.
(a) If and , then , and (b) if , then .
Proof.
When constructing the -th column of PBWT, note that the prefixes of the haplotypes up to column are stably sorted. Therefore, statements (a) and (b) follow directly from this stable ordering.
3 A Lower Bound and an Upper Bound on
In this section, we establish lower and upper bounds on in terms of , where denotes the number of pairs such that and .
Lemma 4.
It holds that .
Proof.
Consider any pair such that . Let denote the length of the longest common prefix between and . Observe that the indices and remain consecutive in for all . Let be the row index such that . By the observation above, we have . Since by the definition of , there must be a run boundary between rows and in the -st column of PBWT. Therefore, each pair with corresponds to a run boundary in PBWT. The mapping from such a pair to a run boundary at is injective, since each haplotype index appears at a unique row in PA of any column. This establishes that .
Corollary 5.
is at least the number of distinct haplotypes in .
Proof.
The statement holds because the number of distinct haplotypes in is at most .
We call an interval canonical with respect to column of the PBWT, for , if is the maximal interval such that . Let denote the number of canonical intervals with respect to column for . Lemma 6 describes the relationship between and .
Lemma 6.
It holds that .
Proof.
Consider column for any . Let denote any canonical interval with respect to this column. Observe that . Hence, corresponds to a contiguous block of identical symbols in , although the block might not be maximal. This implies that .
Lemma 7.
It holds that .
Proof.
The proof proceeds by induction on . Let be the array consisting of in increasing order. It follows that .
For the base case , observe that each interval for (under the convention ) forms a distinct canonical interval with respect to the first column. Since , we have .
Assume inductively that . Let denote any canonical interval with respect to column , so we have . By Proposition 3(b), the integers are consecutive, forming an interval . Furthermore, by the definitions of fore and , the haplotypes for all are identical. Thus, this interval is contained within some canonical interval with respect to column . This containment may be strict whenever multiple canonical intervals with respect to column , corresponding to identical haplotype sequences, are mapped to adjacent positions in column , thereby merging into a single canonical interval with respect to column . Therefore, each canonical interval with respect to column is mapped by fore to a subinterval of a canonical interval with respect to column . Since the union of these mapped intervals covers all rows , the number of canonical intervals in column must be less than or equal to the number in column (). By the induction hypothesis, , completing the proof.
Theorem 8.
It holds that .
Proof.
4 The Three-Overlap Constraint and a Normalization Algorithm
In this section, we define the three-overlap constraint and present a new algorithm for partitioning runs based on it.
Definition 9 (The Three-Overlap Constraint).
Let be a collection of pairwise disjoint intervals that partition the range , where , , and for . Similarly, let be a collection of pairwise disjoint intervals that also partition , where , , and for . We say that satisfies the three-overlap constraint with respect to if every interval in overlaps with at most three intervals in .
Note that the three-overlap constraint differs from the balancing property introduced in the move data structure [12] in two key aspects. Under the balancing property,
-
and are in bijective correspondence – that is, there exists a bijection (with inverse ) such that for each interval (resp., ), the interval belongs to (resp., ), and
-
each interval in contains at most three left endpoints of intervals in ; consequently, a single interval in may overlap with up to four distinct intervals from .
Lemma 10.
Let and denote two lists of intervals into which is partitioned. There exists an -time algorithm that partitions all intervals in into at most sub-intervals, satisfying the three-overlap constraint, with respect to .
Proof.
Let and be pairwise-disjoint intervals into which is partitioned, where , and for . Let . Without loss of generality, assume that ; otherwise, immediately satisfies the three-overlap constraint. Let be pairwise-disjoint intervals into which is partitioned, where , and for .
The algorithm is described as follows. Create a variable and initiate to . Iterate and process each interval in from left to right as follows: If overlaps with at most three intervals of , then skip and move on to the next interval; otherwise, divide into two sub-intervals, and , where is the largest integer such that overlaps three intervals of . Then, substitute for and , increment by one, and move on to the next interval, that is, .
Let denote the list of intervals outputted by the above algorithm. Figure 2 illustrates an example of the algorithm. Clearly, we have and it follows that every interval in overlaps at most three intervals in . It remains to prove that . To this end, we define for any to be the set of intervals in , overlapping .
Claim 11.
For any , let (resp. ) denote the interval in , of which the right endpoint is (resp. ). We have .
Proof.
Observe that we have for any , and thus the integers and are always in different intervals in . Moreover, for any , in view of the algorithm.
Assume that there exists an interval . Let denote the left endpoint of the interval . Then, we have and . Since , we have as well, a contradiction. Hence, the assumption is false.
In view of the algorithm, the interval in ending at for any overlaps exactly three intervals in . In view of Claim 11, we have ; therefore, , for .
Clearly, the algorithm runs in time.
5 Constructing Sub-Runs and Bounding Their Number
In this section, we introduce sub-runs for forward and backward stepping (i.e., fore and back) in the PBWT.
While runs are maximal-length substrings consisting of the same character, we define sub-runs as substrings of the same character without the maximal-length restriction.
We define a run interval with respect to column () as the maximal interval such that all symbols in positions of are identical. Let denote the list of the run intervals in column , sorted in increasing order of their starting positions. Similarly, a sub-run interval is any contiguous subrange contained within a run interval. We abuse notation slightly and use the terms run intervals (resp. sub-run intervals) and runs (resp. sub-runs) interchangeably.
In the following, we define two bijection functions foreL and backL that will be used, respectively, in the construction of two lists and of sub-runs for each column . The lists and are used later to implement back queries and fore queries, respectively. More precisely, returns the list , sorted in increasing order by the left endpoint of each interval, for any set of intervals and any .
By Proposition 3(b), it follows that if . Hence, is well-defined (i.e., for every ) if each interval in is a sub-interval of some interval in .
Symmetrically, we define to return the list , sorted in increasing order by the left endpoint of each interval.
Constructing sub-runs for back queries.
The construction of proceeds by induction. In the base case, we set . For each from to , we construct as follows: we apply the algorithm normalization (see Lemma 10) with and . Recall that the function maps sub-intervals in column to sub-intervals in column . The list of sub-intervals output by this algorithm is assigned to . See Figure 3 for an illustration of the algorithm and an example.
In view of the algorithm in Lemma 10, each interval in for is a sub-interval of some interval in and overlaps at most three intervals in the list . Recall that every interval in corresponds to a run in . Hence, every interval in corresponds to a sub-run in .
Constructing sub-runs for fore queries.
The construction of is also performed by induction. In the base case, we set . Then, for from down to , we construct as follows: we apply the algorithm normalization (see Lemma 10), where and . Let be the list of intervals output by the algorithm; we then assign . Figure 6 (in Appendix A) illustrates the construction scheme along with an example.
By the normalization algorithm shown in Lemma 10, each interval in for is a sub-interval of some interval in and overlaps at most three intervals in . Recall that every interval in corresponds to a run in . Likewise, every interval in corresponds to a sub-run in . Since , every interval in is a sub-run in .
Lemma 12.
We have and .
Proof.
Observe that . Recall that is always true. In the base case, we have . For , we have the recursion , in view of Lemma 10 and the observation above. By solving the recursion, it follows that . Therefore, we have . The bound on the total number of for all can be computed similarly. This concludes the proof.
6 The Data Structure for Constant-Time Queries
In this section, we design the data structure constructed over these sub-runs to support queries and access to entries in the matrix PBWT.
Theorem 13.
There exists a data structure of words, constructed over and for , that supports each of the following operations in constant time – without accessing the original matrix , its PBWT, or its prefix arrays PA:
-
Given an index and the index of the interval in that contains , one can find , determine the index of the interval in containing , and retrieve .
-
Given an index and the index of the interval in that contains , one can find , determine the index of the interval in containing , and retrieve .
Proof.
We first describe the data structure for back queries. For each column of the PBWT, we construct the list as described in Section 5 (see Constructing sub-runs for back queries). Observe that each interval in overlaps at most three intervals in . Moreover, each interval corresponds to the interval belonging to . For every and each interval with , we store a list of quadruples , where:
-
is a distinct interval in that overlaps ;
-
; and
-
is the index of the interval in whose left endpoint is .
Since each overlaps at most three intervals in , the list contains at most three tuples. By Lemma 12, , so the total space usage is words.
Let , given in a query, denote the index of the sub-run in containing . To answer a query , we search in the list for the quadruple satisfying . Then , and is the index of the interval in containing . We return as the result. Since , each query takes time. See Figure 4 for an illustration of the data structure and algorithm.
Accessing from SubIB lists.
We store, for each , an array of length , where each entry is set to . This requires words per column, and words overall. Given the index of the sub-run containing in , we have , which can be retrieved in time.
Data structure for fore queries.
We construct the lists for each column as described in Section 5 (see Constructing sub-runs for fore queries). Each interval corresponds to , and each interval in overlaps at most three intervals in . For every and each interval , we store a list of quintuplets , where:
-
, ,
-
is an interval in that overlaps ,
-
is the index of in .
Since each such interval, i.e., , overlaps at most three intervals in , each has at most three tuples. By Lemma 12, the total space is again words.
Let denote the index of the sub-run containing in . To answer , we search for the quintuple satisfying . Then , and is the index of the interval in containing . We return as the result. Since , each query takes time. An illustration of the data structure and the algorithm is depicted in Figure 7 (in Appendix B).
Accessing from SubIF lists.
Analogously, for each , we store an array of length , where . This requires words per column, and words in total. Given the index of the sub-run containing in , we have , retrievable in time.
7 Applications
In this section, we present applications that rely on the iterative use of queries. Section 7.1 introduces a PBWT-based solution to prefix searches, while our method to haplotype retrieval is given in Section 7.2.
Henceforth, set for every . According to Theorem 13, given and , where , , and , we define that returns such that and . In other words, returns and the index of the sub-interval in that contains .
7.1 A PBWT-Based Solution to Prefix Search
We first provide a solution under the assumption that all haplotypes are of the same length and then generalize it to the case where haplotypes are of arbitrary length.
Similarly as sa-interval in suffix arrays [9], given a query pattern , we define , with , as the maximal continuous range of indices in such that is a prefix of for each . In particular, is defined as , corresponding to the empty string .
Theorem 14.
There exists an -word data structure constructed over an arbitrarily ordered list of haplotypes of length over the alphabet such that, given a pattern , one can compute in time:
-
1.
the longest common prefix between and any haplotype,
-
2.
the number occ of haplotypes prefixed by , and
-
3.
an index such that is prefixed by .
If are lexicographically sorted, then the data structure finds, in time, the interval such that is prefixed by for every and .
In the remainder of this section, we prove Theorem 14.
The data structures.
The construction of the data structure proceeds as follows. We first build the PBWT matrix PBWT and the prefix array matrix PA for the haplotypes, each consisting of columns and rows. Next, we compute the sub-runs for all , as described in Section 5. Over these sub-runs, we then construct the -space data structure from Theorem 13 to support fore queries efficiently.
We also build the following auxiliary arrays for . Recall that .
-
: each entry () stores ;
-
: each entry stores ;
-
: each entry stores the number of occurrences of in , that is, .
We then build the data structures for rank and select queries over as in Lemma 2. After building these arrays and supporting structures, we discard PBWT and PA.
The query algorithm.
The algorithm Partial Prefix Search() iterates through columns from left to right. At each column , it updates a state quintuple defined as follows:
-
represent the interval boundaries and , respectively,
-
are indices such that and , respectively, and
-
stores the value .
Initially, we set the quintuple as , , , and . In the -th iteration (), the following steps are performed:
-
We first determine the positions and , where denote the indices of the first and last occurrences of in within the range . Formally, and . If neither nor exists, the interval corresponding to the prefix is empty. Otherwise, we locate the indices and such that and , respectively. In the pseudocode, we show that all of , , , and can be obtained using rank and select queries over the array . In addition, if , we update the variable . We will later prove that the variable index always stores .
-
Second, if and , we apply the queries and according to Theorem 13, and update and , respectively. Consequently, for , it follows that and . Thus, , corresponding to the prefix , is obtained and stored as , with the values and updated accordingly. If , we instead set and .
-
Third, we increment by 1 and proceed to the next iteration.
We stop proceeding to the next iteration if or . The following observation is crucial: in either case, the longest common prefix shared by and any haplotype is .
If , then is , corresponding to the prefix . If , then the longest common prefix shared by and any haplotype is an empty string. Otherwise, the longest common prefix is by the observation mentioned earlier, and the number of haplotypes prefixed by is by the definition of ; therefore, we return , and as the answer.
If instead , it follows that is the longest common prefix and that and store, respectively, the indices of the first and last occurrences of in , where (note that corresponds to the prefix ). In this case, we compute the numbers of occurrences of in and , which are and , respectively, and store them in variables and . The number of haplotypes prefixed by is . In the end, we return as the answer; recall that the variable stores . The pseudocode of the algorithm can be found in Appendix C.
We have shown that the procedure Partial Prefix Search() identifies the longest prefix shared between and any haplotype, and counts the number of haplotypes prefixed by . It remains to show that the variable index returned by the procedure indeed stores the index of one of these haplotypes. To this end, it suffices to prove that the invariant holds in each iteration .
Lemma 15.
It follows that in each iteration with .
Proof.
We give a proof by induction. When , the procedure sets and . Since , we have ; the base case for holds trivially.
Assume by induction that at the beginning of the -th iteration, we have . Consider the -th iteration. Note that in the beginning of this iteration, we have , as .
If , then ; in this case, the variable remains in this iteration, and the variable is set to . Note that by the definition of fore queries, we have . By the inductive assumption, we have , thereby ; therefore, at the beginning of the next iteration, the statement still holds.
Otherwise, we have ; in this case, the procedure finds the index of the first occurrence of in within the range and the index that satisfies , and sets . Since , we have . If , then the procedure sets ; therefore, we have . When the while-loop terminates in the -th iteration, we have . If , then is set to . By the definition of fore queries, we have . Recall that , so it follows that . Thus, at the beginning of the next iteration, the statement holds, completing the proof.
Moreover, by Proposition 3(a), it follows that the variable returned by the algorithm stores the smallest index such that is prefixed by ; that is, .
The running time analysis.
The while-loop in the algorithm performs at most iterations. Recall that denotes the length of the longest common prefix to return. So, does not exist, and at most iterations are executed. In each iteration , the queries rank and select over the array , as well as the query forePair are called at most twice, respectively. By Lemma 2 and Theorem 13, a rank query takes time, a query select or takes time. Hence, the overall running time of the algorithm is bounded by .
When are sorted lexicographically.
In this case, we first invoke the procedure Partial Prefix Search() to obtain , the count occ, and the index of a haplotype that is prefixed by . We then compute the interval as . To verify correctness, observe that if are presorted lexicographically, then the list forms a sub-list of for every . Recall that . Hence, it follows that and .
This completes the proof of Theorem 14. In Corollary 16, we extend this result to enumerate all haplotype indices prefixed by .
Corollary 16.
There is an -word data structure built over an arbitrary ordered list of haplotypes such that, given a pattern , the indices of the haplotypes prefixed by can be enumerated in time, where is the longest common prefix between and any haplotype and occ denotes the number of haplotypes prefixed by .
Proof.
We first sort all haplotypes in lexicographic order, build the data structure of Theorem 14 over the sorted list, and store the permutation for such that . The resulting data structure uses words of space.
Given a query pattern , Theorem 14 allows us to find the longest common prefix in time, as well as the interval such that for any is prefixed by . The number occ of occurrences is then , and the original indices, before sorting, of these haplotypes prefixed by are . Using the permutation together with the interval , the list of indices can be reported in time.
Handling haplotypes of arbitrary lengths.
We consider a general setting where the haplotypes have arbitrary length. We append a special symbol – assumed to be the smallest – to the end of each haplotype. Next, we construct the PBWT representation PBWT and the prefix arrays PA for the new haplotypes, which consist of symbols in total.
The construction of PBWT proceeds column by column from left to right, as in the case of haplotypes of equal length. In this setting, however, both PBWT and the PA are no longer matrices; instead, each consists of columns of possibly different lengths, denoted by and , respectively. Here, denotes the maximum extended haplotype length among , that is, . When constructing the entries of and , we exclude any haplotype such that . Figure 5 shows an example of PBWT and PA built for haplotypes of arbitrary length.
The construction procedure described above ensures that each column stores a permutation of all entries for every and . Note that . As a result, the symbol # appears in PBWT exactly times across all columns. Let denote the total number of runs in PBWT, and let denote the number of runs excluding those composed entirely of #. Since # occurs times in PBWT, it follows that .
Upon the runs of PBWT for the new haplotypes trailing with #, we build the same data structures as we have seen before for constructing sub-runs ’s, for fore queries, and for prefix searches (Corollary 16). The space cost is bounded by words, and a prefix search query can be answered in time, since the new alphabet set is . Note that a prefix search query never calls for any and such that .
7.2 Haplotype Retrieval within Space
Theorem 17.
The list of haplotypes , each of length , can be represented in words of space, allowing with any to be retrieved in time.
Proof.
We construct the data structure, denoted by , as described in Theorem 13 for supporting fore queries. Let , for , be the starting positions of the -th sub-run in . Clearly, these positions are sorted in increasing order. The list consists of exactly positions. We build the data structure from Lemma 1 over the list to support predecessor queries. Since these positions are drawn from the universe , each predecessor query can be answered in time. The data structure requires words of space.
Given a query position , we apply Lemma 1 to find the index of the sub-run that contains ; that is, is the position of the predecessor of in the list . Using , we can retrieve and in constant time via . The former gives the entry , while the latter provides both the position – where is stored in – and the index of the sub-run in that contains . With and , we can obtain the entry and continue in the same manner for the subsequent columns. The algorithm terminates after all entries of have been retrieved.
The predecessor query is invoked once, costing time by Lemma 1. The forePair query is invoked times, and exactly entries of the matrix PBWT are accessed. Thus, the total query time is bounded by .
8 Conclusions
In this work, we presented new -space data structures and algorithms that support efficient forward and backward stepping operations on the PBWT. Our data structure enables constant-time computation of both fore and back operations. We also established lower and upper bounds on . To demonstrate the utility of the optimal-time mapping, we revisited two applications: prefix search and haplotype retrieval. For the first application, we proposed an –word data structure that answers each query in time. When the haplotypes are provided in lexicographic order, the space requirement reduces to words. Moreover, our PBWT-based approach to prefix search naturally extends to haplotypes of arbitrary length. For the second application, we designed an -word data structure that supports haplotype retrieval in time. While this work primarily focuses on the theoretical approach for achieving constant-time mapping in the run-length encoded PBWT, it also opens new directions for practical implementations and other applications, such as accelerating the computation of SMEMs [4] or MPSC in haplotype threading [13, 3]. We leave these aspects for future work.
References
- [1] Djamal Belazzougui and Gonzalo Navarro. Optimal Lower and Upper Bounds for Representing Sequences. ACM Transactions on Algorithms, 11(4), 2015. doi:10.1145/2629339.
- [2] Paola Bonizzoni, Christina Boucher, Davide Cozzi, Travis Gagie, Dominik Köppl, and Massimiliano Rossi. Data Structures for SMEM-Finding in the PBWT. In Franco Maria Nardini, Nadia Pisanti, and Rossano Venturini, editors, String Processing and Information Retrieval - 30th International Symposium, SPIRE 2023, Pisa, Italy, September 26-28, 2023, Proceedings, Lecture Notes in Computer Science, pages 89–101. Springer, 2023. doi:10.1007/978-3-031-43980-3_8.
- [3] Paola Bonizzoni, Christina Boucher, Davide Cozzi, Travis Gagie, and Yuri Pirola. Solving the Minimal Positional Substring Cover Problem in Sublinear Space. In Shunsuke Inenaga and Simon J. Puglisi, editors, 35th Annual Symposium on Combinatorial Pattern Matching (CPM 2024), volume 296 of LIPIcs, pages 12:1–12:16, Dagstuhl, Germany, 2024. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.CPM.2024.12.
- [4] Davide Cozzi, Massimiliano Rossi, Simone Rubinacci, Travis Gagie, Dominik Köppl, Christina Boucher, and Paola Bonizzoni. - PBWT: a lightweight r-indexing of the PBWT for storing and querying UK Biobank data. Bioinform., 39(9), 2023. doi:10.1093/BIOINFORMATICS/BTAD552.
- [5] Richard Durbin. Efficient haplotype matching and storage using the positional Burrows-Wheeler transform (PBWT). Bioinform., 30(9):1266–1272, 2014. doi:10.1093/BIOINFORMATICS/BTU014.
- [6] Travis Gagie, Giovanni Manzini, and Marinella Sciortino. Teaching the Burrows-Wheeler Transform via the Positional Burrows-Wheeler Transform. CoRR, abs/2208.09840, 2022. doi:10.48550/arXiv.2208.09840.
- [7] Travis Gagie, Gonzalo Navarro, and Nicola Prezza. Fully Functional Suffix Trees and Optimal Text Searching in BWT-Runs Bounded Space. Journal of the ACM, 67(1):2:1–2:54, 2020. doi:10.1145/3375890.
- [8] Bjarni V Halldorsson, Hannes P Eggertsson, Kristjan HS Moore, Hannes Hauswedell, Ogmundur Eiriksson, Magnus O Ulfarsson, Gunnar Palsson, Marteinn T Hardarson, Asmundur Oddsson, Brynjar O Jensson, et al. The sequences of 150,119 genomes in the UK Biobank. Nature, pages 1–9, 2022. doi:10.1038/s41586-022-04965-x.
- [9] Udi Manber and Eugene W. Myers. Suffix Arrays: A New Method for On-Line String Searches. SIAM J. Comput., 22(5):935–948, 1993. doi:10.1137/0222058.
- [10] Donald R. Morrison. PATRICIA - Practical Algorithm To Retrieve Information Coded in Alphanumeric. Journal of the ACM, 15(4):514–534, 1968. doi:10.1145/321479.321481.
- [11] Ardalan Naseri, Degui Zhi, and Shaojie Zhang. Multi-allelic positional Burrows-Wheeler transform. BMC Bioinform., 20-S(11):279:1–279:8, 2019. doi:10.1186/S12859-019-2821-6.
- [12] Takaaki Nishimoto and Yasuo Tabei. Optimal-Time Queries on BWT-Runs Compressed Indexes. In Nikhil Bansal, Emanuela Merelli, and James Worrell, editors, 48th International Colloquium on Automata, Languages, and Programming, ICALP 2021, Glasgow, Scotland (Virtual Conference), July 12-16, 2021, LIPIcs, pages 101:1–101:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2021. doi:10.4230/LIPIcs.ICALP.2021.101.
- [13] Ahsan Sanaullah, Degui Zhi, and Shaoije Zhang. Haplotype Threading Using the Positional Burrows-Wheeler Transform. In Christina Boucher and Sven Rahmann, editors, 22nd International Workshop on Algorithms in Bioinformatics, WABI 2022, Potsdam, Germany, September 5-7, 2022, LIPIcs, pages 4:1–4:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.WABI.2022.4.
Appendix A The Figure Omitted from Section 5
Appendix B The Figure Omitted from Section 6
Appendix C The Pseudocode for Prefix Searches
Partial Prefix Search()
01. ;
02. ;
03. while do
04. ;
05. ;
06. if then
07. ;
08. ;
09. if then
10. break;
11. ;
12. ;
13. ;
14. if then
15. ;
16. ;
17. ;
18. if then
19. ;
20. ;
21. else
22. ;
23. ;
24. ;
25. if then
26. return the longest common prefix is empty;
27. else if
28. return ;
29. else
30. ;
31. ;
32. ;
33. return ;
