-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-sheet-3.Rmd
444 lines (256 loc) · 8.78 KB
/
exercise-sheet-3.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
---
title: "Exercise sheet 3: structure probability"
---
```{r, include=FALSE}
source("assets/custom_functions.R")
library(flextable)
library(officer)
```
---------------------------------
# Exercise 1 - entropy
<!--- --------------------------------- -->
We want to have a short look at the concept of entropy.
Let $X$ be a discrete random variable with probabilities $p(i), (i=1,2,\ldots,n)$.
The amount of information to be associated with an outcome of probability $p(i)$
is defined as $I(p(i)) = \log_2(\frac{1}{p(i)})$.
In information theory, the expected value of the information $I(X)$ for the random variable $X$ is called entropy.
The entropy is given by
$$H(X) = E[I(X)] = \sum_{i=1}^{n}p(i)\log_2(\frac{1}{p(i)}).$$
Note that all logarithms in this exercise are base 2 (standard in information theory).
<!--- --------------------------------- -->
### 1.1
::: {.question data-latex=""}
Compute the entropy of the probability distribution $p(1) = \frac{1}{2},\, p(2) = \frac{1}{4},\, p(3) = \frac{1}{8},\, p(4) = \frac{1}{8}$.
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
Compute the expected value of the information of the random variable $E[I(X)]$ or entropy $H(X)$ as described above.
:::
##### Solution
::: {.answer data-latex=""}
\[
\begin{align*}
H(X) & = p(1)\log\left(\frac{1}{p(1)}\right) + p(2)\log\left(\frac{1}{p(2)}\right) + p(3)\log\left(\frac{1}{p(3)}\right) + p(4)\log\left(\frac{1}{p(4)}\right)\\
& = \frac{1}{2} + \frac{2}{4} + \frac{3}{8} + \frac{3}{8}\\
& = \frac{14}{8}
\end{align*}
\]
:::
#### {-}
<!--- --------------------------------- -->
### 1.2
::: {.question data-latex=""}
Compute the entropy of the distribution $p(i) = \frac{1}{4},\: (i= 1,2,3,4)$.
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
\[
\begin{align*}
H(X) & = & 4 \cdot p(i) \log(\frac{1}{p(i)})\\
& = & 2
\end{align*}
\]
:::
#### {-}
<!--- --------------------------------- -->
### 1.3
::: {.question data-latex=""}
How can you explain the difference in entropy for both probability distributions?
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
Which of the two probability distributions has the higher information content, because you know more about an event before an event happened?
:::
##### Solution
::: {.answer data-latex=""}
For the probability distribution in part 1. the information content of the probability distribution is higher than for 2. as we get more information from the distribution itself (e.g. we know that we are more likely to observe i=1).\\
The information content for the event is higher for part 2. as we can learn more from the event (see coin example from the lecture).
This results in a higher entropy for the probability distribution in part 2..
:::
#### {-}
<!--- --------------------------------- -->
# Exercise 2 - partition function
<!--- --------------------------------- -->
Given the RNA sequence `AUCACCGC` and a minimal loop length of $1$.
Compute the partition function of the molecule using an energy function similar to the Nussinov algorithm:
$$
E(P) = |P|
$$
that is the energy is the number of non-crossing base pairs of a given structure
(only GC and AU pairs are to be considered).
Table of Boltzmann weights for $RT = 1$:
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("assets/tables/exercise-sheet-3/boltzmann-weights.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
<!--- --------------------------------- -->
### 2.1
::: {.question data-latex=""}
Compute $Z$ via exhaustive structure space enumeration. (using the provided Boltzmann weights)
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
To compute Z you need to know all possible structures.
:::
##### Solution
::: {.answer data-latex=""}
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("assets/tables/exercise-sheet-3/e3-1.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
#### {-}
<!--- --------------------------------- -->
### 2.2
::: {.question data-latex=""}
Compute the structure probability for each structure.
:::
#### {.tabset}
##### Hide
##### Formula
::: {.answer data-latex=""}
$$ Pr[P|S] = \frac{e^(-\frac{E(P)}{RT})}{\sum_{P'} e^(-\frac{E(P)}{RT})} $$
:::
##### Solution
::: {.answer data-latex=""}
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("assets/tables/exercise-sheet-3/e3-2.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
#### {-}
<!--- --------------------------------- -->
### 2.3
::: {.question data-latex=""}
Compare the structure probabilities in relation to each other. What is the structure probability of the open chain? What can you observe?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
The open chain is more likely than any other structure including the optimal structure (here $P=\{(2,4)(5,7)\}$).
:::
#### {-}
<!--- --------------------------------- -->
### 2.4
::: {.question data-latex=""}
Is this result expected?
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
Base pairs usually stabilize a structure.
:::
##### Solution
::: {.answer data-latex=""}
This is not expected, the open chain should not have a higher probability than the optimal structure.
:::
#### {-}
<!--- --------------------------------- -->
### 2.5
::: {.question data-latex=""}
If not how can you fix it? Test your idea by recalculating the structure probabilities!
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
How can you ensure that the open chain gets the lowest Boltzmann weight without changing the idea of scoring the number of base pairs for computing the energy of a structure?
:::
##### Solution
::: {.answer data-latex=""}
The reason why the open chain has the highest probability is because the Bolzmann weight decreases with an increasing number of base pairs.
The solution is to negate the energy function, i.e. $E(P) = -|P|$
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("assets/tables/exercise-sheet-3/e3-3_1.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("assets/tables/exercise-sheet-3/e3-3_2.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
We can now search for the optimal structure by energy minimization and the mfe structure is the most probable structure, as expected.
:::
#### {-}
<!--- --------------------------------- -->
# Exercise 3 - Base pair and unpaired probabilities
<!--- --------------------------------- -->
Given the corrected probabilities of the previous exercise for sequence `AUCACCGC`.
<!--- --------------------------------- -->
### 3.1
::: {.question data-latex=""}
Compute and visualize the base pair probabilities in a dot-plot using your corrected energy function. (use the probability values instead of dots.)
:::
#### {.tabset}
##### Hide
##### Formula
::: {.answer data-latex=""}
Compute the base pair probabilities:
$$ PR[(i,j)|S] = \sum_{P \ni (i,j)} Pr[P|S] $$
:::
##### Solution
::: {.answer data-latex=""}
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='50%'}
knitr::include_graphics("assets/figures/exercise-sheet-3/e4-1.png")
```
:::
#### {-}
<!--- --------------------------------- -->
### 3.2
::: {.question data-latex=""}
Compute the probability $P^u(4)$ and $P^u(5)$ to be unpaired at sequence position 4 and 5, resp., and $P^u(4,5)$ that the subsequence $4..5$ is not involved in any base pairing.
:::
#### {.tabset}
##### Hide
##### Formula
::: {.answer data-latex=""}
$$ PR_{u}[(i,j)] = \frac{Z_{i,j}^u}{Z} $$
:::
##### Solution
::: {.answer data-latex=""}
$$
\begin{align*}
P^u(4) &= 0.06 + 0.16 + 0.16 = 0.38\\
P^u(5) &= 0.06 + 0.16 + 0.16 = 0.38\\
P^u(4,5) &= 0.06 + 0.16 = 0.22
\end{align*}
$$
:::
#### {-}
<!--- --------------------------------- -->
### 3.3
::: {.question data-latex=""}
Why can't we compute $P^u(4,5)$ from $P^u(4)$ and $P^u(5)$ using their product, i.e. why is $P^u(4,5) \neq P^u(4)\cdot P^u(5)$?
:::
#### {.tabset}
##### Hide
##### Hint
::: {.answer data-latex=""}
Are $P^u(4)$ and $P^u(5)$ independent?
:::
##### Solution
::: {.answer data-latex=""}
The set of structures considered for $P^u(4,5)$ is a subset of both structure sets used to compute $P^u(4)$ and $P^u(5)$.
Thus, the two probabilities are not independent and can not be multiplied.
:::
#### {-}
<!--- --------------------------------- -->