-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbaye_import.py
78 lines (71 loc) · 2.17 KB
/
baye_import.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
####################################################################
# deprecated on 2015-03-20 12:08 #
# Reason: all code now in bayes.py, call bayes.py -d to display #
# dataframe data in console #
####################################################################
import numpy as np
import pandas as pd
from pandas import *
import re
findings = open('data/Findings_for_2015_decision_support_exercise_v03.txt')
diseases = open('data/Diseases_for_2015_decision_support_exercise_v03.txt')
sx_map = {}
IM_TY = {}
for line in findings:
line = line.rstrip('\r\n')
if (re.match('MX', line)):
line_list = line.split(None, 2)
sx_map[line_list[1]] = line_list[2]
else:
line_list = line.split(None, 4)
IM_TY[line_list[0]] = {line_list[1]:line_list[2],
line_list[3]:line_list[4]}
dz_map = {}
dz_mx = []
dz_lk = []
for line in diseases:
line = line.rstrip('\r\n')
if (re.match('DX', line)):
line_list = line.split(None, 2)
dz_map[line_list[1]] = line_list[2]
dz_set = line_list[1]
elif (re.match('MX', line)):
line_list = line.split(None, 3)
dz_mx.append(
{
'DX':dz_set,
'MX':line_list[2],
'PPV':list(line_list[1])[0],
'NPV':list(line_list[1])[1]
}
)
elif (re.match('LINK', line)):
line_list = line.split(None, 4)
dz_lk.append(
{
'DX':dz_set,
'LINK':line_list[3],
'LINK_t':line_list[1],
'PPV':list(line_list[2])[0],
'NPV':list(line_list[2])[1]
}
)
dz_map[line_list[3]] = line_list[4]
findings.close()
diseases.close()
IM_TY_df = DataFrame(IM_TY)
#print IM_TY_df.T.loc['391']
#sx_map_df = DataFrame(sx_map.items(), columns=['mx_code', 'mx_def'])
sx_map_df = DataFrame(sx_map.values(),index=sx_map.keys(), columns=['mx'])
#print sx_map_df.loc['190']
dz_mx_df = DataFrame(dz_mx)
#print dz_mx_df
dz_lk_df = DataFrame(dz_lk)
#print dz_lk_df
#dz_map_df = DataFrame(dz_map.items(), columns=['dx_code', 'dx_def])
dz_map_df = DataFrame(dz_map.values(),index=dz_map.keys(), columns=['dx'])
#print dz_map_df.loc['60']
print 'sx_map_df\n',sx_map_df.head()
print 'dz_mx_df\n',dz_mx_df.head()
print 'dz_lk_df\n',dz_lk_df.head()
print 'IM_TY_df\n',IM_TY_df.head()