-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathselection.Rmd
469 lines (381 loc) · 25.6 KB
/
selection.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
```{r, warning=FALSE, message=FALSE, echo=FALSE}
source("scripts/plot_selection_estimator.R")
#define starting parameters (p,s) for making the selection estimates
#startpar <- list(p=c(0.2, 0.05), s=c(0.05, 0.1))
startpar <- list(p=c(0.2, 0.05, 0.01), s=c(0.05, 0.05, 0.01))
#filter samples with variants of interest
setAll=getAllStrictoLineages(meta)
#sublineages_BQ <- getStrictoSubLineages("BQ*",meta) #BQ variants
#sublineages_XBB <- getStrictoSubLineages("XBB*",meta) #XBB variants
#sublineages_EG5 <- getStrictoSubLineages("EG.5*",meta)
# sublineage_hv1 <- getStrictoSubLineages("HV.1*",meta)
# sublineages_XBBOther <- sublineages_XBB[!sublineages_XBB %in% c(sublineage_hv1)] #XBB Other
#sublineages_XBBOther <- sublineages_XBB[!sublineages_XBB %in% c(sublineages_EG5,sublineage_hv1)] #XBB Other
#setAll=setAll[!setAll %in% c(sublineages_BQ, sublineages_XBB)] #the rest
sublineage_XEC <- getStrictoSubLineages("XEC*",meta)
sublineage_MC <- getStrictoSubLineages("MC.*", meta)
sublineage_MC <- sublineage_MC[!sublineage_MC %in% c(sublineage_XEC)]
sublineage_KP3 <- getStrictoSubLineages("KP.3*",meta)
sublineage_KP3 <- sublineage_KP3[!sublineage_KP3 %in% c(sublineage_XEC, sublineage_MC)]
# sublineage_KP3 <- getStrictoSubLineages("KP.3*",meta)
# sublineage_MC <- getStrictoSubLineages("MC.*", meta)
# sublineage_KP <- getStrictoSubLineages("KP.*",meta)
# sublineage_KP_other <- sublineage_KP[!sublineage_KP %in% c(sublineage_KP3, sublineage_MC)]
# sublineage_jn1 <- getStrictoSubLineages("JN.1*",meta)
# sublineage_jn1 <- sublineage_jn1[!sublineage_jn1 %in% c(sublineage_KP, sublineage_KP3)] #XBB Other
# sublineage_jn1.11 <- getStrictoSubLineages("JN.1.11*",meta)
# sublineage_jn1 <- sublineage_jn1[!sublineage_jn1 %in% sublineage_jn1.11] #XBB Other
sublineages_other<-setAll[!setAll %in% c(sublineage_XEC, sublineage_MC, sublineage_KP3)] #the rest
reference = sublineage_KP3
#this list defines the mutants we are looking at for plotting. The order of mutants listed will be respected on the respective plots.
#!!!last element is always the reference.
mutants = list(sublineage_XEC, sublineage_MC, sublineages_other)
mutantNames = list("XEC*", "MC*","Others", "KP.3*") #
col <- c("XEC*"=pal["XBB"], "MC*" = "#00eeff","Others"="#CC5500") #define custom color for XBB here because otherwise it will be black cuz recombinant.
#SALLY:SUGGEST THAT WE ADD A FLAG HERE IF THE FOLLOWING ISN'T ZERO
#this check ensures that we dont have overlapping groups in which 1 lineage is present in multiple groups.
if(length(reference)+length(Reduce(union,mutants)) -3 != length(setAll)){
warn("sublineage groups used for selection plots might contain lineages that are in multiple groups.")
}
#wrapper for calling plot.selection.estimate.ggplot() to avoid passing in the same local variables multiple time anjd to include a trycatch statement to show empty plots.
sub.plot.selection.estimate <- function(region,maxdate=NA){
#plot.selection.estimate.ggplot() returns a named list of data used for plotting the case count selection curves, see the function documentation for details.
obj <- tryCatch(
{
obj=plot.selection.estimate.ggplot(region=region,
startdate=startdate, startpar=startpar,
reference=c(reference),
mutants=mutants,
names=mutantNames,
maxdate=maxdate, col=col,
includeReference = T)
},
error=function(cond){
#print(cond)
obj= (list("plot1"=NULL, "plot2"=cond))
})
return(obj)
}
# #calculate estimates for each province
selectionEstimateFits <- list() #named list to store estimates for different provinces
# selectionEstimateFits[["Canada"]] = sub.plot.selection.estimate(region="Canada", maxdate)
# #maxdate = selectionEstimateFits[["Canada"]]$date
for (i in 1:length(all.regions$name)){
selectionEstimateFits[[all.regions$shortname[[i]]]] = sub.plot.selection.estimate(region=all.regions$name[[i]], enddate)
}
#temporarily remove the NS plots because there is just too little data and it mucks up everything
# selectionEstimateFits[["NS"]]$plot1 <- NULL
# selectionEstimateFits[["NS"]]$plot2 <- NULL
# selectionEstimateFits[["NL"]]$plot1 <- NULL
# selectionEstimateFits[["NL"]]$plot2 <- NULL
```
# Selection on recent variants
## {.tabset .tabset-fade .unlisted .unnumbered .toc-ignore}
Here we examine the relative rate of spread of the different sublineages of SARS-CoV-2 currently circulating in Canada. Specifically, we determine if a new or emerging lineage has a selective advantage (s), and by how much, against a previously common reference lineage (broad scale (and in the Fastest Growing Lineages section): `r mutantNames[length(mutantNames)]` and at the fine scale, against `r individualSelectionPlotReference[[1]]`; see [methods](#appendix) for more details about selection and how it is estimated).
Currently, the major group of SARS-CoV-2 lineages circulating are BA.2.86\* variants, particularly JN.1 and its descendants. Thus, at the broad scale, we are currently track the frequencies of JN.1\* descendants other than KP.3\*, KP.3\* descendants, XBB descendants and other BA.2 lineages (mainly BA.2.86 lineages not in JN.1\*).
Left plot: y-axis is the proportion of these sub-lineages over time. Right plot: y-axis describes the logit function, log(freq(`r mutantNames[-length(mutantNames)]`)/freq(`r mutantNames[length(mutantNames)]`)), which gives a straight line whose slope is the selection coefficient if selection is constant over time (see methods).
For comparison, Alpha had a selective advantage of s ~ 6%-11% per day over preexisting SARS-CoV-2 lineages, and Delta had a selective advantage of about 10% per day over Alpha.
**Caveat:** These selection analyses must be interpreted with caution due to the potential for non-representative sampling, lags in reporting, and spatial heterogeneity in prevalence of different sublineages across Canada. Provinces that do not have at least 20 sequences of a lineage during this time frame are not displayed.
```{r, warning=FALSE, message=FALSE, fig.height=8, fig.width5, warning=FALSE, out.width="50%", results='asis', echo=FALSE}
#display all selection plots with each province as a tab.
apply(all.regions,1,function(reg){
cat("###", reg[["shortname"]], " {.unlisted .unnumbered}\n")
n_min=20
if(reg[["name"]]=="Canada"){n_min=50}
cat("####",reg[["name"]],"\n","\n")
if (is.null(selectionEstimateFits[[reg[["shortname"]]]]$plot1))
#uncomment these to pring the error msg instead of some generic error
# {print(getEmptyErrorPlotWithMessage(selectionEstimateFits[[reg[["shortname"]]]]$plot2))
# print(getEmptyErrorPlotWithMessage(selectionEstimateFits[[reg[["shortname"]]]]$plot2))}
{print(getEmptyErrorPlotWithMessage("Not enough data available."))
print(getEmptyErrorPlotWithMessage("Not enough data available."))}
else {
print(selectionEstimateFits[[reg[["shortname"]]]]$plot1)
print(selectionEstimateFits[[reg[["shortname"]]]]$plot2)
}
cat("\n\n")})
```
# Detection trends by variant
## {.tabset .tabset-fade .unlisted .unnumbered .toc-ignore}
These plots follow the number of detected cases per 100,000 individuals (green dots), ignoring the most recent week (hollow circles), which is generally underestimated as data continue to be gathered. A cubic spline is fit to the log of these case counts to illustrate trends (top curve). The last two days of inferred case counts are then used to estimate the daily exponential growth rate r in COVID-19 cases. The fit from the “Selection on Omicron” section above is used to show how each of the sub-lineages is growing or shrinking, with the corresponding growth rate $r$ for each sub-lineage on the last two days of inferred case counts. Note that only a small fraction of cases are currently being officially tested, so the y-axis height is underestimated by orders of magnitude (e.g., by 92-fold in BC mid-2022, Skowronski et al. 2022). Thus, graphs should only be used to describe growth trends and not absolute numbers. For detailed methodology including a change in case data source on 13 July 2024, please see the methods section in the [appendix.](#appendix).
```{r case count selection estimator setup, echo=FALSE, message=F, warning=F}
source("scripts/plot_case_count_selection_estimator.R")
#loads in the case count data for each province into a named list.
caseData <- parsePositivityData(all.regions, params$datestamp, params$datadir)
#loads in population data for /100000invidivudal normalization
populationData <- read.table("resources/CanadianPopulation.tsv", header=T, sep='\t', check.names = F)
#view(caseCountData)
#' function used to generate data required case count selection plots.
#' @param caseCountData The case counts for a specific province. i.e. one item in variable caseData
#' @param selectionEstimateObject The selection estimate object for a specific province. i.e. one item in variable selectionEstimateFits
#' @param filename String. If not NA, it will save a local copy of a plot to $PWD
plotCaseCountSelection <- function(caseCountData, selectionEstimateObject, saveToFile=F){
# #
# caseCountData<-caseData[["Canada"]]
# selectionEstimateObject<-selectionEstimateFits[["Canada"]]
if (selectionEstimateObject$region == "Canada"){
dayToCut = 1
#caseCountData <- head(caseCountData, -1)
} else {
dayToCut = 1
} #define the number of days since most recent data date as "underreported"
#populate a column with reporting accuracy (Accurate | UnderReported])
caseCountData$report_type <- "Accurate"
caseCountData$report_type[(nrow(caseCountData)-dayToCut+1):nrow(caseCountData)] <- "UnderReported"
caseCountData$n <- as.numeric(caseCountData$n) #convert the column to numeric type. For some reason, as of Jan 08, 2024, this column is parsed as character.
caseCountData <- caseCountData[!(caseCountData$report_type=="Accurate" & is.na(caseCountData$n)),]#populate empty cells with 1 because we have to log10 it later
#construct a spline fit for the accurate case counts only
caseFitModel <- getCaseCountSmoothFitWithLambda(caseCountData %>% filter(report_type=="Accurate"))# %>% filter(!is.na(n)))
#extract the y-values for the fit
caseFitLineValues <- 10^(caseFitModel$y)
#extend the previous fit for the "underreported dates" and extract the y values
caseFitLinePredictedValues <- c((10^(predict(caseFitModel, data.frame(x=(nrow(caseCountData)-dayToCut+1):nrow(caseCountData)))[[2]]))$x)
#merge the accurate and underreported case count fit lines and construct a DF with X, and metadata
caseCountFitLine<-data.frame(caseCountData$Reported_Date, c(caseFitLineValues, c(caseFitLinePredictedValues)), caseCountData$report_type)
colnames(caseCountFitLine) <- c("Reported_Date", "n", "type")
#replaces UnderReported with Projected in the "type" column
caseCountFitLine <- caseCountFitLine %>% mutate(type = ifelse(type=="UnderReported", "Projected", "Actual"))
#get the selection estimate fits, scurves and extended scurves from the selection estimate object
selectionFit <- selectionEstimateObject$fit
selectionScurves <- selectionEstimateObject$scurves
selectionScurvesExtended <- selectionEstimateObject$scurvesExtended
#since canada only have data once every 7 days, modify the estimate fit to reflect that.
if (!selectionEstimateObject$region %in% c( "Quebec")){ #"Alberta",
selectionScurves <- selectionEstimateObject$scurves[seq(1, nrow(selectionEstimateObject$scurves), 7), ]
selectionScurvesExtended <- selectionEstimateObject$scurvesExtended[seq(1, nrow(selectionEstimateObject$scurvesExtended), 7), ]
}
#assign names and colors
selectionNames <- selectionEstimateObject$names
selectionColors <- selectionEstimateObject$color
#now we beging constructing the object that contains data for different lines to plot.
caseSelectionLines <- list()
#build to total case line.
caseSelectionLines[[1]] <- list("line"=caseCountFitLine, "names" = "CaseCount", "color"="limegreen")
#build line for each variant
for (i in seq(from=2, to=ncol(selectionScurves))){
x = caseCountData$Reported_Date
actual = caseCountFitLine$n[1:length(selectionScurves[,i])] * selectionScurves[,i]
actual <- actual[!is.na(actual)]
if (length(actual) == length(caseCountData$Reported_Date)){
proj = NULL
} else{
proj = caseCountFitLine$n[(length(selectionScurves[,i])+1):length(caseCountFitLine$n)] * selectionScurvesExtended[,i][(length(selectionScurves[,i])+1):length(caseCountFitLine$n)]
proj <- proj[!is.na(proj)]
}
y = c(actual, proj)
#type <- c(c(rep("actual",length(selectionScurves[,i]))), c(rep("projection", length(caseFit) - length(selectionScurves[,i]))))
line <- data.frame(x,y, c(rep("Actual", length(actual)), rep("Projected", length(proj))))
colnames(line) <- c("Reported_Date", "n", "type")
caseSelectionLines[[i]] <- list("line"=line, "names" = selectionNames[[i-1]], "color"=selectionColors[i-1])
}
#build the line for "the rest"
x <- caseCountData$Reported_Date
actual = caseCountFitLine$n[1:length(selectionScurves[,1])] * selectionScurves[,1]
actual <- actual[!is.na(actual)]
if (length(actual) == length(caseCountData$Reported_Date)){
proj = NULL
} else{
proj = caseCountFitLine$n[(length(selectionScurves[,i])+1):length(caseCountFitLine$n)] * selectionScurvesExtended[,1][(length(selectionScurves[,1])+1):length(caseCountFitLine$n)]
proj <- proj[!is.na(proj)]
}
y = unique(c(actual, proj))
line <- data.frame(x,y, c(rep("Actual", length(actual)), rep("Projected", length(proj))))
colnames(line) <- c("Reported_Date", "n", "type")
caseSelectionLines[[ncol(selectionScurves) + 1]] <- list("line"=line, "names" = "The Rest", "color"="black")
#gather the population data for /100000 individual normalization
population <- as.numeric(populationData[1,selectionEstimateObject$region]) * 7
#pass the lines into the plotting function
plotCaseCountByDate2(caseCountData, rev(caseSelectionLines),population,region=selectionEstimateObject$region, maxdate = enddate, order=mutantNames, saveToFile=saveToFile)
}
```
```{r, warning=FALSE, message=FALSE, fig.height=8, fig.width=11, warning=FALSE, out.width="100%", results='asis', echo=FALSE}
#plots the case count selection plots with each pronvince as a tab.
apply(all.regions,1,function(reg){
cat("###", reg[["shortname"]], "\n")
cat("####",reg[["name"]],"\n","\n")
if (is.null(selectionEstimateFits[[reg[["shortname"]]]]$plot1)){
print(getEmptyErrorPlotWithMessage("Not enough data available."))
#print(getEmptyErrorPlotWithMessage(selectionEstimateFits[[reg[["shortname"]]]]$plot2))
} else if (reg[["shortname"]] %in% names(caseData)){
p<-plotCaseCountSelection(caseData[[reg[["shortname"]]]], selectionEstimateFits[[reg[["shortname"]]]])#,reg[["shortname"]])
print(p)
} else {
print(getEmptyErrorPlotWithMessage("No case count data available."))
}
cat("\n\n")})
```
### {-}
<hr style="border:1px solid gray">
# Fastest growing lineages {.tabset .tabset-fade}
Here we show the selection estimates and their 95% confidence intervals for SARS-CoV-2 lineages with more than 10 sequences in present in a region since `r startdate`, and with enough data to estimate the confidence interval. Each selection estimate measures the growth rate relative to `r individualSelectionPlotReference[[1]]` stricto (i.e., sequences designated as `r individualSelectionPlotReference[[1]]` and not its descendants). Plots showing the change in variant frequency over time in Canada as a whole are given below for lineages with more than 50 sequences. For Canada-wide plot, a dot with a circle border indicates lineages with a positive selection coefficient in multiple provinces. The most prevelant lineage in the last two weeks is highlighted in grey. A table of the selection estimates is available for download below.
Growth advantage of 0-5% corresponds to doubling times of more than two weeks, with 5-10% reflecting one to two week doubling times and over 10% representing significant growth of less than one week doubling time. Note that estimating selection of sub-variants with low sequence counts (points with less than 100 counts) is prone to error, such as mistaking one-time super spreader events or pulses of sequence data from one region as selection. Estimates with lower sequence counts in one region should be considered as very preliminary.
```{r getCoefficientTable, echo = F, warning=FALSE, message=FALSE}
source("scripts/plot_growing_lineages.R")
paramselected=allparams[sapply(allparams,function(p){if(!any(is.na(p$fit))){
x=p$mut[[1]];
(p$fit)$fit[["s1"]]>0 &
sum(p$toplot$n2)>10
}else{FALSE}})]
#this<-Filter(function(x) x$mut == "KP.3.1.1" && x$region == "Alberta", allparams)
coefficientTable <- plot_growing_lineage(paramselected,makeplot=FALSE)
mutantToHighlight <- list(paste0(as.character((lineageDescriptions %>% arrange(desc(`# In Canada Last 2wk`)) %>% dplyr::select(Lineage))[1,1]),"*"))
```
## Plot (stricto) {.tabset .tabset-fade}
This plot highlights single lineages that are growing fastest.
```{r buildStrictoPlots, results='asis', echo = F, warning=FALSE, fig.height=7}
selectparam <- function(p,reg){
if(!any(is.na(p$fit))){
x=p$mut[[1]];
p$region==reg&
(p$fit)$fit[["s1"]]>0 &
sum(p$toplot$n2)>10&
substr(x, nchar(x), nchar(x))!="*"
}else{FALSE}
}
for (i in 1:length(all.regions[["name"]])) {
cat("###", all.regions[['shortname']][[i]], "\n")
if (all.regions[['name']][[i]] == "Canada"){
cat("#### Plot single lineages in", all.regions[['name']][[i]],"*\n","\n")
}else{
cat("#### Plot single lineages in", all.regions[['name']][[i]],"\n","\n")
}
paramselected=allparams[sapply(allparams,function(x){selectparam(x,all.regions[['name']][[i]])})]
n=min(25,length(paramselected)) #top x lineage
if(n!=0){
#print(plot_growing_lineage(paramselected[1:n]))
p<-plot_growing_lineage(paramselected[1:n], coefficientTable=coefficientTable, mutantNamesToHighlight = mutantToHighlight) #A%>% as_widget()
#print(htmltools::tagList(ggplotly(p, height = 700)))
print(p)
}else{
p<-(getEmptyErrorPlotWithMessage("Not enough data available.") )
print(p)
}
cat("\n\n")
}
```
## Plot (non stricto) {.tabset .tabset-fade}
This plot highlights the groups of related lineages that are growing fastest (e.g., JN.1* is the monophyletic clade that includes JN.1.7 and all other JN.1 sublineages, excluding recombinants.
```{r buildNonStrictoPlots, results='asis', echo=FALSE, warning=FALSE, fig.height=7}
source("scripts/plot_growing_lineages.R")
selectparam <- function(p,reg){
if(!any(is.na(p$fit))){
x=p$mut[[1]];
p$region==reg&
(p$fit)$fit[["s1"]]>0 &
sum(p$toplot$n2)>10&
substr(x, nchar(x), nchar(x))=="*"
}else{FALSE}
}
for (i in 1:length(all.regions[["name"]])) {
cat("###", all.regions[['shortname']][[i]], "\n")
cat("#### Plot single lineages in", all.regions[['name']][[i]],"\n","\n")
paramselected=allparams[sapply(allparams,function(x){selectparam(x,all.regions[['name']][[i]])})]
n=min(25,length(paramselected))
if(n!=0){
#print(plot_growing_lineage(paramselected[1:n]))
p<-plot_growing_lineage(paramselected[1:n], coefficientTable=coefficientTable, mutantNamesToHighlight = mutantToHighlight) #A%>% as_widget()
#print(htmltools::tagList(ggplotly(p, height = 700)))
print(p)
}else{
p<-(getEmptyErrorPlotWithMessage("Not enough data available.") )
print(p)
}
cat("\n\n")
}
```
```{r overview of the selection estimator table, echo=FALSE}
dataDownload <- coefficientTable %>% mutate(sel_coeff = sel_coeff / 100) %>% mutate(low_CI = low_CI / 100) %>% mutate(high_CI = high_CI / 100) %>% mutate(reference=ifelse(grepl("\\*", lineage), mutantNames[[length(mutantNames)]], individualSelectionPlotReference[[1]]))
link = DisplayHTMLTableDownloadLink(dataDownload, "GrowingLineages")
#DisplayHTMLTable(plot_growing_lineage(paramselected,makeplot=FALSE))
```
## Table of all the selection estimates
<a href="./downloads/GrowingLineages.tsv" target="_blank" class="btn btn-primary">Download Table</a>
## {-}
<hr style="border:1px solid gray">
# Sublineages selection
```{r general settings for selection estimator BA.2, warning=FALSE, echo=FALSE, message=FALSE}
#source("scripts/scanlineages.R")
source("scripts/plot_selection_estimator.R")
#function to plot all the indivudal variant's selection plot
plotIndividualSublineageSelection <- function(region, minimumSampleCount, parentalNodes, maxdate, excludeRecomb = F){
allSublineagePlots <- list()
plotCounter <- 0
#loop through all params and find...
for(i in seq(1:length(allparams))) {
if(!any(is.na(allparams[[i]]$fit)) && # fit not NA
allparams[[i]]$region==region && #region is the same as what we want
substr(allparams[[i]]$mut[[1]], nchar(allparams[[i]]$mut[[1]]), nchar(allparams[[i]]$mut[[1]]))!="*" && #is the same lineage
isSubLineage(parentalNodes,allparams[[i]]$mut[[1]], excludeRecomb)){ #is child lineage of parentalNodes
if((allparams[[i]]$fit)$fit[["s1"]]>0 && sum(allparams[[i]]$toplot$n2)>minimumSampleCount){ #the numebr of samples are greater than the minimum we want.
plotCounter <- plotCounter + 1
#plot all the variants and save them to a named list
allSublineagePlots[[plotCounter]] <- list("variant" = allparams[[i]]$mut[[1]], "plot" = plotIndividualSelectionPlots.ggplot(plotparam=allparams[[i]], maxdate = enddate))
}
}
}
return(allSublineagePlots)
}
#generate selection variant plots for BA2 and BA5 variants for each province
individualSublineageSelectionPlots.XBB <- list()
individualSublineageSelectionPlots.BA2 <- list()
individualSublineageSelectionPlots.BA5 <- list()
for (i in 1:length(all.regions$name)){
minCount = ifelse(all.regions$shortname[[i]] == "Canada", 50, 20)
individualSublineageSelectionPlots.BA2[[all.regions$shortname[[i]]]] = plotIndividualSublineageSelection(region=all.regions$name[[i]], minCount, "BA.2*", enddate, excludeRecomb = T)
individualSublineageSelectionPlots.XBB[[all.regions$shortname[[i]]]] = plotIndividualSublineageSelection(region=all.regions$name[[i]], minCount, "XBB*", enddate, excludeRecomb = F)
individualSublineageSelectionPlots.BA5[[all.regions$shortname[[i]]]] = plotIndividualSublineageSelection(region=all.regions$name[[i]], minCount, "BA.5*", enddate, excludeRecomb = T)
}
```
## XBB sublineages {.tabset .tabset-fade}
Here we show the trends of the various XBB.\* sublineages over time, relative to the frequency of `r individualSelectionPlotReference[[1]]` by itself (shown for sublineages with at least 50 (Canada) or 20 (provinces) cases). Proportions shown here are only among `r individualSelectionPlotReference[[1]]` (stricto) and the lineage illustrated. Note that these plots are not necessarily representative of trends in each province and that mixing of data from different provinces may lead to shifts in frequency that are not due to selection.
```{r, warning=FALSE, message=FALSE, echo = FALSE, fig.height=5, fig.width=5, warning=FALSE, out.width="33%", results='asis', dpi=150}
#prints the BA.2 plots
apply(all.regions,1,function(reg){
cat("###", reg[["shortname"]], "\n")
n_min=20
if(reg[["name"]]=="Canada"){n_min=50}
cat("####",reg[["name"]],"\n","\n")
if (length(individualSublineageSelectionPlots.XBB[[reg[["shortname"]]]])>0){
i = 0
for (plot in individualSublineageSelectionPlots.XBB[[reg[["shortname"]]]]){
i = i + 1
if (i==4){
cat ("<P>")
cat("<details>")
cat ("<summary><b>Only the three most strongly selected variants are displayed. Click here to see the rest.</b></summary>")
}
print(plot$plot)
}
if (i>3){cat("</details>")}
}else{
print(getEmptyErrorPlotWithMessage("Not enough data available"))
}
cat("\n\n")})
```
## BA.2 sublineages {.tabset .tabset-fade}
Here we show the trends of the various BA.2.\* sublineages over time, excluding any recombinants, relative to the frequency of `r individualSelectionPlotReference[[1]]` by itself (shown for sublineages with at least 50 (Canada) or 20 (provinces) cases). Proportions shown here are only among `r individualSelectionPlotReference[[1]]` (stricto) and the lineage illustrated. Note that these plots are not necessarily representative of trends in each province and that mixing of data from different provinces may lead to shifts in frequency that are not due to selection.
```{r, warning=FALSE, message=FALSE, echo = FALSE, fig.height=5, fig.width=5, warning=FALSE, out.width="33%", results='asis', dpi=150}
#prints the BA.2 plots
apply(all.regions,1,function(reg){
cat("###", reg[["shortname"]], "\n")
n_min=20
if(reg[["name"]]=="Canada"){n_min=50}
cat("####",reg[["name"]],"\n","\n")
if (length(individualSublineageSelectionPlots.BA2[[reg[["shortname"]]]])>0){
i = 0
for (plot in individualSublineageSelectionPlots.BA2[[reg[["shortname"]]]]){
i = i + 1
if (i==4){
cat ("<P>")
cat("<details>")
cat ("<summary><b>Only the three most strongly selected variants are displayed. Click here to see the rest.</b></summary>")
}
print(plot$plot)
}
if (i>3){cat("</details>")}
}else{
print(getEmptyErrorPlotWithMessage("Not enough data avilable"))
}
cat("\n\n")})
```
## {-}