-
Notifications
You must be signed in to change notification settings - Fork 2
/
sars_workflow.R
104 lines (83 loc) · 3.46 KB
/
sars_workflow.R
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
## SARS WORKFLOW
#install.packages("orderly2", repos = c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org"))
#remotes::install_github("mrc-ide/orderly.sharedfile")
#orderly2::orderly_init(".")
library(orderly2)
library(optparse)
library(ids)
library(zip)
option_list <- list(
make_option(c("-l", "--location"), type="character", default = NULL,
help = "Download location for the zipped outputs from the database
tasks. You must specify a fully specified location on your machine.")
)
parser <- OptionParser(option_list = option_list)
args <- parse_args(parser)
location <- args$location
## Retrieve the full path from the location
location <- normalizePath(location)
## Check if the file already exists in the location, and if it does, stop and
## ask the user to delete the file before running the script
#if (file.exists(file.path(location, "sars-outputs.zip"))) {
# stop("The file sars-outputs.zip already exists in the location.
# Please delete the file and run the script again.")
#}
## Download the zipped outputs from the database tasks
url <- "https://github.com/mrc-ide/priority-pathogens/releases/download/sars/sars-outputs.zip"
## Download
download.file(url, destfile = file.path(location, "sars-outputs.zip"), mode = "wb")
## unzip
## The outputs are zipped in a folder called sars-outputs
## Check that the folder does not already exist in the location
if (dir.exists(file.path(location, "sars-outputs"))) {
stop("The folder sars-outputs already exists in the location.
Please delete the folder and run the script again.")
}
unzip(zipfile = file.path(location, "sars-outputs.zip"), exdir = location)
## Initialize orderly
orderly_init()
###############
## DATABASES ##
###############
## The first task db_extraction uses the Access databases that have not been
## uploaded as part of the repository.
## Outputs of the above tasks are made available as a zipped file from the
## associated github release.
## The script will download these files, and add the downloaded folder
## as an orderly location so that the outputs can be used by the tasks below.
## Create a random name for location in case user already has pathogen-outputs
## This will also help ensure that the script can be run multiple times without
## the need to remove location
loc_name <- adjective_animal()
orderly_location_add(
loc_name, type = "path",
args = list(path = file.path(location, "sars-outputs"))
)
orderly_location_pull_metadata(location = loc_name)
orderly_location_pull_packet()
#
# # Sort into double extracted matching and fixing
orderly_run("db_double", parameters = list(pathogen = "SARS"))
#
# # Bring single, matching double, and fixed double together
orderly_run("db_compilation", parameters = list(pathogen = "SARS"))
##############
## ANALYSIS ##
##############
# map figure
orderly_run("sars_world_map", parameters = list(pathogen = "SARS"))
# Delay figures
orderly_run("sars_delays", parameters = list(pathogen = "SARS"))
# Transmission figures
orderly_run("sars_transmission", parameters = list(pathogen = "SARS"))
# Summary figures
orderly_run("sars_summary", parameters = list(pathogen = "SARS"))
# Latex tables
orderly_run("sars_latex_tables", parameters = list(pathogen = "SARS"))
# Risk factor plots
orderly_run("sars_risk_factors", parameters = list(pathogen = "SARS"))
######################
## FIGURES & TABLES ##
######################
# Collate figures and tables
orderly_run("sars_collate", parameters = list(pathogen = "SARS"))