forked from Big-Life-Lab/PHES-ODM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ww_report_template.Rmd
324 lines (261 loc) · 11.1 KB
/
ww_report_template.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
---
knit: (function(input, ...) {
rmarkdown::render(
input,
output_file = paste0("ww_report", '_', Sys.Date(), '.pdf'
),
envir = globalenv()
)
})
output: pdf_document
header-includes:
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---
```{r setup, include=FALSE}
#SARS-CoV-2 Wastewater Epidemiology Lab Regional Report Generator
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(readxl)
library(lubridate)
library(plyr)
library(tidyverse)
library(knitr)
library(kableExtra)
library(googledrive)
```
```{r sampleID}
###### INSERT INFORMATION HERE:
region <- "CSC"
sites <- c("BMI","MH")
site_labels <- c("Bath and Millhaven Combined", "Millhaven")
names(site_labels) <- sites
date <- Sys.Date() #Sys.Date() will give you today's date or use a date in quotes ex. "2021-02-01"
comments <- NULL
authorizedby <- "Robert Delatolla" #your name here inside "quotes"
analysis <- "Solids"
######
```
![](img/Logo_address.png) ![](img/cheologo.png)
```{r Addresses}
addresses.df <- read_excel("data/Client List.xlsx")
address <- filter(addresses.df, Region == region)
address_counter <- 1:nrow(address)
for(i in address_counter){
if(is.na(address$Name[i]) == TRUE) {
clientName <- NULL
clientTitle <- NULL
clientOffice <- NULL
clientAddress1 <- NULL
clientAddress2 <- NULL
clientAddress3 <- NULL
}
else {
clientName <- address$Name[i]
clientTitle <- address$Title[i]
clientOffice <- address$Office_Institution[i]
clientAddress1 <- address$Address_line_1[i]
clientAddress2 <- address$Address_line_2[i]
clientAddress3 <- address$Address_line_3[i]
}
}
```
`r clientName`
`r clientTitle`
`r clientOffice`
`r clientAddress1`
`r clientAddress2`
`r clientAddress3`
# Wastewater Trend Analysis Report: SARS-CoV-2
```{r variables}
##read file and define variables for text portion of report
drive_download(as_id("1bJzYQ_V63of4Ym15RsiSlT9uA7R9OSth"), path = "data/report_data.csv", overwrite = TRUE)
data.df <- read.csv(file.path(getwd(), "data/report_data.csv"))
datetoday <- Sys.Date()
variant.df <- data.df %>%
mutate(sampleDate = as.Date(sampleDate)) %>%
filter(grepl(paste(sites, collapse = "|"), siteID),
testB117 == TRUE)
detection <- ifelse(last(variant.df$detectB117 == TRUE), "Detected", "Not detected")
```
Report Date: `r datetoday` Authorized by: `r authorizedby`
Comments:
\noindent\rule{16cm}{0.4pt}
### Longitudinal data for 5 weeks ending `r date`
### Method Type: `r analysis` RT-qPCR Region: `r region`
### B.1.1.7 variant: `r detection` on `r last(variant.df$sampleDate)`.
## SARS-CoV-2 Detection in Wastewater by CDC N1 & N2 RT-qPCR
```{r plot}
enddate <- as.Date(date)
startdate <- as.Date(enddate - days(35))
#startdate <- as.POSIXct(ymd(enddate) - days(35))
data.df <- filter(data.df, grepl(paste(sites, collapse = "|"), siteID))
plotdata.df <- filter(data.df,
sampleDate <= as.Date(enddate) &
sampleDate >= as.Date(startdate))
plotdata.df$N1_N2_avg <- (plotdata.df$covN1_nPMMoV_meanMnNr+
plotdata.df$covN2_nPMMoV_meanMnNr)/2
plotdata.df$N1_N2_avg_mL <- plotdata.df$N1_N2_avg_L/1000
if(enddate-startdate < 15)
{
xbreaks <- "1 day"
}
if(enddate-startdate > 14 | enddate-startdate < 57)
{
xbreaks <- "1 week"
}
if(enddate-startdate > 56)
{
xbreaks <- "1 month"
}
plotdata.df$confidence <- ifelse(
is.na(plotdata.df$viral_confidence), "0",
ifelse(plotdata.df$viral_confidence == FALSE, "1", "2"))
plotdata.df$norm_confidence <- ifelse(
(is.na(plotdata.df$N1_N2_avg)) & (plotdata.df$qualityFlag == FALSE), "0",
ifelse(
((plotdata.df$N1_N2_avg == 0) & (plotdata.df$qualityFlag == FALSE)), "0",
ifelse(
(plotdata.df$qualityFlag == TRUE), "1",
"2")
)
)
N1_N2_plotdata <- filter(plotdata.df, !(is.na(plotdata.df$qualityFlag)))
N1_N2_plotdata$N1_N2_avg_mL <- ifelse(is.na(N1_N2_plotdata$N1_N2_avg_mL), 0,
N1_N2_plotdata$N1_N2_avg_mL)
N1_N2_plotdata$N1_N2_avg <- ifelse(is.na(N1_N2_plotdata$N1_N2_avg), 0,
N1_N2_plotdata$N1_N2_avg)
N1_N2_plotdata$sampleDate <- as.POSIXct(N1_N2_plotdata$sampleDate)
N1_N2_plotdata <- arrange(N1_N2_plotdata, siteID, sampleDate)
variant_plotdata <- plotdata.df %>%
filter(!(is.na(plotdata.df$fractionB117))) %>%
mutate(pctB117 = fractionB117*100)
variant_plotdata$sampleDate <- as.POSIXct(variant_plotdata$sampleDate)
#variant_plotdata <- filter(variant_plotdata, !is.na(percent))
#variant_plotdata$allelecount <- paste(variant_plotdata$S_SN501Y_WT_alleles, "-", variant_plotdata$S_SN501Y_Var_alleles, sep = "")
N1ymax <- round_any(max(N1_N2_plotdata$N1_N2_avg_mL), 10000, f = ceiling)
viralload_plot <- ggplot(data = N1_N2_plotdata, aes(x = sampleDate, y = N1_N2_avg_mL))+
theme_classic()+
geom_point(aes(shape = confidence, colour = confidence), size = 3.0)+
geom_line(aes(group = 1), stat = "identity", size = 1, color = "black")+
geom_hline(yintercept = 1, color = "darkorange2")+
scale_shape_manual(values = c("0" = 18, "1" = 16, "2" = 16),
labels = c("0" = "Non detection", "1" = "Low confidence", "2" = "High Confidence"),
name = "Confidence:")+
scale_color_manual(values = c("0" = "black", "1" = "lightcoral", "2" = "seagreen3"),
labels = c("0" = "Non detection", "1" = "Low confidence", "2" = "High Confidence"),
name = "Confidence:")+
scale_x_datetime(date_breaks = waiver(), date_minor_breaks = "1 day",
date_labels = "%Y %b %d")+
scale_y_continuous(trans = 'log10', limits = c(1, N1ymax))+
labs(x = "Date Sampled", y = "Viral Load (cp/mL)")+
facet_wrap(vars(siteID), labeller = labeller(siteID = site_labels))+
theme(plot.title = element_text(size = 16, hjust = 0.5),
legend.position = "top",
legend.direction = "horizontal",
axis.text.x = element_text(angle = 90, hjust = 1),
panel.border = element_rect(colour = "black", fill = NA),
strip.background = element_blank())
nrm_copies_plot <- ggplot(data = N1_N2_plotdata, aes(x = sampleDate, y = N1_N2_avg))+
theme_classic()+
geom_point(aes(shape = norm_confidence, colour = norm_confidence), size = 3.0)+
geom_line(aes(group = 1), stat = "identity", size = 1, color = "black")+
scale_shape_manual(values = c("0" = 18, "1" = 16, "2" = 16),
labels = c("0" = "Non detection", "1" = "Low confidence", "2" = "High Confidence"),
name = "Confidence:")+
scale_color_manual(values = c("0" = "black", "1" = "lightcoral", "2" = "seagreen3"),
labels = c("0" = "Non detection", "1" = "Low confidence", "2" = "High Confidence"),
name = "Confidence:") +
scale_x_datetime(date_breaks = waiver(), date_minor_breaks = "1 day",
date_labels = "%Y %b %d")+
#scale_y_continuous(trans = 'log10', limits = c(1, N1ymax))+
labs(x = "Date Sampled", y = "Normalized viral copies")+
facet_wrap(vars(siteID), labeller = labeller(siteID = site_labels))+
theme(plot.title = element_text(size = 16, hjust = 0.5),
legend.position = "top",
legend.direction = "horizontal",
axis.text.x = element_text(angle = 90, hjust = 1),
panel.border = element_rect(colour = "black", fill = NA),
strip.background = element_blank())
plot(viralload_plot)
```
Low confidence: SARS-CoV-2 signal was detected below the method’s limit of quantification.
High confidence: SARS-CoV-2 signal was detected and meets QA/QC requirements.
Orange line represents the limit of quantification of the assay
```{r}
plot(nrm_copies_plot)
```
```{r variant}
variantplot <- ggplot(data = variant_plotdata, aes(x = sampleDate, y = pctB117))+
theme_classic()+
geom_point(size = 3.0)+
geom_line(stat = "identity", size = 1)+
#scale_color_discrete(labels = c("S_SN501Y_percent" = "N501Y", "S_Sdel_percent" = "Sdel"), name = "Allele:")+
scale_x_datetime(date_breaks = waiver(), date_minor_breaks = "1 day",
date_labels = "%Y %b %d")+
scale_y_continuous(limits = c(0, 100))+
labs(x = "Date Sampled", y = "Percent Variant (%)")+
facet_wrap(vars(siteID))+
theme(plot.title = element_text(size = 16, hjust = 0.5),
legend.position = "top",
legend.direction = "horizontal",
axis.text.x = element_text(angle = 90, hjust = 1),
panel.border = element_rect(colour = "black", fill = NA),
strip.background = element_blank())
#plot(variantplot)
```
NOTE:
- This report is the only valid reference in case of differences with other transmitted documents.
- The analysis results refer only to what was provided for testing.
- The information provided in this report is for research use only.
See individual sample report for variances and limitations to sample analysis.
Robert Delatolla, Kamya Bhatnagar, Patrick M. D’Aoust, Élisabeth Mercier,
Alex MacKenzie, and Tyson Graber
Department of Civil Engineering, University of Ottawa & Children’s Hospital
of Eastern Ontario – Research Institute
\newpage
```{r spreadsheet}
# Upload ww_reports
drive_download(as_id("157D3pWH0r47xx4-rNua_Djbc606r_9vM"), path = "data/ww_reports.xlsx", overwrite = TRUE)
ww_reports <- read_excel(path = "data/ww_reports.xlsx", sheet = "7 - WWMeasure") %>%
filter(grepl(paste(sites, collapse = "|"), sampleID)) %>%
filter(!is.na(uWwMeasureID), !is.na(value)) %>%
select(sampleID, labID, analysisDate, reportDate, type, value) %>%
filter(type == "covN1" | type == "covN2") %>%
group_by(sampleID) %>%
mutate(mean = mean(value)) %>%
select(-type, -value) %>%
distinct() %>%
mutate(viral_cp_mL = mean/1000) %>%
select(-mean)
ww_reports$submitted_id <- NA
ww_reports$arr_tmp <- NA
ww_reports$condition <- NA
ww_reports$pcr_date <- NA
report.df <- rename(ww_reports,
"Sample ID" = sampleID,
"Submitted ID" = submitted_id,
"Location" = labID,
"Date Sampled" = analysisDate,
"Date Received" = reportDate,
"Arrival Temp" = arr_tmp,
"Sample Condition" = condition,
"qPCR Date" = pcr_date,
"Average N1 & N2 Copies/mL" = viral_cp_mL)
col_order <- c("Sample ID", "Submitted ID", "Location", "Date Sampled",
"Date Received", "Arrival Temp", "Sample Condition", "qPCR Date",
"Average N1 & N2 Copies/mL")
report.df <- report.df[,col_order]
report.df <- filter(report.df, as.Date(`Date Sampled`) >= as.Date(startdate),
as.Date(`Date Sampled`) <= as.Date(enddate))
report.df <- arrange(report.df, `Sample ID`, desc(`Date Sampled`))
#report.df$`Average N1 Copies/mL` <- round(report.df$`Average N1 Copies/mL`, 2)
kable(report.df, booktabs = T, align = "c") %>%
kable_styling(latex_options = "scale_down") %>%
#kableExtra::landscape() %>%
row_spec(0, angle = 45)
#16cm line for portrait, 23cm line for landscape
```
\noindent\rule{16cm}{0.4pt}
End of report