-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-sheet-4.Rmd
414 lines (274 loc) · 10.5 KB
/
exercise-sheet-4.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
```{r, include=FALSE}
source("custom_functions.R")
library(flextable)
library(officer)
```
---
title: "Exercise sheet 4: Sequence Alignment - affine gap costs"
---
---------------------------------
# Exercise 1 - Waterman-Smith-Beyer traceback
Within the algorithm of Waterman, Smith and Beyer arbitrarily large gaps are considered.
Thus, also the traceback has to investigate all gap sizes. This can be done following two strategies:
- check in increasing gap length (start with smallest gap)
- check in decreasing gap length (start with largest gap)
### 1a)
Given a gap function, are the strategies
(measured in absolute runtime or number operations) expected to be equally
performant or is one of them better than the other?
#### {.tabset}
##### Hide
##### Possible Answers
::: {.answer data-latex=""}
- [ ] both are equally performant.
- [ ] checking in increasing direction performs better
- [ ] checking in decreasing direction performs better
:::
##### Solution
::: {.answer data-latex=""}
- [x] both are equally performant.
- [ ] checking in increasing direction performs better
- [ ] checking in decreasing direction performs better
(You still have to check all possible gap sizes)
:::
#### {-}
### 1b)
Does the order of checking insertion and deletions change the runtime?
#### {.tabset}
##### Hide
##### Possible Answers
::: {.answer data-latex=""}
- [ ] yes, checking insertions first will perform better
- [ ] yes, checking deletions first will perform better
- [ ] no, the order doesn't affect performance
- [ ] checking in an alternating way might improve performance
:::
##### Solution
::: {.answer data-latex=""}
- [ ] yes, checking insertions first will perform better
- [ ] yes, checking deletions first will perform better
- [x] no, the order doesn't affect performance
- [ ] checking in an alternating way might improve performance
(You still have to check all possible gaps and sizes)
:::
#### {-}
# Exercise 2 - Gotoh Algorithm
Consider the following sequences $S1$ , $S2$ and the similarity scoring via $s(x, y)$ and $g(k)$.
\begin{align}
S1 &= TCCGA\\
S2 &= TACGCAGA\\
s(x,y) &=
\begin{cases}
+1 & if\ x = y \\
0 & else\\
\end{cases}\\
g(k) &= -4 - 1 * k
\end{align}
### 2a)
Which optimization scheme (minimization/maximization) needs to be applied to generate
a useful sequence alignment.
#### {.tabset}
##### Hide
##### Solution
Maximization since we are scoring a similarity and not a distance.
#### {-}
### 2b)
Fill the dynamic programming matrices $D_{i,j}$, $Q_{i,j}$ and $P_{i,j}$ using the Gotoh algorithm!
(Remember: $D_{i,j}$ is the match/mismatch matrix. $Q_{i,j}$ corresponds to gaps in $S1$ whilst $P_{i,j}$ corresponds to gaps in $S2$)
#### {.tabset}
##### Hide
##### Hint1: Init Formulae
\begin{align}
D_{0,0} &= 0 \\
D_{0, j} &= g(j) &\forall j: 0 < j \leq n \\
D_{i, 0} &= g(j) &\forall i: 0 < i \leq n \\
Q_{i, 0} &= -\infty &\forall i: 0 < i \leq n \\
P_{0, j} &= -\infty &\forall j: 0 < j \leq n
\end{align}
##### Hint2: Formulae
\begin{align}
g(k) &= \alpha + k * \beta \\
\\
D_{i,j} &= max
\begin{cases}
D_{i-1, j-1} + s(a_i, b_i)\\
P_{i, j}\\
Q_{i,j}
\end{cases}\\
\\
Q_{i,j} &= max
\begin{cases}
D_{i, j-1} + g(1)\\
Q_{i, j-1} + \beta\\
\end{cases}\\
\\
P_{i,j} &= max
\begin{cases}
D_{i-1, j} + g(1)\\
P_{i-1, j} + \beta\\
\end{cases}
\end{align}
##### Hint3: Add the missing values
```{r, include=FALSE}
dij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(" ", " ", " ", " ", " ", " " ),
c = c(" ", " ", " ", -5, -6, -7 ),
d = c(" ", " ", " ", -4, -5, -5 ),
e = c(" ", " ", " ", 2, -3, -4 ),
f = c(" ", " ", " ", -3, 3, -2 ),
g = c(" ", -7, -5, -4, " " , " "),
h = c(" ", -8, -7, -5, " " , " "),
i = c(" ", -9, -8, -6, " " , " "),
j = c(" ", -10, -9, -7, " " , " ")
)
names(dij) <- c("D_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, include=FALSE}
qij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(" ", " ", " ", " ", " ", " " ),
c = c(" ", " ", " ", -12, -13, -14 ),
d = c(" ", " ", " ", -10, -11, -12 ),
e = c(" ", " ", " ", -9, -10, -10 ),
f = c(" ", -6, -5, -3, " " , " "),
g = c(" ", -7, -6, -4, " " , " "),
h = c(" ", -8, -7, -5, " " , " "),
i = c(" ", -9, -8, -6, " " , " "),
j = c(" ", -10, -9, -7, " " , " ")
)
names(qij) <- c("Q_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, include=FALSE}
pij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(" ", " ", " ", " ", " ", " " ),
c = c(" ", " ", " ", -5, -6, -7 ),
d = c(" ", " ", " ", -4, -5, -6 ),
e = c(" ", " ", " ", -8, -3, -4 ),
f = c(" ", -13, -11, -10, " " , " "),
g = c(" ", -14, -12, -10, " " , " "),
h = c(" ", -15, -13, -12, " " , " "),
i = c(" ", -16, -14, -13, " " , " "),
j = c(" ", -17, -15, -14, " " , " ")
)
names(pij) <- c("P_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
dij_ft <- flextable(dij)
dij_ft <- custom_theme(dij_ft)
index_replace(dij_ft)
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
qij_ft <- flextable(qij)
qij_ft <- custom_theme(qij_ft)
index_replace(qij_ft)
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
pij_ft <- flextable(pij)
pij_ft <- custom_theme(pij_ft)
index_replace(pij_ft)
```
##### Solution
```{r, include=FALSE}
dij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(0, -5, -6, -7, -8, -9 ),
c = c(-5, 1, -4, -5, -6, -7 ),
d = c(-6, -4, 1, -4, -5, -5 ),
e = c(-7, -5, -3, 2, -3, -4 ),
f = c(-8, -6, -5, -3, 3, -2 ),
g = c(-9, -7, -5, -4, -2 , 3),
h = c(-10, -8, -7, -5, -3 , -1),
i = c(-11, -9, -8, -6, -4 , -3),
j = c(-12, -10, -9, -7, -5 , -3)
)
names(dij) <- c("D_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, include=FALSE}
qij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(0, "-inf", "-inf", "-inf", "-inf", "-inf" ),
c = c(0, -10, -11, -12, -13, -14 ),
d = c(0, -4, -9, -10, -11, -12 ),
e = c(0, -5, -4, -9, -10, -10 ),
f = c(0, -6, -5, -3, -8 , -9),
g = c(0, -7, -6, -4, -2 , -7),
h = c(0, -8, -7, -5, -3 , -2),
i = c(0, -9, -8, -6, -4, -3),
j = c(0, -10, -9, -7, -5, -4)
)
names(qij) <- c("Q_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, include=FALSE}
pij <- data.frame(a = c("-", "T", "C", "C", "G", "A" ),
b = c(0, 0, 0, 0, 0, 0 ),
c = c("-inf", -10, -4, -5, -6, -7 ),
d = c("-inf", -11, -9, -4, -5, -6 ),
e = c("-inf", -12, -10, -8, -3, -4 ),
f = c("-inf", -13, -11, -10, -8 , -2),
g = c("-inf", -14, -12, -10, -9 , -7),
h = c("-inf", -15, -13, -12, -10 , -8),
i = c("-inf", -16, -14, -13, -11 , -9),
j = c("-inf", -17, -15, -14, -12 , -10)
)
names(pij) <- c("P_{i,j}", "-", "T1", "A1", "C1", "G1", "C2", "A2", "G2", "A3")
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
dij_ft <- flextable(dij)
dij_ft <- custom_theme(dij_ft)
index_replace(dij_ft)
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
qij_ft <- flextable(qij)
qij_ft <- custom_theme(qij_ft)
index_replace(qij_ft)
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
pij_ft <- flextable(pij)
pij_ft <- custom_theme(pij_ft)
index_replace(pij_ft)
```
#### {-}
### 2c)
Calculate all optimal alignments and the corresponding score!
#### {.tabset}
##### Hide
##### Solution
Score: -3
```
T---CCGA TCC---GA TCCG---A
| |:|| |:| || |:|| |
TACGCAGA TACGCAGA TACGCAGA
```
#### {-}
### 2d)
Calculate the alignments using the Waterman-Smith-Beyer algorithm instead.
#### {.tabset}
##### Hide
##### Solution
The same alignments as in (3c), since the same scoring function is optimized.
Calculation is just less efficient.
#### {-}
---------------------------------
# Exercise 3 - Programming assignment
Programming assignments are available via Github Classroom and contain automatic tests.
We recommend doing these assignments since they will help you to further understand this topic.
Access the Github Classroom link: [Programming Assignment: Sheet 04](https://classroom.github.com/a/ZyJHAOPL).
-------------------------------------------
# Preparing for the Exam
Below you find an interactive tool that allows you to create dynamic programming matrices to practice for the exam.
You can fill in the table and check which values are correct via the Check Matrix button. Correctly filled cells will turn green. Please specify infitnity values via -inf or inf
Once you filled in the cells, you can trigger the traceback mode toggle. This will disable the input fields. However, you can now select cells that are part of a traceback. While in traceback mode you can click the Check Traceback button. If you completely marked a correct traceback it will get a green border. Else marked cells will get a red border.
:::: {#explaining .warning-box }
::: {#note-exp .warning-header}
```{r, include=knitr::is_html_output(), echo=FALSE,}
knitr::include_graphics("figures/warningicon.svg")
```
**Warning**
:::
::: {#note-exp .note-body}
This tool is in beta and might contain bugs.
:::
::::
```{r, echo=FALSE}
htmltools::includeHTML("html/Gotoh.html")
```
```{r, echo=FALSE}
htmltools::tags$script(src = "assets/js/gotoh.js", type= "text/javascript")
```