-
Notifications
You must be signed in to change notification settings - Fork 0
/
Review_translocation_quantification.ijm
1379 lines (1373 loc) · 46.3 KB
/
Review_translocation_quantification.ijm
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
var AallROIs;var thresholdmask;var Exptype;var resultstringpath;
macro "Translocation-Quantification Macro" {
macroname="Translocation-Quantification Macro";
tmp_version="1-0";
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
temp_dir=getDirectory("temp");
tmp_file=temp_dir+"Temp file "+macroname+"-Ver"+tmp_version+".txt";
initial_tool=IJ.getToolName();
month=month+1;
if(month<10)smonth="0"+month;
if(month>=10)smonth=month;
if(dayOfMonth<10)sdayOfMonth="0"+dayOfMonth;
if(dayOfMonth>=10)sdayOfMonth=dayOfMonth;
timestamp=""+year+""+smonth+""+sdayOfMonth+"_"+hour+"h"+minute+"min";
date=timestamp;
scwidth=screenWidth;
scheight=screenHeight;
plotwidth=round(450*1.5);
plotheight=round(200*1.5);
Acolor=newArray("black","red","blue","green","orange","magenta","pink","yellow","darkGray","gray","lightGray");
Atrch_method=newArray("None","Manually define two pixel classes","built-in 'Subtract background'","use outer rim of each cell","built-in 'Subtract background' - exclude cytosol");
Segmentationchannel="None";
Asetmeasure=newArray("mean","modal","median","integrated");
Ameasure=newArray("Mean","Mode","Median","RawIntDen");
Atoanalch=newArray(0);
Achnames=newArray(0);
if(nImages==0)exit("No open images. Please open images or stacks and try again.");
Atoanal=newArray(0);
frames=0;
for(i=0;i<nImages;i++){
selectImage(i+1);
Atoanalch=Array.concat(Atoanalch,getTitle());
framesi=nSlices;
if(framesi>frames)frames=framesi;
};
Awindownames=Atoanalch;
//###########################################################################
loadparameter();
Dialog.create(macroname);
help="<html><h2>Help for "+macroname+"</h2> <table border='1'><font size='1'>";
help=help+"<tr> <th>Menu point</th> <th>Possible options</th> <th>Description</th> </tr>";
//help=help+"<tr> <td></td> <td></td> <td></td></tr>";
//help=help+"<tr><td rowspan='3'>Type of experiment:</td> <td> Single time point. </td> <td> Explanation </td></tr>";
//help=help+"<tr> <td> Time series without stimulation. </td> <td> To be chosen if image data set contains multiple time points. No response (amplitude changes) will be calculated. </td></tr>";
Dialog.addString("Name of experiment:",timestamp);
if(roiManager("count")==0)Dialog.addChoice("Which channel should be used for cell segmentation?",Atoanalch);
Dialog.addCheckbox("Time-series data.",parseFloat(List.get("Exptype")));
Dialog.addMessage("Details to quantify translocation:\nChoose names of two pixel classes (regions of the cell) for which the ratio will be calculated.");
Dialog.addString("Marker name (e.g. PM):",List.get("Marker_name"));
Dialog.addString("Background name (e.g. cytosol):",List.get("Background_name"));
Dialog.addMessage("Details to quantify translocation events: \nChoose the 'Marker' channel (e.g. nucleus or plasma membrane marker) for the channels you want to quantify translocation.\n'Marker' channel is used to classifiy pixels of the chosen channel into 'Marker' and 'background' region by thresholding.");
for(i=0;i<Atoanalch.length;i++){
ATransChoice=Array.concat("Ignore channel","Quantify only 'Mean'","No marker channel. Quantify only local events",Atoanalch);//franzi Asegch
Dialog.addChoice(Atoanalch[i],ATransChoice,List.get("TransChoice"+i));
//Dialog.addChoice("How to process 'Marker' channel?",Atrch_method,parseFloat(List.get("method_trch_choice"+i)));
};
Dialog.addMessage("");
Dialog.addChoice("How to process 'Marker' channel?",Atrch_method,List.get("method_trch"));
//Dialog.addChoice("Marker region-Background-ratio should be calculated from which statistical summary?",Ameasure,List.get("Ratio_Measure"));
Dialog.addNumber("Average compartment width [pixel] where local events take place in the cell:",parseFloat(List.get("radius_trch")));
Dialog.addMessage("");
Dialog.addCheckbox("Save results in a text file for down-stream analysis with e.g. R:",parseFloat(List.get("saveRfile")));
Dialog.addMessage("'Name of experiment' is used as the file name for the result-txt-file.");
//Dialog.addCheckbox("asdf",parseFloat(List.get("adf")));
Dialog.addHelp(help);
Dialog.show();
//***********************************************************************
origtitle=Dialog.getString();
if(roiManager("count")==0)Segmentationchannel=Dialog.getChoice();
Exptype=Dialog.getCheckbox();
List.set("Marker_name",Dialog.getString());
List.set("Background_name",Dialog.getString());
List.set("Exptype",Exptype);
nooftrch=0;
for(i=0;i<Atoanalch.length;i++){
TransChoice=Dialog.getChoice();
//TransMethod=Dialog.getChoice();
List.set("TransChoice"+i,TransChoice);
if(TransChoice=="Quantify only 'Mean'"){
Achnames=Array.concat(Achnames,Atoanalch[i]);
};
if(TransChoice!="Ignore channel"&&TransChoice!="Quantify only 'Mean'"){
if(TransChoice!="No marker channel. Quantify only local events")compare_channels(TransChoice,Atoanalch[i]);
Achnames=Array.concat(Achnames,Atoanalch[i]);
nooftrch++;
no=Awindownames.length-1;
POIname=Atoanalch[i];
List.set("POIchannel"+nooftrch,Atoanalch[i]);
List.set("POIname"+nooftrch,POIname);
List.set("Markerchannel"+nooftrch,TransChoice);
//List.set("method_trch"+nooftrch,TransMethod);
if(TransChoice!="No marker channel. Quantify only local events"){
List.set("POI_marker"+nooftrch,""+POIname+" "+List.get("Marker_name")+"-region");
List.set("POI_background"+nooftrch,""+POIname+" "+List.get("Background_name")+"-region");
List.set("POI_ratio"+nooftrch,""+POIname+" "+List.get("Marker_name")+"-"+List.get("Background_name")+"-ratio");
//Marker region
no=Awindownames.length;
Atoanal=Array.concat(Atoanal,no);
Awindownames=Array.concat(Awindownames,List.get("POI_marker"+nooftrch));
Achnames=Array.concat(Achnames,""+POIname+" "+List.get("Marker_name")+"-region");
//Background region
no=Awindownames.length;
Atoanal=Array.concat(Atoanal,no);
Awindownames=Array.concat(Awindownames,List.get("POI_background"+nooftrch));
Achnames=Array.concat(Achnames,""+POIname+" "+List.get("Background_name")+"-region");
//Marker region-Background-ratio
no=Awindownames.length;
Atoanal=Array.concat(Atoanal,no);
Awindownames=Array.concat(Awindownames,List.get("POI_ratio"+nooftrch));
Achnames=Array.concat(Achnames,""+POIname+" "+List.get("Marker_name")+"-"+List.get("Background_name")+"-ratio");
};
if(TransChoice=="No marker channel. Quantify only local events"){
List.set("Markerchannel"+nooftrch,"None");
List.set("Localchannel"+nooftrch,"Local "+Atoanalch[i]);
no=Awindownames.length;
Atoanal=Array.concat(Atoanal,no);
Awindownames=Array.concat(Awindownames,"Local "+Atoanalch[i]);
Achnames=Array.concat(Achnames,"Local "+POIname);
};
};
};
List.set("method_trch",Dialog.getChoice());
//List.set("Ratio_Measure",Dialog.getChoice());
List.set("radius_trch",Dialog.getNumber());
List.set("saveRfile",Dialog.getCheckbox());
saveparameter();
if(Achnames.length>0){
//Save resultsfile
if(List.get("saveRfile")){
dir_save=getDirectory("Choose the directory in which the results txt-file will be saved:");
write_resultstring_header(dir_save,origtitle);
};
//Cell segmentation
thresholdchannel="None";
thresholdmask="None";
run("Colors...", "foreground=white background=black selection=white");
run("Set Measurements...", " mean standard redirect=None decimal=3");
if(!isOpen(Segmentationchannel)){
Segmentationchannel=Achnames[0];
};
selectWindow(Segmentationchannel);
wait(100);
if(Exptype==0){
//roiManager("reset");
roiManager("Associate", "true");
thresholdchannel=create_thresholdchannel(Segmentationchannel);
};
if(Exptype==1){
//roiManager("reset");
roiManager("Associate", "false");
thresholdchannel=create_thresholdpic(Segmentationchannel);
};
if(roiManager("count")==0){
create_ROIs(thresholdchannel);
};
thresholdmask=create_mask_from_ROIs(thresholdchannel);
//Translocation analysis
for(tc=1;tc<=nooftrch;tc++){
if(List.get("Markerchannel"+tc)=="None"){
create_translocationchannel(List.get("POIchannel"+tc),List.get("Localchannel"+tc),List.get("method_trch"),1);
};
if(List.get("Markerchannel"+tc)!="None"){
calculate_translocationratio(List.get("POIchannel"+tc),List.get("Markerchannel"+tc),List.get("POI_marker"+tc),List.get("POI_background"+tc),List.get("POI_ratio"+tc));
};
};
amountrois=roiManager("count");
//Analysis and plotting of Results
if(Exptype==0){
frames=nSlices;
run("Clear Results");
amountrois=roiManager("count");
icAresults=newArray(Achnames.length*amountrois);
icASliceinfo=newArray(amountrois);
icASD=newArray(Achnames.length*amountrois);
icAresultsno=newArray(amountrois);
if(amountrois>0){
counter=0;
for(channelno=0;channelno<Achnames.length;channelno++){
ex=Achnames[channelno];
if(isOpen(ex)){
setmeasure="mean";
run("Set Measurements...", " mean standard stack redirect=["+ex+"] decimal=3");
run("Select None");
run("Clear Results");
roiManager("Deselect");
roiManager("Show All");
roiManager("Measure");
selectWindow("Results");
for (ROIno =0; ROIno < nResults; ROIno++){//amountrois
icAresults[ROIno+channelno*amountrois]=getResult("Mean", ROIno);
icASD[ROIno+channelno*amountrois]=getResult("StdDev", ROIno);
if(channelno==0){
counter++;
slice=getResult("Slice", ROIno)-1;
icASliceinfo[ROIno+channelno*amountrois]=getResult("Slice", ROIno);
icAresultsno[ROIno]=counter;
};
};
if(List.get("saveRfile"))write_in_resultstring2(origtitle,date,ex,icAresultsno,icASliceinfo,extract_array2(icAresults,channelno,amountrois));
};
};
};
run("Set Measurements...", " mean standard redirect=None decimal=3");
run("Clear Results");
cASliceinfo=icASliceinfo;
cAresultsno=icAresultsno;
mean=newArray(Achnames.length);
SDmean=newArray(Achnames.length);
SDEmean=newArray(Achnames.length);
median=newArray(Achnames.length);
SDmedian=newArray(Achnames.length);
minimum=newArray(Achnames.length);
maximum=newArray(Achnames.length);
for(channelno=0;channelno<Achnames.length;channelno++){
ex=Achnames[channelno];
if(cAresultsno.length>0){
cAresultsnoname=add_strings_to_array(cAresultsno,"ROI ","");
PlotRArray(cAresultsnoname,cAresultsno,extract_array2(icAresults,channelno,amountrois),extract_array2(icASD,channelno,amountrois),"Barplot overview of single ROI measurements of "+ex,"ROI","Mean","PM/background quantification");
print_in_results("ROI No",cAresultsno);
print_in_results("ROI from slice",cASliceinfo);
x=extract_array2(icAresults,channelno,amountrois);
print_in_results("Mean of "+ex,extract_array2(icAresults,channelno,amountrois));
print_in_results("StdDev of "+ex,extract_array2(icASD,channelno,amountrois));
};
};
for(channelno=0;channelno<Achnames.length;channelno++){
ex=Achnames[channelno];
if(cAresultsno.length>0){
mean[channelno]=calMean(extract_array2(icAresults,channelno,amountrois));
SDmean[channelno]=calSD(extract_array2(icAresults,channelno,amountrois));
SDEmean[channelno]=calSDE(extract_array2(icAresults,channelno,amountrois));
};
if(cAresultsno.length>3){
median[channelno]=calMedian(extract_array2(icAresults,channelno,amountrois));
SDmedian[channelno]=calQuartilsdiff(extract_array2(icAresults,channelno,amountrois));
minimum[channelno]=calMin(extract_array2(icAresults,channelno,amountrois));
maximum[channelno]=calMax(extract_array2(icAresults,channelno,amountrois));
};
if(cAresultsno.length<=3){
median[channelno]=0;SDmedian[channelno]=0;minimum[channelno]=0;maximum[channelno]=0;
};
print("Results of "+ex);
print("Total mean = "+mean[channelno]+" "+fromCharCode(177)+" "+SDmean[channelno]);
print("Total median = "+median[channelno]+" "+fromCharCode(177)+" "+SDmedian[channelno]);
print("Total minimum = "+minimum[channelno]);
print("Total maximum = "+maximum[channelno]);
print("Total StdErr = "+SDEmean[channelno]);
print(" ");
};
if(cAresultsno.length>0){
Atitle=newArray(Achnames.length);
xValues=newArray(Achnames.length);
for(channelno=0;channelno<Achnames.length;channelno++){
ex=Achnames[channelno];
chno=channelno+1;
xValues[channelno]=chno;
Atitle[channelno]=ex;
};
PlotRArray(Atitle,xValues,mean,SDmean,"Overview Mean of all ROIs","Channel","Mean intensity",List.get("origtitle"));
};
};
if(Exptype==1){
AallROIs=newArray(frames*amountrois*Achnames.length);
for(ch=0;ch<Achnames.length;ch++){
Atime=getFrameArray(Achnames[ch]);
multimeasureresultsplot(Achnames[ch],"Plot - "+Achnames[ch]+" Mean intensity of all ROIs versus time",""+Achnames[ch]+" Mean intensity",Atime,ch);
};
run("Clear Results");
for(ch=0;ch<Achnames.length;ch++){
for(ROIno=0;ROIno<amountrois;ROIno++){
c=ROIno+1;
ROI="ROI No "+c;
print_in_results(""+Achnames[ch]+" "+ROI,extract_array(AallROIs,ROIno,ch,amountrois,frames));
};
};
};
if(isOpen(thresholdmask)){
selectWindow(thresholdmask);
close();
};
if(isOpen(thresholdchannel)){
selectWindow(thresholdchannel);
wait(100);
close();
};
};
setTool(initial_tool);
beep();
waitForUser("Analysis complete!");
};
function create_mask(channel){
selectWindow(channel);
getLocationAndSize(x, y, width, height);
wait(100);
frames=nSlices;
mask="Binary mask of "+channel;
run("Select None");
run("Duplicate...", "title=["+mask+"] duplicate range=1-["+frames+"]");
resize();
setLocation(width,0);
Atlim=threshold_channel(mask,1,List.get("thresholdmethod"),1,List.get("processguieachloop"),"minvalue-"+channel);
selectWindow(mask);
wait(100);
setThreshold(Atlim[0], Atlim[1]);
run("Convert to Mask", "method=Default background=Default black");
resetThreshold();
run("Open","stack");
run("Close-","stack");
return mask;
};
function create_ROIs(ithresholdpic){
if(!isOpen("ROI Manager")){
run("ROI Manager...");
selectWindow("ROI Manager");
setLocation(scwidth-220,0);
};
if(Exptype==0)roiManager("Associate", "true");
if(Exptype==1)roiManager("Associate", "false");
roiManager("Centered", "false");
roiManager("UseNames", "false");
selectWindow(ithresholdpic);
wait(100);
frames=nSlices;
getLocationAndSize(x, y, width, height);
setLocation(width,0);
run("Synchronize Windows");
thresholdmask=create_mask(ithresholdpic);
create_manual_voronoi(ithresholdpic,thresholdmask);
if(isOpen("B&C")){//BC=190x340
selectWindow("B&C");
setLocation(scwidth-200,scheight-340);
};
setForegroundColor(0,0,0);
if(frames==1){
arrange_and_wait(0,thresholdmask,ithresholdpic,"Please check the binary mask and divide cells with the Pencil Tool if necessary. \nUsage of 'Synchronize Windows' is recommended. Click on 'Synchronize All' in this window to make cell division easier.\nThen press OK.",1,"Pencil Tool");
};
if(frames>1){
arrange_and_wait(0,thresholdmask,ithresholdpic,"Please check the binary mask channel and divide cells with the Pencil Tool if necessary.\nDon't forget to go through each frame.\nUsage of 'Synchronize Windows' is recommended. Click on 'Synchronize All' in this window to make cell division easier.\nThen press OK.",1,"Pencil Tool");
};
selectWindow(thresholdmask);
wait(100);
maxvalue=getmaximumpixel(thresholdmask);
run("Threshold...");
setThreshold(1, maxvalue);
run("Analyze Particles...", "size=[50]-[Infinity] circularity=[0]-[1.00] show=Nothing exclude add stack");
resetThreshold();
amountrois=roiManager("count");
if(isOpen("ROI Manager")){//ROI Manager=220x290
selectWindow("ROI Manager");
setLocation(scwidth-220,0);
};
roiManager("Deselect");
roiManager("Show All with labels");
resetThreshold();
run("Synchronize Windows");
arrange_and_wait(0,thresholdmask,ithresholdpic,"Check your ROIs, delete them (if necessary) or add new one's manually.\nDo all changes in the 'ROI manager' window!\nThen press OK.",1,"oval");
amountrois=roiManager("count");
if(frames==1&&Exptype==1){
for(rm=0;rm<amountrois;rm++){
roiManager("Select", rm);
roiManager("Remove Slice Info");
};
roiManager("Deselect");
};
if(isOpen("Synchronize Windows")){
selectWindow("Synchronize Windows");
wait(100);
run("Close");
};
};
function create_thresholdchannel(channelname){
frames=nSlices;
selectWindow(channelname);
wait(100);
getLocationAndSize(x, y, width, height);
ithresholdpic="Mask "+channelname;
run("Select None");
run("Duplicate...", "title=["+ithresholdpic+"] duplicate range=1-["+frames+"]");
resize();
run("Enhance Contrast", "saturated=0.35");
run("Conversions...", "scale");
run("8-bit");
run("Conversions...", " ");
run("Median...", "radius=1 stack");
run("Fire");
return ithresholdpic;
};
function create_thresholdpic(channelname){
selectWindow(channelname);
wait(100);
getLocationAndSize(x, y, width, height);
ithresholdpic="Time projection of "+channelname;
intermediate="Intermediate picture of "+channelname;
run("Select None");
run("Duplicate...", "title=["+intermediate+"] duplicate range=1-["+frames+"]");
resize();
run("Conversions...", "scale");
max=getmaximumpixel(channelname);
selectWindow(intermediate);
setMinAndMax(0, max);
run("8-bit");
run("Conversions...", " ");
run("Median...", "radius=1 stack");
run("Fire");
run("Z Project...", "start=1 stop=["+frames+"] projection=[Average Intensity]");
run("Rename...", "title=["+ithresholdpic+"]");
resize();
if(isOpen(intermediate)){
selectWindow(intermediate);
wait(100);
close();
};
return ithresholdpic;
};
function extract_array(array,ROIno,channelno,amountrois,frames){//[x+y*xmax+z*xmax*ymax]
if(array.length<channelno*amountrois*frames)exit("Mistake occured. Array is not long enough for multiple dimensions!");
sarray=newArray(frames);
for(slice=0;slice<frames;slice++){
sarray[slice]=array[slice+ROIno*frames+channelno*amountrois*frames];
};
return sarray;
};
function getfromResults(columname,rows){
Avalues=newArray(rows);
Array.fill(Avalues,NaN);
if(rows<=nResults){
for (y =0; y < rows; y++){
Avalues[y] = getResult(columname, y);
};
};
return Avalues;
};
function print_in_results(columnname,array){
if(calMean(array)!=0){
rows=array.length;
for(i=0;i<rows;i++){
setResult (columnname,i,array[i]);
};
updateResults();
};
};
function multimeasureresultsplot(channel,plotname,yaxis,Atime,channelno){//AallROIs
if(isOpen(channel)){
run("Clear Results");
selectWindow(channel);
wait(100);
frames=nSlices;
run("Set Measurements...", "mean redirect=["+channel+"] decimal=3");
roiManager("Deselect");
roiManager("Multi Measure");
amountrois=roiManager("count");
ROItraces=newArray(frames*amountrois);
for(c = 1; c <= amountrois; c++){
ROIno=c-1;
value="Mean"+c;
AROI=getfromResults(value,frames);
if(List.get("saveRfile"))write_in_resultstring(origtitle,date,channel,AROI,c,frames);
if(channelno<=Achnames.length){
for(slice=0;slice<frames;slice++){
AallROIs[slice+ROIno*frames+channelno*amountrois*frames]=AROI[slice];
};
};
for(slice=0;slice<frames;slice++){
ROItraces[slice+ROIno*frames]=AROI[slice];
};
};
ROInames=newArray(amountrois);
AanalROIs=newArray(amountrois);
for(i=0;i<amountrois;i++){
ROI=i+1;
ROInames[i]="ROI "+ROI;
AanalROIs[i]=i;
};
PlotmultipleArrays(Atime,ROItraces,ROInames,AanalROIs,plotname,"Frame",yaxis);
run("Clear Results");
};
};
function extract_array2(array,channelno,rows){//[x+y*xmax]
if(array.length<channelno*rows)exit("Mistake occured. Array is not long enough for multiple dimensions!");
sarray=newArray(rows);
for(i=0;i<rows;i++){
sarray[i]=array[i+channelno*rows];
};
return sarray;
};
function PlotmultipleArrays(xValues,yValues,Awindownames,Atoanal,plottitle,xaxis,yaxis){
Alimits=removeNaN(xValues);
Array.getStatistics(Alimits, xMin, xMax, mean, stdDev);
Alimits=removeNaN(yValues);
Array.getStatistics(Alimits, yMin, yMax, mean, stdDev);
xMaxorig=xMax;
xMinorig=xMin;
xspace=abs(xMin-xMax)*0.05;
yspace=abs(yMin-yMax)*0.05;
xMin = xMin-xspace;xMax=xMax+xspace;yMin=yMin-yspace;yMax=yMax+yspace;
if(plotheight/Atoanal.length<14){
plotheight=Atoanal.length*14.2;
};
stringlengthes=newArray(Atoanal.length);
for(l=0;l<2;l++){
heightofchar=14/plotheight;//*********************************
widthofchar=7/plotwidth;//*********************************
begincharheight=1.2*heightofchar;//*********************************
for(i=0;i<Atoanal.length;i++){
c=Atoanal[i];
stringlengthes[i]=lengthOf(Awindownames[c])*widthofchar;
};
stringlength=calMax(stringlengthes);
textlength=stringlength+4*widthofchar;
textwidth=1-textlength;//*********************************
timeswider=textlength+1+widthofchar;//*********************************
if(l==0)xMax=xMax*timeswider;//*********************************
linewidth=0.05*xMaxorig;//*********************************
if(l==0){
plotwidthnew=timeswider*plotwidth;
plotwidth=plotwidthnew;
};
};
Plot.create(plottitle, xaxis, yaxis);
Plot.setFrameSize(plotwidth, plotheight);
Plot.setLineWidth(1);
Plot.setLimits(xMin, xMax, yMin, yMax);
col=0;
for(line=0;line<Atoanal.length;line++){
channelno=Atoanal[line];
Aline=extract_array2(yValues,line,frames);
add_line(xValues,Aline,Acolor[col],Awindownames[channelno],line);
col++;
if(col==Acolor.length)col=0;
};
//Captions
setJustification("center");
Plot.addText(plottitle, 0.5, 0);
Plot.setLineWidth(1);
Plot.show();
};
function add_line(xvalues,Aline,color,name,line){
if(calMean(Aline)!=0){
xvalues=Array.trim(xvalues, Aline.length);
Plot.setColor(color);
Plot.add("line",xvalues,Aline);
setJustification("right");
Plot.addText(""+fromCharCode(9472,9472),1-stringlength-widthofchar,begincharheight+(line*heightofchar));
Plot.setColor("black");
Plot.addText(name, 1-0.5*widthofchar, begincharheight+(line*heightofchar));
};
};
function getFrameArray(channel){
selectWindow(channel);
wait(100);
frames=nSlices;
array=newArray(nSlices);
for(i=0;i<nSlices;i++){
array[i]=i+1;
};
return array;
};
function compare_channels(ch1,ch2){
selectWindow(ch1);
wait(100);
getDimensions(width_ch1, height_ch1, channels_ch1, slices_ch1, frames_ch1);
selectWindow(ch2);
wait(100);
getDimensions(width_ch2, height_ch2, channels_ch2, slices_ch2, frames_ch2);
if(width_ch1!=width_ch2||height_ch1!=height_ch2||channels_ch1!=channels_ch2||slices_ch1!=slices_ch2||frames_ch1!=frames_ch2)exit(""+ch1+" and "+ch2+" don't have the same dimensions.\nPlease choose images with the same dimensions.");
};
function create_translocationchannel(channel,translocationchannel,method,loop){
setBatchMode(true);
showStatus("Macro is running...");
selectWindow(channel);
wait(100);
Bitdorig=bitDepth();
wait(100);
run("Select None");
roiManager("Deselect");
if(method!="use outer rim of each cell"){
selectWindow(channel);
};
if(method=="use outer rim of each cell"){
selectWindow(thresholdmask);
};
wait(100);
run("Duplicate...", "title=["+translocationchannel+"] duplicate range=1-["+nSlices+"]");
run("Conversions...", " ");
run("32-bit");
selectWindow(translocationchannel);
wait(100);
if(Bitdorig==8)run("8-bit");
if(Bitdorig==16)run("16-bit");
if(Bitdorig!=8&&Bitdorig!=16){
run("Conversions...", "scale");
max=getmaximumpixel(translocationchannel);
setMinAndMax(0, max);
run("8-bit");
};
if(method=="built-in 'Subtract background'"){
run("Subtract Background...", "rolling=["+List.get("radius_trch")+"] stack");
};
if(method=="use outer rim of each cell"){
cwidth=round(parseFloat(List.get("radius_trch")));
run("Options...", "iterations=["+cwidth+"] count=1 black edm=Overwrite");
//run("Options...", "iterations=["+List.get("radius_trch")+"] count=1 black edm=Overwrite");
run("Select None");
selectWindow(translocationchannel);
wait(100);
run("Conversions...", "scale");
max=getmaximumpixel(translocationchannel);
setMinAndMax(0, max);
run("8-bit");
run("Conversions...", " ");
run("Erode", "stack");
run("Options...", "iterations=1 count=1 black edm=Overwrite");
run("Invert", "stack");
imageCalculator("Multiply stack", translocationchannel,thresholdmask);
};
if(method=="built-in 'Subtract background' - exclude cytosol"){
selectWindow(thresholdmask);
run("Select None");
wait(100);
run("Duplicate...", "title=cytosol duplicate range=1-["+nSlices+"]");
run("Conversions...", "scale");
selectWindow("cytosol");
wait(100);
max=getmaximumpixel("cytosol");
setMinAndMax(0, max);
run("8-bit");
run("Conversions...", " ");
cwidth=round(parseFloat(List.get("radius_trch"))*1.5);
run("Options...", "iterations=["+cwidth+"] count=1 black edm=Overwrite");
selectWindow("cytosol");
wait(100);
run("Erode", "stack");
run("Options...", "iterations=1 count=1 black edm=Overwrite");
run("Invert", "stack");
make_real_binary("cytosol");
run("8-bit");
selectWindow(translocationchannel);
wait(100);
run("Subtract Background...", "rolling=["+List.get("radius_trch")+"] stack");
imageCalculator("Multiply stack", translocationchannel,"cytosol");
if(isOpen("cytosol")){
selectWindow("cytosol");
wait(100);
if(List.get("savemask")){
fullpath=dir_save+"cytosolic_part.tif";
showStatus("Saving... Cytosolic part");
saveAs("Tiff", fullpath);
};
close();
};
};
run("Conversions...", " ");
selectWindow(translocationchannel);
wait(100);
max=get_theor_maxvalue();
setMinAndMax(0, max);
run("Median...", "radius=1 stack");
resize();
run("32-bit");
run("Conversions...", " ");
getLocationAndSize(x, y, width, height);
if((2*width)<=scwidth)setLocation(width,0);
maxvalue=get_theor_maxvalue();
setBatchMode("exit and display");
selectWindow(translocationchannel);
wait(100);
run("Enhance Contrast", "saturated=0.35");
};
function get_theor_maxvalue(){
Bitd=bitDepth();
maxvalue=pow(2, Bitd)-1;
return maxvalue;
};
function resize(){
getLocationAndSize(x, y, width, height);
wratio=height/width;
hratio=width/height;
wfactor=(scwidth-220)/scwidth;
hfactor=(scheight-220)/scheight;
wspace=screenWidth*wfactor;
hspace=screenHeight*hfactor;
if(parseFloat(List.get("chnumber"))>2){
setLocation(x,y,wspace/2,hspace/2);
};
if(parseFloat(List.get("chnumber"))<=2){
setLocation(x,y,wspace/2,hspace);
};
};
function calculate_translocationratio(POIchannel,markerchannel,POI_markername,POI_backgroundname,Rationame){
if(List.get("method_trch")!="Manually define two pixel classes"){
markermask="Mask of "+markerchannel;
in_markermask="Inverse of "+markermask;
if(!isOpen(markermask)){
create_translocationchannel(markerchannel,markermask,List.get("method_trch"),1);
transform_to_marker_mask(markermask,"minvalue-"+markerchannel,1,1,List.get("thresholdmethod"),List.get("processguieachloop"));
};
selectWindow(markermask);
if(!isOpen(in_markermask)){
in_markermask=make_inverse_mask(markermask);
};
};
if(List.get("method_trch")=="Manually define two pixel classes"){
if(Exptype==0)projectionchannel="Mask "+markerchannel;
if(Exptype==1)projectionchannel="Time projection of "+markerchannel;
markermask="Manual Marker mask of "+projectionchannel;
in_markermask="Manual Background mask of "+projectionchannel;
if(!isOpen(projectionchannel)){
if(Exptype==0){
projectionchannel=create_thresholdchannel(Segmentationchannel);
selectWindow(projectionchannel);
wait(100);
projectionchannel="Mask "+markerchannel;
run("Rename...", "title=["+projectionchannel+"]");
};
if(Exptype==1){
projectionchannel=create_thresholdpic(Segmentationchannel);
selectWindow(projectionchannel);
wait(100);
projectionchannel="Time projection of "+markerchannel;
run("Rename...", "title=["+projectionchannel+"]");
};
};
if(!isOpen(markermask)){
markermask=create_manual_mask(projectionchannel,projectionchannel,"Manual Marker");
};
if(!isOpen(in_markermask)){
in_markermask2=make_inverse_mask(markermask);
make_real_binary(in_markermask2);
run("8-bit");
if(Exptype==0)projectionchannel2="Mask 2 "+markerchannel;
if(Exptype==1)projectionchannel2="Time projection 2 of "+markerchannel;
imageCalculator("Multiply create stack",projectionchannel,in_markermask2);
run("Rename...", "title=["+projectionchannel2+"]");
in_markermask=create_manual_mask(projectionchannel2,projectionchannel,"Manual Background");
if(isOpen(projectionchannel2)){
imageCalculator("Multiply stack",in_markermask,in_markermask2);
selectWindow(projectionchannel2);
wait(100);
close();
};
if(isOpen(in_markermask2)){
selectWindow(in_markermask2);
wait(100);
close();
};
};
};
make_real_binary(markermask);
make_real_binary(in_markermask);
selectWindow(POIchannel);
imageCalculator("Multiply create 32-bit stack",POIchannel,markermask);
run("Rename...", "title=["+POI_markername+"]");
run("Fire");
set_zero_nan(POI_markername);
imageCalculator("Multiply create stack", POIchannel,in_markermask);
run("Rename...", "title=["+POI_backgroundname+"]");
set_zero_nan(POI_backgroundname);
if(tc==nooftrch){
if(isOpen(markermask)){
selectWindow(markermask);
wait(100);
close();
};
};
if(tc==nooftrch){
if(isOpen(in_markermask)){
selectWindow(in_markermask);
wait(100);
close();
};
};
POI_background_mean="Mean "+POI_backgroundname;
POI_marker_mean="Mean "+POI_markername;
replace_ROIs_with_mean(POI_backgroundname,POI_background_mean,"Mean");
replace_ROIs_with_mean(POI_markername,POI_marker_mean,"Mean");
imageCalculator("Divide create 32-bit stack",POI_marker_mean,POI_background_mean);
run("Rename...", "title=["+Rationame+"]");
selectWindow(POI_marker_mean);
wait(100);
close();
selectWindow(POI_background_mean);
wait(100);
close();
setBatchMode("exit and display");
};
function make_inverse_mask(channel){
selectWindow(channel);
wait(100);
inverse="Inverse of "+channel;
run("Select None");
run("Duplicate...", "title=["+inverse+"] duplicate range=1-["+nSlices+"]");
run("Invert", "stack");
return inverse;
};
function make_real_binary(channel){
selectWindow(channel);
wait(100);
max=getmaximumpixel(channel);
run("Divide...", "value="+max+" stack");
run("32-bit");
setMinAndMax(0, 1);
};
function replace_ROIs_with_mean(channel,newname,measure){
selectWindow(channel);
wait(100);
run("Select None");
run("Clear Results");
for(i=0;i<Ameasure.length;i++){
if(measure==Ameasure[i])setmeasure=Asetmeasure[i];
};
run("Set Measurements...", " "+setmeasure+" redirect=None decimal=3");
run("Duplicate...", "title=["+newname+"] duplicate range=1-["+nSlices+"]");
selectWindow(newname);
wait(100);
run("32-bit");
nf=nSlices;
ROIs=roiManager("count");
roiManager("Deselect");
if(Exptype==0){
roiManager("Associate", "true");
roiManager("Show All");
roiManager("Measure");
for (ROI =0; ROI < nResults; ROI++){
roiManager("Select", ROI);
mean=getResult(measure, ROI);
setColor(mean);
fill();
};
};
if(Exptype==1){
roiManager("Associate", "false");
roiManager("Multi Measure");
for(i=0;i<nf;i++){
for(ROI=0;ROI<ROIs;ROI++){
roiManager("Select", ROI);
roiManager("Remove Slice Info");
setSlice(i+1);
roiManager("Select", ROI);
ROIname=ROI+1;
columname=""+measure+ROIname;
mean=getResult(columname, i);
setColor(mean);
fill();
};
};
};
run("Select None");
run("Clear Results");
};
function transform_to_marker_mask(channel,minvaluename,rep,thresholding,thresholdmethod,processguieachloop){
selectWindow(channel);
wait(100);
frames=nSlices;
run("Select None");
resize();
getLocationAndSize(x, y, width, height);
setLocation(width,0);
Atlim=threshold_channel(channel,thresholding,thresholdmethod,rep,processguieachloop,List.get(minvaluename));
List.set(minvaluename,Atlim[0]);
maxvalue=Atlim[1];
selectWindow(channel);
wait(100);
setThreshold(List.get(minvaluename), maxvalue);
if(List.get("thresholding")==3)run("Convert to Mask", "method="+List.get("thresholdmethod")+" background=Default calculate black");
if(List.get("thresholding")!=3)run("Convert to Mask", "method=Default background=Default black");
resetThreshold();
run("Median...", "radius=1 stack");
run("Open", "stack");
};
function set_zero_nan(channelname){
selectWindow(channelname);
wait(100);
run("32-bit");
max=get_theor_maxvalue();
selectWindow(channelname);
wait(100);
setThreshold(1, max);
run("NaN Background", "stack");
resetThreshold();
};
function calMean(arrayf){ //Caclulates the Mean value of arrayf
arrayf=removeNaN(arrayf);
Array.getStatistics(arrayf,min,max,mean,stdDev);
return mean;
};
function calSD(arrayf){ //Calculates the Standard Deviation of arrayf
arrayf=removeNaN(arrayf);
Array.getStatistics(arrayf,min,max,mean,stdDev);
if(arrayf.length<=2)stdDev=0;
return stdDev;
};
function calSDE(array){ //Calculates the Standard Deviation of arrayf
arrayf=removeNaN(array);
Array.getStatistics(arrayf,min,max,mean,stdDev);
if(arrayf.length<=2)return 0;
sderr=stdDev/sqrt(arrayf.length);
return sderr;
};
function calMin(array){
array=removeNaN(array);
Array.getStatistics(array,min,max,mean,stdDev);
return min;
};
function calMax(array){
array=removeNaN(array);
Array.getStatistics(array,min,max,mean,stdDev);
return max;
};
function removeNaN(aA){
c=0;
aA=Array.concat(aA);
while(c<aA.length){
if(isNaN(aA[c])){
bA=Array.slice(aA,0,c);
cA=Array.slice(aA,c+1,aA.length);
aA=Array.concat(bA,cA);
}else c++;
};
return aA;
};
function threshold_channel(channel,thresholding,thresholdmethod,rep,processguieachloop,min){
Atlim=newArray(2);
selectWindow(channel);
wait(100);
lower=min;
upper=get_theor_maxvalue();
frames=nSlices;
getLocationAndSize(x, y, width, height);
run("Threshold...");
if(thresholding==1){//manual during the analysis
run("Threshold...");
if(isOpen("Threshold")){//295x265
selectWindow("Threshold");
setLocation(width,0);
};
arrange_and_wait(1,channel,"Threshold","Please threshold the channel "+channel+" to define signal.\nEverything below the threshold (not coloured in red) will be excluded from the analysis!\nUse the window 'Threshold' to do so. Don't press 'Apply' in this window! Check if you have 'Dark background' ticked.\nThen press OK.",1,"Pencil Tool");
selectWindow(channel);
wait(100);
getThreshold(lower, upper);
};
if(thresholding==3){//Automatic with a predefined thresholding method
setAutoThreshold(thresholdmethod+" dark stack");
run("Threshold...");
getThreshold(lower, upper);
};
selectWindow(channel);
wait(100);
setThreshold(lower, upper);
Atlim[0]=lower;
Atlim[1]=upper;
return Atlim;
};
function arrange_and_wait(threshold,channel,channel2,message,updateRM,tool){
selectWindow(channel);
wait(100);
getLocationAndSize(x, y, width, height);
resetMinAndMax();
run("Enhance Contrast", "saturated=0.35");
xorig=x;
yorig=y;
worig=width;
horig=height;
if(isOpen(channel2)){
selectWindow(channel2);
wait(100);
getLocationAndSize(x, y, width, height);
xorig2=x;
yorig2=y;
worig2=width;
horig2=height;
resetMinAndMax();
run("Enhance Contrast", "saturated=0.35");
};
wfactor=(screenWidth-220)/screenWidth;
hfactor=(screenHeight-220)/screenHeight;
wspace=screenWidth*wfactor;
hspace=screenHeight*hfactor;
if(isOpen("Synchronize Windows")){
selectWindow("Synchronize Windows");
setLocation(wspace/2,hspace);
};
if(isOpen(channel2)){
selectWindow(channel2);
setLocation(wspace/2,0);
roiManager("Show All with labels");
};
selectWindow(channel);
wait(100);
setLocation(0,0,wspace/2,hspace);
getLocationAndSize(x, y, width, height);
selectWindow(channel);
wait(100);
roiManager("Show All with labels");
if(threshold==1){