-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
145 lines (117 loc) · 3.57 KB
/
Snakefile
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
from pathlib import Path
year = 2022
cws_year = 2021
cities = ["bridgeport", "hartford", "new_haven", "stamford"]
fetch_data = f"fetch_data/acs_basic_{year}_fetch_all.rds"
def r_with_args(script):
cmd = f"Rscript {script} {year} {cws_year}"
return cmd
rule testvars:
shell:
"Rscript utils/pkgs_utils.R {year} {cws_year}"
rule readme:
input:
'Snakefile',
output:
"README.md",
script:
"README.Rmd"
# rule run_R:
# input:
# script = 'scripts/{script}.R',
# shell:
# r_with_args("{input.script}")
rule download_meta:
output:
reg_puma = 'utils/reg_puma_list.rds',
# flag = '.meta_downloaded.json',
# headings = 'utils/indicator_headings.txt',
script:
'scripts/00a_download_meta.sh'
rule meta:
input:
# rules.download_meta.output.flag,
rules.download_meta.output.reg_puma,
script = 'scripts/00_make_meta.R',
output:
web=f"utils/{year}_website_meta.rds",
# reg_puma="utils/reg_puma_list.rds",
shell:
r_with_args("{input.script}")
rule fetch:
input:
rules.download_meta.output.reg_puma,
script = 'scripts/01_fetch_acs_data.R',
output:
acs=f"fetch_data/acs_basic_{year}_fetch_all.rds",
shell:
r_with_args("{input.script}")
rule calc_cws:
input:
script = 'scripts/02_calc_cws_data.R',
output:
cws_basic=f"output_data/cws_basic_indicators_{cws_year}.rds",
shell:
r_with_args("{input.script}")
rule calc_acs_towns:
input:
rules.fetch.output.acs,
'utils/indicator_headings.txt',
script = 'scripts/03_calc_acs_towns.R',
output:
acs_csv=f"output_data/acs_town_basic_profile_{year}.csv",
acs_town=f"output_data/acs_town_basic_profile_{year}.rds",
town_distro=f"to_distro/town_acs_basic_distro_{year}.csv",
shell:
r_with_args("{input.script}")
rule calc_acs_nhoods:
input:
rules.fetch.output.acs,
'utils/indicator_headings.txt',
script = 'scripts/04_calc_acs_nhoods.R',
output:
acs_city=f"output_data/acs_nhoods_by_city_{year}.rds",
# can't use expand and params together?
cities_distro=expand(
"to_distro/{city}_acs_basic_neighborhood_{yr}.csv", city=cities, yr=year
),
shell:
r_with_args("{input.script}")
rule prep_distro:
input:
'utils/indicator_headings.txt',
rules.meta.output.web,
rules.calc_acs_towns.output.acs_town,
rules.calc_cws.output.cws_basic,
script = 'scripts/05_assemble_for_distro.R',
output:
website_csv = f"website/5year{year}town_profile_expanded_CWS.csv",
shell:
r_with_args("{input.script}")
rule release:
input:
town = rules.calc_acs_towns.output.acs_town,
nhood = rules.calc_acs_nhoods.output.acs_city,
script = 'scripts/upload_gh_release.sh',
output:
flag = '.uploaded.json',
shell:
'bash {input.script} {input.town} {input.nhood}'
#### MAIN RULES -----
rule distro:
input:
rules.calc_acs_nhoods.output.acs_city,
rules.prep_distro.output,
rules.release.output,
rule all:
input:
rules.readme.output,
rules.distro.input,
rules.calc_acs_towns.output.acs_town,
rules.release.output.flag,
# expand('scripts/{script}.R', script = glob_wildcards('scripts/{script}.R').script)
default_target: True
#### CLEANUP -----
rule clean:
shell:
"rm -f output_data/* to_distro/* fetch_data/* website/* utils/*.rds"