-
Notifications
You must be signed in to change notification settings - Fork 4
/
phylogenetics.Rmd
58 lines (44 loc) · 1.4 KB
/
phylogenetics.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
# Phylogenetic data
[@Rambaut2020Nov]
[@Singer2020Jun]
```{r message=FALSE}
library(sars2pack)
library(ggplot2)
library(dplyr)
library(ggtree)
library(ape)
library(stringr)
```
```{r message=FALSE}
ntr = cov_glue_newick_data()
```
see See Figure \@ref(fig:ggtreeNewick)
```{r ggtreeNewick,out.width='100%',fig.width=12,fig.height=12,fig.cap='abc'}
groups = str_match(ntr$tip.label,'.*_([A-Z][\\.]?[0-9]?[0-9]?).*')
ntr = groupOTU(ntr, split(ntr$tip.label,groups[,2]))
ggtree(ntr, aes(color=group), layout="circular", branch.length="none") +
geom_tiplab(size=3, aes(angle=angle)) +
ggtitle('COVID Glue Phylogenetic Clades')
```
```{r warning=FALSE}
dat = cov_glue_lineage_data()
dat = dat %>%
dplyr::mutate(lineage = sub('^([^.][.]?[^.]+).*', '\\1', lineage)) %>%
dplyr::mutate(region = countrycode::countrycode(country,origin='country.name',
destination='region')) %>%
dplyr::group_by(epiweek,lineage,region) %>%
dplyr::summarize(cases=n()) %>%
dplyr::filter(!is.na(region)) %>%
dplyr::ungroup()
head(dat)
```
```{r lineageSpread,fig.height=12,fig.width=10,out.width='100%', warning=FALSE}
p = dat %>%
ggplot(aes(x=epiweek,y=cases,fill=lineage)) +
geom_bar(stat='identity', position='fill') +
facet_wrap("region",ncol=2) +
theme(legend.position='bottom')
p
```
## Notes
- https://nextstrain.org/help/general/how-to-read-a-tree