-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp_hbdata_binomial.m~
276 lines (199 loc) · 7.05 KB
/
comp_hbdata_binomial.m~
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
clear all;
load hbSD_010611
figure(1); clf;
% cc11 12 13 14 %
Ncc = [125,250,500,1000]; % expected number of on cells.
cc = {cc11; cc12; cc13; cc14};
for c = 1:4
mu = zeros(1,G);
sigma = zeros(1,G);
bi_sig = zeros(1,G);
plot_miss = cell(1,G);
for k=1:G;
plot_miss{k} = foff{k}(cc{c}{k}) ;%foff{k}(cc14{k});
mu(k) = mean(plot_miss{k})*Ncc(c);
sigma(k) = std(plot_miss{k})*Ncc(c);
bi_sig(k) = mu(k)*( 1- nanmean(plot_miss{k}) );
end
rels = logical(1-isnan(sigma));
corc = corrcoef(bi_sig(rels), sigma(rels) ) ;
D = nanmedian((sigma - bi_sig)./bi_sig);
disp(sigma);
disp(bi_sig);
figure(1); subplot(2,2,c); scatter(sigma,bi_sig);
lin = [0,bi_sig,1.1*max(bi_sig)];
hold on; plot(lin,lin,'k');
xlim([0,1.1*max(sigma)]);
ylim([0,1.1*max(bi_sig)]);
title(['hb nucs: ', num2str(Ncc(c)), ' corr= ',num2str(corc(1,2),3), ' dist = ',num2str(D)]);
end
set(gcf,'color','w');
%% Simulate binomial Response across different times.
V = 200; % number of concentration points to check
time = 20 ; % min in cell cylce
stp = 20;
Ts = time*60/stp; % number of time points to check
D = 4.5;% diffusion rate of bcd (according to Dostatni)
cG = 4.8; % c Gregor
N = 50;
C = linspace(2,7,V); % range of concentrations to explore;
Th = 1:1000; % range of thresholds number of molecules to explore
low = cG-cG*.1; % 10% less than threshold bcd concentration
high = cG + cG*.1; % 10% more than threshold bcd concentration
miss_rate = zeros(1,Ts);
figure(4); clf;
ploop = [.22, .13, .22*.13]; col = {'blue','green','red'};
a_effs = [.03, .05, .03+.05]/1.9;
bf = zeros(Ts,N+1);
for e = 1:3;
a = a_effs(e); % effective enhancer size
for t = 1:Ts
T = t*stp;% T = 1*60;
phalf = gammainc(a*cG*D*T,floor(Th),'lower'); % 1 - upper is lower
[err,thresh] = min( abs(phalf - .5) );
pint = 1-gammainc(a*C*D*T,floor(thresh),'upper');
[err,cut] = min( abs(C - low)); % find where lines intersect
miss_rate(t) = pint(cut);
% figure(1); clf; plot(C,pint,'linewidth',2); hold on;
% plot([low,low],[0,1],'c');
% hold on; plot([high,high],[0,1],'r');
% figure(1); hold on; plot([C(cut)], [pint(cut)],'r.')
%
% vert = [C(1:cut)',pint(1:cut)']; vert = [vert; C(cut),0;0,0];
% fac = [1:cut+2];
%
% patch('Faces',fac,'Vertices',vert,'Facecolor',[0,.5,1]);
% alpha(.7);
% end
% figure(2); clf; plot(miss_rate, 'k.');
% bvar = N*miss_rate.*(1-miss_rate);
% figure(2); clf; plot(bvar);
% figure(3); clf; hist(miss_rate,0:.01:1); xlim([0,1]);
% for t=1:Ts
bf(t,:) = binopdf(0:1:N,N,1-(1-miss_rate(t))*(1-ploop(e) ) ); % binopdf(0:1:N,N,1-(1-miss_rate(t))*(1-ploop(e) ) );
end
ns = floor(logspace(0,log10(Ts),10));
figure(1); clf; plot(bf(ns,:)','r');
set(gcf,'color','k');
xbf = linspace(0,1,N+1);
bfD = sum(bf);
bfD = bfD/sum(bfD)*N;
figure(4); hold on; plot(xbf,bfD,'color',col{e});
end
legend('no primary','no shadow','control');
title(['cc13 T = ',num2str(time), 'min N = ',num2str(N), ' cells']);
set(gcf,'color','w');
%sum(bfD)*1/N
%% Dostatni numbers
V = 100;
%770/(.003*1*4.8) % time to count all 770 molecules (takes 891 min, error 3%)
% 1/sqrt(X) = .1 -> X = 100 molecules need to count to have 10% error.
% 100/(.003*1*4.8) --> 115 minutes (Thomas numbers)
% 100/(.003 * 4.5 *4.8) --> still 25 minutes, Dostatni numbers
% 100/(.003*10 * 4.5 *4.8) my enhancer size estimate 2.5 minutes
a = .003;
T = 25*60;% 7*60;
D = 4.5;
c = 4.8;
BP = 1/sqrt(D*a*c*T);
theta = 93;% 25; %
C = linspace(2, 7, V);
intp = zeros(1,V);
for k=1:V;
c= C(k); % c = 2
lambda = a*c*D*T;
n = 0:100;
p = lambda.^n./factorial(n)*exp(-lambda);
% figure(2); clf;
% plot(p,'linewidth',4); set(gcf,'color','k'); colordef black;
% set(gca,'color','k');
% sum( p(logical(1-isnan(p))) );
% sum(p(1:theta)) % the manual integration method
% gammainc(a*c*D*T,floor(theta),'upper') % the cdf method
intp(k) = 1-gammainc(a*c*D*T,floor(theta),'upper');
end
h1 = figure(3); clf; set(gca,'color','w'); colordef white;
plot(C,intp); hold on; plot([4.8,4.8],[0,1],'k');
plot([4.3,4.3],[0,1],'r');
legend('prob detecting > \theta','boundary conc.','10% less than boundary', 'Location','NorthWest' );
xlabel('c, molecules / um^3');
ylabel(['probability of seeing >', num2str(theta),' molecules in time T']);
title(['a = ',num2str(a,3), 'um T = ',num2str(T,3),'s D = ',num2str(D,2), 'um^2/s', ' 1/(DacT)^{1/2} = ' num2str(BP,3)]);
set(gcf,'color','w');
print('-depsc', '-tiff', [fout,'dostatni_calc_25min.eps']);
%% multiple binding sites new effective receptor size of primary enhancer
% factor of pi from binding model version of Berg-Purcell
a = .003;
T = 7*60;
c = 4.8;
b = a*24;
m=6;
D = 4.5;
dcM = 1/sqrt(pi*D*c*T).*sqrt(1/(m*a) + 1/(2*b))
%dcD = 1/sqrt(D*c*T*a_eff) = dcM
a_eff = 1/(dcM*sqrt(D*c*T))^2
%%
V = 100;
a = a_eff;
T = 7*60;
D = 4.5;
c = 4.8;
BP = 1/sqrt(D*a*c*T);
C = linspace(2, 7, V);
intp = zeros(1,V);
for k=1:V;
c= C(k);
lambda = a*c*D*T;
theta = 430;
intp(k) = 1- gammainc(lambda,floor(theta),'upper');
end
h2 = figure(3); clf; plot(C,intp); hold on; plot([4.8,4.8],[0,1],'k');
plot([4.3,4.3],[0,1],'r');
legend('prob detecting > \theta','boundary conc.','10% less than boundary', 'Location','NorthWest' );
xlabel('c, molecules / um^3');
ylabel(['probability of seeing >', num2str(theta),' molecules in time T']);
title(['a = ',num2str(a,3), 'um T = ',num2str(T,3),'s D = ',num2str(D,2), 'um^2/s', ' 1/(DacT)^{1/2} = ' num2str(BP,3)]);
set(gcf,'color','w');
% saveas(h2,[fout,'aeff_calc.eps'],'eps');
print('-depsc', '-tiff', [fout,'aeff_calc2.eps']);
%% Effective size of shadow
a = .003;
T = 7*60;
c = 4.8;
b = a*20; % the 3 bcd sites are only 200 bp apart
m=4;
D = 4.5;
dcM = 1/sqrt(pi*D*c*T).*sqrt(1/(m*a) + 1/(2*b))
%dcD = 1/sqrt(D*c*T*a_eff) = dcM
a_eff = 1/(dcM*sqrt(D*c*T))^2
a = a_eff;
T = 7*60;
D = 4.5;
c = 4.8;
BP = 1/sqrt(D*a*c*T);
C = linspace(2, 7, V);
intp = zeros(1,V);
for k=1:V;
c= C(k);
lambda = a*c*D*T;
theta = 295;
intp(k) = 1- gammainc(lambda,floor(theta),'upper');
end
h2 = figure(3); clf; plot(C,intp); hold on; plot([4.8,4.8],[0,1],'k');
plot([4.3,4.3],[0,1],'r');
legend('prob detecting > \theta','boundary conc.','10% less than boundary', 'Location','NorthWest' );
xlabel('c, molecules / um^3');
ylabel(['probability of seeing >', num2str(theta),' molecules in time T']);
title(['a = ',num2str(a,3), 'um T = ',num2str(T,3),'s D = ',num2str(D,2), 'um^2/s', ' 1/(DacT)^{1/2} = ' num2str(BP,3)]);
set(gcf,'color','w');
% saveas(h2,[fout,'aeff_calc.eps'],'eps');
print('-depsc', '-tiff', [fout,'shadow_calc.eps']);
a = .003;
T = 7*60;
c = 4.8;
b = a*4; % the 3 bcd sites are almost back to back
m=3;
D = 4.5;
dcM = 1/sqrt(pi*D*c*T).*sqrt(1/(m*a) + 1/(2*b))
%dcD = 1/sqrt(D*c*T*a_eff) = dcM
a_eff_Driever = 1/(dcM*sqrt(D*c*T))^2