[bc9e98]: / benchmark / statistics.py

Download this file

622 lines (496 with data), 22.8 kB

  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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
import matplotlib.pyplot as plt
import numpy as np
data_file = "data/raw_data.csv"
import csv, os, pickle
from tqdm import tqdm
import numpy as np
from functools import reduce
from xml.etree import ElementTree as ET
raw_folder = "raw_data"
import seaborn as sns
from matplotlib import font_manager
font_dirs = ["./"]
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
for font_file in font_files:
font_manager.fontManager.addfont(font_file)
sns.set(rc={'figure.figsize':(6,6)})
sns.set_theme(style="ticks", rc={"axes.facecolor": (0, 0, 0, 0)}, font = "Helvetica", font_scale=1.5)
pattern_string = "participants group_id"
def icdcode_text_2_lst_of_lst(text):
text = text[2:-2]
lst_lst = []
for i in text.split('", "'):
i = i[1:-1]
lst_lst.append([j.strip()[1:-1] for j in i.split(',')])
return lst_lst
def row2icdcodelst(row):
icdcode_text = row[6]
icdcode_lst2 = icdcode_text_2_lst_of_lst(icdcode_text)
icdcode_lst = reduce(lambda x,y:x+y, icdcode_lst2)
icdcode_lst = [i.replace('.', '') for i in icdcode_lst]
return icdcode_lst
def xmlfile_2_startyear(xml_file):
tree = ET.parse(xml_file)
root = tree.getroot()
try:
start_date = root.find('start_date').text
start_date = int(start_date.split()[-1])
except:
start_date = -1
return start_date
def file2patientnumber(xml_file):
os.system('grep "' + pattern_string + '" ' + xml_file + ' > tmp')
with open("tmp", 'r') as fin:
lines = fin.readlines()
summ = 0
for line in lines:
summ += int(line.split('"')[3])
return summ
#### data/all_xml
# if True:
# year_lst = []
# nctid2year = dict()
# nctid2patientnumber = dict()
# with open("data/all_xml") as fin:
# lines = fin.readlines()
# for line in tqdm(lines):
# file = line.strip()
# nctid = line.strip().split('/')[-1].split('.')[0]
# start_year = xmlfile_2_startyear(file)
# try:
# patientnumber = file2patientnumber(file)
# nctid2patientnumber[nctid] = patientnumber
# print(patientnumber)
# except:
# pass
# if start_year != -1:
# year_lst.append(start_year)
# nctid2year[nctid] = start_year
# pickle.dump(year_lst, open("data/year_histogram.pkl", 'wb'))
# data = year_lst ##### [2008, 2007, 2000, 2006, 2007, 2008, 2000, 1999, .......]
# data = list(filter(lambda x:x>1998 and x<2020, data))
# pickle.dump(nctid2year, open("data/nctid2year_all.pkl", 'wb'))
# pickle.dump(nctid2patientnumber, open("data/all_nctid2patientnumber.pkl", 'wb'))
# plt.cla()
# fig, ax = plt.subplots()
# num_bins = 23
# n, bins, patches = ax.hist(data, num_bins, )
# plt.tick_params(labelsize=15)
# ax.set_xlabel('Year', fontsize = 25)
# ax.set_ylabel('Number of selected trials', fontsize = 24)
# plt.tight_layout()
# # ax.set_title(r'Histogram of trial number in each year')
# # fig.set_facecolor('cyan') #
# plt.savefig("figure/all_histogram.png")
# plt.cla()
import seaborn as sns
from matplotlib import font_manager
font_dirs = ["./"]
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
for font_file in font_files:
font_manager.fontManager.addfont(font_file)
fig, axes = plt.subplots(1,3, figsize=(25,6))
sns.set(rc={'figure.figsize':(6,6)})
sns.set_theme(style="ticks", rc={"axes.facecolor": (0, 0, 0, 0)}, font = "Helvetica", font_scale=1.5)
ax = axes[0]
# if not (os.path.exists("data/nctid2year.pkl") and os.path.exists("data/nctid2patientnumber.pkl")):
if True:
year_lst = []
nctid2year = dict()
nctid2patientnumber = dict()
with open(data_file) as f:
reader = list(csv.reader(f))[1:]
for line in tqdm(reader):
nctid = line[0]
file = os.path.join(raw_folder, nctid[:7]+"xxxx/"+nctid+".xml")
# assert os.path.exists(file)
start_year = xmlfile_2_startyear(file)
try:
patientnumber = file2patientnumber(file)
nctid2patientnumber[nctid] = patientnumber
# print(patientnumber)
except:
pass
if start_year != -1:
year_lst.append(start_year)
nctid2year[nctid] = start_year
pickle.dump(year_lst, open("data/year_histogram.pkl", 'wb'))
data = year_lst ##### [2008, 2007, 2000, 2006, 2007, 2008, 2000, 1999, .......]
data = list(filter(lambda x:x>1998, data))
pickle.dump(nctid2year, open("data/nctid2year.pkl", 'wb'))
pickle.dump(nctid2patientnumber, open("data/nctid2patientnumber.pkl", 'wb'))
# plt.cla()
# fig, ax = plt.subplots()
ax = axes[0]
num_bins = 23
n, bins, patches = ax.hist(data, num_bins, )
plt.tick_params(labelsize=15)
ax.set_xlabel('Year', fontsize = 25)
ax.set_ylabel('Number of selected trials', fontsize = 24)
ax.set_title('A', fontsize = 25)
# plt.tight_layout()
# ax.set_title(r'Histogram of trial number in each year')
# fig.set_facecolor('cyan') #
# plt.savefig("histogram.png")
# plt.cla()
# else:
# nctid2year = pickle.load(open("data/nctid2year.pkl", 'rb'))
# nctid2patientnumber = pickle.load(open("data/nctid2patientnumber.pkl", 'rb'))
ax = axes[1]
# if not os.path.exists("data/nctid2label.pkl"):
if True:
nctid2label = dict()
nctid2drug = dict()
nctid2disease = dict()
nctid2icd = dict()
with open("data/raw_data.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
label = int(row[3])
nctid2label[nctid] = label
drug = row[7].strip('"[],')
drug_lst = drug.strip("'").split("', '")
# print("drug", drug_lst)
nctid2drug[nctid] = drug_lst
disease = row[5].strip('"[],')
disease_lst = disease.strip("'").split("', '")
# print("disease", disease_lst)
nctid2disease[nctid] = disease_lst
icdcode_lst = row2icdcodelst(row)
nctid2icd[nctid] = icdcode_lst
pickle.dump(nctid2label, open("data/nctid2label.pkl", 'wb'))
pickle.dump(nctid2drug, open("data/nctid2drug.pkl", 'wb'))
pickle.dump(nctid2disease, open("data/nctid2disease.pkl", 'wb'))
pickle.dump(nctid2icd, open("data/nctid2icd.pkl", 'wb'))
else:
nctid2label = pickle.load(open("data/nctid2label.pkl", 'rb'))
nctid2drug = pickle.load(open("data/nctid2drug.pkl", 'rb'))
nctid2disease = pickle.load(open("data/nctid2disease.pkl", 'rb'))
nctid2icd = pickle.load(open("data/nctid2icd.pkl", 'rb'))
disease_lst = [disease for nctid, disease in nctid2disease.items()]
disease_lst = list(reduce(lambda x,y:x+y, disease_lst))
print("total disease", len(set(disease_lst)))
drug_lst = [drug for nctid, drug in nctid2drug.items()]
drug_lst = list(reduce(lambda x,y:x+y, drug_lst))
print("total drug", len(set(drug_lst)))
##### year vs % of approval
from collections import defaultdict
year2num = defaultdict(lambda:[0,0])
for nctid, year in nctid2year.items():
label = nctid2label[nctid]
year2num[year][0] += label
year2num[year][1] += 1
year2approvalrate = []
for year in range(1998,2021):
year2approvalrate.append(year2num[year][0] / year2num[year][1] * 100)
pickle.dump(year2approvalrate, open("data/year2approvalrate.pkl", 'wb'))
ax.plot(list(range(1998,2021)),year2approvalrate)
ax.set_xlabel("Year", fontsize = 24)
ax.set_ylabel("Success rate (%)", fontsize=25)
ax.set_title('B', fontsize = 25)
# plt.tight_layout()
# plt.savefig("year2approvalrate.png")
# plt.cla()
##### year vs # of recruit
ax = axes[2]
year2recruitnum = defaultdict(lambda:[0,0])
for nctid, patientnumber in nctid2patientnumber.items():
try:
year = nctid2year[nctid]
except:
continue
year2recruitnum[year][0] += patientnumber
year2recruitnum[year][1] += 1
year2recruitnum_lst = []
for year in range(1998, 2021):
year2recruitnum_lst.append(year2recruitnum[year][0])
pickle.dump(year2recruitnum_lst, open("data/year2recruitnum.pkl", 'wb'))
ax.plot(list(range(1998,2021)),year2recruitnum_lst)
ax.set_xlabel("Year", fontsize = 24)
ax.set_ylabel("# of recruited patients", fontsize=25)
ax.set_title('C', fontsize = 25)
# plt.tight_layout()
# plt.savefig("year2recruitedpatients.png")
plt.savefig('figure/1.pdf', bbox_inches='tight')
# plt.savefig("time_distribution.pdf")
exit()
print('-----------------------------------------------')
data = [year for nctid,year in nctid2year.items()]
target_year_range = [(1900,1999), (2000,2004), (2005,2009), (2010,2014), (2015,2022)]
for year1, year2 in target_year_range:
print('-----------------------------------------------')
print(year1, year2)
selected_nctids = [nctid for nctid,year in nctid2year.items() if year>=year1 and year<=year2]
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print("# trials", len(selected_nctids))
print('-----------------------------------------------')
print('########### neoplasm ############')
selected_nctids = [nctid for nctid,disease in nctid2disease.items() \
if 'neoplasm' in ' '.join(disease).lower() or \
'tumor' in ' '.join(disease).lower() or \
'cancer' in ' '.join(disease).lower()]
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
from ccs_utils import file2_icd2ccs_and_ccs2description, file2_icd2ccsr
# icd2ccs, ccscode2description = file2_icd2ccs_and_ccs2description()
icd2ccsr = file2_icd2ccsr()
print('-----------------------------------------------')
print('########### respiratory ############')
selected_nctids = []
for nctid, icdcode_lst in nctid2icd.items():
for icdcode in icdcode_lst:
try:
ccsr = icd2ccsr[icdcode]
if ccsr == 'RSP':
selected_nctids.append(nctid)
break
except:
pass
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### digestive ############')
selected_nctids = []
for nctid, icdcode_lst in nctid2icd.items():
for icdcode in icdcode_lst:
try:
ccsr = icd2ccsr[icdcode]
if ccsr == 'DIG':
selected_nctids.append(nctid)
break
except:
pass
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### nervous ############')
selected_nctids = []
for nctid, icdcode_lst in nctid2icd.items():
for icdcode in icdcode_lst:
try:
ccsr = icd2ccsr[icdcode]
if ccsr == 'NVS':
selected_nctids.append(nctid)
break
except:
pass
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### other diseases ############')
selected_nctids = []
for nctid, icdcode_lst in nctid2icd.items():
for icdcode in icdcode_lst:
try:
ccsr = icd2ccsr[icdcode]
if not (ccsr == 'NVS' or ccsr == 'DIG' or ccsr == 'RSP' or ccsr == 'NEO'):
selected_nctids.append(nctid)
break
except:
pass
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### phase I ############')
selected_nctids = []
if True:
with open("data/phase_I_train.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_I_test.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_I_valid.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
phase1_nctids = selected_nctids[:]
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### phase II ############')
selected_nctids = []
if True:
with open("data/phase_II_train.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_II_test.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_II_valid.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
phase2_nctids = selected_nctids[:]
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### phase III ############')
selected_nctids = []
if True:
with open("data/phase_III_train.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_III_test.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
with open("data/phase_III_valid.csv") as fin:
readers = list(csv.reader(fin))[1:]
for row in readers:
nctid = row[0]
selected_nctids.append(nctid)
phase3_nctids = selected_nctids[:]
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
print('-----------------------------------------------')
print('########### phase 1,2,3 ############')
selected_nctids = phase1_nctids + phase2_nctids + phase3_nctids
positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
disease_set, drug_set = set(), set()
for nctid in selected_nctids:
disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
disease_set = disease_set.union(set(disease_lst))
drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
drug_set = drug_set.union(set(drug_lst))
print("disease ", len(disease_set))
print("drug", len(drug_set))
# print('-----------------------------------------------')
# print('########### indication ############')
# selected_nctids = []
# if True:
# with open("data/indication_train.csv") as fin:
# readers = list(csv.reader(fin))[1:]
# for row in readers:
# nctid = row[0]
# selected_nctids.append(nctid)
# with open("data/indication_test.csv") as fin:
# readers = list(csv.reader(fin))[1:]
# for row in readers:
# nctid = row[0]
# selected_nctids.append(nctid)
# with open("data/indication_valid.csv") as fin:
# readers = list(csv.reader(fin))[1:]
# for row in readers:
# nctid = row[0]
# selected_nctids.append(nctid)
# positive_sample = len(list(filter(lambda x:x in nctid2label and nctid2label[x]==1, selected_nctids)))
# print("total samples:", len(selected_nctids), "positive sample:", positive_sample, "negative sample", len(selected_nctids)-positive_sample)
# patientnumber_lst = [nctid2patientnumber[nctid] for nctid in selected_nctids if nctid in nctid2patientnumber]
# print("patient number ", np.mean(patientnumber_lst), np.std(patientnumber_lst), np.percentile(patientnumber_lst,[25,50,75]))
# disease_set, drug_set = set(), set()
# for nctid in selected_nctids:
# disease_lst = nctid2disease[nctid] if nctid in nctid2disease else []
# disease_set = disease_set.union(set(disease_lst))
# drug_lst = nctid2drug[nctid] if nctid in nctid2drug else []
# drug_set = drug_set.union(set(drug_lst))
# print("disease ", len(disease_set))
# print("drug", len(drug_set))