forked from ucscCancer/cgData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackClinical.py
63 lines (51 loc) · 2.02 KB
/
TrackClinical.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
import CGData
import re
class TrackClinical(CGData.CGMergeObject):
DATA_FORM = None
typeSet = {
'clinicalMatrix' : True,
'clinicalFeature' : True
}
def __init__(self):
CGData.CGMergeObject.__init__(self)
def get_name( self ):
return "%s" % ( self.members[ "clinicalMatrix" ].get_name() )
def gen_sql_heatmap(self, id_table):
CGData.log("ClincalTrack SQL " + self.get_name())
matrix = self.members["clinicalMatrix"]
matrix.feature_type_setup()
features = self.members["clinicalFeature"]
for a in features:
if "stateOrder" in features[a]:
#this weird bit of code is to split on ',', but respect \,
#if you can think of a better way, please replace this
tmp = re.split(r'([^,]),', features[a]["stateOrder"][0])
enums = []
word = True
appending = False
e = 0
while e < len(tmp):
if word:
if appending:
enums[-1] += tmp[e]
else:
enums.append(tmp[e])
word = False
else:
if tmp[e] != "\\":
enums[-1] += tmp[e]
appending = False
else:
enums[-1] += ","
appending = True
word = True
e += 1
i = 0
for e in matrix.enum_map[a]:
if e in enums:
matrix.enum_map[a][e] = enums.index(e)
else:
matrix.enum_map[a][e] = len(enums) + i
i += 1
for a in matrix.gen_sql_heatmap(id_table, skip_feature_setup=True):
yield a