-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-sheet-10.Rmd
388 lines (232 loc) · 7.77 KB
/
exercise-sheet-10.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
---
title: "Exercise sheet 10: UPGMA"
---
---------------------------------
```{r, include=FALSE}
source("custom_functions.R")
library(flextable)
library(officer)
```
::::{#img1-p .extra-m}
::: {#img3 .tutorial-img}
A phylogenetic tree (also phylogeny or evolutionary tree [^1]) is a branching diagram or a tree showing the evolutionary relationships among various biological species or other entities based upon similarities and differences in their physical or genetic characteristics. All life on Earth is part of a single phylogenetic tree, indicating common ancestry.
*https://en.wikipedia.org/wiki/Phylogenetic_tree*
:::
::::
::::{#img1-p .extra-m}
::: {#img3 .tutorial-img}
UPGMA (Unweighted Pair Group Method with Arithmetic Mean) is a simple agglomerative or hierarchical clustering method used in bioinformatics for the creation of phylogenetic trees. UPGMA assumes a constant rate of evolution (molecular clock hypothesis), and is not a well-regarded method for inferring phylogenetic trees unless this assumption has been tested and justified for the data set being used.
*https://en.wikipedia.org/wiki/UPGMA*
:::
::::
# Exercise 1 - WPGMA
:::: {#explaining .message-box }
::: {#note-exp .note-header}
```{r, include=knitr::is_html_output(), echo=FALSE,}
knitr::include_graphics("figures/infoicon.svg")
```
**Note**
:::
::: {#note-exp .note-body}
Distances for a merged cluster $e$, where $e = c \cup d$:
$$
WPGMA: dist(x, e) = \dfrac{dist(x,c) + dist(x,d)}{2}
$$
:::
::::
In the following steps we calculate the evolutionary tree using WPGMA and the pairwise distances in the following distance matrix.
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e1.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
### 1a)
Which leaves should be selected first?
#### {.tabset }
##### Hide
##### Hint
- [ ] c and d
- [ ] a and b
- [ ] d and e
##### Solution
- [ ] c and d
- [x] a and b
- [ ] d and e
#### {-}
### 1b)
Calculate the corresponding distance for the set of leaves from *a)*.
#### {.tabset}
##### Hide
##### Solution
**1.5**
#### {-}
### 1c)
Fill in the distance matrix with the correct distances form the set of leaves
(aka. internal node) from *a)* to all other leaves.
#### {.tabset}
##### Hide
##### Solution
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e1c.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
#### {-}
### 1d)
Which nodes are joined next given the correct distance matrix from *c)*?
#### {.tabset}
##### Hide
##### Hint
- [ ] c and d
- [ ] {a,b} and e
- [ ] {c, d} and e
- [ ] e and a
##### Solution
- [x] c and d
- [ ] {a,b} and e
- [ ] {c, d} and e
- [ ] e and a
#### {-}
### 1e)
Fill in a distance matrix with the remaining nodes and leaves.
#### {.tabset}
##### Hide
##### Solution
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e1e.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
#### {-}
### 1f)
What does the **subpart** of the tree look like in Newick format after selecting and joining your answer from *e)*
:::: {#explaining .message-box }
::: {#note-exp .note-header}
```{r, include=knitr::is_html_output(), echo=FALSE,}
knitr::include_graphics("figures/infoicon.svg")
```
**Note**
:::
::: {#note-exp .note-body}
The following answers will be given in [Newick format](https://en.wikipedia.org/wiki/Newick_format).
Feel free to inspect them using an [online tool](http://www.trex.uqam.ca/index.php?action=newick&project=trex).
:::
::::
#### {.tabset}
##### Hide
##### Hint
- [ ] `((c : 3, d : 3) : 3.5, e : 3.5);`
- [ ] `((c : 3, d : 3) : 0.5, e : 3.5);`
- [ ] `((a : 1.5, b : 1.5) : 2.75, e : 4.25);`
##### Solution
- [ ] `((c : 3, d : 3) : 3.5, e : 3.5);`
- [x] `((c : 3, d : 3) : 0.5, e : 3.5);`
- [ ] `((a : 1.5, b : 1.5) : 2.75, e : 4.25);`
#### {-}
### 1g)
Following the approach from the previous exercises, what does the **whole tree** look like.
#### {.tabset}
##### Hide
##### Hint
- [ ] `((a : 1.5, b : 1.5) : 4, ((c : 3, d : 3) : 0.5, e : 3.5) : 2);`
- [ ] `((a : 1.5, b : 1.5) : 4.25, ((c : 3, d : 3) : 0.5, e : 3.5) : 2.25);`
- [ ] `(((c : 3, d : 3) : 3.5, e : 3.5): 4, (a : 1.5, b : 1.5) : 2);`
##### Solution
- [x] `((a : 1.5, b : 1.5) : 4, ((c : 3, d : 3) : 0.5, e : 3.5) : 2);`
- [ ] `((a : 1.5, b : 1.5) : 4.25, ((c : 3, d : 3) : 0.5, e : 3.5) : 2.25);`
- [ ] `(((c : 3, d : 3) : 3.5, e : 3.5): 4, (a : 1.5, b : 1.5) : 2);`
#### {-}
# Exercise 2 - UPGMA
### 2a)
Imagine using UPGMA instead of WPGMA for construction of a tree. Which of the following statements is True?
#### {.tabset}
##### Statements
- [ ] There will only be a difference in edge lengths. Overall topology will stay the same.
- [ ] The tree in Exercise 1 will not change
- [ ] UPGMA is equal to WPGMA if the number of leaves in the two clusters (|c| and |d|) is the same.
- [ ] UPGMA can end up with wrong topologies when using non-ultrametric distances.
##### Hint: Formula
$$
UPGMA: dist(x, e) = \dfrac{|c|dist(x,c) + |d|dist(x,d)}{|c| + |d|}
$$
##### Solution
- [ ] There will only be a difference in edge lengths. Overall topology will stay the same.
- [ ] The tree in Exercise 1 will not change
- [x] UPGMA is equal to WPGMA if the number of leaves in the two clusters (|c| and |d|) is the same.
- [x] UPGMA can end up with wrong topologies when using non-ultrametric distances.
#### {-}
# Exercise 3 - Ultrametric
### 3a)
Which of the following distance matrices are ultrametric?
:::: {.flex-container}
::: {#half .half}
1)
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e3_1.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
::: {#half .half}
2)
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e3_2.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
::::
:::: {.flex-container}
::: {#half .half}
3)
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e3_3.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
::: {#half .half}
4)
```{r, results="asis", include=knitr::is_html_output(), echo=FALSE}
sij <- read.csv("tables/sheet10_e3_4.csv", check.names=FALSE, sep=";")
sij_ft <- flextable(sij)
sij_ft <- custom_theme(sij_ft)
index_replace(sij_ft)
```
:::
::::
#### {.tabset}
##### Hide
##### Hint
:::: {#explaining .message-box }
::: {#note-exp .note-header}
```{r, include=knitr::is_html_output(), echo=FALSE,}
knitr::include_graphics("figures/infoicon.svg")
```
**Note**
:::
::: {#note-exp .note-body}
Definition Ultra-Metric:
\begin{align}
w(x,y) &= 0 \leftrightarrow x = y\ &\text{(identity)}\\
w(x, y) &= w(y, x)\ &\text{(symmetric)}\\
w (x, z) &\leq w (x, y ) + w (y , z) &\text{(triangle inequality)}\\
w (x, z) &\leq max\{ w (x, y ), w (y , z)\} &\text{(strong triangle inequality)}
\end{align}
:::
::::
##### Solution
**2)**
#### {-}
---------------------------------
# Exercise 4 - 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 10](https://classroom.github.com/a/8drZT6qI).
[^1]: Felsenstein, Joseph, and Joseph Felenstein. Inferring phylogenies. Vol. 2. Sunderland, MA: Sinauer associates, 2004.