-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_sample.py
80 lines (62 loc) · 1.7 KB
/
make_sample.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
import random
import string
import csv
# the number of outcomes
N_OCS = 10000
# the number of max studies
N_STUS = 50
# the output file name
fn = 'sample.csv'
# make the studies
study_dict = {}
for i in range(N_STUS):
# make the study name
study = 'S%02d' % i
# make the study treatment and control
t = random.choice(string.ascii_uppercase)
c = random.choice(string.ascii_uppercase.replace(t, ''))
study_dict[study] = {
'phase': random.choice([2, 3]),
'year': random.randint(2000, 2021),
'type_of_therapy': random.choice([1, 2]),
'type_of_cancer': random.randint(0, 9),
}
# for saving the generated records
rs = []
for i in range(N_OCS):
# make an outcome name
oc_name = 'M%04d' % i
# generate the number of studies to be generated
n = random.randint(1, N_STUS)
# generate those studies
for j in range(n):
# generate a study name
study = 'S%02d' % random.randint(0, N_STUS-1)
# generate the Et, Ec
Et = random.randint(0, 50)
Ec = random.randint(0, 50)
# generate the Nt, Nc
Nt = Et + random.randint(1, 50)
Nc = Ec + random.randint(1, 50)
t = 'T'
c = 'C'
# add this record to rs
rs.append(
[oc_name, study, Et, Nt, Ec, Nc, t, c]
)
print('* generated all records %s' % (len(rs)))
print('* writing recrods to %s' % fn)
# the columns
cols = [
'outcome', 'study', 'Et', 'Nt', 'Ec', 'Nc',
'treatment', 'control'
]
# write the records
with open(fn, 'w') as csvfile:
# create a csv writer
cw = csv.writer(csvfile)
# write columns
cw.writerow(cols)
# write the records
cw.writerows(rs)
print("* done!")