東京大学 新領域創成科学研究科 メディカル情報生命専攻 2023年8月実施 問題12
Author
zephyr
Description
(1) The iterative equations below are for calculation of the score of global alignment of two sequences x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m , y = y 1 ⋯ y n y = y_1 \cdots y_n y = y 1 ⋯ y n , where s ( a , b ) s(a, b) s ( a , b ) is the match score of character a a a and b b b , and 0 < e < d 0 < e < d 0 < e < d . The initial values are not shown here.
for i = 1 , ⋯ , m for j = 1 , ⋯ , n M i , j = max { M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j ) X i , j = max { M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d Y i , j = max { M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e \begin{align*}
&\text{for } i = 1, \cdots, m \\
&\quad \text{for } j = 1, \cdots, n \\
&\quad \quad M_{i,j} = \max \begin{cases}
M_{i-1,j-1} + s(x_i, y_j) \\
X_{i-1,j-1} + s(x_i, y_j) \\
Y_{i-1,j-1} + s(x_i, y_j)
\end{cases} \\
&\quad \quad X_{i,j} = \max \begin{cases}
M_{i-1,j} - d \\
X_{i-1,j} - e \\
Y_{i-1,j} - d
\end{cases} \\
&\quad \quad Y_{i,j} = \max \begin{cases}
M_{i,j-1} - d \\
X_{i,j-1} - d \\
Y_{i,j-1} - e
\end{cases}
\end{align*} for i = 1 , ⋯ , m for j = 1 , ⋯ , n M i , j = max ⎩ ⎨ ⎧ M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j ) X i , j = max ⎩ ⎨ ⎧ M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d Y i , j = max ⎩ ⎨ ⎧ M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e
(1-1) Show the formula of the penalty for a gap of length k k k .
(1-2) Suppose that some of the initial values are
M 0 , 0 = 0 M_{0,0} = 0 M 0 , 0 = 0 , X 0 , 0 = − ∞ X_{0,0} = -\infty X 0 , 0 = − ∞ , Y 0 , 0 = − ∞ Y_{0,0} = -\infty Y 0 , 0 = − ∞ ,
for j = 1 , ⋯ , n j = 1, \cdots, n j = 1 , ⋯ , n : M 0 , j = X 0 , j = − ∞ M_{0,j} = X_{0,j} = -\infty M 0 , j = X 0 , j = − ∞ ,
for i = 1 , ⋯ , m i = 1, \cdots, m i = 1 , ⋯ , m : M i , 0 = Y i , 0 = − ∞ M_{i,0} = Y_{i,0} = -\infty M i , 0 = Y i , 0 = − ∞ .
Show the initial values X i , 0 X_{i,0} X i , 0 ( i = 1 , ⋯ , m ) (i = 1, \cdots, m) ( i = 1 , ⋯ , m ) and Y 0 , j Y_{0,j} Y 0 , j ( j = 1 , ⋯ , n ) (j = 1, \cdots, n) ( j = 1 , ⋯ , n ) .
(1-3) Show the iterative equations to calculate the maximum score of local alignment using the same type of gap penalty.
(1-4) Explain a method to get a local alignment with the maximum score using the calculation of (1-3).
(2) There is a sequence x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m consisting of a , c , g , t a, c, g, t a , c , g , t . Define the complementary character of a , c , g , t a, c, g, t a , c , g , t as
comp ( a ) = t , comp ( c ) = g , comp ( g ) = c , comp ( t ) = a . \begin{align*}
\text{comp}(a) &= t, \\
\text{comp}(c) &= g, \\
\text{comp}(g) &= c, \\
\text{comp}(t) &= a.
\end{align*} comp ( a ) comp ( c ) comp ( g ) comp ( t ) = t , = g , = c , = a .
(2-1) Explain what is reported by the following algorithm.
for i = 1 , ⋯ , m : H i , m + 1 = 0 for j = 1 , ⋯ , m + 1 : H 0 , j = 0 for i = 1 , ⋯ , m for j = m , ⋯ , i if x i = comp ( x j ) then H i , j = H i − 1 , j + 1 + 1 else H i , j = 0 if H i − 1 , j + 1 ≥ k then report a pair of ranges [ i − H i − 1 , j + 1 + 1 , i − 1 ] and [ j + 1 , j + H i − 1 , j + 1 ] . \begin{align*}
&\text{for } i = 1, \cdots, m: H_{i,m+1} = 0 \\
&\text{for } j = 1, \cdots, m + 1: H_{0,j} = 0 \\
&\text{for } i = 1, \cdots, m \\
&\quad \text{for } j = m, \cdots, i \\
&\quad \quad \text{if } x_i = \text{comp}(x_j) \text{ then } \\
&\quad \quad \quad H_{i,j} = H_{i-1,j+1} + 1 \\
&\quad \quad \text{else } H_{i,j} = 0 \\
&\quad \quad \text{if } H_{i-1,j+1} \ge k \text{ then } \\
&\quad \quad \quad \text{report a pair of ranges } [i - H_{i-1,j+1} + 1, i - 1] \text{ and } [j + 1, j + H_{i-1,j+1}].
\end{align*} for i = 1 , ⋯ , m : H i , m + 1 = 0 for j = 1 , ⋯ , m + 1 : H 0 , j = 0 for i = 1 , ⋯ , m for j = m , ⋯ , i if x i = comp ( x j ) then H i , j = H i − 1 , j + 1 + 1 else H i , j = 0 if H i − 1 , j + 1 ≥ k then report a pair of ranges [ i − H i − 1 , j + 1 + 1 , i − 1 ] and [ j + 1 , j + H i − 1 , j + 1 ] .
(2-2) Let us define the 'reverse complementary alignment score' of two subsequences x i ⋯ x i + p x_{i} \cdots x_{i+p} x i ⋯ x i + p and x j − q ⋯ x j x_{j-q} \cdots x_{j} x j − q ⋯ x j of length p + 1 p + 1 p + 1 and q + 1 q + 1 q + 1 as the maximum score of global alignment of x i ⋯ x i + p x_{i} \cdots x_{i+p} x i ⋯ x i + p and x j − q ⋯ x j x_{j-q} \cdots x_{j} x j − q ⋯ x j . Note that x j − q ⋯ x j x_{j-q} \cdots x_{j} x j − q ⋯ x j is reverse ordered.
Also define the substitution matrix of the alignment as
s ( a , b ) = { 1 if comp ( a ) = b − 1 otherwise s(a, b) = \begin{cases}
1 & \text{if } \text{comp}(a) = b \\
-1 & \text{otherwise}
\end{cases} s ( a , b ) = { 1 − 1 if comp ( a ) = b otherwise
and the gap penalty is the number of gaps (a gap of length k k k has penalty k k k ).
Show an algorithm to report a pair of (possibly empty) subsequences of x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m with the maximum reverse complementary alignment score.
(1) 下列迭代方程用于计算两个序列 x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m 和 y = y 1 ⋯ y n y = y_1 \cdots y_n y = y 1 ⋯ y n 的全局比对得分,其中 s ( a , b ) s(a, b) s ( a , b ) 是字符 a a a 和 b b b 的匹配得分,且 0 < e < d 0 < e < d 0 < e < d 。初始值未显示。
对于 i = 1 , ⋯ , m 对于 j = 1 , ⋯ , n M i , j = max { M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j ) X i , j = max { M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d Y i , j = max { M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e \begin{align*}
&\text{对于 } i = 1, \cdots, m \\
&\quad \text{对于 } j = 1, \cdots, n \\
&\quad \quad M_{i,j} = \max \begin{cases}
M_{i-1,j-1} + s(x_i, y_j) \\
X_{i-1,j-1} + s(x_i, y_j) \\
Y_{i-1,j-1} + s(x_i, y_j)
\end{cases} \\
&\quad \quad X_{i,j} = \max \begin{cases}
M_{i-1,j} - d \\
X_{i-1,j} - e \\
Y_{i-1,j} - d
\end{cases} \\
&\quad \quad Y_{i,j} = \max \begin{cases}
M_{i,j-1} - d \\
X_{i,j-1} - d \\
Y_{i,j-1} - e
\end{cases}
\end{align*} 对于 i = 1 , ⋯ , m 对于 j = 1 , ⋯ , n M i , j = max ⎩ ⎨ ⎧ M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j ) X i , j = max ⎩ ⎨ ⎧ M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d Y i , j = max ⎩ ⎨ ⎧ M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e
(1-1) 展示长度为 k k k 的空隙的惩罚公式。
(1-2) 假设一些初始值为
M 0 , 0 = 0 M_{0,0} = 0 M 0 , 0 = 0 , X 0 , 0 = − ∞ X_{0,0} = -\infty X 0 , 0 = − ∞ , Y 0 , 0 = − ∞ Y_{0,0} = -\infty Y 0 , 0 = − ∞ ,
对于 j = 1 , ⋯ , n j = 1, \cdots, n j = 1 , ⋯ , n : M 0 , j = X 0 , j = − ∞ M_{0,j} = X_{0,j} = -\infty M 0 , j = X 0 , j = − ∞ ,
对于 i = 1 , ⋯ , m i = 1, \cdots, m i = 1 , ⋯ , m : M i , 0 = Y i , 0 = − ∞ M_{i,0} = Y_{i,0} = -\infty M i , 0 = Y i , 0 = − ∞ 。
展示初始值 X i , 0 X_{i,0} X i , 0 ( i = 1 , ⋯ , m ) (i = 1, \cdots, m) ( i = 1 , ⋯ , m ) 和 Y 0 , j Y_{0,j} Y 0 , j ( j = 1 , ⋯ , n ) (j = 1, \cdots, n) ( j = 1 , ⋯ , n ) 。
(1-3) 使用相同类型的空隙惩罚展示计算局部比对最大得分的迭代方程。
(1-4) 解释一种使用 (1-3) 的计算方法获取最大得分的局部比对的方法。
(2) 有一个由 a , c , g , t a, c, g, t a , c , g , t 组成的序列 x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m 。定义 a , c , g , t a, c, g, t a , c , g , t 的互补字符为
comp ( a ) = t , comp ( c ) = g , comp ( g ) = c , comp ( t ) = a . \begin{align*}
\text{comp}(a) &= t, \\
\text{comp}(c) &= g, \\
\text{comp}(g) &= c, \\
\text{comp}(t) &= a.
\end{align*} comp ( a ) comp ( c ) comp ( g ) comp ( t ) = t , = g , = c , = a .
(2-1) 解释以下算法报告的内容。
对于 i = 1 , ⋯ , m : H i , m + 1 = 0 对于 j = 1 , ⋯ , m + 1 : H 0 , j = 0 对于 i = 1 , ⋯ , m 对于 j = m , ⋯ , i 如果 x i = comp ( x j ) 那么 H i , j = H i − 1 , j + 1 + 1 否则 H i , j = 0 如果 H i − 1 , j + 1 ≥ k 那么 报告一对范围 [ i − H i − 1 , j + 1 + 1 , i − 1 ] 和 [ j + 1 , j + H i − 1 , j + 1 ] . \begin{align*}
&\text{对于 } i = 1, \cdots, m: H_{i,m+1} = 0 \\
&\text{对于 } j = 1, \cdots, m + 1: H_{0,j} = 0 \\
&\text{对于 } i = 1, \cdots, m \\
&\quad \text{对于 } j = m, \cdots, i \\
&\quad \quad \text{如果 } x_i = \text{comp}(x_j) \text{ 那么 } \\
&\quad \quad \quad H_{i,j} = H_{i-1,j+1} + 1 \\
&\quad \quad \text{否则 } H_{i,j} = 0 \\
&\quad \quad \text{如果 } H_{i-1,j+1} \ge k \text{ 那么 } \\
&\quad \quad \quad \text{报告一对范围 } [i - H_{i-1,j+1} + 1, i - 1] \text{ 和 } [j + 1, j + H_{i-1,j+1}].
\end{align*} 对于 i = 1 , ⋯ , m : H i , m + 1 = 0 对于 j = 1 , ⋯ , m + 1 : H 0 , j = 0 对于 i = 1 , ⋯ , m 对于 j = m , ⋯ , i 如果 x i = comp ( x j ) 那么 H i , j = H i − 1 , j + 1 + 1 否则 H i , j = 0 如果 H i − 1 , j + 1 ≥ k 那么 报告一对范围 [ i − H i − 1 , j + 1 + 1 , i − 1 ] 和 [ j + 1 , j + H i − 1 , j + 1 ] .
(2-2) 定义两个子序列 x i ⋯ x i + p x_{i} \cdots x_{i+p} x i ⋯ x i + p 和 x j − q ⋯ x j x_{j-q} \cdots x_{j} x j − q ⋯ x j 的“反向互补对齐得分”为 p + 1 p + 1 p + 1 和 q + 1 q + 1 q + 1 的全局对齐的最大得分。注意 x j − q ⋯ x j x_{j-q} \cdots x_{j} x j − q ⋯ x j 是反向排列的。
同样,定义对齐的替换矩阵为
s ( a , b ) = { 1 如果 comp ( a ) = b − 1 否则 s(a, b) = \begin{cases}
1 & \text{如果 } \text{comp}(a) = b \\
-1 & \text{否则}
\end{cases} s ( a , b ) = { 1 − 1 如果 comp ( a ) = b 否则
并且间隙惩罚是间隙的数量(长度为 k k k 的间隙有惩罚 k k k )。
展示一个算法报告 x = x 1 ⋯ x m x = x_1 \cdots x_m x = x 1 ⋯ x m 的一对(可能为空)子序列,具有最大反向互补对齐得分。
题目描述
第 1 部分:序列比对。 给定序列 x = x 1 ⋯ x m x=x_1\cdots x_m x = x 1 ⋯ x m 、y = y 1 ⋯ y n y=y_1\cdots y_n y = y 1 ⋯ y n ,字符配对得分为 s ( a , b ) s(a,b) s ( a , b ) ,间隙开启与延伸参数满足 0 < e < d 0<e<d 0 < e < d 。上文三状态动态规划以 M i , j M_{i,j} M i , j 表示字符对齐结尾状态,以 X i , j , Y i , j X_{i,j},Y_{i,j} X i , j , Y i , j 表示两个方向的间隙结尾状态:新开间隙扣 d d d ,同向延伸扣 e e e 。
写出长度为 k k k 的间隙罚分公式。
已知
M 0 , 0 = 0 , X 0 , 0 = Y 0 , 0 = − ∞ , M_{0,0}=0,\qquad X_{0,0}=Y_{0,0}=-\infty, M 0 , 0 = 0 , X 0 , 0 = Y 0 , 0 = − ∞ ,
M 0 , j = X 0 , j = − ∞ ( j = 1 , … , n ) , M_{0,j}=X_{0,j}=-\infty\quad(j=1,\ldots,n), M 0 , j = X 0 , j = − ∞ ( j = 1 , … , n ) ,
M i , 0 = Y i , 0 = − ∞ ( i = 1 , … , m ) , M_{i,0}=Y_{i,0}=-\infty\quad(i=1,\ldots,m), M i , 0 = Y i , 0 = − ∞ ( i = 1 , … , m ) ,
求其余边界值 X i , 0 X_{i,0} X i , 0 与 Y 0 , j Y_{0,j} Y 0 , j 。
在相同仿射间隙罚分下,写出计算局部比对最大得分的三状态迭代式。
说明如何利用第 3 问的填表结果恢复一组得分最大的局部比对。
第 2 部分:反向互补片段。 序列 x = x 1 ⋯ x m x=x_1\cdots x_m x = x 1 ⋯ x m 仅含 a , c , g , t a,c,g,t a , c , g , t ,互补映射为
comp ( a ) = t , comp ( c ) = g , comp ( g ) = c , comp ( t ) = a . \operatorname{comp}(a)=t,\quad
\operatorname{comp}(c)=g,\quad
\operatorname{comp}(g)=c,\quad
\operatorname{comp}(t)=a. comp ( a ) = t , comp ( c ) = g , comp ( g ) = c , comp ( t ) = a .
解释上文算法报告的内容。该算法设置 H i , m + 1 = 0 H_{i,m+1}=0 H i , m + 1 = 0 、H 0 , j = 0 H_{0,j}=0 H 0 , j = 0 ,对 i = 1 , … , m i=1,\ldots,m i = 1 , … , m 及 j = m , … , i j=m,\ldots,i j = m , … , i ,在
x i = comp ( x j ) x_i=\operatorname{comp}(x_j) x i = comp ( x j )
时令 H i , j = H i − 1 , j + 1 + 1 H_{i,j}=H_{i-1,j+1}+1 H i , j = H i − 1 , j + 1 + 1 ,否则置零;若 H i − 1 , j + 1 ≥ k H_{i-1,j+1}\ge k H i − 1 , j + 1 ≥ k ,则报告区间对
[ i − H i − 1 , j + 1 + 1 , i − 1 ] , [ j + 1 , j + H i − 1 , j + 1 ] . [i-H_{i-1,j+1}+1,i-1],\qquad
[j+1,j+H_{i-1,j+1}]. [ i − H i − 1 , j + 1 + 1 , i − 1 ] , [ j + 1 , j + H i − 1 , j + 1 ] .
对正向片段 x i ⋯ x i + p x_i\cdots x_{i+p} x i ⋯ x i + p 与按反向次序使用的片段 x j − q ⋯ x j x_{j-q}\cdots x_j x j − q ⋯ x j ,把“反向互补比对得分”定义为二者全局比对最大得分,其中
s ( a , b ) = { 1 , comp ( a ) = b , − 1 , 否则 , s(a,b)=
\begin{cases}
1,&\operatorname{comp}(a)=b,\\
-1,&\text{否则},
\end{cases} s ( a , b ) = { 1 , − 1 , comp ( a ) = b , 否则 ,
且长度为 k k k 的间隙罚分为 k k k 。设计一个算法,报告 x x x 中一对允许为空、使反向互补比对得分最大的子序列。
全局与局部序列比对 :在匹配及两个间隙状态间转移,设置仿射罚分边界,并通过加入零状态和回溯实现局部比对。
反向互补连续片段检测 :利用 H i − 1 , j + 1 H_{i-1,j+1} H i − 1 , j + 1 沿反对角线累计互补字符连续长度,解释阈值 k k k 触发的区间报告。
反向互补比对动态规划 :把第二片段反向读取,以互补匹配矩阵和线性间隙罚分联合优化片段起止位置及比对路径。
Kai
Written by zephyr
解题思路
本题涉及两个序列的全局和局部比对问题。题目给出了全局比对的迭代公式,并要求推导出相关的公式和算法。序列比对中,常用的评分包括匹配分、错配分和插入/删除(gap)的罚分。罚分由 gap opening penalty 和 gap extension penalty 组成。
反向互补序列是 DNA 双链结构中的一个重要概念。在 DNA 中,A 与 T 配对,C 与 G 配对,两条链的方向相反。因此,一条链的序列可以决定另一条链的序列。这个概念在本题的后半部分起到了关键作用。
1. Global Alignment with Affine Gap Penalty
Let's denote the penalty for a gap of length k k k as P ( k ) P(k) P ( k ) . From the given equations, we can see that:
Opening a gap costs d d d
Extending a gap costs e e e for each additional position
Therefore, the formula for the penalty of a gap of length k k k is:
P ( k ) = d + ( k − 1 ) e P(k) = d + (k-1)e P ( k ) = d + ( k − 1 ) e
Note : This is known as an affine gap penalty model.
1-2: Initial Values for X i , 0 X_{i,0} X i , 0 and Y 0 , j Y_{0,j} Y 0 , j
Given the initial conditions:
M 0 , 0 = 0 M_{0,0} = 0 M 0 , 0 = 0
X 0 , 0 = − ∞ X_{0,0} = -\infty X 0 , 0 = − ∞ , Y 0 , 0 = − ∞ Y_{0,0} = -\infty Y 0 , 0 = − ∞
M 0 , j = X 0 , j = − ∞ M_{0,j} = X_{0,j} = -\infty M 0 , j = X 0 , j = − ∞ for j = 1 , ⋯ , n j = 1, \cdots, n j = 1 , ⋯ , n
M i , 0 = Y i , 0 = − ∞ M_{i,0} = Y_{i,0} = -\infty M i , 0 = Y i , 0 = − ∞ for i = 1 , ⋯ , m i = 1, \cdots, m i = 1 , ⋯ , m
We need to determine X i , 0 X_{i,0} X i , 0 ( i = 1 , ⋯ , m ) (i = 1, \cdots, m) ( i = 1 , ⋯ , m ) and Y 0 , j Y_{0,j} Y 0 , j ( j = 1 , ⋯ , n ) (j = 1, \cdots, n) ( j = 1 , ⋯ , n ) .
For X i , 0 X_{i,0} X i , 0 ( i = 1 , ⋯ , m ) (i = 1, \cdots, m) ( i = 1 , ⋯ , m ) :
X i , 0 X_{i,0} X i , 0 represents a gap in sequence y y y at the beginning. According to the recurrence relation:
X i , 0 = max { M i − 1 , 0 − d = − ∞ X i − 1 , 0 − e Y i − 1 , 0 − d = − ∞ X_{i,0} = \max \begin{cases}
M_{i-1,0} - d = -\infty \\
X_{i-1,0} - e \\
Y_{i-1,0} - d = -\infty
\end{cases} X i , 0 = max ⎩ ⎨ ⎧ M i − 1 , 0 − d = − ∞ X i − 1 , 0 − e Y i − 1 , 0 − d = − ∞
Therefore, X i , 0 = X i − 1 , 0 − e = − d − ( i − 1 ) e X_{i,0} = X_{i-1,0} - e = -d - (i-1)e X i , 0 = X i − 1 , 0 − e = − d − ( i − 1 ) e .
For Y 0 , j Y_{0,j} Y 0 , j ( j = 1 , ⋯ , n ) (j = 1, \cdots, n) ( j = 1 , ⋯ , n ) :
Y 0 , j Y_{0,j} Y 0 , j represents a gap in sequence x x x at the beginning. It's symmetrical to X i , 0 X_{i,0} X i , 0 :
Y 0 , j = − d − ( j − 1 ) e Y_{0,j} = -d - (j-1)e Y 0 , j = − d − ( j − 1 ) e
Hence, the initial values of X i , 0 X_{i,0} X i , 0 and Y 0 , j Y_{0,j} Y 0 , j are as follows:
X i , 0 = − d − ( i − 1 ) e X_{i,0} = -d - (i - 1)e X i , 0 = − d − ( i − 1 ) e
Y 0 , j = − d − ( j − 1 ) e Y_{0,j} = -d - (j - 1)e Y 0 , j = − d − ( j − 1 ) e
1-3: Iterative Equations for Local Alignment
To compute the local alignment, the iterative equations are modified to allow for the possibility of starting a new alignment, indicated by a score of 0:
M i , j = max { 0 M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j ) M_{i,j} = \max \begin{cases}
0 \\
M_{i-1,j-1} + s(x_i, y_j) \\
X_{i-1,j-1} + s(x_i, y_j) \\
Y_{i-1,j-1} + s(x_i, y_j)
\end{cases} M i , j = max ⎩ ⎨ ⎧ 0 M i − 1 , j − 1 + s ( x i , y j ) X i − 1 , j − 1 + s ( x i , y j ) Y i − 1 , j − 1 + s ( x i , y j )
X i , j = max { 0 M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d X_{i,j} = \max \begin{cases}
0 \\
M_{i-1,j} - d \\
X_{i-1,j} - e \\
Y_{i-1,j} - d
\end{cases} X i , j = max ⎩ ⎨ ⎧ 0 M i − 1 , j − d X i − 1 , j − e Y i − 1 , j − d
Y i , j = max { 0 M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e Y_{i,j} = \max \begin{cases}
0 \\
M_{i,j-1} - d \\
X_{i,j-1} - d \\
Y_{i,j-1} - e
\end{cases} Y i , j = max ⎩ ⎨ ⎧ 0 M i , j − 1 − d X i , j − 1 − d Y i , j − 1 − e
1-4: Obtaining a Local Alignment with Maximum Score
To obtain a local alignment with the maximum score:
Initialize all cells in the first row and column to 0.
Fill the dynamic programming matrix using the equations from (1-3).
Find the cell ( i ∗ , j ∗ ) (i^*, j^*) ( i ∗ , j ∗ ) with the maximum score in the entire matrix.
Perform a traceback from ( i ∗ , j ∗ ) (i^*, j^*) ( i ∗ , j ∗ ) until reaching a cell with score 0 or the matrix boundary.
The path of this traceback gives the optimal local alignment.
2. Reverse Complementary Sequence Analysis
2-1: Explanation of the Algorithm
The algorithm scans a sequence x x x for reverse complementary matches. It uses a matrix H H H to record the length of matching substrings that are reverse complements. If the length of the match exceeds a threshold k k k , the algorithm reports the corresponding subsequences.
Specifically:
H i , j H_{i,j} H i , j stores the length of the reverse complementary match ending at x i x_i x i and x j x_j x j .
The algorithm compares x i x_i x i with the complement of x j x_j x j for j j j from m m m down to i i i .
If a match is found, it extends the previous match (H i − 1 , j + 1 H_{i-1,j+1} H i − 1 , j + 1 ) by 1.
If the length of the match (H i − 1 , j + 1 H_{i-1,j+1} H i − 1 , j + 1 ) is at least k k k , it reports the corresponding ranges.
The reported ranges [ i − H i − 1 , j + 1 + 1 , i − 1 ] [i - H_{i-1,j+1} + 1, i - 1] [ i − H i − 1 , j + 1 + 1 , i − 1 ] and [ j + 1 , j + H i − 1 , j + 1 ] [j + 1, j + H_{i-1,j+1}] [ j + 1 , j + H i − 1 , j + 1 ] represent the start and end positions of reverse complementary subsequences of length at least k k k .
2-2: Algorithm for Maximum Reverse Complementary Alignment Score
Algorithm
The algorithm to find the maximum reverse complementary alignment score is as follows:
Initialize a dynamic programming matrix dp where dp[i][j] represents the maximum reverse complementary alignment score ending at positions i i i and j j j .
Fill the matrix using a modified Smith-Waterman algorithm, considering reverse complementary matches.
Keep track of the maximum score and its position.
Perform a traceback from the position of the maximum score to reconstruct the aligned subsequences.
Return the pair of subsequences with the maximum reverse complementary alignment score.
The expected time complexity of this algorithm is O ( m 2 ) O(m^2) O ( m 2 ) , where m m m is the length of the sequence x x x . The expected space complexity is also O ( m 2 ) O(m^2) O ( m 2 ) due to the dynamic programming matrix.
Code Implementation
def max_reverse_complementary_alignment ( x ) : m = len ( x ) dp = [ [ 0 for * in range ( m + 1 ) ] for * in range ( m + 1 ) ] max_score = 0 max_pos = ( 0 , 0 ) def comp ( a ) : return { 'a' : 't' , 'c' : 'g' , 'g' : 'c' , 't' : 'a' } [ a ] def s ( a , b ) : return 1 if comp ( a ) == b else - 1 for i in range ( 1 , m + 1 ) : for j in range ( m , 0 , - 1 ) : match = dp [ i - 1 ] [ j + 1 ] + s ( x [ i - 1 ] , x [ j - 1 ] ) delete = dp [ i - 1 ] [ j ] - 1 insert = dp [ i ] [ j + 1 ] - 1 dp [ i ] [ j ] = max ( 0 , match , delete , insert ) if dp [ i ] [ j ] > max_score : max_score = dp [ i ] [ j ] max_pos = ( i , j ) i , j = max_pos seq1 , seq2 = [ ] , [ ] while dp [ i ] [ j ] > 0 : if dp [ i ] [ j ] == dp [ i - 1 ] [ j + 1 ] + s ( x [ i - 1 ] , x [ j - 1 ] ) : seq1 . append ( x [ i - 1 ] ) seq2 . append ( x [ j - 1 ] ) i -= 1 j += 1 elif dp [ i ] [ j ] == dp [ i - 1 ] [ j ] - 1 : seq1 . append ( x [ i - 1 ] ) seq2 . append ( '-' ) i -= 1 elif dp [ i ] [ j ] == dp [ i ] [ j + 1 ] - 1 : seq1 . append ( '-' ) seq2 . append ( x [ j - 1 ] ) j += 1 return '' . join ( reversed ( seq1 ) ) , '' . join ( seq2 )
Knowledge
难点思路
这道题目的难点主要在于理解和设计反向互补序列的比对算法。我们需要修改传统的局部比对算法 (Smith-Waterman 算法) 来适应这个特殊的需求。关键是要理解如何在动态规划矩阵中正确地比较序列元素,以及如何进行回溯以重构最优的子序列对。
解题技巧和信息
对于序列比对问题,通常可以考虑使用动态规划方法。
在设计动态规划算法时,要注意初始条件的设置,这往往对算法的正确性至关重要。
对于带有间隔惩罚的序列比对,通常使用仿射间隔惩罚模型 (affine gap penalty model)。
在处理 DNA 序列时,要注意互补碱基对的概念 (A-T, C-G)。
局部比对和全局比对的主要区别在于是否允许比对从序列中间开始和结束。
在处理反向互补序列时,可以通过逆序遍历一个序列来模拟反向操作,同时使用互补碱基对的映射来处理互补关系。
重点词汇
global alignment 全局比对
local alignment 局部比对
affine gap penalty 仿射间隔惩罚
reverse complementary 反向互补
dynamic programming 动态规划
traceback 回溯
subsequence 子序列
palindromic sequence 回文序列
nucleotide 核苷酸
base pair 碱基对
DNA strand DNA 链
complementary base pairing 互补碱基配对
参考资料
Durbin, R., Eddy, S. R., Krogh, A., & Mitchison, G. (1998). Biological sequence analysis: probabilistic models of proteins and nucleic acids. Cambridge university press. Chapter 2-3.
Gusfield, D. (1997). Algorithms on strings, trees, and sequences: computer science and computational biology. Cambridge university press. Chapter 11-12.