-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaers_reports.py
493 lines (418 loc) · 16.5 KB
/
vaers_reports.py
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
# import os.path
import string
import sys
from InputFile import InputFile
################################################################################
class VaersData():
################################################################################
def __init__( self ):
self.data = {}
################################################################################
def read_csv( self, filename ):
rows = []
with open(filename, encoding="ascii", errors='ignore') as csvfile:
reader = csv.DictReader( csvfile )
for row in reader:
rows.append( row )
return rows
################################################################################
def read_data( self, filename, ages ):
select_age = {}
for age in ages:
select_age[age] = True
df = InputFile()
df.setFileName( filename )
df.openFile()
line = df.nextLine()
header = line.split( "," )
while ( df.isEndOfFile() == 0 ):
line = df.nextLine()
if ( line != "" ):
tokens = df.splitLine( "," )
row = {}
for i in range(0, len(header)):
row[ header[i] ] = tokens[i]
id = int(row["VAERS_ID"])
age = -1
if len(row["AGE_YRS"]) > 0:
age = int(float(row["AGE_YRS"]))
# Add this vaccine record for this individual
if (age in select_age):
# Check for new individual
if (id in self.data.keys()) == False:
self.data[id] = {}
self.data[id]["data"] = row
# Close the data file.
df.closeFile()
################################################################################
def read_list( self, filename ):
symptoms = []
df = InputFile()
df.setFileName( filename )
df.openFile()
while ( df.isEndOfFile() == 0 ):
line = df.nextLine()
if ( line != "" ) and (len(line) > 0):
symptoms.append( line )
# Close the data file.
df.closeFile()
return symptoms
################################################################################
def read_symptoms( self, filename ):
df = InputFile()
df.setFileName( filename )
df.openFile()
line = df.nextLine()
header = line.split( "," )
while ( df.isEndOfFile() == 0 ):
line = df.nextLine()
if ( line != "" ):
tokens = df.splitLine( "," )
row = {}
for i in range(0, len(header)):
row[ header[i] ] = tokens[i]
id = int(row["VAERS_ID"])
# Check if individual is selected
if (id in self.data.keys()):
# Check for first symptoms for this individual
if ("aes" in self.data[id].keys()) == False:
self.data[id]["aes"] = []
self.data[id]["ae"] = {}
# Add this vaccine record for this individual
self.data[id]["aes"].append( row )
# Make the symptoms easily searchable by name
names = ["SYMPTOM1", "SYMPTOM2", "SYMPTOM3", "SYMPTOM4", "SYMPTOM5"]
for name in names:
symptom = row[name]
if len(symptom) > 0:
self.data[id]["ae"][symptom] = True
################################################################################
def read_vax( self, filename ):
df = InputFile()
df.setFileName( filename )
df.openFile()
line = df.nextLine()
header = line.split( "," )
while ( df.isEndOfFile() == 0 ):
line = df.nextLine()
if ( line != "" ):
tokens = df.splitLine( "," )
row = {}
for i in range(0, len(header)):
row[ header[i] ] = tokens[i]
id = int(row["VAERS_ID"])
# Check if individual is selected
if (id in self.data.keys()):
# Check for first vaccine for this individual
if ("vax" in self.data[id].keys()) == False:
self.data[id]["vax"] = []
# Add this vaccine record for this individual
self.data[id]["vax"].append( row )
################################################################################
def tally_symptoms( self, symptoms ):
tally = {}
tally_type = {}
vax_count = {}
vax_count["name"] = {}
vax_count["type"] = {}
for id in self.data.keys():
for symptom in symptoms:
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()) and (symptom in self.data[id]["ae"].keys()):
for vax in self.data[id]["vax"]:
vax_name = vax["VAX_NAME"]
if vax_name in tally:
tally[vax_name] += 1
else:
tally[vax_name] = 1
vax_type = vax["VAX_TYPE"]
if vax_type in tally_type:
tally_type[vax_type] += 1
else:
tally_type[vax_type] = 1
# Total up the vaccines administered
for vax in self.data[id]["vax"]:
vax_name = vax["VAX_NAME"]
if vax_name in vax_count["name"].keys():
vax_count["name"][vax_name] += 1
else:
vax_count["name"][vax_name] = 1
vax_type = vax["VAX_TYPE"]
if vax_type in vax_count["type"].keys():
vax_count["type"][vax_type] += 1
else:
vax_count["type"][vax_type] = 1
print("Vaccine code report")
print( "Vaccine name\tSymptoms\tAdministered\tFrequency")
for name in tally_type.keys():
freq = 0.0
if vax_count["type"][name] > 0:
freq = (tally_type[name] * 100000) / vax_count["type"][name]
print(name + "\t" + str(tally_type[name]) + "\t" + str(vax_count["type"][name]) + "\t" + str(int(freq)))
print("\nVaccine name report")
print( "Vaccine name\tSymptoms\tAdministered\tFrequency")
for name in tally.keys():
freq = 0.0
if vax_count["name"][name] > 0:
freq = (tally[name] * 100000) / vax_count["name"][name]
print(name + "\t" + str(tally[name]) + "\t" + str(vax_count["name"][name]) + "\t" + str(int(freq)))
################################################################################
def age_report( self, symptoms ):
vax_total = {}
for id in self.data.keys():
for vax in self.data[id]["vax"]:
if ("data" in self.data[id].keys()):
# vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
data = self.data[id]["data"]
age = data["AGE_YRS"]
if len(age) < 1:
age = "-1"
else:
age = str(int(float(age)))
# Check if new vaccine name.
if (vax_type in vax_total.keys()) == False:
vax_total[vax_type] = {}
# Check if first of this age for this vaccine name.
if (age in vax_total[vax_type].keys()) == False:
vax_total[vax_type][age] = {}
vax_total[vax_type][age][id] = True # Avoid double counting for multiple doses
tally = {}
for id in self.data.keys():
for symptom in symptoms:
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()) and (symptom in self.data[id]["ae"].keys()):
for vax in self.data[id]["vax"]:
# vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
data = self.data[id]["data"]
age = data["AGE_YRS"]
if len(age) < 1:
age = "-1"
else:
age = str(int(float(age)))
# Check if new vaccine name.
if (vax_type in tally.keys()) == False:
tally[vax_type] = {}
# Check if first of this age for this vaccine name.
if (age in tally[vax_type].keys()) == False:
tally[vax_type][age] = {}
tally[vax_type][age][id] = True # Avoid double counting for multiple doses
print( "\nAge report:" )
# Print the report header line.
print( "Age", end="" )
for vax_type in tally.keys():
print( "\t" + vax_type, end="" )
print()
for age in range(-1, 121):
print( str(age), end="")
for vax_type in tally.keys():
count = 0
freq = 0
total = 0
if str(age) in tally[vax_type].keys():
count = len(tally[vax_type][str(age)].keys())
total = len(vax_total[vax_type][str(age)].keys())
if total > 0:
freq = int( (count * 100000) / total)
print( "\t" + str(count), end="" )
print()
print( "\nAge report: count|total|freq/100K" )
# Print the report header line.
print( "Age", end="" )
for vax_type in tally.keys():
print( "\t" + vax_type, end="" )
print()
for age in range(-1, 121):
print( str(age), end="")
for vax_type in tally.keys():
count = 0
freq = 0
total = 0
if str(age) in tally[vax_type].keys():
count = len(tally[vax_type][str(age)].keys())
if str(age) in vax_total[vax_type].keys():
total = len(vax_total[vax_type][str(age)].keys())
if total > 0:
freq = int( (count * 100000) / total)
print( "\t" + str(count) + "|" + str(total) + "|" + str(freq), end="" )
print()
################################################################################
def onset_report( self, symptoms ):
print( "\nOnset report:" )
tally = {}
for id in self.data.keys():
for symptom in symptoms:
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()) and (symptom in self.data[id]["ae"].keys()):
for vax in self.data[id]["vax"]:
# vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
data = self.data[id]["data"]
numdays = data["NUMDAYS"]
if len(numdays) < 1:
numdays = "-1"
# Check if new vaccine name.
if (vax_type in tally.keys()) == False:
tally[vax_type] = {}
# Check if first of this onset for this vaccine name.
if (numdays in tally[vax_type].keys()) == False:
tally[vax_type][numdays] = {}
tally[vax_type][numdays][id] = True # Avoid double counting for multiple doses
# Print the report header line.
print( "Onset", end="" )
for vax_type in tally.keys():
print( "\t" + vax_type, end="" )
print()
for onset in range(-1, 121):
print( str(onset), end="")
for vax_type in tally.keys():
count = ""
if str(onset) in tally[vax_type].keys():
count = str(len(tally[vax_type][str(onset)].keys()))
print( "\t" + count, end="" )
print()
################################################################################
def shots_report( self, symptoms ):
total = {}
kids = {}
for id in self.data.keys():
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()):
shots = len(self.data[id]["vax"])
for vax in self.data[id]["vax"]:
# vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
data = self.data[id]["data"]
age = -1
if len(data["AGE_YRS"]) > 0:
age = int(float(data["AGE_YRS"]))
# Check if new vaccine name.
if (vax_type in total.keys()) == False:
total[vax_type] = {}
kids[vax_type] = {}
# Check if first of this onset for this vaccine name.
if (shots in total[vax_type].keys()) == False:
total[vax_type][shots] = {}
kids[vax_type][shots] = {}
total[vax_type][shots][id] = True # Avoid double counting for multiple doses
if (age >= 0) and (age < 6):
kids[vax_type][shots][id] = True # Avoid double counting for multiple doses
tally = {}
kid_tally = {}
for id in self.data.keys():
for symptom in symptoms:
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()) and (symptom in self.data[id]["ae"].keys()):
shots = len(self.data[id]["vax"])
for vax in self.data[id]["vax"]:
# vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
data = self.data[id]["data"]
age = -1
if len(data["AGE_YRS"]) > 0:
age = int(float(data["AGE_YRS"]))
# Check if new vaccine name.
if (vax_type in tally.keys()) == False:
tally[vax_type] = {}
kid_tally[vax_type] = {}
# Check if first of this onset for this vaccine name.
if (shots in tally[vax_type].keys()) == False:
tally[vax_type][shots] = {}
kid_tally[vax_type][shots] = {}
tally[vax_type][shots][id] = True # Avoid double counting for multiple doses
if (age >= 0) and (age < 6):
kid_tally[vax_type][shots][id] = True # Avoid double counting for multiple doses
print( "\nShots report:" )
# Print the report header line.
print( "Shots", end="" )
for vax_type in tally.keys():
print( "\t" + vax_type, end="" )
print()
for shots in range(1, 26):
print( str(shots), end="")
for vax_type in tally.keys():
count = ""
if shots in tally[vax_type].keys():
count = str(len(tally[vax_type][shots]))
print( "\t" + count, end="" )
print()
print( "\nShots frequency report: count|total|frequency/100K" )
# Print the report header line.
print( "Shots", end="" )
for vax_type in tally.keys():
print( "\t" + vax_type, end="" )
print()
for shots in range(1, 26):
print( str(shots), end="")
for vax_type in tally.keys():
count = ""
freq = 0
shots_total = 0
if shots in tally[vax_type].keys():
count = len(tally[vax_type][shots])
shots_total = len(total[vax_type][shots])
freq = int((count * 100000) / shots_total)
print( "\t" + str(count) + "|" + str(shots_total) + "|" + str(freq), end="" )
print()
print( "\nChildren age 0-5 shots frequency report: count|total|frequency/100K" )
# Print the report header line.
print( "Shots", end="" )
for vax_type in kid_tally.keys():
print( "\t" + vax_type, end="" )
print()
for shots in range(1, 26):
print( str(shots), end="")
for vax_type in kid_tally.keys():
count = ""
freq = 0
shots_total = 0
if shots in kid_tally[vax_type].keys():
count = len(kid_tally[vax_type][shots])
shots_total = len(kids[vax_type][shots])
if shots_total > 0:
freq = int((count * 100000) / shots_total)
print( "\t" + str(count) + "|" + str(shots_total) + "|" + str(freq), end="" )
print()
################################################################################
def details_report( self, symptoms ):
print( "\nDetails report:" )
print( "VAERS ID\tVaccine Code\tVaccine Name\tVax lot\tVax series\tVax route\tAge\tGender\tOnset")
for id in self.data.keys():
for symptom in symptoms:
if ("data" in self.data[id].keys()) and ("ae" in self.data[id].keys()) and (symptom in self.data[id]["ae"].keys()):
for vax in self.data[id]["vax"]:
vax_name = vax["VAX_NAME"]
vax_type = vax["VAX_TYPE"]
vax_series = vax["VAX_DOSE_SERIES"]
vax_lot = vax["VAX_LOT"]
vax_route = vax["VAX_ROUTE"]
data = self.data[id]["data"]
age = data["AGE_YRS"]
gender = data["SEX"]
numdays = data["NUMDAYS"]
print(str(id) + "\t" + vax_type + "\t" + vax_name + "\t" + vax_lot + "\t" + vax_series + "\t" + vax_route + "\t" + age + "\t" + gender + "\t" + numdays)
################################################################################
def read_vaers( self, name, ages ):
self.read_data( name + "VAERSDATA.csv", ages )
self.read_vax( name + "VAERSVAX.csv" )
self.read_symptoms( name + "VAERSSYMPTOMS.csv" )
################################################################################
arg_count = len(sys.argv)
if ( arg_count >= 1 ):
sym_file = sys.argv[1]
app = VaersData()
# Read in the symptoms
symptoms = app.read_list( sym_file )
print( symptoms )
# Data selections
# ages = range( 0, 6 )
ages = range( -1, 121 )
years = range( 1990, 2024 )
# Read in the VAERS data files
for year in years:
app.read_vaers( str(year), ages )
app.read_vaers( "NonDomestic", ages )
# Generate the reports
app.tally_symptoms( symptoms )
app.age_report( symptoms )
app.onset_report( symptoms )
app.shots_report( symptoms )
app.details_report( symptoms )
else:
print( "usage: python vaers_reports.py <symptoms list file>" )