-
Notifications
You must be signed in to change notification settings - Fork 0
/
cath.py
66 lines (55 loc) · 1.64 KB
/
cath.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
'''
To run, simply pass the input file as the only parameter, for example:
python cath.py cath_examples.txt
'''
import re
import sys
matches = dict()
matches['Enoxaparin'] = ['all']
matches['Lovenox'] = ['all']
matches['Bivalirudin'] = ['all']
matches['Angiomax'] = ['all']
matches['Eptifiatide'] = ['all']
matches['Integrilin'] = ['all']
matches['Unfractionated'] = ['all']
matches['Abciximab'] = ['all']
matches['Reopro'] = ['all']
matches['Smoker'] = ['all']
matches['Height'] = ['all']
matches['Weight'] = ['all']
#f = open("cathrpt_itemsneeded.txt");
#for line in f:
# m = re.search("\\w*@@([A-Za-z_0-9]*)", line)
# if m != None:
# print "matches['" + m.group(1) +"'] = ['all']"
def isMatch(line):
f = open("cathrpt_itemsneeded.txt")
for masterSearchTerm in matches:
m = re.search("^\\W*("+masterSearchTerm+")\\W", line, re.IGNORECASE)
if m != None:
for subSearchTerm in matches[masterSearchTerm]:
if subSearchTerm == "all":
return 1
else:
m2 = re.search(subSearchTerm, line, re.IGNORECASE)
if m2 != None:
return 1
return 0
f = open(sys.argv[1])
reading_header = 0
reading_body = 0
header = ""
for line in f:
if line.__contains__("S_O_H"):
header = ""
reading_body = 0
reading_header = 1
elif line.__contains__("E_O_H"):
reading_header = 0
reading_body = 1
elif line.__contains__("E_O_R"):
reading_body = 0
elif (reading_header):
header = line.rstrip()
if isMatch(line):
print header + " | " + line.rstrip()