-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelManager.py
More file actions
287 lines (212 loc) · 8.84 KB
/
modelManager.py
File metadata and controls
287 lines (212 loc) · 8.84 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
#/usr/bin/env python
import sys
from collections import OrderedDict
from os.path import basename
#**********************************************************************#
class Models:
def __init__ (self, MODEL_DIR):
self.work_dir = MODEL_DIR
FNAME_PREFIX = "cellcycle."
# define input file names:
self.fname_models = self.work_dir + 'models.transitioning.csv'
self.fname_states = self.work_dir + FNAME_PREFIX + 'states.csv'
self.fname_mpr = self.work_dir + FNAME_PREFIX + 'mpr.csv'
self.fname_dnr = self.work_dir + FNAME_PREFIX + 'dnr.csv'
self.fname_tsh = self.work_dir + FNAME_PREFIX + 'tsh.csv'
self.fname_fch = self.work_dir + FNAME_PREFIX + 'fch.csv'
self.fname_hco = self.work_dir + FNAME_PREFIX + 'hco.csv'
# define dictionaries for storing models
#self.model_dict = OrderedDict()
# define dictionaries for storing expressions and parameters:
self.EXP_dict = OrderedDict()
self.MPR_dict = OrderedDict()
self.DNR_dict = OrderedDict()
self.TSH_dict = OrderedDict()
self.FCH_dict = OrderedDict()
self.HCO_dict = OrderedDict()
self._load_expressions()
#print(self.EXP_dict.keys())
#print(self.EXP_dict.values())
self.MPR_dict = self._load_node_params(self.fname_mpr)
#print(self.MPR_dict.keys())
#print(self.MPR_dict.values())
self.DNR_dict = self._load_node_params(self.fname_dnr)
#print(self.DNR_dict.keys())
#print(self.DNR_dict.values())
self.TSH_dict = self._load_edge_params(self.fname_tsh)
#print(self.TSH_dict.keys())
#print(self.TSH_dict.values())
self.FCH_dict = self._load_edge_params(self.fname_fch)
#print(self.FCH_dict.keys())
#print(self.FCH_dict.values())
self.HCO_dict = self._load_edge_params(self.fname_hco)
#print(self.HCO_dict.keys())
#print(self.HCO_dict.values())
return None
#-----------------------------------------------------------------#
def _load_expressions(self):
#print("loading expressions")
NO_META_COLS = 4
fhandle = open(self.fname_states, 'r')
# skip the header line:
next(fhandle)
# load expression pairs into the dictionary:
while True:
# first state:
line = fhandle.readline()
fields = line.strip().split(sep=',')
#if(not representInt(model_no)): break
if(not representInt(fields[0])): break
#model_no = fields[0]
model_no = int(fields[0])
# get cluster no of the state:
cluster_no_state_1 = fields[3]
# get state expressions:
exp_state_1 = fields[(NO_META_COLS):]
# second state:
line = fhandle.readline()
fields = line.strip().split(sep=',')
#model_no = fields[0]
# get cluster no of the state:
cluster_no_state_2 = fields[3]
# get state expressions:
exp_state_2 = fields[(NO_META_COLS):]
# insert the expression pairs intot the dictionary:
self.EXP_dict[model_no] = (cluster_no_state_1, exp_state_1, \
cluster_no_state_2, exp_state_2)
if not line: break # EOF
fhandle.close()
return None
#-----------------------------------------------------------------#
def _load_node_params(self, fname_node_params):
#print("loading node params")
NO_META_COLS = 1
param_dict = OrderedDict()
fhandle = open(fname_node_params, 'r')
# skip the header line:
next(fhandle)
# load node params into the dictionary:
while True:
# first state:
line = fhandle.readline()
fields = line.strip().split(sep=',')
#if(not representInt(model_no)): break
if(not representInt(fields[0])): break
#model_no = fields[0]
model_no = int(fields[0])
node_params = fields[(NO_META_COLS):]
# insert the params into the dictionary:
param_dict[model_no] = node_params
if not line: break # EOF
fhandle.close()
return param_dict
#-----------------------------------------------------------------#
def _load_edge_params(self, fname_edge_params):
#print("loading edge params")
NO_META_COLS = 1
param_dict = OrderedDict()
fhandle = open(fname_edge_params, 'r')
# skip the header line:
next(fhandle)
# load node params into the dictionary:
while True:
# first state:
line = fhandle.readline()
fields = line.strip().split(sep=',')
#if(not representInt(model_no)): break
if(not representInt(fields[0])): break
#model_no = fields[0]
model_no = int(fields[0])
node_params = fields[(NO_META_COLS):]
# insert the params into the dictionary:
param_dict[model_no] = node_params
if not line: break # EOF
fhandle.close()
return param_dict
#-----------------------------------------------------------------#
def get_EXP_dict(self):
return self.EXP_dict
#-----------------------------------------------------------------#
def get_MPR_dict(self):
return self.MPR_dict
#-----------------------------------------------------------------#
def get_DNR_dict(self):
return self.DNR_dict
#-----------------------------------------------------------------#
def get_TSH_dict(self):
return self.TSH_dict
#-----------------------------------------------------------------#
def get_FCH_dict(self):
return self.FCH_dict
#-----------------------------------------------------------------#
def get_HCO_dict(self):
return self.HCO_dict
#---------------------------------------------------------------------#
def representInt(s):
try:
int(s)
return True
except ValueError:
return False
#**********************************************************************#
#-----------------------------------------------------------------------------#
def set_parameters_bymodel(rcp, MO, model_no):
#nodeParam_dict: node to (MPR,DNR) mapping:
#key: node, value: tuple (MPR,DNR)
nodeParam_dict=OrderedDict()
#import config_dict, node_dict, source_dict, target_dict:
config_dict=rcp.get_config_dict()
node_dict=rcp.get_node_dict()
source_dict=rcp.get_source_dict()
target_dict=rcp.get_target_dict()
master_dict=rcp.get_master_dict()
# extract model specific parameters
EXP_dict = MO.get_EXP_dict()
MPR_dict = MO.get_MPR_dict()
DNR_dict = MO.get_DNR_dict()
TSH_dict = MO.get_TSH_dict()
FCH_dict = MO.get_FCH_dict()
HCO_dict = MO.get_HCO_dict()
mpr_list = MPR_dict[model_no]
dnr_list = DNR_dict[model_no]
tsh_list = list(TSH_dict[model_no])
fch_list = list(FCH_dict[model_no])
hco_list = list(HCO_dict[model_no])
#update nodeParam_dict, source_dict, master_dict:
#with node and edge parameters:
node_no = 0
edge_no = 0
for node in node_dict.keys():
(node_type,mpr_range,dnr_range)=node_dict[node]
nodeParam_dict[node]=(node_type, float(mpr_list[node_no]), \
float(dnr_list[node_no]))
for (idx,e) in target_dict[node].items():
target,reg_type,tsh_range,hco_range,fch_range=e
#store the edge parameters in source_dict:
source_dict[target][idx]=source_dict[target][idx]+\
[float(tsh_list[edge_no]),\
float(hco_list[edge_no]),\
float(fch_list[edge_no])]
# update master_dict with edge parameters from supplied values:
master_dict[idx]=(node, target, reg_type, float(tsh_list[edge_no]), \
float(hco_list[edge_no]), \
float(fch_list[edge_no]))
edge_no = edge_no + 1
node_no = node_no + 1
return (nodeParam_dict,source_dict,master_dict)
#**********************************************************************#
if __name__ == '__main__':
print("This file contains modules to read raw data and parameters " +\
"for a set of models.")
'''
MODEL_DIR = "/Users/kateba/research/cellcycle-3.stoch/data-raw/earlyG1-midG1/"
models = Models(MODEL_DIR)
d = models.get_EXP_dict()
#print(d.keys())
#print(d.values())
for k,v in d.items():
print(k)
print(v[0], v[1])
print(v[2], v[3])
'''
sys.exit(0)