-
Notifications
You must be signed in to change notification settings - Fork 4
/
coreScript.sh
500 lines (354 loc) · 15.8 KB
/
coreScript.sh
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/bash
# This script sweaves the whole analysis from start-finish
# (Not automation quality..some parts may contain remarks for manual tasks)
# ::: REMARKS :::
# Syntax here are written for terminal on MacOS.
# Modifications are needed for Linux.
#####################################################
# #
# Section 1: Gathering and processing raw data #
# #
#####################################################
mkdir -p 00-RawData
mkdir -p 01-TabulatedData
###############
# Brazil #
###############
# Location name mappings
# Mapping of accent-removed names and actual names
# as well as abbreviations
# saved in: 01-TabulatedData/Mappings-Brazil-Location.csv
# Dengue
# Dataset archive (1986-2006)
# reported by the National Health Foundation - FUNASA. The system was centralized into the
# Sistema de Informação de Agravos de Notificação (SINAN) in 2001.
# These counts represent the total number of dengue cases (including classical dengue, complicated
# dengue, haemorrhagic fever and toxic shock syndrome). Incomplete notification forms that do not
# specify dengue type are also included in the totals. The month represents the month of initial
# sypmtoms. November 2006 is a partial result and data for 1991 was indicated as defective).
# saved in 01-TabulatedData/Dengue-Brazil-DatasetArchiveTotal/Archive1986-2006_totals.csv
# Batch retrieve tabnet severity data (2001-2012)
# : Needs Selenium on python and Chromedriver installed.
# : "fig43" and "fig45" correspond to field ids of severity (Grau FHD dropdown)
# : on the respective websites.
# Tabnet data (2001-2006)
python Scripts/00-retrieveTabnetSeverity.py \
"http://tabnet.datasus.gov.br/cgi/deftohtm.exe?sinanwin/cnv/denguebr.def" \
"00-RawData/Dengue-Brazil-TabnetSeverity" \
"fig43"
# Tabnet data (2007-2012)
python Scripts/00-retrieveTabnetSeverity.py \
"http://tabnet.datasus.gov.br/cgi/deftohtm.exe?sinannet/cnv/denguebr.def" \
"00-RawData/Dengue-Brazil-TabnetSeverity" \
"fig45"
mkdir 00-RawData/Dengue-Brazil-TabnetTotal
mv 00-RawData/Dengue-Brazil-TabnetSeverity/total*.csv \
00-RawData/Dengue-Brazil-TabnetTotal
# EpiBulletin previous year data (2013 Epiweek 14 to 2017 Epiweek 42) from
# Boletim Epidemiológico of 2014 Epiweek 14 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Dengue-Brazil-EpiBulletinPrevYear
# File names refers to time in which the numbers corresponds to,
# which is one year prior the time in which the numbers were reported.
# EpiBulletin original reports (2014 Epiweek 14 to 2018 Epiweek 42) from
# Boletim Epidemiológico of 2014 Epiweek 14 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Dengue-Brazil-EpiBulletin
# Zika
# EpiBulletin previous year data (2016 Epiweek 4 to 2017 Epiweek 42) from
# Boletim Epidemiológico of 2017 Epiweek 4 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Zika-Brazil-EpiBulletinPrevYear
# File names refers to time in which the numbers corresponds to,
# which is one year prior the time in which the numbers were reported.
# EpiBulletin original reports (2016 Epiweek 13 to 2018 Epiweek 42) from
# Boletim Epidemiológico of 2016 Epiweek 13 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Zika-Brazil-EpiBulletin
# Chikungunya
# EpiBulletin previous year data (2015 Epiweek 9 to 2017 Epiweek 42) from
# Boletim Epidemiológico of 2016 Epiweek 9 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Chik-Brazil-EpiBulletinPrevYear
# File names refers to time in which the numbers corresponds to,
# which is one year prior the time in which the numbers were reported.
# EpiBulletin original reports (2016 Epiweek 9 to 2018 Epiweek 42) from
# Boletim Epidemiológico of 2016 Epiweek 9 to 2018 Epiweek 42
# reported by Secretaria de Vigilância em Saúde, Ministério da Saúde.
# saved in: 01-TabulatedData/Chik-Brazil-EpiBulletin
# Microcephaly
# Monitoramento dos casos de microcefalias no Brasil
# CENTRO DE OPERAÇÕES DE EMERGÊNCIAS EM SAÚDE PÚBLICA SOBRE MICROCEFALIA
# reported by Ministério da Saúde Brasil.
# http://portalms.saude.gov.br/saude-de-a-z/microcefalia/informes-epidemiologicos
# Data (2016) most recently downloaded October 17, 2017
# saved in: 01-TabulatedData/Microcephaly-Brazil-Microcephaly
# Population size
# Data source: Instituto Brasileiro de Geografia e Estatística
# Data (2001-2018) most recently downloaded on December 21, 2018
# from https://sidra.ibge.gov.br/tabela/6579
# saved in: 00-RawData/Population-size/Brazil_pop_2001_2018.xlsx
# Data (1986-2000) downloaded on December 1, 2006
# saved in: 00-RawData/Population-size/Brazil_pop_1986_2000.csv
#################
# Colombia #
#################
# Location name mappings
# Mapping of accent-removed names and actual names
# as well as abbreviations
# saved in: 01-TabulatedData/Mappings-Colombia-Location.csv
# Dengue
# Ministry data (2007-2017)
# downloaded December 24, 2018
# saved in: 00-RawData/Colombia-Ministry2007_2017
# Zika
# EpiBulletin (2015 Epiweek 45 - 2017 Epiweek 52) from
# Boletín Epidemiológico reported by
# Instituto Nacional de Salud Colombia
# and El Ministerio de Salud y Protección Social.
# saved in: 01-TabulatedData/Zika-Colombia-EpiBulletin
# Chikungunya
# EpiBulletin (2014 Epiweek 48 - 2017 Epiweek 52) from
# Boletín Epidemiológico reported by
# Instituto Nacional de Salud Colombia
# and El Ministerio de Salud y Protección Social.
# saved in: 01-TabulatedData/Chik-Colombia-EpiBulletin
# Population size
# Sistema Estadístoco Nacional Colombia
# Departamento Administrativo Nacional de Estadística
# Downloaded from
# https://www.dane.gov.co/files/investigaciones/poblacion/proyepobla06_20/Municipal_area_1985-2020.xls
# saved in: 00-RawData/Population-size/Colombia_population_1985-2020_raw.xls
#########################################################
# #
# Section 2: Transform datasets into unified format #
# #
#########################################################
# Process the data to obtain unified CSV files for downstream analyses
mkdir -p 02-UnifiedCsvData
# function for processing EpiBulletins
unifyBulletins(){
# parameter1 : directory name of tabulated data
# parameter2 : date (to force as start date)
for infile in $(ls 01-TabulatedData/${1}/* | grep -vi 'template' ) ; do
echo "Processing:" ${infile} "-------------------------"
outfile=02-UnifiedCsvData${infile#01-TabulatedData}
#year=$(echo $(basename ${infile}) | cut -d'-' -f1 | cut -d'_' -f3 )
Rscript --vanilla Scripts/02-ProcessTab-EpiBulletin.R \
${infile} \
${outfile} \
${2}
done
}
###############
# Brazil #
###############
# Geographical attributes mapping
# Mapping of geographical attributes to unified location names
# used earlier in mapping files of the earlier phase
# saved in: 02-UnifiedCsvData/Mappings-Brazil-Location.csv
# Dengue
# Dengue-Brazil-DatasetArchiveTotal
# : process and truncate to 2000
Rscript --vanilla Scripts/02-ProcessTab-DatasetArchiveBrazilTotals.R \
01-TabulatedData/Dengue-Brazil-DatasetArchiveTotal/Archive1986-2006_totals.csv \
02-UnifiedCsvData/Dengue-Brazil-DatasetArchiveTotal/Archive1986-2000_totals.csv \
"01-TabulatedData/Mappings-Brazil-Location.csv"
# Dengue-Brazil-TabnetTotal
Rscript --vanilla Scripts/02-ProcessTab-TabnetSeverity.R \
'00-RawData/Dengue-Brazil-TabnetTotal' \
'02-UnifiedCsvData/Dengue-Brazil-TabnetTotal'
# Dengue-EpiBulletin
unifyBulletins Dengue-Brazil-EpiBulletin
unifyBulletins Dengue-Brazil-EpiBulletinPrevYear
# Zika
# Zika-EpiBulletin
unifyBulletins Zika-Brazil-EpiBulletin
unifyBulletins Zika-Brazil-EpiBulletinPrevYear
# Chikungunya
# Chik-EpiBulletin
unifyBulletins Chik-Brazil-EpiBulletin
unifyBulletins Chik-Brazil-EpiBulletinPrevYear
# Microcephaly
# Microcephaly-Brazil (2016) data
Rscript --vanilla Scripts/00-Convert2Tab-BrazilMicrocephaly.R \
"01-TabulatedData/Microcephaly-Brazil-Microcephaly" \
"02-UnifiedCsvData/Microcephaly-Brazil-Microcephaly"
#################
# Colombia #
#################
# Geographical attributes mapping
# Mapping of geographical attributes to unified location names
# used earlier in mapping files of the earlier phase
# saved in: 02-UnifiedCsvData/Mappings-Colombia-Location.csv
# Dengue
# Denuge-Colombia-Ministry
for f in 00-RawData/Colombia-Ministry2007_2017/* ; do
year=${f##*_}
year=${year%%.*}
Rscript --vanilla Scripts/02-ProcessTab-ColombiaMinistryRawXlsx.R \
${f} \
02-UnifiedCsvData/Dengue-Colombia-Ministry2007_2017/${year}.csv \
"dengue" \
${year}
done
# Zika
# Zika-EpiBulletin
# Zika cases in Colombia were first reported in the
# 2015 Epiweek 32 bulletin (starts on August 9, 2015).
# We incorporate that information here.
for infile in $(ls 01-TabulatedData/Zika-Colombia-EpiBulletin/* | grep -vi 'template' ) ; do
outfile=02-UnifiedCsvData${infile#01-TabulatedData}
year=$(echo $(basename ${infile}) | cut -d'-' -f1 | cut -d'_' -f3 )
if [[ ${year} -lt 2017 ]]; then
startDate="2015-08-09"
else
startDate=""
fi
Rscript --vanilla Scripts/02-ProcessTab-EpiBulletin.R \
${infile} \
${outfile} \
${startDate}
done
# Chikungunya
# Chik-EpiBulletin
unifyBulletins Chik-Colombia-EpiBulletin
###########################################################
# #
# Section 3: Combine into time-series and fit splines #
# #
###########################################################
# Fortmat each of the datasets as time-series by
# converting the numbers to cumulative cases throughout the time period
mkdir 03-TimeSeries
###############
# Brazil #
###############
# Function to combine the use of previous year and
# current year data. Previous year data is prioritized.
# Current year data is used when previous year data is
# not available.
lumpPrevCurrentYearCsv()
{
csvdir=${1}"PrevYear"
firstPrev=$(ls ${csvdir} | head -n 1 )
firstPrev=${firstPrev##*_}
lastPrev=$(ls ${csvdir} | tail -n 1 )
lastPrev=${lastPrev##*_}
lumpdir=${1}-lumped
mkdir -p ${lumpdir}
ln ${csvdir}/*.csv ${lumpdir}
csvdir=${1}
for f in ${csvdir}/*.csv ; do
fbase=${f##*_}
if [[ ${fbase} > ${lastPrev} ]]; then
ln ${f} ${lumpdir}
elif [[ ${fbase} < ${firstPrev} ]]; then
ln ${f} ${lumpdir}
else
echo 'omitted:' ${f}
fi
done
}
# Dengue
# Dengue-Brazil-probable: total counts (DataArchive + Tabnet + EpiBulletin)
# : Previous Year EpiBulletins
lumpPrevCurrentYearCsv \
02-UnifiedCsvData/Dengue-Brazil-EpiBulletin
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Dengue-Brazil-probable "probable_countCumu" \
"02-UnifiedCsvData/Dengue-Brazil-DatasetArchiveTotal" \
"02-UnifiedCsvData/Dengue-Brazil-TabnetTotal" \
"02-UnifiedCsvData/Dengue-Brazil-EpiBulletin-lumped"
rm -rf "02-UnifiedCsvData/Dengue-Brazil-EpiBulletin-lumped"
# Zika
# Zika-Brazil
lumpPrevCurrentYearCsv \
02-UnifiedCsvData/Zika-Brazil-EpiBulletin
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Zika-Brazil "countCumu" \
02-UnifiedCsvData/Zika-Brazil-EpiBulletin-lumped
rm -rf "02-UnifiedCsvData/Zika-Brazil-EpiBulletin-lumped"
# Chikungunya
# Chik-Brazil
lumpPrevCurrentYearCsv \
02-UnifiedCsvData/Chik-Brazil-EpiBulletin
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Chik-Brazil "countCumu" \
02-UnifiedCsvData/Chik-Brazil-EpiBulletin-lumped
rm -rf "02-UnifiedCsvData/Chik-Brazil-EpiBulletin-lumped"
# Microcephaly
# Microcephaly-Brazil: 2016
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Microcephaly-Brazil "countCumu" \
"02-UnifiedCsvData/Microcephaly-Brazil-Microcephaly"
#################
# Colombia #
#################
# Dengue
# Dengue-Colombia-Total
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Dengue-Colombia-Total "countCumu" \
"02-UnifiedCsvData/Dengue-Colombia-Ministry2007_2017"
# Zika
# Zika-Colombia
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Zika-Colombia "countCumu" \
02-UnifiedCsvData/Zika-Colombia-EpiBulletin
# Chikungunya
# Chik-Colombia
Rscript --vanilla Scripts/03-makeTimeSeries.R \
03-TimeSeries/Chik-Colombia "countCumu" \
02-UnifiedCsvData/Chik-Colombia-EpiBulletin
###########################################################
# #
# Section 4: Simulate counts from the fitted splines #
# #
###########################################################
# Function to generate 1000 simulations of counts for each subnational-level location
run1000sim()
{
Rscript --vanilla Scripts/04-simulateCounts.R \
03-TimeSeries/${1} \
04-TsSimulations/${1} \
1000 \
"tsCountMid"
}
# Function to summarize the simulations
summarizeSimulations()
{
echo 01-TabulatedData/Population-size/$( echo ${1} | cut -d'-' -f2 )*.csv
for tsdir in 04-TsSimulations/${1}/*tsCount* ; do
Rscript --vanilla Scripts/05-summarizeSimulation.R \
${tsdir} \
05-simulationSummary/${tsdir#04-TsSimulations} \
01-TabulatedData/Population-size/$( echo ${1} | cut -d'-' -f2 )*.csv
done
}
###############
# Brazil #
###############
# Dengue
run1000sim Dengue-Brazil-probable
summarizeSimulations Dengue-Brazil-probable
# Zika
run1000sim Zika-Brazil
summarizeSimulations Zika-Brazil
# Chikungunya
run1000sim Chik-Brazil
summarizeSimulations Chik-Brazil
# Microcephaly
run1000sim Microcephaly-Brazil
summarizeSimulations Microcephaly-Brazil
#################
# Colombia #
#################
# Dengue
run1000sim Dengue-Colombia-Total
summarizeSimulations Dengue-Colombia-Total
# Zika
run1000sim Zika-Colombia
summarizeSimulations Zika-Colombia
# Chikungunya
run1000sim Chik-Colombia
summarizeSimulations Chik-Colombia