-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariantAnimation-UK.Rmd
219 lines (175 loc) · 7.78 KB
/
VariantAnimation-UK.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
---
title: "Animation of projected weekly cases - United Kingdom"
output:
html_document:
df_print: paged
code_folding: hide
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
gganimate = list(
nframes = 0
),
out.width = "100%"
)
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, fig.dim = c(12, 5))
```
```{r}
suppressPackageStartupMessages({
library(covmuller)
library(COVID19)
library(tidyverse)
})
theme_set(CovmullerTheme())
```
# Get variants data for United Kingdom
```{r, warning=FALSE, message=FALSE}
gisaid_metadata <- qs::qread("~/data/epicov/metadata_tsv_2024_04_11.qs")
gisaid_United_Kingdom <- gisaid_metadata %>%
filter(Country == "United Kingdom") %>%
filter(Host == "Human")
# format metadata
gisaid_United_Kingdom <- FormatGISAIDMetadata(gisaid_United_Kingdom)
gisaid_United_Kingdom <- gisaid_United_Kingdom %>%
arrange(State, MonthYearCollected) %>%
filter(pangolin_lineage != "Unknown")
vocs <- GetVOCs()
custom_voc_mapping <- list(
`JN.1` = "JN.1",
`JN.1.*` = "JN.1",
`HV.1` = "HV.1",
`HV.1.*` = "HV.1",
`B.1` = "B.1",
`B.1.1.306` = "B.1",
`B.1.1.306.*` = "B.1",
`B.1.1.326` = "B.1",
`B.1.36.29` = "B.1",
`B.1.560` = "B.1",
`B.1.1` = "B.1",
`B.1.210` = "B.1",
`B.1.36.8` = "B.1",
`B.1.36` = "B.1",
`B.1.36.*` = "B.1"
)
gisaid_United_Kingdom <- gisaid_United_Kingdom %>% filter(pangolin_lineage != "None")
gisaid_United_Kingdom <- CollapseLineageToVOCs(
variant_df = gisaid_United_Kingdom,
vocs = vocs,
custom_voc_mapping = custom_voc_mapping,
summarize = FALSE
)
```
# Get weekly cases for United Kingdom
```{r, warning=FALSE, message=FALSE}
GetCases <- function() {
data <- read.csv("https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/cases_deaths/new_cases.csv")
confirmed <- data %>% select(date, United.Kingdom)
colnames(confirmed)[2] <- c("cases")
confirmed$MonthYear <- GetMonthYear(confirmed$date)
confirmed$WeekYear <- tsibble::yearweek(confirmed$date)
return(confirmed)
}
GetCasesLong <- function() {
data <- read.csv("https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/cases_deaths/new_cases.csv")
confirmed <- data %>% select(date, United.Kingdom)
colnames(confirmed)[2] <- c("cases")
confirmed$cases[is.na(confirmed$cases)] <- 0
confirmed$MonthYear <- GetMonthYear(confirmed$date)
confirmed$WeekYear <- tsibble::yearweek(confirmed$date)
confirmed_subset_weekwise <- confirmed %>%
group_by(WeekYear) %>%
summarise(cases = mean(cases, na.rm = T)) %>%
arrange(WeekYear)
confirmed_subset_weekwise$cases <- ceiling(confirmed_subset_weekwise$cases)
confirmed_subset_dateweekwise_long_india <- confirmed_subset_weekwise %>%
rename(n = cases) %>%
rename(WeekYearCollected = WeekYear)
}
confirmed <- GetCases()
confirmed_subset_dateweekwise_long <- GetCasesLong()
gisaid_United_Kingdom_weekwise <- SummarizeVariantsWeekwise(gisaid_United_Kingdom)
```
# Distribution of variants
```{r, fig.width=12, fig.height=5}
state_month_counts <- SummarizeVariantsMonthwise(gisaid_United_Kingdom)
state_month_counts$State <- "United Kingdom"
state_month_prevalence <- CountsToPrevalence(state_month_counts)
vocs <- GetVOCs()
state_month_prevalence <- CollapseLineageToVOCs(
variant_df = state_month_prevalence,
vocs = vocs,
custom_voc_mapping = custom_voc_mapping, summarize = FALSE
)
p5 <- StackedBarPlotPrevalence(state_month_prevalence)
p5
```
# Project weekly cases to variant prevalence data from GISAID
```{r, warning=FALSE, message=FALSE}
voc_to_keep <- gisaid_United_Kingdom_weekwise %>%
group_by(lineage_collapsed) %>%
summarise(n_sum = sum(n)) %>%
filter(n_sum > 50) %>%
pull(lineage_collapsed) %>%
unique()
gisaid_United_Kingdom_weekwise <- gisaid_United_Kingdom_weekwise %>% filter(lineage_collapsed %in% voc_to_keep)
United_Kingdom_cases_pred_prob_sel_long <- FitMultinomWeekly(gisaid_United_Kingdom_weekwise, confirmed_subset_dateweekwise_long)
the_anim <- PlotVariantPrevalenceAnimated(United_Kingdom_cases_pred_prob_sel_long, title = "Estimated cases (weekly average) in United Kingdom by variant", caption = "**Source: gisaid.org and ourworldindata.org/coronavirus**<br>", date_breaks = "120 days")
gganimate::anim_save(filename = here::here("docs/articles/United_Kingdom_animated.gif"), animation = the_anim)
```
![](United_Kingdom_animated.gif)
Look at cases from 2022,
```{r}
confirmed_subset_dateweekwise_long <- GetCasesLong() %>%
filter(WeekYearCollected >= tsibble::yearweek("2021 W35"))
gisaid_United_Kingdom_subset <- gisaid_United_Kingdom %>% filter(MonthYearCollected > "Oct 2021")
gisaid_United_Kingdom_weekwise <- SummarizeVariantsWeekwise(gisaid_United_Kingdom_subset)
voc_to_keep <- gisaid_United_Kingdom_weekwise %>%
group_by(lineage_collapsed) %>%
summarise(n_sum = sum(n)) %>%
filter(n_sum > 50) %>%
pull(lineage_collapsed) %>%
unique()
gisaid_United_Kingdom_weekwise <- gisaid_United_Kingdom_weekwise %>% filter(lineage_collapsed %in% voc_to_keep)
United_Kingdom_cases_pred_prob_sel_long <- FitMultinomWeekly(gisaid_United_Kingdom_weekwise, confirmed_subset_dateweekwise_long)
the_anim <- PlotVariantPrevalenceAnimated(United_Kingdom_cases_pred_prob_sel_long, title = "Estimated cases (weekly average) in United Kingdom by variant", caption = "**Source: gisaid.org and ourworldindata.org/coronavirus**<br>", date_breaks = "90 days")
gganimate::anim_save(filename = here::here("docs/articles/United_Kingdom_animated_2021.gif"), animation = the_anim)
```
![](United_Kingdom_animated_2021.gif)
Look at cases from 2023
```{r}
confirmed_subset_dateweekwise_long <- GetCasesLong() %>%
filter(WeekYearCollected >= tsibble::yearweek("2022 W35"))
gisaid_United_Kingdom_subset <- gisaid_United_Kingdom %>% filter(MonthYearCollected > "October 2022")
gisaid_United_Kingdom_weekwise <- SummarizeVariantsWeekwise(gisaid_United_Kingdom_subset)
voc_to_keep <- gisaid_United_Kingdom_weekwise %>%
group_by(lineage_collapsed) %>%
summarise(n_sum = sum(n)) %>%
filter(n_sum > 50) %>%
pull(lineage_collapsed) %>%
unique()
gisaid_United_Kingdom_weekwise <- gisaid_United_Kingdom_weekwise %>% filter(lineage_collapsed %in% voc_to_keep)
United_Kingdom_cases_pred_prob_sel_long <- FitMultinomWeekly(gisaid_United_Kingdom_weekwise, confirmed_subset_dateweekwise_long)
the_anim <- PlotVariantPrevalenceAnimated(United_Kingdom_cases_pred_prob_sel_long, title = "Estimated cases (weekly average) in United Kingdom by variant", caption = "**Source: gisaid.org and ourworldindata.org/coronavirus**<br>", date_breaks = "90 days")
gganimate::anim_save(filename = here::here("docs/articles/United_Kingdom_animated_2023.gif"), animation = the_anim)
```
![](United_Kingdom_animated_2023.gif)
Look at cases in the past few weeks
```{r}
confirmed_subset_dateweekwise_long <- GetCasesLong() %>%
filter(WeekYearCollected >= tsibble::yearweek("2023 W23"))
gisaid_United_Kingdom_subset <- gisaid_United_Kingdom %>% filter(MonthYearCollected > "June 2023")
gisaid_United_Kingdom_weekwise <- SummarizeVariantsWeekwise(gisaid_United_Kingdom_subset)
voc_to_keep <- gisaid_United_Kingdom_weekwise %>%
group_by(lineage_collapsed) %>%
summarise(n_sum = sum(n)) %>%
filter(n_sum > 50) %>%
pull(lineage_collapsed) %>%
unique()
gisaid_United_Kingdom_weekwise <- gisaid_United_Kingdom_weekwise %>% filter(lineage_collapsed %in% voc_to_keep)
United_Kingdom_cases_pred_prob_sel_long <- FitMultinomWeekly(gisaid_United_Kingdom_weekwise, confirmed_subset_dateweekwise_long)
the_anim <- PlotVariantPrevalenceAnimated(United_Kingdom_cases_pred_prob_sel_long, title = "Estimated cases (weekly average) in United Kingdom by variant", caption = "**Source: gisaid.org and ourworldindata.org/coronavirus**<br>")
gganimate::anim_save(filename = here::here("docs/articles/United_Kingdom_animated_2024.gif"), animation = the_anim)
```
![](United_Kingdom_animated_2024.gif)