动机:新一代 DNA 测序技术产生的海量短读长序列,迫切需要开发快速且准确的读长比对程序。第一代基于哈希表的方法已经出现,其中包括 MAQ,它准确、功能丰富且速度足以比对单个个体的短读长。然而,MAQ 不支持单端读长的空位比对,这使其不适用于 indel 频繁发生的较长读长的比对。当比对规模扩大到数百个个体的重测序时,MAQ 的速度也成为一个问题。
Motivation: The enormous amount of short reads generated by the new DNA sequencing technologies call for the development of fast and accurate read alignment programs. A first generation of hash table-based methods has been developed, including MAQ, which is accurate, feature rich and fast enough to align short reads from a single individual. However, MAQ does not support gapped alignment for single-end reads, which makes it unsuitable for alignment of longer reads where indels may occur frequently. The speed of MAQ is also a concern when the alignment is scaled up to the resequencing of hundreds of individuals.
结果:我们实现了 Burrows-Wheeler 比对工具(BWA),这是一个基于 Burrows–Wheeler 变换(BWT)反向搜索的新型读长比对软件包,能够高效地将短测序读长比对到大型参考序列(如人类基因组),支持错配和空位。BWA 同时支持碱基空间读长(如来自 Illumina 测序仪)和来自 AB SOLiD 仪器的颜色空间读长。在模拟数据和真实数据上的评估表明,BWA 比 MAQ 快约 10–20 倍,同时达到相似的准确度。此外,BWA 以新的标准 SAM(Sequence Alignment/Map)格式输出比对结果。比对后的变异检测和其他下游分析可以通过开源软件包 SAMtools 完成。
Results: We implemented Burrows-Wheeler Alignment tool (BWA), a new read alignment package that is based on backward search with Burrows–Wheeler Transform (BWT), to efficiently align short sequencing reads against a large reference sequence such as the human genome, allowing mismatches and gaps. BWA supports both base space reads, e.g. from Illumina sequencing machines, and color space reads from AB SOLiD machines. Evaluations on both simulated and real data suggest that BWA is ∼10–20× faster than MAQ, while achieving similar accuracy. In addition, BWA outputs alignment in the new standard SAM (Sequence Alignment/Map) format. Variant calling and other downstream analyses after the alignment can be achieved with the open source SAMtools software package.
可用性: http://maq.sourceforge.net
Availability: http://maq.sourceforge.net
联系方式: rd@sanger.ac.uk
Contact: rd@sanger.ac.uk
BWA 的历史定位:2009 年前后正值第二代测序(NGS)爆发期,Illumina Genome Analyzer、AB SOLiD 等平台每天产出数千万条短读长(25–100 bp)。第一代比对工具(MAQ、SOAP、ELAND)普遍采用种子-哈希策略——将读长切分为种子片段,通过哈希表快速定位到参考基因组上的候选位点。这种策略在短读长(≤36 bp)且错配数较少时效果尚可,但当读长增加、需要支持 gap 比对时,哈希索引的内存和计算开销急剧膨胀。BWA 的出现标志着从"哈希种子"到"全文索引"的范式转换——利用 BWT/FM-index 将整个参考基因组压缩为可搜索的索引结构,将比对问题转化为一系列字符匹配操作,其复杂度仅取决于读长而非基因组大小。
FM-index 对比哈希方法的根本差异:哈希方法需要为每条读长构建多个种子,每次种子命中触发验证阶段(Smith-Waterman 等动态规划),时间复杂度为 O(N·R·G),其中 N 为读长数、R 为种子数、G 为参考覆盖度。而 FM-index 的反向搜索以 O(m) 复杂度(m 为读长)在索引上逐步延伸匹配,本质上是一个在线搜索过程,无需预先生成候选集。更重要的是,FM-index 的空间效率极高——人类基因组约 1.3 GB,比原始序列的 2 倍小得多。这并非来自简单的 gzip 压缩,而是 BWT 将基因组重组为高度可压缩的形式,配合 wavelet tree 实现 O(1) 的 rank 查询,从而在压缩空间内完成快速搜索。这种"压缩域搜索"(search in compressed space)的思想深刻影响了后续的生物信息学工具。
SAM 格式的标准化意义:BWA 与 SAMtools 几乎是同时诞生的,二者的关系类似"浏览器与网页标准"——BWA 是第一个默认以 SAM 格式输出的比对工具,而 SAMtools 提供了读写、排序、索引等功能。之所以叫"Sequence Alignment/Map"而非"Mapping",是因为 SAM 的设计不仅要存储比对结果(alignment),还要记录未比对上的读长(unaligned reads),从而保证完整的数据保真度。SAM 的二进制版本 BAM 成为测序数据的通用交换格式,后来催生了 CRAM(进一步利用参考基因组压缩)和 Pysam 等生态。这种"工具 + 标准同步发布"的策略在当时并不多见,也是 BWA 生态能迅速占领市场的重要原因。
SOLiD 颜色空间的工程权衡:AB SOLiD 平台使用双碱基编码(dinucleotide encoding),即每个碱基被两个连续的探针读取(因此称为"颜色空间")。这一设计使得每个碱基被读取两次,理论上可以将原始测序错误率从 ~1% 降至 ~0.01%。但代价是:如果某个颜色发生错误,后续所有碱基都会被错误解释。BWA 通过内部颜色-核苷酸转换直接支持颜色空间比对,这比在比对前进行纠错转换更精确。值得注意的是,SOLiD 最终被 Illumina 淘汰,颜色空间比对成为一个历史注脚,但这段工程实践展示了比对工具设计中"平台兼容性"的权衡——是强制用户转换数据还是工具内部隐式处理。
Illumina/Solexa 测序技术通常每次运行产生 5000 万到 2 亿条 32–100 bp 的读段。将如此海量的短读段比对到人类基因组这样庞大的参考序列上,对现有的序列比对程序构成了巨大挑战。为满足高效且准确的短读段比对需求,许多新的比对程序应运而生。其中第一类软件,如 Eland(Cox, 2007,未发表资料)、RMAP(Smith et al., 2008)、MAQ(Li et al., 2008a)、ZOOM(Lin et al., 2008)、SeqMap(Jiang and Wong, 2008)、CloudBurst(Schatz, 2009)和 SHRiMP(http://compbio.cs.toronto.edu/shrimp),通过对读段序列做哈希然后扫描参考序列来完成比对。这一类程序通常具有灵活的内存占用,但当真比对读段很少时,仍可能需要扫描整个基因组。第二类软件,包括 SOAPv1(Li et al., 2008b)、PASS(Campagna et al., 2009)、MOM(Eaves and Gao, 2009)、ProbeMatch(Jung Kim et al., 2009)、NovoAlign(http://www.novocraft.com)、ReSEQ(http://code.google.com/p/re-seq)、Mosaik(http://bioinformatics.bc.edu/marthlab/Mosaik)和 BFAST(http://genome.ucla.edu/bfast),则对基因组做哈希。这些程序可以很容易地通过多线程并行化,但通常需要大量内存来为人类基因组建索引。此外,这些软件常采用的迭代策略可能使它们的速度对测序错误率敏感。第三类包括 slider(Malhis et al., 2009),通过对参考子序列和读段序列进行归并排序来完成比对。
The Illumina/Solexa sequencing technology typically produces 50–200 million 32–100 bp reads on a single run of the machine. Mapping this large volume of short reads to a genome as large as human poses a great challenge to the existing sequence alignment programs. To meet the requirement of efficient and accurate short read mapping, many new alignment programs have been developed. Some of these, such as Eland (Cox, 2007, unpublished material), RMAP (Smith et al., 2008), MAQ (Li et al., 2008a), ZOOM (Lin et al., 2008), SeqMap (Jiang and Wong, 2008), CloudBurst (Schatz, 2009) and SHRiMP (http://compbio.cs.toronto.edu/shrimp), work by hashing the read sequences and scan through the reference sequence. Programs in this category usually have flexible memory footprint, but may have the overhead of scanning the whole genome when few reads are aligned. The second category of software, including SOAPv1 (Li et al., 2008b), PASS (Campagna et al., 2009), MOM (Eaves and Gao, 2009), ProbeMatch (Jung Kim et al., 2009), NovoAlign (http://www.novocraft.com), ReSEQ (http://code.google.com/p/re-seq), Mosaik (http://bioinformatics.bc.edu/marthlab/Mosaik) and BFAST (http://genome.ucla.edu/bfast), hash the genome. These programs can be easily parallelized with multi-threading, but they usually require large memory to build an index for the human genome. In addition, the iterative strategy frequently introduced by these software may make their speed sensitive to the sequencing error rate. The third category includes slider (Malhis et al., 2009) which does alignment by merge-sorting the reference subsequences and read sequences.
最近,基于 Burrows–Wheeler 变换(BWT)(Burrows and Wheeler, 1994)的字符串匹配理论引起了多个研究小组的关注,由此催生了 SOAPv2(http://soap.genomics.org.cn/)、Bowtie(Langmead et al., 2009)以及本文所述的新比对器 BWA。本质上,通过 BWT 结合反向搜索(Ferragina and Manzini, 2000; Lippert, 2005),我们能够以较小的内存占用(Lam et al., 2008)有效地模拟对基因组前缀树的自顶向下遍历,并在 O(m) 时间内统计一条长度为 m 的字符串的精确命中数,该时间与基因组大小无关。对于不精确搜索,BWA 从隐式前缀树中采样与查询读段编辑距离小于 k 的不同子串。由于精确重复在前缀树上被折叠为一条路径,我们无需将读段与每个重复副本分别比对。这是基于 BWT 的算法高效的主要原因。
Recently, the theory on string matching using Burrows–Wheeler Transform (BWT) (Burrows and Wheeler, 1994) has drawn the attention of several groups, which has led to the development of SOAPv2 (http://soap.genomics.org.cn/), Bowtie (Langmead et al., 2009) and BWA, our new aligner described in this article. Essentially, using backward search (Ferragina and Manzini, 2000; Lippert, 2005) with BWT, we are able to effectively mimic the top-down traversal on the prefix trie of the genome with relatively small memory footprint (Lam et al., 2008) and to count the number of exact hits of a string of length m in O(m) time independent of the size of the genome. For inexact search, BWA samples from the implicit prefix trie the distinct substrings that are less than k edit distance away from the query read. Because exact repeats are collapsed on one path on the prefix trie, we do not need to align the reads against each copy of the repeat. This is the main reason why BWT-based algorithms are efficient.
本文将对 BWT 和精确匹配反向搜索的背景知识做充分的介绍,并给出 BWA 中实现的不精确匹配算法。我们通过在模拟数据上将 BWA 比对结果与模拟中的真实比对位置进行比较,以及在真实双端数据上检查一致比对对的读段比例和统计比对到混合基因组上的错误比对读段数,来评估 BWA 的性能。
In this article, we will give a sufficient introduction to the background of BWT and backward search for exact matching, and present the algorithm for inexact matching which is implemented in BWA. We evaluate the performance of BWA on simulated data by comparing the BWA alignment with the true alignment from the simulation, as well as on real paired-end data by checking the fraction of reads mapped in consistent pairs and by counting misaligned reads mapped against a hybrid genome.
引言中介绍了三类比对方法。第一类(哈希读段)在比对读段少时仍需扫描整个基因组——想象你在图书馆找一本特定的书,却要把所有书架都走一遍,只是因为你的"索引"建在你要找的东西上而不是图书馆的结构上。第二类(哈希基因组)需要为人类基因组建立巨大的索引,内存开销惊人。第三类(归并排序)则相对小众。这些方法在人类重测序项目——尤其是千人基因组计划(1000 Genomes Project)——面前暴露了可扩展性的根本缺陷:当测序深度从 1 个个体扩展到 100 个甚至 1000 个个体时,这些方法的计算成本线性增长,无法应付。
BWT 方法最关键的优势在于"精确重复在前缀树上被折叠为一条路径"。人类基因组中约 50% 是重复序列(Alu、LINE 等),传统哈希方法必须为每个重复副本都做一次比对——如果一段 Alu 序列在基因组中出现 100 万次,哈希方法就要比对 100 万次。而 BWT 方法将所有这些重复折叠成前缀树上的同一条路径,只需要处理一次。这就解释了为什么 BWT 能做到 O(m) 时间(m 是读段长度)——这个时间与重复次数完全无关。
2009 年是短读段比对历史上的里程碑年份。几乎同时出现了三个基于 BWT 的比对器:Bowtie(Langmead et al.)、SOAPv2(华大基因)和 BWA(Li & Durbin)。这不是巧合——2008 年前后,Lam 等人证明了 BWT/FM-index 可以用来模拟前缀树遍历,为将 BWT 应用于基因组比对铺平了道路。三者各有侧重:SOAPv2 面向大规模并行,Bowtie 追求极致速度(但不支持空位比对),BWA 则在速度与准确率之间取得平衡,并首次默认输出 SAM 格式。这场"BWT 三剑客"的竞争直接推动了比对格式标准化和下游分析工具(如 SAMtools)的发展。
BWA 之所以诞生,背景就是千人基因组计划带来的计算压力。MAQ 虽好,但在面对 1000 人级别的重测序时速度不够,且不支持单端空位比对。BWA 的 10–20 倍加速意味着原本需要 10 天的计算可以在半天内完成,这对项目可行性至关重要。事实上,BWA 后来确实成为千人基因组计划(以及后续许多大型群体基因组项目)的默认比对器,在整个基因组学领域影响深远。
字符串 X 的前缀树是一棵树,其中每条边标记一个符号,从叶节点到根节点路径上边符号的字符串拼接构成 X 的一个唯一前缀。在前缀树上,从某节点到根节点路径上边符号的字符串拼接构成 X 的一个唯一子串,称为该节点所代表的字符串。注意,X 的前缀树与 reverse(X) 的后缀树完全相同,因此后缀树的相关理论也适用于前缀树。
The prefix trie for string X is a tree where each edge is labeled with a symbol and the string concatenation of the edge symbols on the path from a leaf to the root gives a unique prefix of X. On the prefix trie, the string concatenation of the edge symbols from a node to the root gives a unique substring of X, called the string represented by the node. Note that the prefix trie of X is identical to the suffix trie of reverse of X and therefore suffix trie theories can also be applied to prefix trie.
借助前缀树,测试查询串 W 是否为 X 的精确子串等价于查找代表 W 的节点,这可以通过从根节点出发,将 W 中每个符号与边进行匹配,在 O(|W|) 时间内完成。若允许错配,则可以穷举遍历前缀树,将 W 与每条可能的路径进行匹配。我们稍后将展示如何利用 W 的前缀信息来加速该搜索。图1给出了字符串 'GOOGOL' 的前缀树示例。每个节点中的后缀数组(SA)区间将在2.3节中解释。
With the prefix trie, testing whether a query W is an exact substring of X is equivalent to finding the node that represents W, which can be done in O(|W|) time by matching each symbol in W to an edge, starting from the root. To allow mismatches, we can exhaustively traverse the trie and match W to each possible path. We will later show how to accelerate this search by using prefix information of W. Figure 1 gives an example of the prefix trie for 'GOOGOL'. The suffix array (SA) interval in each node is explained in Section 2.3.

一、为何前缀树适用反向搜索? BWT 反向搜索沿查询串从右向左逐字符匹配,每步将新字符添加到当前匹配串的左侧。前缀树的结构恰好与此匹配:从根向叶每走一步,就向当前串左侧添加一个字符——这正是反向搜索的操作方向。而显式后缀树的物理结构不支持 O(1) 的左侧扩展,这也是 FM-index 选择前缀树视角的根本原因。
二、数学对偶:X 的前缀树 ≡ reverse(X) 的后缀树。 将 X 反转后建立后缀树,与直接在 X 上建立前缀树,得到完全相同的树形结构。这一对偶关系意味着后缀树的所有经典算法(后缀链接、最长公共前缀等)均可直接移植到前缀树语境下。BWA 也利用了这一对偶:同时维护正向与反向参考序列的 FM-index,使得 §2.5 的 D(i) 剪枝能双向验证子串存在性——这是 BWA 区别于其他 BWT 比对器的关键设计。
三、SA 区间:前缀树节点的紧凑表示。 显式前缀树的每个节点在 FM-index 中仅需用一对整数 [L, R] 表示——即该节点对应子串在后缀数组中的起止范围。匹配过程中区间不断收缩:L ≤ R 表示有匹配,L > R 表示无匹配。这种 SA 区间的紧凑编码使得 FM-index 能在 O(n) 空间内模拟原本需要 O(n²) 空间的显式前缀树——这是 BWA 以小内存实现基因组级搜索的核心洞察。
设 Σ 为一个字母表。符号 $ 不在 Σ 中,且字典序小于 Σ 中的所有符号。字符串 X=a0a1…an−1 总是以符号 $ 结尾(即 an−1=$),且该符号仅出现在末尾。令 X[i]=ai,i=0, 1,…, n−1,表示 X 的第 i 个符号,X[i, j]=ai…aj 为子串,Xi=X[i, n−1] 为 X 的一个后缀。字符串 X 的后缀数组 S 是整数 0…n−1 的一个排列,使得 S(i) 是第 i 小后缀的起始位置。X 的 BWT 定义为:当 S(i)=0 时 B[i]=$,否则 B[i]=X[S(i)−1]。同时定义字符串 X 的长度为 |X|,因此 |X|=|B|=n。图 2 给出了构造 BWT 和后缀数组的一个例子。
Let Σ be an alphabet. Symbol $ is not present in Σ and is lexicographically smaller than all the symbols in Σ. A string X=a0a1…an−1 is always ended with symbol $ (i.e. an−1=$) and this symbol only appears at the end. Let X[i]=ai, i=0, 1,…, n−1, be the i-th symbol of X, X[i, j]=ai …aj a substring and Xi=X[i, n−1] a suffix of X. Suffix array S of X is a permutation of the integers 0…n−1 such that S(i) is the start position of the i-th smallest suffix. The BWT of X is defined as B[i]=$ when S(i)=0 and B[i]=X[S(i)−1] otherwise. We also define the length of string X as |X| and therefore |X|=|B|=n. Figure 2 gives an example on how to construct BWT and suffix array.

图 2 所示的算法在时间和空间上均为二次复杂度。然而,这并非必需。实际中,我们通常先构造后缀数组,再生成 BWT。大多数构造后缀数组的算法至少需要 n⌈log2n⌉ 比特的工作空间,对人类基因组而言约为 12 GB。最近,Hon 等人(2007)提出了一种新算法,仅需 n 比特的工作空间,在构建人类基因组 BWT 时的峰值内存消耗低于 1 GB。该算法已在 BWT-SW 中实现(Lam 等人,2008)。我们适配了其源代码使其适用于 BWA。
The algorithm shown in Figure 2 is quadratic in time and space. However, this is not necessary. In practice, we usually construct the suffix array first and then generate BWT. Most algorithms for constructing suffix array require at least n⌈log2n⌉ bits of working space, which amounts to 12 GB for human genome. Recently, Hon et al. (2007) gave a new algorithm that uses n bits of working space and only requires <1 GB memory at peak time for constructing the BWT of human genome. This algorithm is implemented in BWT-SW (Lam et al., 2008). We adapted its source code to make it work with BWA.
这一节建立了 BWT 与后缀数组之间的核心桥梁关系 B[i] = X[S(i)−1]。理解这条公式的含义是理解后续所有 BWT 算法的关键——BWT 字符串的每个字符恰好是排序后后缀的「前一个字符」。
1. BWT 的聚集效应:由于 BWT 按后缀的字典序排列字符,相同的上下文会自然相邻。例如在「googol$」中,以「o」开头的后缀排在一起,BWT 中对应的位置出现两个连续的「o」(即「lo$oogg」中的「oo」)。这种「相同上下文聚集」的特性使得 BWT 成为极高效的压缩基础,也是 FM-index 精确搜索的理论前提。
2. B + S 的互补关系:BWT 本身比后缀数组紧凑得多——B 只占 n 个字符(人类基因组约 3 GB),而完整后缀数组需要 n⌈log₂n⌉ 位(约 12 GB)。配合辅助数组 C(计数数组)和 O(Occ 数组),BWT 可以完整还原出后缀数组的所有功能,这就是 §2.6 将介绍的 FM-index 核心思想。
3. LF-mapping 的铺垫:公式 B[i] = X[S(i)−1] 暗示了一个重要事实——给定 BWT 某一行的字符,你可以确定其前一行的字符。这个「前驱映射」关系就是 §2.4 将介绍的 LF-mapping,也是所有反向搜索算法的数学基础。
4. Hon 算法的工程奇迹:从 12 GB 降到 <1 GB 的索引构建内存,Hon 等人(2007)的算法使得在普通服务器上为人类基因组建 FM-index 成为可能。这一成果被 BWT-SW 和 BWA 直接采纳,成为 BWA 实用性得以保障的关键工程基础。
若字符串 W 是 X 的子串,则 W 在 X 中每次出现的位置在后缀数组中会落在一个连续区间内。这是因为所有以 W 为前缀的后缀在排序时会聚集在一起。基于这一观察,我们定义:
If string W is a substring of X, the position of each occurrence of W in X will occur in an interval in the suffix array. This is because all the suffixes that have W as prefix are sorted together. Based on this observation, we define:


特别地,若 W 为空串 ε,则 R(W) = 1,R̄(W) = |X| + 1。区间 [R(W), R̄(W)) 称为 W 的SA 区间,而 W 在 X 中的所有出现位置的集合为 { S(k) : R(W) ≤ k < R̄(W) }。例如在 图 2 中,字符串「go」的 SA 区间为 [1, 2)。该区间内的后缀数组值为 3 和 0,分别给出「go」所有出现位置。
In particular, if W is an empty string, R(W)=1 and
. The interval
is called the SA interval of W and the set of positions of all occurrences of W in X is
. For example in Figure 2, the SA interval of string ‘go’ is [1, 2]. The suffix array values in this interval are 3 and 0 which give the positions of all the occurrences of ‘go’.
已知后缀数组中的区间即可还原出实际位置。因此,序列比对问题等价于在 X 中搜索所有与查询序列匹配的子串所对应的 SA 区间。对于精确匹配问题,我们只需找到唯一一个这样的区间;而对于非精确匹配(允许错配和 gap),则可能存在多个区间。
Knowing the intervals in suffix array we can get the positions. Therefore, sequence alignment is equivalent to searching for the SA intervals of substrings of X that match the query. For the exact matching problem, we can find only one such interval; for the inexact matching problem, there may be many.
区间连续性原理:后缀数组将所有后缀按字典序排列。若两个后缀共享相同的前缀 W,在以 W 为前缀的子区间内它们必须相邻——因为任何不以 W 开头但字典序介于二者之间的后缀都会破坏排序一致性。因此所有以 W 开头的后缀自然形成一个连续区间,不可能被「非 W 前缀」的后缀打断。
与前缀树的对应关系:SA 区间等价于前缀树(trie)中的某个内部节点——该节点到根的路径即前缀 W,而子树下的叶节点数即为区间宽度。区间宽度 R̄(W) − R(W) 恰好等于 W 在参考基因组 X 中的出现次数。例如「go」的区间宽度为 2,意味着在「GOOGOL$」中出现 2 次。
序列比对 ≡ 搜索 SA 区间:一旦确定了查询串在参考基因组中匹配的所有子串的 SA 区间,只需从后缀数组中读出区间内的 S(k) 值,即可获得所有出现位置的起始坐标。因此,序列比对问题被等价地转换为 FM-index 上的区间搜索问题——这是 BWA 将字符串比对归结为索引查询的核心思想。
精确 vs 非精确匹配的本质区别:精确匹配产生唯一一个 SA 区间(可能为空),而非精确匹配(允许错配/空位)产生多个候选 SA 区间。这使得非精确搜索的复杂度从 O(|W|) 跃升为对前缀树的有界遍历,这正是 §2.5 将解决的难题。
令 C(a) 表示 X[0, n−2] 中字典序小于 a ∈ Σ 的符号数量,O(a, i) 表示 a 在 B[0, i] 中的出现次数。Ferragina 和 Manzini(2000)证明了:若 W 是 X 的子串,则有公式 (3)(4),且当且仅当 R(aW) ≤ R̅(aW) 时,aW 是 X 的子串。这一结果使得我们可以通过从 W 末端开始迭代计算 R 和 R̅,在 O(|W|) 时间内测试 W 是否为 X 的子串并统计其出现次数。这一过程称为反向搜索(backward search)。
Let C(a) be the number of symbols in X[0, n−2] that are lexicographically smaller than a ∈ Σ and O(a, i) the number of occurrences of a in B[0, i]. Ferragina and Manzini (2000) proved that if W is a substring of X:
(3)
(4)and that
if and only if aW is a substring of X. This result makes it possible to test whether W is a substring of X and to count the occurrences of W in O(|W|) time by iteratively calculating R and
from the end of W. This procedure is called backward search.
需要特别指出的是,公式 (3) 和 (4) 实际上实现了对 X 前缀树的自顶向下遍历,因为我们可以在已知父节点 SA 区间的情况下,在常数时间内计算出子节点的 SA 区间。从这个意义上说,反向搜索等价于在前缀树上的精确字符串匹配,但无需将前缀树显式地存储在内存中。
It is important to note that Equations (3) and (4) actually realize the top-down traversal on the prefix trie of X given that we can calculate the SA interval of a child node in constant time if we know the interval of its parent. In this sense, backward search is equivalent to exact string matching on the prefix trie, but without explicitly putting the trie in the memory.
C(a) 与 O(a, i) 的几何直觉。 C(a) 是所有字典序小于字符 a 的字符总数——在 BWT 矩阵第一列(F 列)中,它给出了字符 a 的起始偏移位置。O(a, i) 是 a 在 BWT 串 B[0, i] 中的 rank——在 F 列中,它表示 a 块内的偏移量。公式 C(a) + O(a, i) 正是 LF 映射的数学表达:给出 BWT 最后一列位置 i 处字符 a 映射到 F 列中的对应位置。将 LF 映射应用于 i = R(W) − 1 和 i = R̅(W),就得到了扩展串 aW 的 SA 区间边界,即公式 (3)(4)。公式 (4) 中不含 −1+1 是因为 R̅(W) 本身就是区间上界,O(a, R̅(W)) 已包含该位置的所有 a 计数;而公式 (3) 中用 R(W) − 1 排除区间左边界之前的位置,再 +1 得到 aW 在 SA 中的第一个出现位置。这一不对称性恰恰体现了闭区间端点计数的精确性。
为什么 O(|W|) 与基因组大小无关? 传统的哈希索引方法需要对基因组建立 k-mer 哈希表,其索引大小随基因组长度 n 线性增长,查询时还需定位和验证。而反向搜索只依赖 C 和 O 两张小表:C 表大小固定为 |Σ|(4 或 5),O 表的每次查询是 O(1) 的 rank 操作。无论人类基因组 30 亿碱基还是细菌基因组 5 百万碱基,反向搜索每一步只做两次 O 查询 + 一次加法和一次比较,总时间完全由查询串长度 |W| 决定,与 n 无关。这就是 FM-index 实现「索引大小与文本长度无关的查询时间」的关键所在。
FM-index 的存储奇迹:2.3GB 取代 12GB SA。 人类基因组的后缀数组原始存储约 12GB(n 个 32 位整数)。FM-index 通过三部分实现压缩:(1)BWT 串 B → 2-bit 编码 ≈ 0.75GB;(2)C 表 → 5 个 32 位整数,可忽略;(3)O 表采样 → 每 128 位置存储一次 rank 值,≈ n × 4 / 128 × 5 ≈ 0.5GB;加上 Ψ⁻¹ 用于重建后缀值 ≈ 1GB,合计约 2.3GB——将原本需要的 12GB SA 完整存储压缩为索引空间约 2.3GB,同时保持了 O(|W|) 的超高效查询速度。这是全文索引领域最深远的理论成果之一在实践中的完美落地。
反向搜索本质:隐式前缀树遍历。 前缀树需要显式存储每个节点和边,空间消耗对基因组不可接受。然而公式 (3)(4) 揭示了:对任意父节点(已知其 SA 区间 [R(W), R̅(W)]),只需两次 O 查询 + 两次加法,即可在 O(1) 时间内得到任一子节点 aW 的 SA 区间。这意味着我们可以在不存储任何树结构的情况下「遍历」整棵前缀树——每次步进相当于沿某个字符边向下走一步。树的拓扑结构被数学编码在 C 和 O 两张表里,遍历操作变成了两条简单公式。这正是 Burrows-Wheeler 变换最令人惊叹的性质。
图 3 给出了一个递归算法,用于搜索 X 中与查询串 W 匹配且差异数(错配或空位)不超过 z 的子串的 SA 区间。本质上,该算法利用反向搜索从基因组中采样不同的子串。这一过程由 D(·) 数组界定,其中 D(i) 是 W[0, i] 中差异数的下界。D 的估计越精确,搜索空间越小,算法效率越高。一个朴素的下界是令所有 i 的 D(i)=0,但由此产生的算法在差异数上显然是指数级的,效率较低。
Figure 3 gives a recursive algorithm to search for the SA intervals of substrings of X that match the query string W with no more than z differences (mismatches or gaps). Essentially, this algorithm uses backward search to sample distinct substrings from the genome. This process is bounded by the D(·) array where D(i) is the lower bound of the number of differences in W[0, i]. The better the D is estimated, the smaller the search space and the more efficient the algorithm is. A naive bound is achieved by setting D(i)=0 for all i, but the resulting algorithm is clearly exponential in the number of differences and would be less efficient.

图 3 中的 CalculateD 过程给出了一个更好(虽非最优)的下界。它在概念上等同于图 4 中描述的算法,后者更易于理解。我们使用反向(非互补)参考基因组的 BWT 来测试 W 的某个子串是否也是 X 的子串。需要注意的是,如果仅用 BWT 串 B 来完成此测试,CalculateD 将是一个 O(|W|2) 的过程,而非图 3 中描述的 O(|W|)。为理解 D 的作用,我们回到在 X=GOOGOL$ 中搜索 W=LOL 的例子(图 1)。如果令所有 i 的 D(i)=0 且不允许空位(移除算法中两行带星号的行),则 InexRecur 的调用图(一棵树)实际上模拟了图 1 中虚线所示的搜索路径。然而,通过 CalculateD,我们知道 D(0)=0 而 D(1)=D(2)=1。于是我们可以避免进入前缀树中 'G' 和 'O' 子树,从而大幅缩小搜索空间。
The CalculateD procedure in Figure 3 gives a better, though not optimal, bound. It is conceptually equivalent to the one described in Figure 4, which is simpler to understand. We use the BWT of the reverse (not complemented) reference sequence to test if a substring of W is also a substring of X. Note that to do this test with BWT string B alone would make CalculateD an O(|W|2) procedure, rather than O(|W|) as is described in Figure 3.
To understand the role of D, we come back to the example of searching for W = LOL in X = GOOGOL$ (Fig. 1). If we set D(i)=0 for all i and disallow gaps (removing the two star lines in the algorithm), the call graph of InexRecur, which is a tree, effectively mimics the search route shown as the dashed line in Figure 1. However, with CalculateD, we know that D(0)=0 and D(1)=D(2)=1. We can then avoid descending into the 'G' and 'O' subtrees in the prefix trie to get a much smaller search space.

图 3 中的算法保证找到所有允许最多 z 个差异的区间。理论上它是完备的,但在实践中,我们还做了若干改进。第一,我们对错配、空位开放和空位延伸分别赋予不同的罚分,这更符合生物学数据的实际。第二,我们使用堆式数据结构来维护部分命中,而非使用递归。该堆式结构按部分命中的比对得分进行优先级排序,使 BWA 始终优先找到最佳区间。反向互补的读段序列也同时被处理。注意,图 3 中的递归实际上模拟了前缀树上的深度优先搜索(DFS),而 BWA 使用该堆式数据结构实现了广度优先搜索(BFS)。第三,我们采用了一种迭代策略:如果最优区间是重复的,默认不搜索次优区间;如果最优区间唯一且具有 z 个差异,则仅搜索差异数不超过 z + 1 的命中。这一迭代策略在加速 BWA 的同时保留了生成比对质量的能力。然而,这也使 BWA 的速度对读段与参考序列之间的错配率敏感,因为寻找差异更多的命中通常更慢。第四,我们允许对读段前几十个碱基对中允许的最大差异数设置限制,我们称之为种子序列。在 70 bp 模拟读段上,对 32 bp 种子内允许最多 2 个差异的比对比不加种子快 2.5 倍。比对错误率(模拟中可靠比对中错误比对所占的比例,另见第 3.2 节)仅从 0.08% 增加到 0.11%。种子策略对较短读段的效果较差。
The algorithm in Figure 3 guarantees to find all the intervals allowing maximum z differences. It is complete in theory, but in practice, we also made various modifications. First, we pay different penalties for mismatches, gap opens and gap extensions, which is more realistic to biological data. Second, we use a heap-like data structure to keep partial hits rather than using recursion. The heap-like structure is prioritized on the alignment score of the partial hits to make BWA always find the best intervals first. The reverse complemented read sequence is processed at the same time. Note that the recursion described in Figure 3 effectively mimics a depth-first search (DFS) on the prefix trie, while BWA implements a breadth-first search (BFS) using this heap-like data structure. Third, we adopt an iterative strategy: if the top interval is repetitive, we do not search for suboptimal intervals by default; if the top interval is unique and has z difference, we only search for hits with up to z + 1 differences. This iterative strategy accelerates BWA while retaining the ability to generate mapping quality. However, this also makes BWA's speed sensitive to the mismatch rate between the reads and the reference because finding hits with more differences is usually slower. Fourth, we allow to set a limit on the maximum allowed differences in the first few tens of base pairs on a read, which we call the seed sequence. Given 70 bp simulated reads, alignment with maximum two differences in the 32 bp seed is 2.5× faster than without seeding. The alignment error rate, which is the fraction of wrong alignments out of confident mappings in simulation (see also Section 3.2), only increases from 0.08% to 0.11%. Seeding is less effective for shorter reads.
D(i) 作为可采纳启发式函数(admissible heuristic)。 BWA 的有界遍历本质上是一种 A* 搜索或分支定界(branch-and-bound)策略。D(i) 提供了当前部分匹配 W[0, i] 已累积差异数的下界估计——它永远不会高估实际差异数,因此是「可采纳」的(admissible)。这一性质保证算法不会错误地剪掉可行解。若 D(i) > z,意味着即使 W[i+1, |W|−1] 完美匹配,总差异数也已超过 z,该分支可以安全放弃。D(i) 越紧(接近真实差异数),剪枝越早,搜索空间越小。令 D(i)=0 相当于放弃了所有剪枝能力,退化为穷举搜索。
为什么需要反向基因组的 BWT。 正向参考基因组的 BWT 支持从右向左匹配 W 的后缀(即反向搜索:给定 Wi 的后缀区间 [k, l],可以在 O(1) 时间内计算 Wi−1 的后缀区间)。但 CalculateD 需要完成相反的操作:给定 W[0, i](前缀),测试 W[0, i+1] 是否在 X 中出现。这等价于测试 reverse(W[0, i+1]) 是否是 reverse(X) 的后缀。因此,需要构建 reverse(X) 的 BWT。注意这里取的是反向(reverse)而非反向互补(reverse complement)——后者用于双端比对时处理另一端读段,两者用途不同。如果没有反向 BWT,CalculateD 每次测试子串都需要 O(|W|) 的扫描,使整体复杂度退化为 O(|W|2)。
DFS vs BFS:BWA 与 Bowtie 的设计哲学对比。 图 3 的递归算法天然对应 DFS——深入探索一条路径直到被剪枝或命中。这正是 Bowtie 采用的策略:用递归/栈结构按深度优先遍历前缀树。DFS 的优势是实现简单、内存开销小;缺点是找到的第一个命中不一定是最高得分的命中(最佳命中可能在其他分支中)。BWA 改用 BFS(基于堆的优先级队列),按部分命中的比对得分排序,始终先展开最有前途的分支。这使得 BWA 能优先找到最佳命中,从而在迭代策略中更快收敛——如果最优区间已唯一且得分足够高,就无需继续搜索次优区间。BFS 的代价是额外的堆维护开销,但配合 D(i) 剪枝后,实际进入堆的分支数量有限。这一设计选择是 BWA 与 Bowtie 最根本的算法差异之一。
种子序列:理论完备性与工程实用性之间的妥协。 不加种子的有界遍历理论上可以找到所有满足差异数约束的命中,是完备的。但在实践中,允许短读段末尾有大量错配会导致搜索空间急剧膨胀(D(i) 对末尾位置的约束力最弱)。种子序列限制前 k bp 内的差异数,等价于在搜索早期提供一个更强的剪枝条件,大幅减少无效分支的探索。32 bp 种子允许 2 个差异,对应的错配容忍度约为 6.25%,足以覆盖 Illumina 测序平台典型的 1%–2% 错误率。比对错误率仅从 0.08% 升至 0.11%,表明种子策略几乎不影响准确性。对更短的读段(如 35 bp),种子长度与读段长度的比例过大,种子策略的加速效果自然会减弱。
为什么这是 BWA 最核心的算法创新。 §2.1–§2.4 介绍的反向搜索仅支持精确匹配,这在生物信息学中几乎无用(测序错误和自然变异不可避免)。§2.5 的有界遍历/回溯将反向搜索从精确匹配推广到不精确匹配,是整个 BWA 算法从理论可行走向实际可用的关键突破。此外,D(i) 下界的设计利用了 BWT 的双向搜索能力(正向 + 反向基因组的 BWT),充分挖掘了 FM-index 的数据结构潜力。四个工程优化(差异罚分、BFS 堆、迭代策略、种子序列)进一步弥合了理论算法与实际测序数据之间的鸿沟。可以说,没有 §2.5,前面的 FM-index 反向搜索只是一道优雅的理论习题;有了 §2.5,BWA 才真正成为一款实用的短读段比对工具。
「有界遍历」的命名深意。 「有界」(bounded)一词的双重含义值得品味:一方面指 D(i) 下界(lower bound)为搜索深度设定了理论上界;另一方面指 z 参数从外部约束了允许的最大差异数。两者结合,使搜索从指数爆炸的「穷举遍历」收缩为可控的「有界遍历」。回溯(backtracking)则提示读者:当一条路径被证明不可行(D(i) > z)时,算法回溯至上一个决策点尝试其他分支。这两个词精确概括了算法的全部核心思想。
上述算法需要将出现数组 O 和后缀数组 S 载入内存。存储完整的 O 和 S 数组需要巨大的内存。幸运的是,我们可以通过仅存储 O 和 S 的一小部分、其余部分即时计算来减少内存。BWT-SW(Lam 等,2008)和 Bowtie(Langmead 等,2009)采用了类似的策略,该策略最早由 Ferragina 和 Manzini(2000)提出。给定大小为 n 的基因组,出现数组 O(·, ·) 需要 4n⌈log2n⌉ 比特,因为每个整数占 ⌈log2n⌉ 比特,且数组中共有 4n 个整数。在实际中,我们在内存中仅存储 O(·, k),其中 k 是 128 的倍数,其余元素借助 BWT 字符串 B 进行计算。用 2 比特表示一个核苷酸时,B 占用 2n 比特。因此反向搜索的内存为 2n+n⌈log2n⌉/32 比特。由于我们还需要存储反向基因组的 BWT 来计算边界,计算区间所需的内存翻倍,对于一个 3 Gb 的基因组约为 2.3 GB。综上,比对过程共使用 4n+n⌈log2n⌉/8 比特,对于小于 4 Gb 的基因组约为 n 字节。这包括正向和反向基因组的 BWT 字符串、部分出现数组和部分后缀数组的内存。此外,堆、缓存及其他数据结构还需要数百 MB 的内存。
The algorithm described above needs to load the occurrence array O and the suffix array S in the memory. Holding the full O and S arrays requires huge memory. Fortunately, we can reduce the memory by only storing a small fraction of the O and S arrays, and calculating the rest on the fly. BWT-SW (Lam et al., 2008) and Bowtie (Langmead et al., 2009) use a similar strategy which was first introduced by Ferragina and Manzini (2000).
Given a genome of size n, the occurrence array O(·, ·) requires 4n⌈log2n⌉ bits as each integer takes ⌈log2n⌉ bits and there are 4n of them in the array. In practice, we store in memory O(·, k) for k that is a factor of 128 and calculate the rest of elements using the BWT string B. When we use two bits to represent a nucleotide, B takes 2n bits. The memory for backward search is thus 2n+n⌈log2n⌉/32 bits. As we also need to store the BWT of the reverse genome to calculate the bound, the memory required for calculating intervals is doubled, or about 2.3 GB for a 3 Gb genome.
In all, the alignment procedure uses 4n+n⌈log2n⌉/8 bits, or n bytes for genomes <4 Gb. This includes the memory for the BWT string, partial occurrence array and partial suffix array for both original and the reversed genome. Additionally, a few hundred megabyte of memory is required for heap, cache and other data structures.
枚举每个匹配位置需要后缀数组 S。如果将完整的 S 放入内存,将占用 n⌈log2n⌉ 比特。然而,已知 S 的一部分时也可以重建完整的 S。事实上,S 与逆压缩后缀数组(inverse CSA)Ψ−1(Grossi 和 Vitter,2000)满足公式 (5):S(k) = S((Ψ−1)(j)(k)) − j,其中 (Ψ−1)(j) 表示对变换 Ψ−1 反复施加 j 次。逆 CSA Ψ−1 可以通过出现数组 O 按公式 (6) 计算:Ψ−1(i) = C(B[i]) + O(B[i], i) + 1。在 BWA 中,我们仅在内存中存储 S(k),其中 k 能被 32 整除。对于不是 32 的倍数的 k,我们反复施加 Ψ−1,直到某个 j 使得 (Ψ−1)(j)(k) 是 32 的倍数,此时可以查表得到 S((Ψ−1)(j)(k)),再通过公式 (5) 计算出 S(k)。
Enumerating the position of each occurrence requires the suffix array S. If we put the entire S in memory, it would use n⌈log2n⌉ bits. However, it is also possible to reconstruct the entire S when knowing part of it. In fact, S and inverse compressed suffix array (inverse CSA) Ψ−1 (Grossi and Vitter, 2000) satisfy:

where (Ψ−1)(j) denotes repeatedly applying the transform Ψ−1 for j times. The inverse CSA Ψ−1 can be calculated with the occurrence array O:

In BWA, we only store in memory S(k) for k that can be divided by 32. For k that is not a factor of 32, we repeatedly apply Ψ−1 until for some j, (Ψ−1)(j)(k) is a factor of 32 and then S((Ψ−1)(j)(k)) can be looked up and S(k) can be calculated with Equation (5).
Ψ−1 = LF-mapping 的本质关系。 逆 CSA Ψ−1 的本质就是 LF-mapping——将 BWT 矩阵中某一行的字符映射到前一行的相同字符位置。公式 (6) 直观地表达了这一过程:C(B[i]) 给出字典序小于 B[i] 的字符总数,O(B[i], i) 给出在 B[i] 之前出现的相同字符数,两者相加再加 1 即为该字符在 F 列(第一列)中的位置。这正是反向搜索中每次迭代所需的核心计算。在公式 (5) 中,反复施加 Ψ−1 j 次相当于沿 LF 链向前追溯 j 步:每次追溯相当于从后缀中移除第一个字符,因此 k 位置对应的后缀值比 j 步前的后缀值恰好大 j。
时间-空间权衡:O 数组步长 128 vs S 数组步长 32。 对 O 数组每 128 个位置采样一次,对 S 数组每 32 个位置采样一次。步长越大,内存占用越小,但计算时需要更多次 Ψ−1 迭代来追溯到最近的采样点。O 的查询频率远高于 S(每次反向搜索迭代都需查询 O),因此 O 采用更稀疏的 128 采样以控制内存;S 仅在匹配最终定位时才需要查询,因此可用更密的 32 采样以加速重建。这一策略源自 Ferragina 和 Manzini(2000)提出的「机会数据结构」思想。
内存账单拆解:2.3 GB 从何而来。 对于 3 Gb(n=3×109)的人类基因组:BWT 字符串 B 用 2 比特/碱基 → 2n = 6 Gb = 0.75 GB;O 数组采样存储:n⌈log2n⌉/32 ≈ 0.375 GB。合计约 1.125 GB。由于需要同时存储正向和反向基因组的 BWT 和 O(用于计算 D 边界),翻倍后约 2.25 GB,加上部分 S 数组(约 0.375 GB),总计约 2.6+ GB,加上堆和缓存等开销后约 2.3 GB。最终比对过程总内存约 n 字节(≈ 3 GB)加上数百 MB 开销,在 2009 年的桌面计算机上是革命性的节省。
BWT-SW、Bowtie 与 BWA 的共同遗产。 三款工具在几乎同一时期独立采用了相同的采样策略来压缩 O 和 S 数组,它们共享相同的理论基础——Ferragina 和 Manzini(2000)关于压缩后缀数组的开创性工作。该工作首次提出了在仅存储部分后缀数组和逆 CSA 的前提下,通过 Ψ 函数重建任意后缀数组值的技术,为所有基于 BWT 的短序列比对工具奠定了内存效率的基石。
读段上的非 A/C/G/T 碱基被直接视为错配,这在算法中隐式处理(图 3)。参考基因组上的非 A/C/G/T 碱基被转换为随机核苷酸。这样做可能导致在充满模糊碱基的区域产生假命中。幸运的是,由于读段相对较长,这种情况发生的可能性很小。我们尝试了 200 万条 32 bp 读段,没有发现任何读段因随机原因比对到 poly-N 区域。
Non-A/C/G/T bases on reads are simply treated as mismatches, which is implicit in the algorithm (Fig. 3). Non-A/C/G/T bases on the reference genome are converted to random nucleotides. Doing so may lead to false hits to regions full of ambiguous bases. Fortunately, the chance that this may happen is very small given relatively long reads. We tried 2 million 32 bp reads and did not see any reads mapped to poly-N regions by chance.
BWA 支持双端比对。它首先找到所有良好命中的位置,按染色体坐标排序,然后对所有潜在命中进行线性扫描以配对双端。计算所有染色体坐标需要频繁查询后缀数组。这个配对过程很耗时,因为用上述方法实时生成完整的后缀数组代价高昂。为加速配对,我们缓存大区间。这一策略将配对时间减半。
BWA supports paired-end mapping. It first finds the positions of all the good hits, sorts them according to the chromosomal coordinates and then does a linear scan through all the potential hits to pair the two ends. Calculating all the chromosomal coordinates requires to look up the suffix array frequently. This pairing process is time consuming as generating the full suffix array on the fly with the method described above is expensive. To accelerate pairing, we cache large intervals. This strategy halves the time spent on pairing.
在配对过程中,BWA 以 256K 读段对为一批进行处理。在每个批次中,BWA 将完整的 BWA 索引加载到内存,为每个命中位置生成染色体坐标,从两端均以高于 20 的比对质量比对的读段对中估计插入片段长度分布,然后进行配对。之后,BWA 从内存中清除 BWT 索引,加载 2 位编码的参考序列,对未比对上但其配对端能可靠比对的读段执行 Smith–Waterman 比对。Smith–Waterman 比对可挽救一些差异过多的读段。
In pairing, BWA processes 256K read pairs in a batch. In each batch, BWA loads the full BWA index into memory, generates the chromosomal coordinate for each occurrence, estimates the insert size distribution from read pairs with both ends mapped with mapping quality higher than 20, and then pairs them. After that, BWA clears the BWT index from the memory, loads the 2 bit encoded reference sequence and performs Smith–Waterman alignment for unmapped reads whose mates can be reliably aligned. Smith–Waterman alignment rescues some reads with excessive differences.
256K 批次的工程权衡。 BWA 的配对策略是一个典型的内存-速度权衡设计。BWT 索引本身很大(人类基因组约 2–3 GB),若每条读段对都单独加载/清除索引,IO 开销将占主导。采用 256K 的批次大小意味着:一次加载完整的 BWT 索引,处理完这批所有读段对,然后才切换为 2 位编码的参考序列做 SW rescue。256K 这个数字是经验折中——批次太小则索引加载次数过多,批次太大则排序和坐标计算的内存峰值过高。对于当时的计算机(2009 年),这个值使得单机 8 GB 内存即可运行人类基因组的双端比对。
SW rescue 机制。 对于双端中一端比对上而另一端未比上的读段,BWA 不直接丢弃,而是利用配对端的位置信息限定搜索范围,用 Smith–Waterman 做局部精准比对尝试挽救。这相当于用配对信息将搜索空间从全基因组裁剪到一个小的窗口(约 ±3 倍插入片段标准差),再用敏感但慢的 SW 算法在该窗口内精细匹配。这种「粗筛 + 精细 rescue」的两阶段策略是 BWA 灵敏度高于 MAQ 的关键原因之一。
给定一条长度为 m 的读段,BWA 仅容忍最多 k 个差异(错配或间隙)的命中,其中 k 的选择满足:对于具有 2% 均匀碱基错误率的 m-长读段,差异数超过 k 的比例小于 4%。按此配置:
| 读段长度 (bp) | k |
|---|---|
| 15–37 | 2 |
| 38–63 | 3 |
| 64–92 | 4 |
| 93–123 | 5 |
| 124–156 | 6 |
Given a read of length m, BWA only tolerates a hit with at most k differences (mismatches or gaps), where k is chosen such that <4% of m-long reads with 2% uniform base error rate may contain differences more than k. With this configuration, for 15–37 bp reads, k equals 2; for 38–63 bp, k=3; for 64–92 bp, k=4; for 93–123 bp, k=5; and for 124–156 bp reads, k=6.
对每条比对结果,BWA 计算一个比对质量(MAPQ)分数,即该比对为错误的 Phred 标度概率。该算法与 MAQ 类似,不同之处在于 BWA 假设真实命中总能被找到。我们做此修改是因为我们注意到 MAQ 的公式高估了遗漏真实命中的概率,从而导致比对质量被低估。模拟表明,由于这一修改,BWA 可能高估比对质量,但偏差相对较小。例如,在 1,569,108 条模拟的 70 bp 读段中,BWA 将 11 条以比对质量 60 比对的读段比对到了错误位置。这些 Q60 比对结果的错误率 7×10−6(=11/1,569,108)高于理论期望值 10−6。
For each alignment, BWA calculates a mapping quality score, which is the Phred-scaled probability of the alignment being incorrect. The algorithm is similar to MAQ's except that in BWA we assume the true hit can always be found. We made this modification because we are aware that MAQ's formula overestimates the probability of missing the true hit, which leads to underestimated mapping quality. Simulation reveals that BWA may overestimate mapping quality due to this modification, but the deviation is relatively small. For example, BWA wrongly aligns 11 reads out of 1 569 108 simulated 70 bp reads mapped with mapping quality 60. The error rate 7 × 10−6 (= 11/1 569 108) for these Q60 mappings is higher than the theoretical expectation 10−6.
MAPQ 高估 vs MAQ 低估。 MAPQ 定义为 −10·log10(P(比对错误))。MAQ 在计算时额外乘了一个「可能遗漏真实命中」的概率项,这导致 MAQ 总是低估真正的比对置信度——即使比对实际上是对的,MAQ 给出的 Q 值也偏低。BWA 删除了这一项,假设真实命中总在候选列表中。这个「乐观」假设使得 BWA 的 MAPQ 略偏高:从论文数据看,Q60 的理论错误率应该是 10−6(即百万分之一),但实际观测到 7×10−6,约高估了 7 倍。然而,相比于 MAQ 的大幅低估(可能低几个数量级),BWA 的高估幅度在实际应用中是可接受的——下游分析通常以 Q20 或 Q30 为阈值,这个范围内的偏差更小。
Q60 ≈ Q51.5 的实际含义。 如果 BWA 给出一条比对 Q60,意味着 BWA 声称错误概率为 10−6。但实际错误概率约 7×10−6,对应的「真实 Q 值」约为 −10·log10(7×10−6) ≈ 51.5。换言之,BWA 的 Q60 实际可信度约等于 Phred 标度下的 51.5。这个偏差在 Q30–Q40 区间通常更小(因此时候选命中更多,MAQ 高估的效应被稀释),因此对绝大多数应用场景的影响有限。
对于 SOLiD 读段,BWA 将参考基因组转换为双核苷酸「颜色」序列,并为颜色基因组构建 BWT 索引。读段在颜色空间中进行比对,其中序列的反向互补与反向相同,因为颜色的互补就是颜色自身。对于 SOLiD 双端比对,如果满足以下两种情形之一,则读段对被视为方向正确:(i) 两端均比对到基因组正链,且 R3 读段坐标较小;(ii) 两端均比对到基因组反链,且 F3 读段坐标较小。Smith–Waterman 比对同样在颜色空间中进行。
For SOLiD reads, BWA converts the reference genome to dinucleotide 'color' sequence and builds the BWT index for the color genome. Reads are mapped in the color space where the reverse complement of a sequence is the same as the reverse, because the complement of a color is itself. For SOLiD paired-end mapping, a read pair is said to be in the correct orientation if either of the two scenarios is true: (i) both ends mapped to the forward strand of the genome with the R3 read having smaller coordinate; and (ii) both ends mapped to the reverse strand of the genome with the F3 read having smaller coordinate. Smith–Waterman alignment is also done in the color space.
比对完成后,BWA 利用动态规划(DP)将颜色读段序列解码为核苷酸序列。给定一条核苷酸参考子序列 b1b2…bl+1 和一条比对到该子序列的颜色读段序列 c1c2…cl,BWA 推断一条核苷酸序列 ĝ = ĝ1ĝ2…ĝl+1,使得以下目标函数最小化。其中 q′ 是突变的 Phred 标度概率,qi 是颜色 ci 的 Phred 质量值,函数 g(b, b′)=g(b′, b) 给出两个相邻核苷酸 b 和 b′ 对应的颜色。本质上,如果 ĝi ≠ bi,我们支付惩罚 q′;如果 g(ĝi, ĝi+1) ≠ ci,我们支付惩罚 qi。

After the alignment, BWA decodes the color read sequences to the nucleotide sequences using dynamic programming. Given a nucleotide reference subsequence b1b2…bl+1 and a color read sequence c1c2…cl mapped to the subsequence, BWA infers a nucleotide sequence
such that it minimizes the following objective function:

where q′ is the Phred-scaled probability of a mutation, qi is the Phred quality of color ci and function g(b, b′)=g(b′, b) gives the color corresponding to the two adjacent nucleotides b and b′. Essentially, we pay a penalty q′ if
and a penalty qi if
.
这一优化可通过动态规划求解,因为位置 i 之后的最优解码仅依赖于 ĝi+1 的选择。设 M(i, ĝi+1) 为到 i 为止的最优解码得分,迭代方程如下。BWA 按如下方式近似碱基质量:令 q̃i 为与 ĝi 最匹配的核苷酸的 Phred 质量,第 i 个碱基质量 q̃i+1(i=2…l)按下方公式计算。BWA 将序列 ĝ 和质量值 q̃ 作为 SOLiD 比对的最终结果输出。



This optimization can be done by dynamic programming because the best decoding beyond position i only depends on the choice of
. Let
be the best decoding score up to i. The iteration equations are


BWA approximates base qualities as follows. Let
. The i-th base quality
, i=2…l, is calculated as:

BWA outputs the sequence
and the quality
as the final result for SOLiD mapping.
颜色空间 = HMM Viterbi 解码。 SOLiD 测序仪的「颜色空间」本质上是将连续两个核苷酸编码为一个颜色(即双核苷酸标签,共 4²=16 种组合映射到 4 种颜色)。这相当于对原始核苷酸序列做了一次相邻依赖的隐状态编码。BWA 的颜色→核苷酸解码过程可以理解为在隐马尔可夫模型(HMM)上做 Viterbi 解码:隐状态是推断的核苷酸 ĝi,观测是颜色 ci,转移由参考序列 bi 约束。DP 迭代方程正是 Viterbi 的标准递推形式。这种视角让 SOLiD 比对问题与经典序列标注问题统一起来。
DP 解码的技术通用性。 虽然 SOLiD 平台已退出市场,但 BWA 的颜色空间 DP 解码思路并不局限于二碱基编码。任何将原始信号编码为相邻依赖格式的测序技术(如一些三代测序的碱基修饰检测、甲基化分析中的 CpG 上下文编码),都可以采用类似的「在颜色空间比对 + DP 解码到碱基空间」两阶段策略。这种将比对与解码分离的设计模式,使得比对引擎(BWT/FM-index)无需感知具体的编码方案,只需在比对完成后由独立的解码模块处理——模块化设计降低了工程复杂度。
SOLiD 的历史淘汰与技术遗产。 SOLiD 在 2008–2011 年间以极高准确率(因双碱基编码的纠错特性,原始准确率可达 99.94%)著称,但读长短(35–75 bp)、通量增长不及 Illumina,且颜色空间数据下游分析生态不成熟,最终被淘汰。然而,BWA 对 SOLiD 的支持使得 BWA 成为当时唯一同时支持 Illumina、SOLiD 和 454 三大平台的短序列比对工具——这是 BWA 迅速普及的重要原因之一。颜色空间的处理代码至今仍保留在 BWA 源码中,作为多平台兼容性设计的见证。
我们基于参考基因组的 BWT 实现了 BWA,用于短读段比对。它支持单端读段的带间隙比对、双端比对、生成比对质量值,以及按需返回多个匹配位点。默认的输出比对格式为 SAM(Sequence Alignment/Map format)。用户可使用 SAMtools(http://samtools.sourceforge.net)提取指定区域的比对结果、合并/排序比对、获取 SNP 和 indel 检出,并对比对进行可视化。BWA 遵循 GNU 通用公共许可证(GPL)分发。文档及源代码可在 MAQ 网站免费获取:http://maq.sourceforge.net。
We implemented BWA to do short read alignment based on the BWT of the reference genome. It performs gapped alignment for single-end reads, supports paired-end mapping, generates mapping quality and gives multiple hits if required. The default output alignment format is SAM (Sequence Alignment/Map format). Users can use SAMtools (http://samtools.sourceforge.net) to extract alignments in a region, merge/sort alignments, get single nucleotide polymorphism (SNP) and indel calls and visualize the alignment.
BWA is distributed under the GNU General Public License (GPL). Documentations and source code are freely available at the MAQ web site: http://maq.sourceforge.net.
为评估 BWA 的性能,我们测试了另外三个比对程序:MAQ(Li et al., 2008a)、SOAPv2(http://soap.genomics.org.cn)和 Bowtie(Langmead et al., 2009)。MAQ 使用哈希表对读段进行索引,然后扫描基因组。它是我们之前为大规模读段比对开发的软件包。SOAPv2 和 Bowtie 是我们所知的两个基于 BWT 的短读段比对工具。最新的 SOAP-2.1.7(Li et al.,未发表数据)使用 2way-BWT(Lam et al.,未发表数据)进行比对。它在 35 bp 种子序列之外容许更多错配,并支持限制为单个间隙打开的带间隙比对。Bowtie(版本 0.9.9.2)部署了与 BWA 类似的算法。然而,它并非通过 D(i) 界定搜索范围来缩减搜索空间,而是巧妙地同时比对原始读段与其反向互补序列,从而绕过向前缀树根节点的不必要搜索。默认情况下,Bowtie 在前缀树上执行深度优先搜索(DFS),一旦找到第一个合格匹配即停止。因此,即使禁用种子策略,它也可能遗漏最佳非精确匹配。通过在命令行添加 '--best' 选项,可以使 Bowtie 执行广度优先搜索(BFS),但这会降低 Bowtie 的速度。Bowtie 目前不支持带间隙比对。
To evaluate the performance of BWA, we tested additional three alignment programs: MAQ (Li et al., 2008a), SOAPv2 (http://soap.genomics.org.cn) and Bowtie (Langmead et al., 2009). MAQ indexes reads with a hash table and scans through the genome. It is the software package we developed previously for large-scale read mapping. SOAPv2 and Bowtie are the other two BWT-based short read aligners that we are aware of. The latest SOAP-2.1.7 (Li et al., unpublished data) uses 2way-BWT (Lam et al., unpublished data) for alignment. It tolerates more mismatches beyond the 35 bp seed sequence and supports gapped alignment limited to one gap open. Bowtie (version 0.9.9.2) deploys a similar algorithm to BWA. Nonetheless, it does not reduce the search space by bounding the search with D(i), but by cleverly doing the alignment for both original and reverse read sequences to bypass unnecessary searches towards the root of the prefix trie. By default, Bowtie performs a DFS on the prefix trie and stops when the first qualified hit is found. Thus, it may miss the best inexact hit even if its seeding strategy is disabled. It is possible to make Bowtie perform a BFS by applying '–best' at the command line, but this makes Bowtie slower. Bowtie does not support gapped alignment at the moment.
包括 BWA 在内的四个程序均将重复读段随机分配到多个等同最佳位置上。我们在实践中主要关注可信比对,因此需要排除重复匹配。SOAPv2 给出读段的等同最佳匹配数目,仅保留唯一比对。我们还要求 SOAPv2 将可能的间隙大小限制在最多 3 bp。我们使用 '--best -k 2' 命令行选项运行 Bowtie,使其输出读段的 top 2 匹配。如果次优匹配与最优匹配含有相同数量的错配,则丢弃该读段的比对结果。MAQ 和 BWA 生成比对质量值。我们使用比对质量阈值 1(MAQ)和 10(BWA)来判断可信比对。使用不同阈值是因为我们知道 MAQ 的比对质量被低估,而 BWA 的比对质量被高估。
All the four programs, including BWA, randomly place a repetitive read across the multiple equally best positions. As we are mainly interested in confident mappings in practice, we need to rule out repetitive hits. SOAPv2 gives the number of equally best hits of a read. Only unique mappings are retained. We also ask SOAPv2 to limit the possible gap size to at most 3 bp. We run Bowtie with the command-line option '–best -k 2', which renders Bowtie to output the top two hits of a read. We discard a read alignment if the second best hit contains the same number of mismatches as the best hit. MAQ and BWA generate mapping qualities. We use mapping quality threshold 1 for MAQ and 10 for BWA to determine confident mappings. We use different thresholds because we know that MAQ's mapping quality is underestimated, while BWA's is overestimated.
比对质量阈值为何不统一? 作者对 MAQ 使用阈值 1、对 BWA 使用阈值 10 来判断「可信比对」,初看似乎对 MAQ 不公平,但实际上这恰恰是公平比较的方法论精髓。MAQ 的比对质量计算基于贝叶斯模型但偏保守,往往低估真实质量值(一个理应 Q30 的比对可能只得到 Q11);而 BWA 的比对质量估算假设「真正命中总能被找到」,相对乐观,容易高估。如果统一用相同阈值(比如都选 Q10),会使得 MAQ 因低估而流失大量本应可信的比对,或者 BWA 因高估而纳入更多错误比对。根据不同工具的质量分值分布特性分别标定阈值,使得每个工具都在其「最佳工作点」进行比较,这才是科学公平的基准测试方法。
Bowtie DFS 默认行为的工程后果。 Bowtie 在前缀树上执行深度优先搜索,一旦找到第一个合格的匹配就停止——这意味着它不会探索其他分支来寻找更好的匹配(比如更少错配的那个)。即使禁用种子策略,这一 DFS 特性仍然存在。加上 '--best' 选项切换为 BFS 可以缓解此问题,但 §3.3 的模拟评估披露:使用默认选项时 Bowtie 可达到惊人的 151 秒(极快),但其中高达 6.4% 的可信比对是错误的。这揭示了 DFS 策略的根本性弱点:速度优势以准确率为代价。BWA 的 BFS 策略(基于堆的优先级队列)则始终优先展开最有前途的分支,虽比 DFS 慢,但能保证找到最优命中。这本质上是「近似解 vs 最优解」的经典算法设计选择。
SOAPv2 的 2way-BWT 是什么? SOAPv2 使用的 2way-BWT(Lam 等人未发表数据)是 BWT 搜索空间剪枝的另一种策略。传统 BWA 的反向搜索只能从读段右端向左端逐步扩展;2way-BWT 支持双向搜索——既可以从种子向右扩展(正向搜索),也可以向左扩展(反向搜索)。这使得 SOAPv2 能以更灵活的方式处理 35 bp 种子序列之外的错配:先通过种子精确定位候选区域,再在种子两侧分别进行双向扩展,容忍更多的碱基差异。这不同于 BWA 的 D(i) 全局下界限制策略——BWA 在整个读段上统一剪枝,而 SOAPv2 在种子内外采用不同的容错策略。理解这两种不同的搜索空间压缩方法,有助于对比两类基于 BWT 的比对器在速度-准确率权衡上的不同设计哲学。
我们使用 SAMtools 软件包中的 wgsim 程序从人类基因组模拟读段,然后用四个程序将读段比对回人类基因组。由于已知每条读段的精确坐标,我们可以计算比对错误率。
We simulated reads from the human genome using the wgsim program that is included in the SAMtools package and ran the four programs to map the reads back to the human genome. As we know the exact coordinate of each read, we are able to calculate the alignment error rate.
表1 显示 BWA 和 MAQ 达到了相似的比对准确率。在可信比对读段的占比和可信比对的错误率方面,BWA 均优于 Bowtie 和 SOAPv2。值得注意的是,SOAP-2.1.7 针对长度超过 35 bp 的读段进行了优化。对于 32 bp 读段,SOAP-2.0.1 的表现优于最新版本。
Table 1 shows that BWA and MAQ achieve similar alignment accuracy. BWA is more accurate than Bowtie and SOAPv2 in terms of both the fraction of confidently mapped reads and the error rate of confident mappings. Note that SOAP-2.1.7 is optimized for reads longer than 35 bp. For the 32 bp reads, SOAP-2.0.1 outperforms the latest version.
| 单端 (Single-end) | 双端 (Paired-end) | |||||
|---|---|---|---|---|---|---|
| Program | Time (s) | Conf (%) | Err (%) | Time (s) | Conf (%) | Err (%) |
| Bowtie-32 | 1271 | 79.0 | 0.76 | 1391 | 85.7 | 0.57 |
| BWA-32 | 823 | 80.6 | 0.30 | 1224 | 89.6 | 0.32 |
| MAQ-32 | 19797 | 81.0 | 0.14 | 21589 | 87.2 | 0.07 |
| SOAP2-32 | 256 | 78.6 | 1.16 | 1909 | 86.8 | 0.78 |
| Bowtie-70 | 1726 | 86.3 | 0.20 | 1580 | 90.7 | 0.43 |
| BWA-70 | 1599 | 90.7 | 0.12 | 1619 | 96.2 | 0.11 |
| MAQ-70 | 17928 | 91.0 | 0.13 | 19046 | 94.6 | 0.05 |
| SOAP2-70 | 317 | 90.3 | 0.39 | 708 | 94.5 | 0.34 |
| Bowtie-125 | 1966 | 88.0 | 0.07 | 1701 | 91.0 | 0.37 |
| BWA-125 | 3021 | 93.0 | 0.05 | 3059 | 97.6 | 0.04 |
| MAQ-125 | 17506 | 92.7 | 0.08 | 19388 | 96.3 | 0.02 |
| SOAP2-125 | 555 | 91.5 | 0.17 | 1187 | 90.8 | 0.14 |
分别从人类基因组模拟了 100 万对 32 bp、70 bp 和 125 bp 读段,SNP 突变率为 0.09%,indel 突变率为 0.01%,均匀测序碱基错误率为 2%。32 bp 读段的插入片段长度来自正态分布 N(170, 25),70 bp 和 125 bp 读段来自 N(500, 50)。表中列出:2.5 GHz Xeon E5420 处理器单核上的 CPU 时间(秒)、可信比对读段百分比(Conf)以及可信比对中的错误比对百分比(Err)。
在速度方面,SOAPv2 最快,而且如果禁用带间隙比对,其双端比对速度实际上还可提升 30–80%。Bowtie 使用默认选项时(数据未显示)在单端比对上的速度是当前设置 '--best -k 2' 的数倍,但速度的提升以准确率大幅下降为代价。例如,使用默认选项时,Bowtie 可在 151 秒内完成 200 万条单端 32 bp 读段的比对,但其中 6.4% 的可信比对是错误的。如此高的比对错误率会使结构变异的检测复杂化,并可能影响 SNP 的准确性。BWA 与 MAQ 相比,BWA 速度快 6–18 倍,具体取决于读段长度。MAQ 的速度不受读段长度影响,因为其内部将所有读段视为 128 bp。可以像 Bowtie 和 SOAPv2 那样通过不检查次优匹配来加速 BWA,但这样无法计算比对质量值。我们认为生成恰当的比对质量值对下游分析(如结构变异检测)非常有用。
On speed, SOAPv2 is the fastest and actually it would be 30–80% faster for paired-end mapping if gapped alignment was disabled. Bowtie with the default option (data not shown) is several times faster than the current setting '–best -k 2' on single-end mapping. However, the speed is gained at a great cost of accuracy. For example, with the default option, Bowtie can map the two million single-end 32 bp reads in 151 s, but 6.4% of confident mappings are wrong. This high alignment error rate may complicate the detection of structural variations and potentially affect SNP accuracy. Between BWA and MAQ, BWA is 6–18× faster, depending on the read length. MAQ's speed is not affected by read length because internally it treats all reads as 128 bp. It is possible to accelerate BWA by not checking suboptimal hits similar to what Bowtie and SOAPv2 are doing. However, calculating mapping quality would be impossible in this case and we believe generating proper mapping quality is useful to various downstream analyses such as the detection of structural variations.
在内存方面,SOAPv2 使用 5.4 GB。Bowtie 和 BWA 在单端比对时均使用 2.3 GB,双端比对时约 3 GB,均高于 MAQ 的 1 GB 内存占用。然而,三种基于 BWT 的比对工具的内存使用量与待比对读段数无关,而 MAQ 的内存使用量与读段数呈线性关系。此外,所有基于 BWT 的比对工具均支持多线程,这在多核计算机上可降低每 CPU 核心的内存消耗。在现代计算机服务器上,基于 BWT 的比对工具的内存不再是实际问题。
On memory, SOAPv2 uses 5.4 GB. Both Bowtie and BWA uses 2.3 GB for single-end mapping and about 3 GB for paired-end, larger than MAQ's memory footprint 1 GB. However, the memory usage of all the three BWT-based aligners is independent of the number of reads to be aligned, while MAQ's is linear in it. In addition, all BWT-based aligners support multi-threading, which reduces the memory per CPU core on a multi-core computer. On modern computer servers, memory is not a practical concern with the BWT-based aligners.
三个读段长度的实验设计逻辑。 作者选用了 32 bp、70 bp、125 bp 三个读段长度,这并非随意选择,而是有明确的工程考量:32 bp 是 Illumina 测序早期(GA1)的典型读长,也是理解 BWA 短读段能力边界的下限;70 bp 是 2009 年前后 Illumina GAIIx 的主流读长;125 bp 则是对读长增长趋势的预测性评估。三个读长对应的最大差异数 k 分别为 2、4、5(见 §2.7.3),使得不同读长下的算法搜索空间和容错能力形成对比。特别值得注意的是,32 bp 读段下的差异容限仅 2 个(错配率上限 ~6.25%),这种严苛约束使得 BWA 和 Bowtie 的可信比对占比(Conf)都较低(约 80%),而随着读长增加至 125 bp,Conf 提升至 90%+——这印证了「读段越长、比对越准确」的基本直觉。
从表 1 看速度-准确率的帕累托前沿。 将四个工具按 Conf 和 Time 绘成散点图,可以清晰观察到两个簇:MAQ 单独占据「高准确率 + 极慢」的区域(Conf 94.6%,时间 19046 秒),SOAPv2 和 Bowtie 则在「低准确率 + 极快」区域(SOAP2-70 仅 317 秒但 Err 0.39%),而 BWA 恰好位于二者的「甜点」中间(BWA-70:1599 秒、Err 0.12%)。这种分布不是偶然的——BWA 的 BFS 堆式搜索和迭代策略本质上就是在做一个「可控的」速度-准确率折衷:当最优区间唯一时快速退出,当最优区间重复时才需要额外搜索。这比 Bowtie 的「一刀切」DFS 更灵活,又比 MAQ 的全扫描更轻量。
内存的「不变性」是最被低估的优势。 表 1 的脚注揭示了 BWT 方法的一个关键特性:三种 BWT 比对器的内存使用量与待比对读段数无关(O(1) 对输入大小),而 MAQ 的内存使用量与读段数呈线性增长。假设要对齐 1 亿条读段,MAQ 的内存需求将从 1 GB 线性增长至数 GB 甚至数十 GB——这在 2009 年是不可接受的。而 BWA 无论处理 100 万还是 1 亿条读段,内存始终保持在 2.3 GB。这种「恒内存」特性使得 BWT 方法天生适合大规模人群测序场景,是其在 1000 Genomes Project 中被广泛采用的核心工程原因。
为评估在真实数据上的表现,我们从 European Read Archive(AC:ERR000589)下载了约 1220 万对 51 bp 读段。这些读段由 Illumina 为 NA12750(一位参与 1000 Genomes Project 的男性,http://www.1000genomes.org)产生。读段被比对到人类基因组 NCBI build 36。表2 显示,MAQ 和 BWA 的几乎所有可信比对均以一致配对形式存在,尽管 MAQ 给出的可信比对数量较少。BWA 的一个较慢模式(无种子策略;即使最优匹配是重复序列仍搜索次优匹配)表现更佳。在该模式下,BWA 在 6.3 小时内可信比对 89.2% 的所有读段,其中 99.2% 的可信比对以一致配对形式存在。
To assess the performance on real data, we downloaded about 12.2 million pairs of 51 bp reads from European Read Archive (AC:ERR000589). These reads were produced by Illumina for NA12750, a male included in the 1000 Genomes Project (http://www.1000genomes.org). Reads were mapped to the human genome NCBI build 36. Table 2 shows that almost all confident mappings from MAQ and BWA exist in consistent pairs although MAQ gives fewer confident alignments. A slower mode of BWA (no seeding; searching for suboptimal hits even if the top hit is a repeat) did even better. In that mode, BWA confidently mapped 89.2% of all reads in 6.3 hours with 99.2% of confident mappings in consistent pairs.
| Program | Time (h) | Conf (%) | Paired (%) |
|---|---|---|---|
| Bowtie | 5.2 | 84.4 | 96.3 |
| BWA | 4.0 | 88.9 | 98.8 |
| MAQ | 94.9 | 86.1 | 98.7 |
| SOAP2 | 3.4 | 88.3 | 97.5 |
1220 万对读段被比对到人类基因组。表中列出:2.5 GHz Xeon E5420 处理器单核上的 CPU 时间(小时)、可信比对读段百分比(Conf)以及双端方向正确且插入片段在 300 bp 以内的可信比对百分比(Paired)。
在本实验中,若禁用带间隙比对,SOAPv2 速度将提升至两倍,但可信比对百分比(Conf)和成对比对百分比(Paired)各下降约 1%。相比之下,BWA 仅执行无间隙比对时速度提升至 1.4 倍。但即使禁用了基于 BWT 的带间隙比对,借助双端读段信息,BWA 仍能通过 Smith–Waterman 比对恢复出许多短 indel。
In this experiment, SOAPv2 would be twice as fast with both percent confident mapping (Conf) and percent paired (Paired) dropping by 1% if gapped alignment was disabled. In contrast, BWA is 1.4 times as fast when it performs ungapped alignment only. But even with BWT-based gapped alignment disabled, BWA is still able to recover many short indels with Smith–Waterman alignment given paired-end reads.
我们还获取了鸡基因组序列(版本 2.1),并将这 1220 万对读段比对到人-鸡混合参考序列上。可信比对百分比与人-only 比对相比几乎未变。就比对到鸡基因组上的读段数量而言,Bowtie 比对到 2640 条,BWA 2942 条,MAQ 3005 条,SOAPv2 比对到 4531 条错误基因组。考虑到鸡序列占人-鸡混合参考序列的四分之一,BWA 的比对错误率约为 0.06%(=2942×4/12.2M/0.889)。需要注意的是,这种比对错误率估计可能偏低,因为错误比对的人类读段往往与人类重复序列相关,从而仍被比对回人类序列;也可能偏高,因为存在高度保守的序列、人类基因组组装不完整或鸡基因组组装错误。
We also obtained the chicken genome sequence (version 2.1) and aligned these 12.2 million read pairs against a human–chicken hybrid reference sequence. The percent confident mappings is almost unchanged in comparison to the human-only alignment. As for the number of reads mapped to the chicken genome, Bowtie mapped 2640, BWA 2942, MAQ 3005 and SOAPv2 mapped 4531 reads to the wrong genome. If we consider that the chicken sequences take up one-quarter of the human–chicken hybrid reference, the alignment error rate for BWA is about 0.06% (=2942×4/12.2M/0.889). Note that such an estimate of the alignment error rate may be underestimated because wrongly aligned human reads tend to be related to repetitive sequences in human and to be mapped back to the human sequences. The estimate may also be overestimated due to the presence of highly conservative sequences and the incomplete assembly of human or misassembly of the chicken genome.
如果我们希望减少错误,BWA 和 MAQ 生成的比对质量值允许我们选择准确率更高的比对。如果将 BWA 判断可信匹配的比对质量阈值提高至 25,则 86.4% 的读段可被可信比对,且仅有 1927 条读段比对到鸡基因组,在可信比对百分比和比对到错误基因组的读段数两方面均优于 Bowtie。
If we want fewer errors, the mapping quality generated by BWA and MAQ allows us to choose alignments of higher accuracy. If we increased the mapping quality threshold in determining a confident hit to 25 for BWA, 86.4% of reads could be aligned confidently with 1927 reads mapped to the chicken genome, outperforming Bowtie in terms of both percent confident mappings and the number of reads mapped to the wrong genome.
人-鸡嵌合测试的实验设计智慧。 这是本节最精妙的方法论贡献。将人类样本 NA12750 的读段比对到人-鸡混合参考基因组上,任何比对到鸡染色体上的读段必然是错误的(因为人类样本不含鸡 DNA)。通过统计落入鸡基因组的读段数来估算假阳性率,作者巧妙地绕过了「真实数据没有标准答案」的困局。乘以 4 是因为鸡基因组(约 1 Gb)只占混合参考序列的 ~1/4(人 ~3 Gb),这相当于假定「错误比对的读段在四个等大小的参考子集中均匀分布」。最终估算 BWA 错误率为 0.06%——这是一个非常保守的上界估计,因为真正源自重复序列的错误比对很可能仍落在人类区域而被忽略。作者诚实地指出了这一偏差,展现了严谨的科学写作素养。
从表 2 解读真实数据的 Speed-Accuracy 模式。 与模拟数据不同,真实数据评估无法精确计算 Err(因为没有真值),因此作者改用 Paired(一致配对比例)作为间接准确率指标。四个工具在真实 51 bp 双端数据上的表现出现了一些有趣的模式变化:(1) MAQ 的 Conf 降至 86.1%(低于 BWA 的 88.9%),这是因为 MAQ 的保守质量评分在真实数据中进一步放大了「可信偏少」的倾向;(2) SOAPv2 在真实数据上的表现与模拟数据一致——速度最快(3.4h)但 Paired 率最低(97.5%),暗示其可能有更多错误比对;(3) BWA 在 4 小时内可信比对 88.9%,Paired 率 98.8%,与 MAQ 的准确率持平但速度快 23.7 倍——这完美展示了 BWT 方法在真实应用场景中的实用价值。
MAPQ 阈值的可调性作为工程特性。 BWA 生成的质量分值具有良好的区分度:将阈值从 Q10 提高到 Q25 后,比对到鸡基因组的读段从 2942 降至 1927(降低 34%),同时 Conf 仅从 88.9% 降至 86.4%(仅损失 2.5 个百分点)。这说明 BWA 的质量分值与真实错误率之间呈良好的单调关系——分值越高,确实越可信。用户可以根据下游分析的需求灵活选择阈值:变异检测可用 Q10 获取更多候选位点,结构变异检测可用 Q25 减少假阳性。这种可调性在 SOAPv2 和 Bowtie 中不存在(它们不输出质量分值),是 BWA + SAMtools 生态相比竞品的一个关键差异化优势。
针对人类参考基因组的短读段比对,BWA 比 MAQ 快一个数量级,同时实现了相似的比对准确度。BWA 支持单端读段的缺口比对(gapped alignment),随着读段变长且倾向于包含插入缺失(indel),这一功能日益重要。BWA 以 SAM 格式输出比对结果,以利用 SAMtools 实现的各种下游分析。BWA 加上 SAMtools 提供了 MAQ 软件包的大部分功能,并附带额外的特性。
For short read alignment against the human reference genome, BWA is an order of magnitude faster than MAQ while achieving similar alignment accuracy. It supports gapped alignment for single-end reads, which is increasingly important when reads get longer and tend to contain indels. BWA outputs alignment in the SAM format to take the advantage of the downstream analyses implemented in SAMtools. BWA plus SAMtools provides most of functionality of the MAQ package with additional features.
与速度、内存占用和比对读段数相比,比对准确度在真实数据上更难评估,因为我们不知道真实答案。在本文中,我们使用了三个标准来评估比对器的准确度。第一个标准(只能通过模拟数据评估)是「高置信比对数量」与「高置信比对中的比对错误率」的组合。请注意,单独统计高置信比对数量可能不是一个好的标准:我们可以以牺牲准确度为代价来比对更多读段。第二个标准是「比对读段数」与「以一致配对方式比对的读段数」的组合,该标准适用于真实数据,前提是实验中的配对信息正确且结构变异罕见。虽然该标准与比对器定义配对「一致性」的方式有关,但根据我们的经验,如果配对参数设置正确,该标准具有很强的信息量。第三个标准是:当我们故意加入来自分歧物种的参考序列时,比对到错误参考序列的读段比例。
In comparison to speed, memory and the number of mapped reads, alignment accuracy is much harder to evaluate on real data as we do not know the ground truth. In this article, we used three criteria for evaluating the accuracy of an aligner. The first criterion, which can only be evaluated with simulated data, is the combination of the number of confident mappings and the alignment error rate out of the confident mappings. Note that the number of confident mappings alone may not be a good criterion: we can map more at the cost of accuracy. The second criterion, which is the combination of the number of aligned reads and the number of reads mapped in consistent pairs, works on real data on the assumption that the mating information from the experiment is correct and that structural variations are rare. Although this criterion is related to the way an aligner defines pair 'consistency', in our experience it is highly informative if the pairing parameters are set correctly. The third criterion is the fraction of reads mapped to the wrong reference sequence if we intentionally add reference sequences from a diverged species.
虽然理论上 BWA 可以处理任意长度的读段,但在长读段上其性能会下降,尤其当测序错误率较高时。此外,BWA 始终要求将整个读段从头到尾全部比对(即相对于读段是全局比对),但长读段更可能被结构变异或参考基因组中的装配错误所中断,这将导致 BWA 比对失败。对于长读段,一个可能更好的解决方案是将读段分割为多个短片段,使用上述算法分别比对这些片段,然后将部分比对连接起来以获得完整的读段比对结果。
Although in theory BWA works with arbitrarily long reads, its performance is degraded on long reads especially when the sequencing error rate is high. Furthermore, BWA always requires the full read to be aligned, from the first base to the last one (i.e. global with respect to reads), but longer reads are more likely to be interrupted by structural variations or misassemblies in the reference genome, which will fail BWA. For long reads, a possibly better solution would be to divide the read into multiple short fragments, align the fragments separately with the algorithm described above and then join the partial alignments to get the full alignment of the read.
BWA 2009 的四大遗产:这篇论文不仅定义了 BWA 工具本身,更奠定了四项深远影响:(1) D(i)——不等长查询的精确匹配上限,将反向搜索从精确匹配扩展到容错场景,是利用 FM-index 双向量化剪枝的核心创新;(2) Ψ⁻¹——逆置换向量的压缩存储,配合 O 数组采样使人类基因组 BWT 索引仅需 ~2.3 GB,将 12 GB 的后缀数组完整存储压缩为可在普通工作站运行的工程实现;(3) 三标准评估方法论——模拟数据置信比对错误率 + 真实数据一致配对比例 + 混合基因组错配比例,成为比对器评估的事实标准框架,后人很难绕开这套标准来宣称一个比对器的优劣;(4) SAM/BAM 格式标准化——BWA 是首批原生输出 SAM 格式的比对器,与 SAMtools 形成完整的比对-分析生态,将比对→排序→去重→变异检测的管线标准化,其对生物信息学基础架构的影响甚至不亚于 BWA 算法本身。
进化链 2009→2010→2013:本文末尾指出的长读段全局比对局限直接催生了后续发展。BWA-SW (2010) 改用 Smith–Waterman 策略支持局部比对和 split alignment,可处理 454/Roche 平台的中等读长;BWA-MEM (2013) 以 Maximal Exact Match 为种子,成为 PacBio/Nanopore 长读段的标准工具。三篇论文构成完整演化谱系:短读段(2009)→中长读段(2010)→超长读段(2013)。
为什么 D(i) 今天依然重要?D(i) 的思想——用动态规划估计前缀匹配数上限以避免无效搜索——在 minimap2 等当代长读段比对器中仍以更复杂的 chaining 策略延续。理解 D(i) 是理解「BWT 类算法在容错搜索时为何高效」的关键。而 Ψ⁻¹ 所代表的「采样 + 即时重建」的压缩后缀数组思想,影响了 CRAM(基于参考基因组的 BAM 压缩格式)和后续所有基于全文本索引的比对工具设计,是生物信息学压缩数据结构领域的基石思想。
我们感谢 Broad Institute 的 Mark DePristo 和 Jared Maguire 就比对程序评估标准标准化提出的建议,以及三位匿名审稿人,他们的意见帮助我们改进了稿件。我们也感谢 Durbin 研究组的成员对初稿提出的意见。
We are grateful to Mark DePristo and Jared Maguire from the Broad Institute for their suggestions on standardizing the criteria for evaluating alignment programs, and to the three anonymous reviewers whose comments helped us to improve the manuscript. We also thank the members of the Durbin research group for the comments on the initial draft.
资金资助: Wellcome Trust/077192/Z/05/Z。
Funding: Wellcome Trust/077192/Z/05/Z.
利益冲突: 未声明。
Conflict of Interest: none declared.