-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsybil_epi.py
503 lines (456 loc) · 28.3 KB
/
sybil_epi.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
494
495
496
497
498
499
500
501
502
503
import argparse
MODEL_1 = { "age_x_duration": -0.00458450762,
"age": 0.218479962,
"bmi": -0.0173239431,
"copd": 0.181490211,
"education": -0.0811663292,
"black": 0.230840954,
"asian": 0.172128535,
"others": 0.364427352,
"family_history": 0.099145017,
"personal_history": 0.208211636,
"duration": 0.369158627,
"intensity": 0.0182317466,
"quit_time": 0.00262488699,
"smoking_status": 0.0338289601,
"sybil_score": 7.02617157,
"intercept": -20.79038191,
}
MODEL_2 = { "age_x_duration": 0.00171930035,
"age": -0.0940677396,
"bmi": -0.0199431848,
"copd": 0.232235992,
"education": -0.0811599402,
"black": 0.157668516,
"asian": 0.435645147,
"others": 0.305746067,
"family_history": 0.089258818,
"personal_history": 0.24459386,
"duration": -0.048558,
"intensity": 0.0196900714,
"quit_time": 0.0133071369,
"smoking_status": 0.149713551,
"sybil_score": 6.96079105,
"intercept": -0.24621993,
}
MODEL_3 = { "age_x_duration": -0.00103727472,
"age": 0.0185323478,
"bmi": -0.0224721393,
"copd": 0.189604676,
"education": -0.052010514,
"black": 0.238942239,
"asian": 0.311381652,
"others": 0.592043695,
"family_history": -0.00728941902,
"personal_history": 0.175685519,
"duration": 0.131503757,
"intensity": 0.0173455502,
"quit_time": 0.00645552283,
"smoking_status": 0.119615903,
"sybil_score": 6.92597482,
"intercept": -7.40740562,
}
MODEL_4 = { "age_x_duration": -0.00367140897,
"age": 0.131959544,
"bmi": -0.0190635739,
"copd": 0.372005191,
"education": -0.0683654211,
"black": 0.220218144,
"asian": -0.0580279624,
"others": 0.546870804,
"family_history": 0.0529735063,
"personal_history": 0.178575329,
"duration": 0.305061372,
"intensity": 0.0191591891,
"quit_time": 0.00959059658,
"smoking_status": 0.175888389,
"sybil_score": 7.24776249,
"intercept": -14.9808314,
}
MODEL_5 = { "age_x_duration": 0.00381010544,
"age": -0.101655343,
"bmi": -0.0282311644,
"copd": 0.476940467,
"education": -0.0506923612,
"black": 0.451206665,
"asian": 0.0230400934,
"others": -0.034782781,
"family_history": 0.0285130751,
"personal_history": 0.0770597605,
"duration": -0.167556279,
"intensity": 0.0192993904,
"quit_time": 0.00837984637,
"smoking_status": 0.143223644,
"sybil_score": 7.47072426,
"intercept": 0.01625732,
}
CALIBRATOR_1 = {"thresholds": [-6.83084097765182, -5.54535145507885, -5.54443742079984,
-5.31175599485575, -5.31143200626821, -5.08199266314459,
-5.0816819409446, -5.03867510600285, -5.03822641268466,
-4.9376550049408, -4.93695653610866, -4.76914044854747,
-4.76895524803483, -4.52447036706167, -4.52429109634284,
-4.1851070855342, -4.18507857823729, -4.13856683549135,
-4.13834600108628, -4.12227312343759, -4.1222142981056,
-4.05303979153328, -4.05303564896005, -3.86110437983613,
-3.86110032761937, -3.80980785285466, -3.80976013309103,
-3.76522223698408, -3.76469486998651, -3.63506267680873,
-3.63504437844557, -3.58218684183874, -3.58212663522492,
-3.41422959054526, -3.41407934535584, -3.39395767263892,
-3.3936194461336, -3.35075959553484, -3.35049833366132,
-3.32526202667457, -3.32425346311377, -3.16743242146143,
-3.16648078040121, -3.11974481801039, -3.11949547782089,
-2.88716205883827, -2.88679264910134, -2.28351814304314,
-2.28341771334039, -2.25075681964111, -2.24722264484806,
-1.81503763638207, -1.80981471342024, -1.56220188001589,
-1.56203367410988, -0.883730771581255, -0.881204139655352,
-0.747571012833969, -0.747516347831869, 0.26902159779528,
0.347617076263695, 0.350744122092173, 0.364813256341062,
1.32971502224201, 1.33205349683115, 2.25257322093028,
2.28793489335508, 3.22150837109364
],
"values": [0, 0, 0.00157480314960629, 0.00157480314960629,
0.00488997555012224, 0.00488997555012224, 0.0104166666666666,
0.0104166666666666, 0.0143540669856459, 0.0143540669856459,
0.0175849941383352, 0.0175849941383352, 0.0215404699738903,
0.0215404699738903, 0.0225340136054421, 0.0225340136054421,
0.0234604105571847, 0.0234604105571847, 0.0241935483870967,
0.0241935483870967, 0.0417536534446764, 0.0417536534446764,
0.0432653061224489, 0.0432653061224489, 0.050314465408805,
0.050314465408805, 0.0519480519480519, 0.0519480519480519,
0.0521885521885521, 0.0521885521885521, 0.0588235294117647,
0.0588235294117647, 0.062700964630225, 0.062700964630225,
0.0862068965517241, 0.0862068965517241, 0.0983606557377049,
0.0983606557377049, 0.126984126984126, 0.126984126984126,
0.132832080200501, 0.132832080200501, 0.158730158730158,
0.158730158730158, 0.187943262411347, 0.187943262411347,
0.192737430167597, 0.192737430167597, 0.222222222222222,
0.222222222222222, 0.3125, 0.3125, 0.510204081632653,
0.510204081632653, 0.528089887640449, 0.528089887640449,
0.588235294117647, 0.588235294117647, 0.60204081632653,
0.60204081632653, 0.666666666666666, 0.666666666666666,
0.790697674418604, 0.790697674418604, 0.8, 0.8, 1, 1
]
}
CALIBRATOR_2 = {"thresholds": [-5.13976202645897, -4.45855247691666, -4.4582698193259,
-4.2518450533451, -4.25157297578535, -4.12103947494856,
-4.12091177902061, -4.02640561549037, -4.02639931241959,
-3.87850590132921, -3.87836333800783, -3.78265108085928,
-3.78263902318789, -3.66874059942404, -3.66865649809458,
-3.50333686239594, -3.50322676511143, -3.38260458926028,
-3.38239050905076, -3.36134026536294, -3.3611225958752,
-3.30651259082491, -3.30631233790642, -3.20914725751849,
-3.20902487646987, -3.11694062505718, -3.11679462879763,
-2.96532175570692, -2.96511797871301, -2.69559229246829,
-2.69501884194289, -2.62274546546793, -2.6223546843081,
-2.48658932345086, -2.48610328068047, -2.30092176611133,
-2.30071351946817, -2.24700122492978, -2.24684490923774,
-2.01801620372871, -2.01495607993973, -1.66317335999902,
-1.6569219881803, -1.08676074827303, -1.08249227836323,
-1.07366923763311, -1.07010276090708, 0.0705479290336056,
0.0738831826353788, 0.401184842679566, 0.402345918309606,
0.645414076527883, 0.653619752845769, 1.38234013948577,
1.38787187448386, 1.48660866194891, 1.50162544808152,
1.69133780551668, 1.70614331310756, 2.0612330181618,
2.14202917083523, 3.91208317660163
],
"values": [0, 0, 0.00130378096479791, 0.00130378096479791,
0.00404312668463611, 0.00404312668463611, 0.0045662100456621,
0.0045662100456621, 0.00699300699300699, 0.00699300699300699,
0.0122767857142857, 0.0122767857142857, 0.0186005314437555,
0.0186005314437555, 0.0245398773006134, 0.0245398773006134,
0.0252427184466019, 0.0252427184466019, 0.0261780104712041,
0.0261780104712041, 0.0295983086680761, 0.0295983086680761,
0.0464135021097046, 0.0464135021097046, 0.0606617647058823,
0.0606617647058823, 0.0787096774193548, 0.0787096774193548,
0.0954598370197904, 0.0954598370197904, 0.124260355029585,
0.124260355029585, 0.129921259842519, 0.129921259842519,
0.151658767772511, 0.151658767772511, 0.166666666666666,
0.166666666666666, 0.2, 0.2, 0.266272189349112,
0.266272189349112, 0.284360189573459, 0.284360189573459,
0.333333333333333, 0.333333333333333, 0.503816793893129,
0.503816793893129, 0.558823529411764, 0.558823529411764,
0.676470588235294, 0.676470588235294, 0.709090909090909,
0.709090909090909, 0.75, 0.75, 0.833333333333333,
0.833333333333333, 0.923076923076923, 0.923076923076923,
1, 1
]
}
CALIBRATOR_3 = {"thresholds": [-5.40896695555443, -4.44557905591795, -4.44556769824729,
-4.20796960678975, -4.20739595368818, -3.91552915782963,
-3.91548039595661, -3.5345198348362, -3.53431434149028,
-3.43490951844732, -3.43488087385878, -3.42904077520323,
-3.4288999459988, -3.41768951227193, -3.41754960133783,
-3.39211171288659, -3.39205300926651, -3.32995536982051,
-3.32990172496423, -3.24685531071719, -3.24671206819021,
-3.11901522252616, -3.11886226305581, -2.99974728760598,
-2.99956474429094, -2.91765833557168, -2.91750760894448,
-2.90054878707901, -2.90028915863532, -2.6475189963683,
-2.64741434406712, -2.62150132519831, -2.6209657404627,
-2.59858231770701, -2.59812553384104, -2.4554499391278,
-2.45529021102402, -2.39397293199902, -2.39363220142586,
-1.87769220955232, -1.87523366083048, -1.84412706174444,
-1.84244882776309, -1.59368802685856, -1.59106147350401,
-1.56382787161001, -1.55982641375981, -1.4549350688779,
-1.44902791926516, -1.40284906648665, -1.40284160717211,
-1.31017627785731, -1.30232455720342, -1.19292612431877,
-1.18992323507933, -1.17861833654162, -1.17606128036306,
-0.413588502397382, -0.402302355080826, -0.278037063043519,
-0.252188292713815, 0.28318091010164, 0.284280188256867,
0.828005605867875, 0.860334523461037, 0.996858651407914,
1.00118109607741, 1.05344457993507, 1.0754991844332,
1.66608973697844, 1.76795244660686, 2.91795097929127,
2.94294776493842, 3.53725043203523
],
"values": [0, 0, 0.0050251256281407, 0.0050251256281407,
0.00583657587548638, 0.00583657587548638, 0.0096698899633211,
0.0096698899633211, 0.0177725118483412, 0.0177725118483412,
0.0204081632653061, 0.0204081632653061, 0.0212765957446808,
0.0212765957446808, 0.0241545893719806, 0.0241545893719806,
0.0264227642276422, 0.0264227642276422, 0.0287277701778385,
0.0287277701778385, 0.0375275938189845, 0.0375275938189845,
0.0395061728395061, 0.0395061728395061, 0.0506607929515418,
0.0506607929515418, 0.0666666666666666, 0.0666666666666666,
0.0817120622568093, 0.0817120622568093, 0.0952380952380952,
0.0952380952380952, 0.123076923076923, 0.123076923076923,
0.126262626262626, 0.126262626262626, 0.130081300813008,
0.130081300813008, 0.134304207119741, 0.134304207119741,
0.17391304347826, 0.17391304347826, 0.211678832116788,
0.211678832116788, 0.222222222222222, 0.222222222222222,
0.24074074074074, 0.24074074074074, 0.25, 0.25,
0.263157894736842, 0.263157894736842, 0.333333333333333,
0.333333333333333, 0.428571428571428, 0.428571428571428,
0.439759036144578, 0.439759036144578, 0.5, 0.5, 0.52,
0.52, 0.625, 0.625, 0.692307692307692, 0.692307692307692,
0.777777777777777, 0.777777777777777, 0.878048780487804,
0.878048780487804, 0.923076923076923, 0.923076923076923, 1, 1
]
}
CALIBRATOR_4 = {"thresholds": [-5.40297596576861, -4.145046360106, -4.14399863519635,
-3.96469127014186, -3.96433456464248, -3.79821097842455,
-3.79779347620638, -3.78276999952974, -3.7827334089108,
-3.71202032064926, -3.71195047309248, -3.58669159781696,
-3.58668557313358, -3.36313485155923, -3.36309455610468,
-3.34856928840831, -3.34843950750268, -3.25175025722636,
-3.25173129770055, -3.24480312347089, -3.244576314838,
-2.89445996228474, -2.89442920543924, -2.43294566623595,
-2.43273732882454, -2.35438840883121, -2.35399267156437,
-2.32665326581679, -2.32644944266306, -2.00073280666356,
-1.99758423146622, -1.87517611131506, -1.87334395146985,
-1.47428118372159, -1.47404665717457, -1.2238632031688,
-1.22335885613264, -0.94569571043684, -0.943034578788692,
-0.170516290240955, -0.159465347170856, 0.00728976386126056,
0.0145462944545293, 0.0674686168349953, 0.0689045131453163,
0.794428399251971, 0.794991274019949, 0.860753576674929,
0.861091367961949, 1.1731265029034, 1.17327917862875,
1.20119869829976, 1.20950964955107, 1.65124958904896,
1.6735448032525, 1.86887592828489, 1.88419092062132,
2.65929028108868, 2.67248359202892, 2.76664158066157,
2.78591249999188, 3.84403802653575
],
"values": [0, 0, 0.00229621125143513, 0.00229621125143513,
0.00884955752212389, 0.00884955752212389,
0.00952380952380952, 0.00952380952380952,
0.0116731517509727, 0.0116731517509727, 0.0128055878928987,
0.0128055878928987, 0.0199155099577549, 0.0199155099577549,
0.0253164556962025, 0.0253164556962025, 0.0260416666666666,
0.0260416666666666, 0.0476190476190476, 0.0476190476190476,
0.0486707566462167, 0.0486707566462167, 0.0659340659340659,
0.0659340659340659, 0.072072072072072, 0.072072072072072,
0.0806451612903225, 0.0806451612903225, 0.0842293906810035,
0.0842293906810035, 0.102739726027397, 0.102739726027397,
0.131832797427652, 0.131832797427652, 0.158730158730158,
0.158730158730158, 0.288659793814433, 0.288659793814433,
0.343915343915343, 0.343915343915343, 0.4, 0.4,
0.428571428571428, 0.428571428571428, 0.541176470588235,
0.541176470588235, 0.545454545454545, 0.545454545454545,
0.567567567567567, 0.567567567567567, 0.6, 0.6, 0.612244897959183,
0.612244897959183, 0.695652173913043, 0.695652173913043,
0.741935483870967, 0.741935483870967, 0.8, 0.8, 1, 1
]
}
CALIBRATOR_5 = {"thresholds": [-5.34372288616349, -4.00900324181277, -4.008262731788,
-3.84370310240735, -3.84285955438415, -3.49562213214767,
-3.49548891109088, -3.19647540660684, -3.19574010845561,
-3.14630729811392, -3.14629122540069, -2.95688490723843,
-2.95664182722659, -2.31745946097859, -2.31720653772112,
-2.30899511048998, -2.3089006058332, -1.72097525226115,
-1.72092762782885, -1.68686596037886, -1.68654701114382,
-1.236526434842, -1.23644413938852, -1.11165732156823,
-1.11144435180836, -1.06707253269346, -1.0656848188659,
-0.899850540104916, -0.899122118493487, -0.235687989432131,
-0.231686727236445, -0.0682802062167959, -0.0655954118333348,
-0.0517199399968599, -0.0515587696700816, 0.496278828219814,
0.496381921331663, 0.670826030444628, 0.672084076515664,
0.773830880197755, 0.786770287499513, 2.20130937840007,
2.25738212058063, 2.39931731317832, 2.42177386174513,
2.68056055833383, 2.68100312409866, 2.88201473762726,
2.91232541743944, 3.95594449481789, 3.97198777284055,
4.33025189595118, 4.33776582233737, 5.81635295182968
],
"values": [0, 0, 0.00617283950617283, 0.00617283950617283,
0.00625, 0.00625, 0.00674915635545556,
0.00674915635545556, 0.0114285714285714, 0.0114285714285714,
0.0181347150259067, 0.0181347150259067, 0.0225442834138486,
0.0225442834138486, 0.0227272727272727, 0.0227272727272727,
0.0361819434872501, 0.0361819434872501, 0.0410958904109589,
0.0410958904109589, 0.0479812755997659, 0.0479812755997659,
0.0509915014164305, 0.0509915014164305, 0.0787401574803149,
0.0787401574803149, 0.0828729281767955, 0.0828729281767955,
0.102428722280887, 0.102428722280887, 0.152, 0.152,
0.153846153846153, 0.153846153846153, 0.175, 0.175,
0.212765957446808, 0.212765957446808, 0.258064516129032,
0.258064516129032, 0.391705069124424, 0.391705069124424,
0.5, 0.5, 0.527777777777777, 0.527777777777777,
0.607142857142857, 0.607142857142857, 0.648351648351648,
0.648351648351648, 0.75, 0.75, 1, 1
]
}
def calibrate_result(model_result, calibrator):
if model_result <= calibrator["thresholds"][0]:
return calibrator["values"][0]
last_index = len(calibrator["thresholds"]) - 1
if model_result >= calibrator["thresholds"][last_index]:
return calibrator["values"][last_index]
for index in range(0, len(calibrator["thresholds"])):
if model_result <= calibrator["thresholds"][index]:
break
if model_result == calibrator["thresholds"][index]:
return calibrator["values"][index]
if calibrator["values"][index] == calibrator["values"][index-1]:
return calibrator["values"][index]
m = ((calibrator["values"][index] - calibrator["values"][index-1]) /
(calibrator["thresholds"][index] - calibrator["thresholds"][index-1]))
linear_interpolation = m * (model_result - calibrator["thresholds"][index-1])
return linear_interpolation
def calculate_sybil_epi_score(args):
models = [MODEL_1, MODEL_2, MODEL_3, MODEL_4, MODEL_5]
calibrators = [CALIBRATOR_1, CALIBRATOR_2, CALIBRATOR_3, CALIBRATOR_4, CALIBRATOR_5]
model_result_total = 0.0
for model_coeffs, calibrator in zip(models, calibrators):
ethnicity_coeff = 0
match args.ethnicity:
case "Asian":
ethnicity_coeff = model_coeffs["asian"]
case "Black":
ethnicity_coeff = model_coeffs["black"]
case "Others":
ethnicity_coeff = model_coeffs["others"]
model_result = (args.risk_sybil_6_year * model_coeffs["sybil_score"] +
args.age * model_coeffs["age"] +
args.bmi * model_coeffs["bmi"] +
args.copd * model_coeffs["copd"] +
args.education * model_coeffs["education"] +
ethnicity_coeff +
args.family_history * model_coeffs["family_history"] +
args.personal_history * model_coeffs["personal_history"] +
args.smoking_duration * model_coeffs["duration"] +
args.smoking_intensity * model_coeffs["intensity"]+
args.smoking_quit * model_coeffs["quit_time"] +
args.smoking_status * model_coeffs["smoking_status"] +
args.age * args.smoking_duration * model_coeffs["age_x_duration"] +
model_coeffs["intercept"]
)
model_result_calibrated = calibrate_result(model_result, calibrator)
model_result_total += model_result_calibrated
model_result_average = model_result_total / len(models)
return model_result_average
def range_risk_sybil_6_year(arg):
"""Type function for 6-year risk Sybil with predefined bounds."""
try:
sybil_risk = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("6-year risk Sybil must be a floating point number")
MIN_BMI, MAX_BMI = 0.0, 1.0
if sybil_risk <= MIN_BMI or sybil_risk >= MAX_BMI:
raise argparse.ArgumentTypeError(
"6-year risk Sybil must be <= " + str(MAX_BMI) + " and >= " + str(MIN_BMI))
return sybil_risk
def range_age(arg):
"""Type function for age with predefined bounds."""
try:
age = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("Age must be a floating point number")
MIN_AGE, MAX_AGE = 0.0, 200.0
if age <= MIN_AGE or age >= MAX_AGE:
raise argparse.ArgumentTypeError(
"Age must be <= " + str(MAX_AGE) + " and >= " + str(MIN_AGE))
return age
def range_bmi(arg):
"""Type function for BMI with predefined bounds."""
try:
bmi = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("BMI must be a floating point number")
MIN_BMI, MAX_BMI = 0.0, 100.0
if bmi <= MIN_BMI or bmi >= MAX_BMI:
raise argparse.ArgumentTypeError(
"BMI must be <= " + str(MAX_BMI) + " and >= " + str(MIN_BMI))
return bmi
def range_smoking_duration(arg):
"""Type function for smoking duration with predefined bounds."""
try:
duration = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("Smoking duration must be a floating point number")
MIN_DURATION, MAX_DURATION = 0.0, 200.0
if duration <= MIN_DURATION or duration >= MAX_DURATION:
raise argparse.ArgumentTypeError(
"Smoking duration must be <= " + str(MAX_DURATION) + " and >= " + str(MIN_DURATION))
return duration
def range_smoking_intensity(arg):
"""Type function for smoking intensity with predefined bounds."""
try:
intensity = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("Smoking intensity must be a floating point number")
MIN_INTENSITY, MAX_INTENSITY = 0.0, 1000.0
if intensity <= MIN_INTENSITY or intensity >= MAX_INTENSITY:
raise argparse.ArgumentTypeError(
"Smoking intensity must be <= " + str(MAX_INTENSITY) + " and >= " + str(MIN_INTENSITY))
return intensity
def range_smoking_quit(arg):
"""Type function for smoking quit time with predefined bounds."""
try:
quit_time = float(arg)
except ValueError:
raise argparse.ArgumentTypeError("Smoking quit time must be a floating point number")
MIN_QUIT_TIME, MAX_QUIT_TIME = 0.0, 200.0
if quit_time <= MIN_QUIT_TIME or quit_time >= MAX_QUIT_TIME:
raise argparse.ArgumentTypeError(
"Smoking quit time must be <= " + str(MAX_QUIT_TIME) + " and >= " + str(MIN_QUIT_TIME))
return quit_time
def prepare_argument_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--risk_sybil_6_year", type=range_risk_sybil_6_year, required=True,
help="Vaue of 6-year risk calculated using Sybil.",)
parser.add_argument("--age", type=range_age, required=True,
help="Age of the subject, in years.",)
parser.add_argument("--bmi", type=range_bmi, required=True,
help="BMI of the subject, in kg/m^2.",)
parser.add_argument("--copd", type=int, choices={0, 1}, required=True,
help="1 if the subject presents COPD, 0 otherwise.",)
parser.add_argument("--education", type=int, choices={1, 2, 3, 4, 5, 6}, required=True,
help="Education level of the subject. Less than high-school graduate (1), \
high-school graduate (2), some training after high school (3), some college (4), \
college graduate (5) or postgraduate or professional degree (6).",)
parser.add_argument("--ethnicity", type=str, choices={"Asian", "Black", "White", "Others"}, required=True,
help="Ethnicity of the subject.",)
parser.add_argument("--family_history", choices={0, 1}, type=int, required=True,
help="1 if the subject presents lung cancer family history, 0 otherwise.",)
parser.add_argument("--personal_history", choices={0, 1}, type=int, required=True,
help="1 if the subject presents any cancer history, 0 otherwise.",)
parser.add_argument("--smoking_duration", type=range_smoking_duration, required=True,
help="Years of smoking.",)
parser.add_argument("--smoking_intensity", type=range_smoking_intensity, required=True,
help="Average number of cigarettes smoked per day.",)
parser.add_argument("--smoking_quit", type=range_smoking_quit, required=True,
help="Time in years since the subject quit smoking.",)
parser.add_argument("--smoking_status", type=int, choices={0, 1}, required=True,
help="1 if the subject is a current smoker, 0 otherwise.",)
return parser
if __name__ == "__main__":
parser = prepare_argument_parser()
args = parser.parse_args()
sybil_epi_score = calculate_sybil_epi_score(args)
print(f"The Sybil-Epi score is {sybil_epi_score}")