-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayRoom.py
286 lines (209 loc) · 8.24 KB
/
PlayRoom.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
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
import LoadModifiedCellstates as LMC
import AddProteins as App
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import math
#ak
def load_data(nframes,lambd):
cellstate = LMC.not_another_main(nframes,lambd)
print "Loaded, adding radius"
print "radius ready"
#cellstate = LMC.load_unmod(1500)
return cellstate
#--------------------------------------------------------------------
def calculate_sum_prot(cellstate,t):
n = sum([cell.red_protein for id,cell in cellstate[t].iteritems()])
return n
def get_R_max_t(cells_t): #get max R
R_max_t = 0.0
for id,cell in cells_t.iteritems():
if cell.r_dist > R_max_t:
R_max_t = cell.r_dist
return R_max_t
#def calculate_number_density(cellstates,N,t):
# for id,cell in cellstates[t]:
# sum_n_N = cell.redprot - N
def bin_check(cell_dist,r_bins,j):
if cell_dist >= r_bins[j] and cell_dist < r_bins[j+1]:
return True
else:
return False
#--------------------------------------------------------------------
#obtener curvas convergentes:
def obtain_convergent_curves(cellstate,t1,t2,nbins):
n_norm = []
for t in range(t1,t2):
cells_t = cellstate[t]
R_max_t = get_R_max_t(cells_t)
N_prot = calculate_sum_prot(cellstate,t) #total num proteins in t
n_prot = N_prot/(np.pi*(R_max_t**2))
r_bins = np.linspace(0,1,nbins)
n_i= np.array([])
for j in range(0,len(r_bins)-1):
bin_value = 0
for id,cell in cells_t.iteritems():
cell_dist = cell.r_dist/R_max_t
if bin_check(cell_dist,r_bins,j) == True:
bin_value += cell.red_protein
else:
bin_value += 0.0
area_i = np.pi*((r_bins[j+1])**2-(r_bins[j])**2)
bin_value = bin_value/area_i
n_i = np.append(n_i,bin_value)
n_n = (n_i-n_prot)
n_norm.append(n_n/max(n_i))
return np.array(n_norm),r_bins
#--------------------------------------------------------------------
def calc_average_vol(cellstate):
volume = []
for t in range(len(cellstate)):
for id,cell in cellstate[t].iteritems():
r1 = cell.radius
l1 = cell.length
area1 = np.pi*r1**2 + 2*r1*l1
volume.append(area1)
volume = np.array(volume)
avg_vol = np.average(volume)
return avg_vol
def get_volume(cellstate_t):
volume = []
for id,cell in cellstate_t.iteritems():
r1 = cell.radius
l1 = cell.length
area1 = np.pi*r1**2 + 2*r1*l1
volume.append(area1)
volume_t = np.sum(volume)
return volume_t
def idea2(cellstate,t1,t2):
volume_t = np.array([get_volume(cellstate[t]) for t in range(t1,t2)])
avg_vol = calc_average_vol(cellstate)
print "average volume: ",avg_vol
N_t = np.array([len(cellstate[t]) for t in range(t1,t2)])
R_max_t = np.array([get_R_max_t(cellstate[t]) for t in range(t1,t2)])
R_t = np.sqrt(N_t*np.average(volume_t)/np.pi)
#R_t does not match R_max_t, missing space between cells
return volume_t,avg_vol,N_t,R_max_t,R_t
def fix_Radii(volume_t,avg_vol,R_max_t,N_t):
#volume expected by R_max_t:
V_t = np.pi*(R_max_t**2)
#we calculate the volume lost/cell
Vv = (V_t-volume_t)/N_t #void volume per cell, converges to about 1
#add new value to R_t as shown:
R_t = np.sqrt(N_t*(avg_vol+Vv[-1])/np.pi)
return R_t,Vv #correctamente se comapra con R_max_t
#--------------------------------------------------------------------
def obtain_Ik(N_t,t1,t2):
dN = np.array([np.float(N_t[t+1] - N_t[t]) for t in range(t1,t2-2)])
return dN
#--------------------------------------------------------------------
def obtain_n_t(cellstate,t1,t2):
n_t = []
for t in range(t1,t2):
n_sum_t = calculate_sum_prot(cellstate,t)
n_t.append(n_sum_t)
return n_t
#--------------------------------------------------------------------
def add_grow_rate_i(cellstate,t):
for id,cell in cellstate[t].iteritems():
if t == 0:
cell.mu = 0
try:
cellstate[t+1][id]
r1 = cell.radius
l1 = cell.length
r2 = cellstate[t+1][id].radius
l2 = cellstate[t+1][id].length
area1 = np.pi*r1**2 + 2*r1*l1
area2 = np.pi*r2**2 + 2*r2*l2
mu_i = (1.0/area1)*(area2-area1)
cell.mu = mu_i
except:
mu_i = cellstate[t-1][id].mu
cell.mu = mu_i
return cellstate[t]
def mu_bin_r(cellstate,t,nbins = 20):
cells_t = cellstate[t]
R_max_t = get_R_max_t(cells_t)
r_bins = np.linspace(0,1,nbins)
mu_r = np.array([])
for j in range(0,len(r_bins)-1):
bin_value = 0
for id,cell in cells_t.iteritems():
cell_dist = cell.r_dist/R_max_t
if bin_check(cell_dist,r_bins,j) == True:
bin_value += cell.mu
else:
bin_value += 0.0
mu_r = np.append(mu_r,bin_value)
return mu_r,r_bins
def get_mu_t(cellstate,t1,t2):
mu_t = np.array([get_mu_single_t(cellstate,t) for t in range(t1,t2)])
return mu_t
def get_mu_single_t(cellstate,t):
mu_total = 0
cells_t = cellstate[t]
for id,cell in cells_t.iteritems():
mu_total += cell.mu
mu_total = mu_total/len(cellstate[t])
return mu_total
'''
def mu_bin_t(cellstate,t,nbins=20):
cells_t = cellstate[t]
T_max_t = len(cellstate)
r_bins = np.linspace(0,1,nbins)
mu_r = np.array([])
for j in range(0,len(r_bins)-1):
bin_value = 0
for id,cell in cells_t.iteritems():
cell_dist = cell.r_dist/R_max_t
if bin_check(cell_dist,r_bins,j) == True:
bin_value += cell.mu
else:
bin_value += 0.0
mu_r = np.append(mu_r,bin_value)
return mu_r,r_bins
'''
def plot_mu_r_t(r,t,mu_bins):
ax = Axes3D(plt.gcf())
ax.set_xlabel('r/R_max(t)')
ax.set_ylabel('t/Nframes')
ax.set_zlabel('mu/mu_max')
ax.plot_wireframe(r,t,mu_bins)
def get_mu_r_t(cellstate,tbins = 897,nbins=50):
for t in range(1,898):
cellstate = add_grow_rate_i(cellstate,t)
t_bins = np.linspace(0,1,tbins)
r_bins = np.linspace(0,1,nbins)
mu_bins = np.array([mu_bin_r(cellstate,t,nbins)[0] for t in range(1,tbins+1)])
r_bins,t_bins = np.meshgrid(r_bins[:-1],t_bins)
return r_bins,t_bins,mu_bins
def theoretical_N_t(cellstate,t1,t2):
for t in range(t1,t2):
cellstate[t] = add_grow_rate_i(cellstate,t)
v_t,a_v,N_t,R_max_t,R_t = idea2(cellstate,t1,t2)
R_t,Vv = fix_Radii(v_t,a_v,R_max_t,N_t)
mu_t = get_mu_t(cellstate,t1,t2)
int_mu = np.array([sum(mu_t[0:t]) for t in range(t1,t2)])
N_tt = 1*np.exp(int_mu)
R_tt = np.sqrt(v_t[0]/np.pi)*np.exp(0.5*int_mu)
A_tt = v_t[0]*np.exp(int_mu)
return N_tt,R_tt,A_tt,N_t,R_t,v_t,int_mu,Vv
cellstates = load_data(900,1)
N_tt,R_tt,A_tt,N_t,R_t,v_t,int_mu,Vv = theoretical_N_t(cellstates,0,899)
'''
fig, ax = plt.subplots()
ax.plot(a, c, 'k--', label='Model length')
ax.plot(a, d, 'k:', label='Data length')
ax.plot(a, c + d, 'k', label='Total message length')
legend = ax.legend(loc='upper center', shadow=True, fontsize='x-large')
'''
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------