-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbatch.py
1997 lines (1821 loc) · 88 KB
/
batch.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from pylab import *
import sys,os,numpy,subprocess
from neuron import h,rxd
from math import ceil
h.load_file("stdrun.hoc") # creates cvode object - not really needed here
from vector import *
from nqs import *
from conf import *
from cawave import myloaddata, caCYT_init, wavespeed, wavedur, waveonset, wavenq, wavetime, wavedist
import multiprocessing
from Queue import Queue
import matplotlib.gridspec as gridspec
#from IPython.core.debugger import Tracer; debug_here = Tracer() #debugging using ipdb
ion() # interactive mode
# append line s to filepath fn
def appline (s,fn):
fp = open(fn,"a"); fp.write(s + "\n"); fp.close()
# check that the batch dir exists
def checkdir (d):
try:
if not os.path.exists(d): os.mkdir(d)
return True
except:
print "could not create directory :" + d
return False
# make a list of the sims that have already had their output saved, can then
# pass it into batchRun to skip those sims
def getSkipList (whichParams):
lsec,lopt,lval = whichParams()
sidx,lskip = -1,[]
for i in xrange(len(lopt[0])):
if lopt[0][i] == 'simstr':
sidx = i
break
if sidx == -1:
print "no simstr found!"
return None
for i in xrange(len(lval)):
if os.path.exists("./data/" + lval[i][sidx] + "_.npz"):
lskip.append(i)
return lskip
# run a batch using multiprocessing
# based on http://www.bryceboe.com/2011/01/28/the-python-multiprocessing-queue-and-large-objects/
def batchRun (whichParams,blog,skip=[],qsz=10,bdir="./batch"):
if not checkdir(bdir): return False
jobs = multiprocessing.Queue()
lsec,lopt,lval = whichParams()
def myworker (jobs):
while True:
scomm = jobs.get()
if scomm == None: break
print "worker starting : " , scomm
os.system(scomm) #worker function, invoked in a process.
for i in xrange(len(lsec)):
if i in skip: continue
cfgname = os.path.join(bdir, str(i) + ".cfg")
writeconf(cfgname,sec=lsec[i],opt=lopt[i],val=lval[i])
cmd = "python cawave.py " + cfgname
appline(cmd,blog)
jobs.put(cmd)
workers = []
for i in range(qsz):
jobs.put(None)
tmp = multiprocessing.Process(target=myworker, args=(jobs,))
tmp.start()
workers.append(tmp)
for worker in workers: worker.join()
return jobs.empty()
# pass in a function pointer that specifies parameters (whichParams) and run the sims
def shortRun (whichParams,skip=[]):
lsec,lopt,lval = whichParams()
for i in xrange(len(lsec)):
if i in skip: continue
writeconf("tmp.cfg",sec=lsec[i],opt=lopt[i],val=lval[i])
os.system("python cawave.py tmp.cfg")
# return results from sims specified by function pointer whichParams
def shortRead (whichParams):
lsec,lopt,lval = whichParams()
dat,sidx = [],0
for i in xrange(len(lopt[0])):
if lopt[0][i] == 'simstr':
sidx=i
for l in lval: dat.append(myloaddata(l[sidx])) # assumes that l[0] has simulation string
return dat
# convert params to NQS
def params2nq (whichParams):
lsec,lopts,lval = whichParams()
ncol,nrow = len(lopts[0]),len(lopts)
nq = NQS(ncol)
for i in xrange(ncol): nq.s[i].s = lopts[0][i]
if nq.fi("simstr") != -1: nq.strdec("simstr")
for i in xrange(nrow):
for j in xrange(ncol):
print i,j
if nq.s[j].s == "simstr":
nq.appi(j,lval[i][j])
else:
nq.appi(j,double(lval[i][j]))
return nq
# load/return data from the simstr entry of nq at specified row
def loadfromnq (nq,row):
nq.tog("DB")
if row < 0 or row >= nq.v[0].size():
print "row", row, " out of bounds: ", nq.v[0].size()
simstr = nq.get("simstr",row).s
print "loading " , simstr , " data "
return myloaddata(simstr)
# add a column of wavenq objects
def addwavenqcol (nq,thresh):
nq.tog("DB");
if nq.fi("nqw") == -1:
nq.resize("nqw")
nq.odec("nqw");
nq.pad()
sz = int(nq.v[0].size())
for row in xrange(sz):
print "up to row ", row, " of " , sz
s = nq.get("simstr",row).s
dat = loadfromnq(nq,row)
nqw = wavenq(dat["cytca"],thresh)
nq.set("nqw",row,nqw)
del dat
# add the wave properties to the nqs
def addwavepropcols (nq):
nq.tog("DB")
if nq.fi("nqw") == -1:
print "error: make sure this nqs has nqw (wavenq) column!"
return False
if nq.fi("speed") == -1:
nq.resize("speed","dur","time","amp","onset","dist"); nq.pad()
sz = int(nq.v[0].size())
for row in xrange(sz):
dat = loadfromnq(nq,row)
nqw = nq.get("nqw",row).o[0]
nqw.verbose=0
nq.getcol("speed").x[row]=wavespeed(data=dat,nqw=nqw)
nq.getcol("dur").x[row]=wavedur(data=dat,nqw=nqw);
nq.getcol("time").x[row]=wavetime(data=dat,nqw=nqw)
nq.getcol("amp").x[row]=amax(dat["cytca"])
nq.getcol("onset").x[row]=waveonset(data=dat,nqw=nqw)
nq.getcol("dist").x[row]=wavedist(data=dat,nqw=nqw)
nqw.tog("DB")
nqw.verbose=1
del dat
return True
# append to the lists
def NewParam (lsec,lopt,lval,sec,opt,val):
lsec.append(sec); lopt.append(opt); lval.append(val)
#####################################################################################
# baseline figure
# params for baseline figure
def baseParams ():
lsec,lopt,lval = [],[],[]
# baseline
lsec.append(["run","run","run","run"])
lopt.append(["simstr","runit","saveout","tstop"])
lval.append(["simBase_","1","1","6000"])
return lsec, lopt, lval
def baseRun ():
shortRun(baseParams)
def baseRead ():
return shortRead(baseParams)
# draw baseline simulation
def baseDraw (dat=None,miny=250,maxy=750):
if dat is None: dat = baseRead()[0]
from cawave import wavenq,mydraw,data,recdt
mint,maxt=2,6
tx, ty = -0.15, 1.06
figure();
ax=subplot(1,2,1); imshow(dat["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,6,0,1000),origin='lower'); colorbar();
xlim((mint,maxt)); ylim((miny,maxy)); title(r'$Ca^{2+}_{cyt}$ (mM)'); xlabel('Time (s)'); ylabel(r'Position ($\mu$m)');
text(tx,ty,"a",fontsize=14,fontweight='bold',transform=ax.transAxes)
ax=subplot(1,2,2); imshow(dat["erca"],vmin=0,vmax=0.011,aspect='auto',extent=(0,6,0,1000),origin='lower'); colorbar();
xlim((mint,maxt)); ylim((miny,maxy)); title(r'$Ca^{2+}_{er}$ (mM)'); xlabel('Time (s)');
text(tx,ty,"b",fontsize=14,fontweight='bold',transform=ax.transAxes)
#####################################################################################
#####################################################################################
# slide 18 -- hotspots == extra IP3R or extra ER ?
# params for slide 18 ( baseline, double IP3R, quadruple ER )
def hsTestParams ():
lsec,lopt,lval = [],[],[]
# baseline
lsec.append(["run","run","run"])
lopt.append(["simstr","runit","saveout"])
lval.append(["hsTestBase_","1","1"])
# double IP3R
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","boost_every"])
lval.append(["hsTest2IP3R_","1","1",str(2.0*12040.0),"50.0"])
# quadruple ER
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","boost_every","er_scale"])
lval.append(["hsTest4ER_","1","1","50.0","4.0"])
return lsec, lopt, lval
# run sims for slide 18 and save output ( baseline, double IP3R, quadruple ER )
def hsTestRun (skip=[]):
shortRun(hsTestParams,skip)
# read results from slide 18 sims
def hsTestRead ():
return shortRead(hsTestParams)
# draw results from slide 18
def hsTestDraw (dat=None):
from cawave import wavenq,mydraw,data,recdt
if dat is None: dat = hsTestRead()
tx, ty = -0.15, 1.06
sca = r'$Ca^{2+}_{cyt}$ (mM)'
ltitles = ["Baseline: "+sca, r"$2X$ IP3R: "+sca, r"$4X$ ER: "+sca]; txl = ["a", "b", "c"];
for i in xrange(len(ltitles)):
nq = wavenq(dat[i]["cytca"]); nq.select("overlap",0,"up",1,"y",">=",500); ld=nqs2pyd(nq); nqsdel(nq);
ax=subplot(2,len(ltitles),i+1);
imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower');
xlim((0,12)); ylim((400,600));
if i == 0: ylabel('Position (um)');
# if i == len(ltitles)-1: colorbar()
title(ltitles[i]);
text(tx,ty,txl[i],fontsize=14,fontweight='bold',transform=ax.transAxes)
subplot(2,len(ltitles),i+4);
plot(ld['startt']/1e3,ld['durt']/1e3,'k'); plot(ld['startt']/1e3,ld['durt']/1e3,'ko');
# plot(ld['startt']/1e3,ld['speed']*500,'r'); plot(ld['startt']/1e3,ld['speed']*500,'ro');
xlabel('Time(s)');
if i==0: ylabel('Duration (s)');
grid(True); xlim((0,12)); ylim((0,5));
#####################################################################################
#####################################################################################
# slide 19 -- spacing between hotspots
# params for slide 19
def hsSpaceParams (space = [50, 25, 12.5, 6.25]):
lsec,lopt,lval = [],[],[]
for b in space:
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","boost_every"])
lval.append(["hsSpaceTest_"+str(b),"1","1",str(2.0*12040.0),str(b)])
return lsec, lopt, lval
# run sims for slide 19 and save output ( baseline, double IP3R, quadruple ER )
def hsSpaceRun (skip=[]):
shortRun(hsSpaceParams,skip)
# read results from slide 19 sims
def hsSpaceRead ():
return shortRead(hsSpaceParams)
# draw results from slide 19
def hsSpaceDraw (dat=None):
if dat is None: dat = hsSpaceRead()
from cawave import wavenq,mydraw,data,recdt
tx, ty = -0.15, 1.06
ltitles = ["50", "25", "12.5", "6.25"];
tlx = ["a","b","c","d"];
for i in xrange(len(ltitles)):
nq = wavenq(dat[i]["cytca"]); nq.select("overlap",0,"up",1,"y",">=",500); ld=nqs2pyd(nq); nqsdel(nq);
ax=subplot(2,len(ltitles),i+1);
im=imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
if i == 0: ylabel('Position (um)');
ylim((200,800)); xlim((0,25));
# if gn == len(ltitles): colorbar(im, use_gridspec=True)
# title("Boost "+ltitles[i]+ " uM : " + r'$Ca^{2+}_{cyt}$ (mM)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[i],fontsize=14,fontweight='bold',transform=ax.transAxes)
subplot(2,len(ltitles),i+5);
plot(ld['startt']/1e3,ld['durt']/1e3,'k');
plot(ld['startt']/1e3,ld['durt']/1e3,'ko');
xlabel('Time(s)'); grid(True);
xlim((0,25)); ylim((0,5));
if i == 0: ylabel('Duration (s)');
#####################################################################################
#####################################################################################
# -- spacing between coldspots
# params for coldspot spacing
def csSpaceParams (space = [50, 25, 12.5, 6.25]):
lsec,lopt,lval = [],[],[]
for b in space:
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","boost_every"])
lval.append(["csSpaceTest_"+str(b),"1","1",str(0.85*12040.0),str(b)])
return lsec, lopt, lval
# run sims for coldspot spacing and save output
def csSpaceRun (skip=[]):
shortRun(csSpaceParams,skip)
# read results from coldspot spacing sims
def csSpaceRead ():
return shortRead(csSpaceParams)
# draw results from coldspot spacing
def csSpaceDraw (dat=None):
if dat is None: dat = csSpaceRead()
from cawave import wavenq,mydraw,data,recdt
tx, ty = -0.15, 1.06
ltitles = ["50", "25", "12.5", "6.25"];
tlx = ["a","b","c","d"];
for i in xrange(len(ltitles)):
nq = wavenq(dat[i]["cytca"]); nq.select("overlap",0,"up",1,"y",">=",500); ld=nqs2pyd(nq); nqsdel(nq);
ax=subplot(2,len(ltitles),i+1);
im=imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
if i == 0: ylabel('Position (um)');
ylim((400,600)); xlim((0,10));
# if gn == len(ltitles): colorbar(im, use_gridspec=True)
# title("Boost "+ltitles[i]+ " uM : " + r'$Ca^{2+}_{cyt}$ (mM)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[i],fontsize=14,fontweight='bold',transform=ax.transAxes)
subplot(2,len(ltitles),i+5);
plot(ld['startt']/1e3,ld['durt']/1e3,'k');
plot(ld['startt']/1e3,ld['durt']/1e3,'ko');
xlabel('Time(s)'); grid(True);
xlim((0,10)); ylim((0,5));
if i == 0: ylabel('Duration (s)');
#####################################################################################
#####################################################################################
# slide 20 -- hot spots that decrease spread
# params for slide 20
def hsDecParams (b=100,fctr=2.0):
lsec,lopt,lval = [],[],[]
# baseline
lsec.append(["run","run","run"])
lopt.append(["simstr","runit","saveout"])
lval.append(["hsDecBase_","1","1"])
# hotspots which are too closely spaced - causing decreased duration wave
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","boost_every"])
simstr = "hsDecTest_boost_every_"+str(b)+"_ip3_origin_"+str(fctr*12040.0)
lval.append([simstr,"1","1",str(fctr*12040.0),str(b)])
return lsec, lopt, lval
# run sims for slide 20 and save output ( baseline, decreased wave spread via hotspot )
def hsDecRun (skip=[]):
shortRun(hsDecParams,skip)
# read results from slide 20 sims
def hsDecRead ():
return shortRead(hsDecParams)
# draw results from slide 20
def hsDecDraw (dat=None):
if dat is None: dat = hsDecRead()
gn = 1; ltitles = ["Baseline", "Hotspots"];
for i in xrange(len(ltitles)):
subplot(len(ltitles),1,gn);
if gn == len(ltitles): xlabel('Time(s)');
imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylabel('Position (um)');
colorbar()
title(ltitles[i]); gn += 1;
show()
#####################################################################################
#####################################################################################
# slide 21 -- varies gip3r everywhere
# params for slide 21
def gIP3RParams (lfctr=[0.9, 1.0, 1.1]):
lsec,lopt,lval = [],[],[]
for fctr in lfctr:
lsec.append(["run","run","run","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","ip3_notorigin"])
simstr = "gIP3RTest_gip3r_"+str(fctr*12040.0)
lval.append([simstr,"1","1",str(fctr*12040.0),str(fctr*12040.0)])
return lsec, lopt, lval
# run sims for slide 21 and save output
def gIP3RRun (skip=[]):
shortRun(gIP3RParams,skip)
# read results from slide 21 sims
def gIP3RRead ():
return shortRead(gIP3RParams)
# draw results from slide 21
def gIP3RDraw (dat=None,lfctr=[0.9, 1.0, 1.1]):
if dat is None: dat = gIP3RRead()
gn,i = 1,0
tx, ty = -0.15, 1.06
tlx = ["a", "b", "c"]
for fctr in lfctr:
ax=subplot(1,len(lfctr),gn); xlabel('Time(s)');
imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
xlim((0,15)); ylim((400,600));
if gn == 1: ylabel('Position (um)');
# if gn == len(lfctr): colorbar();
# title("gIP3R: " + str(fctr) + r"$X$: "
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[i],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1; i += 1;
#####################################################################################
#####################################################################################
# slide 22,23 -- varies gserca everywhere
# params for slide 22,23
def gSERCAParams (lfctr=[0.4, 0.5, 0.75]):
lsec,lopt,lval = [],[],[]
for fctr in lfctr:
lsec.append(["run","run","run","set"])
lopt.append(["simstr","runit","saveout","gserca"])
simstr = "gSERCATest_"+str(fctr*0.3913)
lval.append([simstr,"1","1",str(fctr*0.3913)])
return lsec, lopt, lval
# run sims for slide 22,23 and save output
def gSERCARun (skip=[]):
shortRun(gSERCAParams,skip)
# read results from slide 22,23 sims
def gSERCARead ():
return shortRead(gSERCAParams)
# draw results from slide 22,23
def gSERCADraw (dat=None,lfctr=[0.4, 0.5, 0.75]):
if dat is None: dat = gSERCARead()
gn,i = 1,0
tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"]
for fctr in lfctr:
ax=subplot(1,len(lfctr),gn); xlabel('Time(s)');
imshow(dat[i]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((275,725));
if gn == 1: ylabel('Position (um)');
#if gn == len(lfctr): colorbar();
#title("gserca: " + str(fctr) + "X");
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[i],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1; i += 1;
#####################################################################################
#####################################################################################
# slide 24 -- long batch varying gserca and gip3
######################
# gip3 variations
#
def gIP3RBatchLims ():
return numpy.linspace(0.8,2.0,109)
# params for slide 24 - part that varies gip3
def gIP3RBatchParams (lfctr=gIP3RBatchLims()):
lsec,lopt,lval = [],[],[]
for fctr in lfctr:
lsec.append(["run","run","run","set","set","set","set","set","set"])
lopt.append(["simstr","runit","saveout","ip3_origin","ip3_notorigin","ip3_stim","ip3_stimT","gleak","gserca"])
simstr = "gIP3RBatch_"+str(fctr*120400.0)
lval.append([simstr,"1","1",str(fctr*120400.0),str(fctr*120400.0),"1.25","2e3","18.06","1.9565"])
return lsec, lopt, lval
# run sims for gipr part of slide 24 and save output
def gIP3RBatchRun (skip=[],blog="gIP3RBatch/gIP3RBatch.log",bdir="gIP3RBatch",qsz=10):
batchRun(gIP3RBatchParams,blog,skip=skip,qsz=qsz,bdir=bdir)
# read results from slide 24 sims
def gIP3RBatchRead ():
return shortRead(gIP3RBatchParams)
#
def subxgtzero (lon, startt):
plon = []
for i in xrange(len(lon)):
if lon[i] > 0:
plon.append(lon[i]-startt)
else:
plon.append(0)
return plon
# draw figure showing sensitivity to IP3R density
def gIP3RBatchDraw (dat=None,lnq=None,ldw=None,lsp=None,ldur=None,lamp=None,lon=None,xl=(0.75,1.8),stimT=2000, lidx=[11, 18, 86]):
if dat is None: dat = gIP3RBatchRead()
if lnq is None: lnq,ldw,lsp,ldur,lamp,lon=getwavenqs(gIP3RBatchParams,dat)
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"]#; lidx = [15, 86]
G = gridspec.GridSpec(2, 4)
for idx in [lidx[0], lidx[-1]]:
ax=subplot(G[0,gn*2:gn*2+2]);
xlabel('Time(s)');
imshow(dat[idx]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((200,800)); xlim((2,7));
if gn == 0: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1;
# lidx = [15, 18, 86] # reset lidx to include baseline
sz1,sz2 = 10,10; gfctr = gIP3RBatchLims();
ax=subplot(G[1,0]); xlim(xl); grid(True);
text(tx,ty,"c",fontsize=14,fontweight='bold',transform=ax.transAxes);
plon = subxgtzero(lon,stimT)
plot(gfctr[0:86],plon[0:86],'ko',markersize=sz1); xlabel("IP3R density"); title("Onset (ms)");
gtt = [gfctr[lidx[0]], gfctr[lidx[1]] ,gfctr[lidx[2]]];
ltt = [plon[lidx[0]], plon[lidx[1]], plon[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2);
# print the values of red dots
print '\nred dots values for onset:'
for val in enumerate(gtt):
print 'red dot index({0}):\nip3rDensity={1}, onset(ms)={2}'.format(val[0],val[1],ltt[val[0]])
ylim((0,250));
ax=subplot(G[1,1]); xlim(xl); grid(True);
text(tx,ty,"d",fontsize=14,fontweight='bold',transform=ax.transAxes);
#plot(gfctr,lsp,'ko',markersize=sz1); xlabel("IP3R density"); title(r"Speed ($\mu$m/s)");
plot(gfctr[0:86],lsp[0:86],'ko',markersize=sz1); xlabel("IP3R density"); title(r"Speed ($\mu$m/s)");
ltt = [lsp[lidx[0]], lsp[lidx[1]], lsp[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2);
# print the values of red dots
print '\nred dots values for speed:'
for val in enumerate(gtt):
print 'red dot index({0}):\nip3rDensity={1}, speed(um/s)={2}'.format(val[0],val[1],ltt[val[0]])
ax=subplot(G[1,2]); xlim(xl); grid(True);
text(tx,ty,"e",fontsize=14,fontweight='bold',transform=ax.transAxes);
plot(gfctr[0:86],numpy.array(ldur)[0:86]/1e3,'ko',markersize=sz1); xlabel("IP3R density"); title("Duration (s)");
ltt = [ldur[lidx[0]]/1e3, ldur[lidx[1]]/1e3, ldur[lidx[2]]/1e3 ]; plot(gtt,ltt,'ro',markersize=sz2); ylim((0,1.2));
# print the values of red dots
print '\nred dots values for duration:'
for val in enumerate(gtt):
print 'red dot index({0}):\nip3rDensity={1}, duration(s)={2}'.format(val[0],val[1],ltt[val[0]])
ax=subplot(G[1,3]); xlim(xl); grid(True);
text(tx,ty,"f",fontsize=14,fontweight='bold',transform=ax.transAxes);
plot(gfctr[0:86],lamp[0:86],'ko',markersize=sz1); xlabel("IP3R density"); title("Amplitude (mM)");
ltt = [lamp[lidx[0]], lamp[lidx[1]], lamp[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2); ylim((0,0.0021));
print '\nred dots values for amplitude:'
for val in enumerate(gtt):
print 'red dot index({0}):\nip3rDensity={1}, amplitude(mM)={2}'.format(val[0],val[1],ltt[val[0]])
tight_layout()
##############################################################################################################
# test ip3diff (and cadiff??) in the continuous model
#
def IP3DIFFBatchLims ():
return numpy.linspace(0,10,101)
#
def IP3DIFFBatchParams (ldiff=IP3DIFFBatchLims()):
lsec,lopt,lval = [],[],[]
alls,allo,allv = [],[],[] # params shared across sims in this batch
NewParam(alls,allo,allv,"set","ip3_stim","1.25")
NewParam(alls,allo,allv,"set","ip3_stimT","2e3")
NewParam(alls,allo,allv,"set","boost_halfw","5.0")
NewParam(alls,allo,allv,"set","ip3_origin","120400.0")
NewParam(alls,allo,allv,"set","ip3_notorigin","120400.0")
NewParam(alls,allo,allv,"set","gleak",str(18.06))
NewParam(alls,allo,allv,"set","gserca",str(1.9565))
NewParam(alls,allo,allv,"run","runit","1")
NewParam(alls,allo,allv,"run","saveout","1")
for IP3DIFF in 1.415 * ldiff: # variations in ip3 diffusion coefficient
tmpsec,tmpopt,tmpval=[],[],[]
for i in xrange(len(alls)): tmpsec.append(alls[i]); tmpopt.append(allo[i]); tmpval.append(allv[i]);
simstr = "IP3DIFF_"+str(IP3DIFF)
NewParam(tmpsec,tmpopt,tmpval,"set","ip3Diff",str(IP3DIFF))
NewParam(tmpsec,tmpopt,tmpval,"run","simstr",simstr)
lsec.append(tmpsec); lopt.append(tmpopt); lval.append(tmpval);
return lsec, lopt, lval
#
def IP3DIFFBatchRun (skip=[],blog="IP3DIFFBatch/IP3DIFFBatch.log",bdir="IP3DIFFBatch",qsz=12):
batchRun(IP3DIFFBatchParams,blog,skip=skip,qsz=qsz,bdir=bdir)
#
def IP3DIFFBatchRead ():
return shortRead(IP3DIFFBatchParams)
#
def IP3DIFFBatchDraw (dat=None,lnq=None,ldw=None,lsp=None,ldur=None,lamp=None,lon=None,xl=(0.12,2.0),stimT=2000, lidx=[1, 10, 14]):
if dat is None: dat = gIP3RBatchRead()
if lnq is None: lnq,ldw,lsp,ldur,lamp,lon=getwavenqs(IP3DIFFBatchParams,dat)
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"]#; lidx = [15, 86]
G = gridspec.GridSpec(2, 4)
for idx in [lidx[0], lidx[-1]]:
ax=subplot(G[0,gn*2:gn*2+2]);
xlabel('Time(s)');
imshow(dat[idx]["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((300,700)); xlim((2,5));
if gn == 0: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1;
sz1,sz2 = 10,10; gfctr = IP3DIFFBatchLims() * 1.415;
xltxt=r'$IP_3$ diff ($\mu$m$^2$/ms)'
sidx,eidx=1,15
ax=subplot(G[1,0]); xlim(xl); grid(True);
text(tx,ty,"c",fontsize=14,fontweight='bold',transform=ax.transAxes);
plon = subxgtzero(lon,stimT)
plot(gfctr[sidx:eidx],plon[sidx:eidx],'ko',markersize=sz1); xlabel(xltxt); title("Onset (ms)");
gtt = [gfctr[lidx[0]], gfctr[lidx[1]] ,gfctr[lidx[2]]];
ltt = [plon[lidx[0]], plon[lidx[1]], plon[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2);
# print the values of red dots
print '\nred dots values for onset:'
for val in enumerate(gtt):
print 'red dot index({0}):\nIP3DIFF={1}, onset(ms)={2}'.format(val[0],val[1],ltt[val[0]])
ylim((0,250));
ax=subplot(G[1,1]); xlim(xl); grid(True);
text(tx,ty,"d",fontsize=14,fontweight='bold',transform=ax.transAxes);
#plot(gfctr,lsp,'ko',markersize=sz1); xlabel(xltxt); title(r"Speed ($\mu$m/s)");
plot(gfctr[sidx:eidx],lsp[sidx:eidx],'ko',markersize=sz1); xlabel(xltxt); title(r"Speed ($\mu$m/s)");
ltt = [lsp[lidx[0]], lsp[lidx[1]], lsp[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2);
# print the values of red dots
print '\nred dots values for speed:'
for val in enumerate(gtt):
print 'red dot index({0}):\nIP3DIFF={1}, speed(um/s)={2}'.format(val[0],val[1],ltt[val[0]])
ax=subplot(G[1,2]); xlim(xl); grid(True);
text(tx,ty,"e",fontsize=14,fontweight='bold',transform=ax.transAxes);
plot(gfctr[sidx:eidx],numpy.array(ldur)[sidx:eidx]/1e3,'ko',markersize=sz1); xlabel(xltxt); title("Duration (s)");
ltt = [ldur[lidx[0]]/1e3, ldur[lidx[1]]/1e3, ldur[lidx[2]]/1e3 ]; plot(gtt,ltt,'ro',markersize=sz2); ylim((0,1.2));
# print the values of red dots
print '\nred dots values for duration:'
for val in enumerate(gtt):
print 'red dot index({0}):\nIP3DIFF={1}, duration(s)={2}'.format(val[0],val[1],ltt[val[0]])
ax=subplot(G[1,3]); xlim(xl); grid(True);
text(tx,ty,"f",fontsize=14,fontweight='bold',transform=ax.transAxes);
plot(gfctr[sidx:eidx],lamp[sidx:eidx],'ko',markersize=sz1); xlabel(xltxt); title("Amplitude (mM)");
ltt = [lamp[lidx[0]], lamp[lidx[1]], lamp[lidx[2]] ]; plot(gtt,ltt,'ro',markersize=sz2); ylim((0,0.0021));
print '\nred dots values for amplitude:'
for val in enumerate(gtt):
print 'red dot index({0}):\nIP3DIFF={1}, amplitude(mM)={2}'.format(val[0],val[1],ltt[val[0]])
tight_layout()
##############################################################################################################
######################
# test IP3R hot-spots (modulates IP3R density at hotspots and spacing of hotspots) - HSIP3RBatch
# limits for HS densities
def HSIP3RBatchLimsDense ():
return numpy.linspace(0.8,2,55)
# limits for HS spacing
def HSIP3RBatchLimsSpace ():
return numpy.linspace(15,100,18)
# params for batch varying IP3R hotspots (density and spacing)
def HSIP3RBatchParams (lfdense=HSIP3RBatchLimsDense(),lfspace=HSIP3RBatchLimsSpace(),cs=0.8):
lsec,lopt,lval = [],[],[]
alls,allo,allv = [],[],[] # params shared across sims in this batch
NewParam(alls,allo,allv,"set","ip3_stim","1.25")
NewParam(alls,allo,allv,"set","ip3_stimT","2e3")
NewParam(alls,allo,allv,"set","gleak","18.06")
NewParam(alls,allo,allv,"set","gserca","1.9565")
NewParam(alls,allo,allv,"set","boost_halfw","5.0")
NewParam(alls,allo,allv,"set","ip3_notorigin",str(cs*120400.0))
NewParam(alls,allo,allv,"run","tstop","15000")
for dense in lfdense: # variations in density of IP3R hotspots
for space in lfspace: # variations in distance between IP3R hotspots
tmpsec,tmpopt,tmpval=[],[],[]
for i in xrange(len(alls)): tmpsec.append(alls[i]); tmpopt.append(allo[i]); tmpval.append(allv[i]);
simstr = "HSIP3RBatch_Dense_"+str(dense*120400.0)+"_Space_"+str(space)
NewParam(tmpsec,tmpopt,tmpval,"run","simstr",simstr)
NewParam(tmpsec,tmpopt,tmpval,"run","runit","1")
NewParam(tmpsec,tmpopt,tmpval,"run","saveout","1")
NewParam(tmpsec,tmpopt,tmpval,"set","ip3_origin",str(dense*120400.0))
NewParam(tmpsec,tmpopt,tmpval,"set","boost_every",str(space))
lsec.append(tmpsec); lopt.append(tmpopt); lval.append(tmpval);
return lsec, lopt, lval
# run this batch
def HSIP3RBatchRun (skip=[],blog="HSIP3RBatch/HSIP3RBatch.log",bdir="HSIP3RBatch",qsz=12):
batchRun(HSIP3RBatchParams,blog,skip=skip,qsz=qsz,bdir=bdir)
# read data from this batch
def HSIP3RBatchRead ():
return shortRead(HSIP3RBatchParams)
# print the values at the row in the nqs (div by baseline IP3R density of 120400.0)
def HSIP3RBatchParamsAtRow (nq,row):
nq.tog("DB")
simstr = nq.get("simstr",row).s
dense = nq.getcol("ip3_origin").x[row] / 120400.0
cs = nq.getcol("ip3_notorigin").x[row] / 120400.0
space = nq.getcol("boost_every").x[row]
print "row " , row, ": dense: " , dense, " space : " , space, " CS: " , cs, ", simstr:",simstr
speed, amp = nq.getcol("speed").x[row],nq.getcol("amp").x[row]
dur, onset = nq.getcol("dur").x[row],nq.getcol("onset").x[row]
print "\t speed:",speed,", amp:",amp,", dur:",dur,", onset:",onset
return dense,cs,space,speed,amp,dur,onset
# draw the waves for first part of the figure
def HSIP3RBatchDrawWaves (nq,lidx=[163, 577, 973, 865, 871, 877]):
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"];
lfdense,lfspace = HSIP3RBatchLimsDense(),HSIP3RBatchLimsSpace()
nrows,ncols = 2,3
for idx in lidx:
ax=subplot(nrows,ncols,gn+1);
dat = loadfromnq(nq,idx);
HSIP3RBatchParamsAtRow(nq,idx) # print info
imshow(dat["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((0,1000)); xlim((2,10));
if gn == 0 or gn == 3: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
if gn > 2: xlabel('Time (s)');
gn += 1;
# draw waves/features
def HSIP3RBatchDrawSub (nq,G,gRow,fixedspace=True):
lfdense,lfspace = HSIP3RBatchLimsDense(),HSIP3RBatchLimsSpace()
lidx,gctr,lidx2,xtxt=[],[],[],"";
if fixedspace: # fixed spacing
lidx = [109, 973] # index into nqs # new run of sims
#lidx = [163, 973] # index into nqs
nq.select("boost_every",20.0)
xtxt = r"Density"
gfctr = lfdense
else: # fixed density
lidx = [864, 881] # index into nqs # new run of sims
#lidx = [865, 877] # index into nqs
nq.select("ip3_origin",lfdense[48]*120400.0)
xtxt = r"Spacing ($\mu$m)"
gfctr = lfspace
lsp,ldur,lamp,lon,ltmp = getwpropcols(nq,db=False); nq.tog("DB")
#return ltmp # dubgging code
lidx2 = [ltmp.index(lidx[0]), ltmp.index(lidx[1])];
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c"]
if not fixedspace: tlx = ["d", "e", "f"];
for idx in lidx: # draw the waves
dat = loadfromnq(nq,idx); HSIP3RBatchParamsAtRow(nq,idx) # load data, print info
ax=subplot(G[gRow,gn:gn+1]); xlabel('Time(s)');
imshow(dat["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,15,0,1000),origin='lower')
ylim((300,700)); xlim((2,6));
if gn == 0: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1;
ly = [ (0,115) ]; ltitles = [r"Speed ($\mu$m/s)"]; gn = 2; sz1,sz2=10,10;
scaley = [1.0,1.0,1.0/1e3,1.0]; naxbins=6; lvals=[ lsp ];
for pdx in xrange(1): # plots for the four wave features
ax=subplot(G[gRow,gn:gn+1]); xlabel(xtxt); title(ltitles[pdx]); ylim(ly[pdx]);
xlim([amin(gfctr)-amin(gfctr)/5.0,amax(gfctr)+amin(gfctr)/5.0]); # to avoid data points being flush with graph borders
#xlim([amin(gfctr)-amin(gfctr)/10.0,amax(gfctr)+amin(gfctr)/10.0]);
ax.locator_params(nbins=naxbins);
text(tx,ty,tlx[pdx+2],fontsize=14,fontweight='bold',transform=ax.transAxes); grid(True);
plot(gfctr,numpy.array(lvals[pdx])*scaley[pdx],'ko',markersize=sz1);
gtt,ltt=[gfctr[lidx2[0]],gfctr[lidx2[1]]],[lvals[pdx][lidx2[0]],lvals[pdx][lidx2[1]]];
plot(gtt,numpy.array(ltt)*scaley[pdx],'ro',markersize=sz1);
print '\nred dots values for ' + xtxt + ' :'
for val in enumerate(gtt):
print 'red dot index({0}):\n{3}={1}, Speed(um)={2}'.format(val[0],val[1],ltt[val[0]],xtxt)
gn += 1;
# draw waves and speeds
def HSIP3RBatchDraw (nq):
nrows,ncols = 2,3
G = gridspec.GridSpec(nrows, ncols);
HSIP3RBatchDrawSub(nq,G,0,fixedspace=True) # fixed spacing
HSIP3RBatchDrawSub(nq,G,1,fixedspace=False) # fixed density
tight_layout()
# draw the wave properties stored in the nqs (from HSIP3RBatchNQS)
def HSIP3RBatchDrawWaveProps (nq,xl=(15,100),yl=(0.8,2),stimt=2e3):
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"];
lcols = ["speed", "onset"]
ltitles = [r'speed ($\mu$m/s)','onset (ms)'];
lvmin,lvmax = [40, 0, 0], [80, 300, 0.002]
for col in lcols:
ax=subplot(1,len(lcols),gn+1); S,extent = getmatbyparams(nq,col);
if col == "time":
imshow(S/1e3,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
elif col == "onset":
imshow(S-stimt,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
else:
imshow(S,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
ylim(yl); xlim(xl); xlabel(r'Hotspot spacing ($\mu$m)'); title(ltitles[gn]);
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes); colorbar();
if gn == 0: ylabel(r'IP3R density');
gn += 1
# get the NQS with batch data / wave properties
def HSIP3RBatchNQS ():
return NQS("data/13sep09_HSIP3RBatch_wp2.nqs")
# creates a matrix with values arranged by HS,CS values
# nq from params2nq -> addwavenqcol -> addwavepropcols
# col specifies which column from nqs to use
def getmatbyparams (nq,colval,xparm=HSIP3RBatchLimsSpace,yparm=HSIP3RBatchLimsDense,coly="ip3_origin",colx="boost_every",scaley=120400.0,scalex=1):
lx,ly = xparm(),yparm()
S = numpy.zeros((len(ly),len(lx)))
for i in xrange(len(ly)):
for j in xrange(len(lx)):
N = nq.select(-1,coly,scaley*ly[i],colx,scalex*lx[j])
if N < 1: continue
idx = int(nq.ind.x[0])
S[i][j] = nq.getcol(colval).x[idx]
extent=amin(lx),amax(lx),amin(ly),amax(ly)
return S,extent
######################
# test ER stacks (density and spacing) - STACKERBatch
# limits for STACK densities
def STACKERBatchLimsDense ():
return numpy.linspace(0.8,2.0,55)
# limits for STACK spacing
def STACKERBatchLimsSpace ():
return numpy.linspace(15,100,18)
# get the NQS with batch data / wave properties
def STACKERBatchNQS ():
return NQS("data/13sep11_STACKERBatch_wp2.nqs")
# params for batch varying ER STACKS
# cs is density between the stacks
def STACKERBatchParams (lfdense=STACKERBatchLimsDense(),lfspace=STACKERBatchLimsSpace(),cs=0.8):
lsec,lopt,lval = [],[],[]
alls,allo,allv = [],[],[] # params shared across sims in this batch
NewParam(alls,allo,allv,"set","ip3_stim","1.25")
NewParam(alls,allo,allv,"set","ip3_stimT","2e3")
NewParam(alls,allo,allv,"set","boost_halfw","5.0")
gip3r, gsercar, gleakr = cs*120400.0, cs*1.9565, cs*18.06
NewParam(alls,allo,allv,"set","ip3_origin",str(gip3r))
NewParam(alls,allo,allv,"set","ip3_notorigin",str(gip3r))
NewParam(alls,allo,allv,"set","gleak",str(gleakr))
NewParam(alls,allo,allv,"set","gserca",str(gsercar))
NewParam(alls,allo,allv,"run","runit","1")
NewParam(alls,allo,allv,"run","saveout","1")
allsimstr = "STACKERBatch_BoostHW5_IP3R_" + str(gip3r) + "_GLEAK_"+str(gleakr)+"_GSERCA_"+str(gsercar)
for dense in lfdense: # variations in density of ER stacks
for space in lfspace: # variations in distance between ER stacks
tmpsec,tmpopt,tmpval=[],[],[]
for i in xrange(len(alls)): tmpsec.append(alls[i]); tmpopt.append(allo[i]); tmpval.append(allv[i]);
ers = dense*1.0/cs
simstr = allsimstr + "_DENSE_" + str(dense) + "_ERScale_"+str(ers)+"_Space_"+str(space)
NewParam(tmpsec,tmpopt,tmpval,"run","simstr",simstr)
NewParam(tmpsec,tmpopt,tmpval,"set","er_scale",str(ers))
NewParam(tmpsec,tmpopt,tmpval,"set","boost_every",str(space))
lsec.append(tmpsec); lopt.append(tmpopt); lval.append(tmpval);
return lsec, lopt, lval
# run this batch
def STACKERBatchRun (skip=[],blog="STACKERBatch/STACKERBatch.log",bdir="STACKERBatch",qsz=12):
batchRun(STACKERBatchParams,blog,skip=skip,qsz=qsz,bdir=bdir)
# read data from this batch
def STACKERBatchRead ():
return shortRead(STACKERBatchParams)
# print the values at the row in the nqs (div by baseline ER density)
def STACKERBatchParamsAtRow (nq,row):
nq.tog("DB")
simstr = nq.get("simstr",row).s
gip3r = nq.getcol("ip3_origin").x[row] / 120400.0
cs = nq.getcol("ip3_notorigin").x[row] / 120400.0
space = nq.getcol("boost_every").x[row]
ers = nq.getcol("er_scale").x[row]
gleak = nq.getcol("gleak").x[row]
gserca = nq.getcol("gserca").x[row]
print "row ",row,",gip3r:",gip3r,",space:",space,",CS:",cs,"er_scale:",ers,",gleak:",gleak,",gserca:",gserca,",simstr:",simstr
speed, amp = nq.getcol("speed").x[row],nq.getcol("amp").x[row]
dur, onset = nq.getcol("dur").x[row],nq.getcol("onset").x[row]
print "\t speed:",speed,", amp:",amp,", dur:",dur,", onset:",onset
return gip3r,cs,space,ers,gleak,gserca,row,simstr
# draw the waves for first part of the figure
def STACKERBatchDrawWaves (nq,lidx=[163, 577, 973, 865, 871, 877]):
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"];
lfdense,lfspace = STACKERBatchLimsDense(),STACKERBatchLimsSpace()
nrows,ncols = 2,3
for idx in lidx:
ax=subplot(nrows,ncols,gn+1);
dat = loadfromnq(nq,idx);
STACKERBatchParamsAtRow(nq,idx) # print info
imshow(dat["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((0,1000)); xlim((2,10));
if gn == 0 or gn == 3: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
if gn > 2: xlabel('Time (s)');
gn += 1;
# draw the wave properties stored in the nqs (from STACKERBatchNQS)
def STACKERBatchDrawWaveProps (nq,xl=(15,100),yl=(0.8,2),stimt=2e3,cs=0.8):
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c", "d", "e", "f"];
lcols = ["speed", "onset"]
ltitles = [r'speed ($\mu$m/s)','onset (ms)'];
lvmin,lvmax = [40, 0, 0], [80, 300, 0.002]
for col in lcols:
ax=subplot(1,len(lcols),gn+1);
S,extent = getmatbyparams(nq,col,xparm=STACKERBatchLimsSpace,yparm=STACKERBatchLimsDense,coly="er_scale",colx="boost_every",scaley=1.0/cs,scalex=1.0);
if col == "time":
imshow(S/1e3,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
elif col == "onset":
imshow(S-stimt,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
else:
imshow(S,vmin=lvmin[gn],vmax=lvmax[gn],aspect='auto',extent=extent,origin='lower',interpolation='None')
ylim(yl); xlim(xl); xlabel(r'Stack spacing ($\mu$m)'); title(ltitles[gn]);
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes); colorbar();
if gn == 0: ylabel(r'ER density');
gn += 1
# draw waves/features
def STACKERBatchDrawSub (nq,G,gRow,fixedspace=True):
lfdense,lfspace = STACKERBatchLimsDense(),STACKERBatchLimsSpace()
lidx,gctr,lidx2,xtxt=[],[],[],"";
if fixedspace: # fixed spacing
lidx = [1, 973] # index into nqs
nq.select("boost_every",20.0)
xtxt = r"Density"
gfctr = lfdense
else: # fixed density
lidx = [864, 881] # index into nqs
nq.select("er_scale",lfdense[48]*1.0/0.8)
xtxt = r"Spacing ($\mu$m)"
gfctr = lfspace
lsp,ldur,lamp,lon,ltmp = getwpropcols(nq,db=False); nq.tog("DB")
lidx2 = [ltmp.index(lidx[0]), ltmp.index(lidx[1])];
gn,i = 0,0; tx, ty = -0.15, 1.06
tlx = ["a", "b", "c"]
if not fixedspace: tlx = ["d", "e", "f"];
for idx in lidx: # draw the waves
dat = loadfromnq(nq,idx); STACKERBatchParamsAtRow(nq,idx) # load data, print info
ax=subplot(G[gRow,gn:gn+1]); xlabel('Time(s)');
imshow(dat["cytca"],vmin=0,vmax=0.002,aspect='auto',extent=(0,30,0,1000),origin='lower')
ylim((300,700)); xlim((2,6));
if gn == 0: ylabel(r'Position ($\mu$m)');
title(r'$Ca^{2+}_{cyt}$ (mM)');
text(tx,ty,tlx[gn],fontsize=14,fontweight='bold',transform=ax.transAxes)
gn += 1;
#ly = [ (65,95) ]; ltitles = [r"Speed ($\mu$m/s)"]; gn = 2; sz1,sz2=10,10;
ly = [ (0,115) ]; ltitles = [r"Speed ($\mu$m/s)"]; gn = 2; sz1,sz2=10,10; #changed ylimits to be similar to the hotspots graph
scaley = [1.0,1.0,1.0/1e3,1.0]; naxbins=6; lvals=[ lsp ];
for pdx in xrange(1): # for the four wave features
ax=subplot(G[gRow,gn:gn+1]); xlabel(xtxt); title(ltitles[pdx]); ylim(ly[pdx]);
xlim([amin(gfctr)-amin(gfctr)/10.0,amax(gfctr)+amin(gfctr)/10.0]);
ax.locator_params(nbins=naxbins);
text(tx,ty,tlx[pdx+2],fontsize=14,fontweight='bold',transform=ax.transAxes); grid(True);
plot(gfctr,numpy.array(lvals[pdx])*scaley[pdx],'ko',markersize=sz1);
gtt,ltt=[gfctr[lidx2[0]],gfctr[lidx2[1]]],[lvals[pdx][lidx2[0]],lvals[pdx][lidx2[1]]];
plot(gtt,numpy.array(ltt)*scaley[pdx],'ro',markersize=sz1);
gn += 1;
# draw waves and speeds
def STACKERBatchDraw (nq):
nrows,ncols = 2,3
G = gridspec.GridSpec(nrows, ncols);
STACKERBatchDrawSub(nq,G,0,fixedspace=True) # fixed spacing
STACKERBatchDrawSub(nq,G,1,fixedspace=False) # fixed density
tight_layout()
######################
# test diffusion coefficient effect on IP3R hotspots
#
def HSDIFFBatchLims ():
return numpy.linspace(0,10,101)
# params for batch varying Ca2+ diffusion coefficient with the IP3R hotspots
# hs is IP3R density at hotspots, cs is IP3R density between the hotspots
def HSDIFFBatchParams (ldiff=HSDIFFBatchLims(),hs=1.75,cs=0.8):
lsec,lopt,lval = [],[],[]
alls,allo,allv = [],[],[] # params shared across sims in this batch
NewParam(alls,allo,allv,"set","ip3_stim","1.25")
NewParam(alls,allo,allv,"set","ip3_stimT","2e3")
NewParam(alls,allo,allv,"set","boost_halfw","5.0")
hsip3r,csip3r = 120400.0*hs,120400.0*cs
NewParam(alls,allo,allv,"set","ip3_origin",str(hsip3r))
NewParam(alls,allo,allv,"set","ip3_notorigin",str(csip3r))
NewParam(alls,allo,allv,"set","gleak",str(18.06))
NewParam(alls,allo,allv,"set","gserca",str(1.9565))
NewParam(alls,allo,allv,"run","runit","1")
NewParam(alls,allo,allv,"run","saveout","1")
NewParam(alls,allo,allv,"set","boost_every","20.0")