-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrgaMovie_Main.ijm
6999 lines (6449 loc) · 261 KB
/
OrgaMovie_Main.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
// check if macro was opened from Start macro or locally
passargument = getArgument();
if (passargument == ""){
waitForUser("You started the wrong macro.\n \nRun OrgaMovie_Start.ijm instead?");
Macro_location = getDirectory("plugins") + "OrgaMovie" + File.separator;
runMacro(Macro_location + "OrgaMovie_Start.ijm");
}
input_arguments = split(passargument, "$");
// turn lines below on for troubleshooting of input arguments
//print("inside main macro");
//print(passargument);
//for(i = 0; i < input_arguments.length; i++) print(i,input_arguments[i]);
t_step = input_arguments[0];
unused = input_arguments[1];
prefix = input_arguments[2];
do_registration = input_arguments[3];
do_autocrop = input_arguments[4];
do_autoBC = input_arguments[5];
do_autotime = input_arguments[6];
do_autoZ = input_arguments[7];
gamma_factor_import = input_arguments[8];
multiply_factor_import = input_arguments[9];
sec_p_frame = input_arguments[10];
inputfilename = input_arguments[11];
movie_index = input_arguments[12];
if (isNaN(movie_index)) {
movie_index = movie_index; // i.e. do nothing
} else if (movie_index < 10) {
movie_index = "0" + d2s(movie_index, 0);
} else movie_index = d2s(movie_index, 0);
run_mode = input_arguments[13]; // "queue" OR "process"
minOrgaSize = input_arguments[14];
minOrgaSize = parseInt(minOrgaSize);
cropBoundary = input_arguments[15];
loop_number = input_arguments[16];
loop_number = parseInt(loop_number);
min_thresh_meth = input_arguments[17];
//max_thresh_meth = input_arguments[18];
overexp_percile = input_arguments[18];
export_format = input_arguments[19];
makeAVI = true;
if (export_format == "*.tif only") makeAVI = false;
makeTIF = true;
if (export_format == "*.avi only") makeTIF = false;
minBrightnessFactor = input_arguments[20];
covCutoff = input_arguments[21];
minMovieLength = input_arguments[22];
channel_number_for_use = input_arguments[23];
if (run_mode == "process"){
for(i = 0; i < input_arguments.length; i++){
if (input_arguments[i] == "Movie_index_1_follows"){
movie_index_1 = i+1;
i += 1000000;
}
}
movie_index_list = Array.slice(input_arguments, movie_index_1, input_arguments.length);
print("list of movies to be be processed:");
Array.print(movie_index_list);
}
export_folder = "Output_Movies";
micron = getInfo("micrometer.abbreviation");
lastframe = 0;
/*
t_step = 3;
date = "25-3-2021";
prefix = "Pos_";
do_registration = 0;
do_autocrop = 1;
do_autoBC = 1;
do_autotime = 0;
do_autoZ = 0;
gamma_factor_import = 0.7;
multiply_factor_import = 1.0;
sec_p_frame = 1.3;
inputfilename = File.openDialog("Choose LIF-file to process");
run_mode = "queue";
movie_index = "00";
minOrgaSize = 350;
cropBoundary = 75;
*/
if (run_mode == "queue"){
print("macro initiated for movie: " + movie_index);
print("wait for file to open");
print(inputfilename);
} else print("macro entered in process mode");
LimitTimepointForDebugging = 0;
TempDisk = "F"; ///////////// If the MACRO does not do all timepoints then check line 2 This is a setting to speed up testing (and I might have forgotten to reset it...)
OutputDisk = "D";
PrintLikeCrazy = 0;
PauseAfterSettings = 1;
SingleTPtoZstack = 0;
if (SingleTPtoZstack) {
waitForUser("Sure you want SingleTPtoZstack @ 1 ????");
} //bp
GreenEnhanceContrastSaturationFactor = 0.1; //bp ---> line ~ 1000 --> run("Enhance Contrast", "saturated="+GreenEnhanceContrastSaturationFactor);
// set at 0 --> no saturated pixels
MarginForScaleBar = 4;
MinimalTextSize = 12;
GarbageEverynTimes = 4; // bp37
tiffFile = 0; // if you load an tiff file, it will be recognized
nd2File = 0; // if you load an nd2 file, it will be recognized
TCPForOverruling = ""; //nw//
Timo = 0;
TempXtoD = 0;
//INDEX OF MACRO:
//GENERAL SETTINGS
//FIRST DIALOG (restart? transmitted? check position?)
//RESTART, CHECK LAST POSITION
//LOAD SETTINGS
//RESTART, SETTINGS
//RESTART, DIALOG, CHOSE POSITION
//NORMAL, SETTINGS\
//NORMAL, POSITION NUMBER
//NORMAL, POSITION NAME
//NORMAL, TRANSMITTED CHANNEL
//NORMAL, CHANGE LUT SETTING FOR WHITE CHANNELS
//NORMAL, SAVE SETTINGS
//SET STANDARD SETTINGS (OR LOAD FROM SETTINGSFILE)
//NORMAL, DIALOG "SETTINGS"
//NORMAL, DIALOG "Chose channels for DeadDye and Nuclei"
//NORMAL, DIALOG "Extended settings"
//NORMAL, SAVE SETTINGS 2
//RESTART, GET SETTING FOR ALL POSITIONS
//NORMAL, SET ROI, ZPLANE AND B&C
//NORMAL, CHECK LAST TIMEPOINT BLACK
//NORMAL, MAKE TEMPORARY WINDOWS FOR B&C NON-TRANSMITTED CHANNELS
//NORMAL, DELETE Z-planes, CREATE 2 WINDOWS
//NORMAL, DELETE Z-planes, GET TOP AND BOTTOM
//NORMAL, DELETE Z-planes, GET MULTIPY FACTOR FOR DEPTHCODING
//NORMAL, SAVE SETTINGS 3
//ALL, START OF ACTUAL PROCESSING OPEN POSITION
//ALL, PROCESS TRANSMITTED
//ALL, PROCESS CHANNELS
//ALL, SAV PROGRESS TO NETWORK
//ALL, MERGE TIMEPOINTS
//ALL, COMBINE THE CHANNELS AND TRANS/DEPTHCODING
//ALL, SAVE PROGRESS FILE FOR RESTART
//ALL, SAVE PROGRESS TO NETWORK
//FUNCTIONS
// wegwerken : StringPreviousRun
// dat vinkje in de restart-dialog moet nog weg
run("Close All");
run("Collect Garbage");
ImageJDirectory = getDirectory("imagej");
if (File.exists("D:\\ANALYSIS DUMP\\")) {
OutputDisk = "D";
TempDisk = "D";
}
if (File.exists("F:\\ANALYSIS DUMP\\")) {
TempDisk = "F";
} // kan met length of string omdat-i achteraan staat!!!
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\Queue-info.txt")) {
QueueString = File.openAsRawString(TempDisk + ":\\ANALYSIS DUMP\\Queue-info.txt");
Index = indexOf(QueueString, "nQueuedExp_");
nQueuedExp = substring(QueueString, Index + 11, lengthOf(QueueString));
nQueuedExp = 1 * nQueuedExp;
} else {
nQueuedExp = 0;
}
QueueFinished = 1;
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\RunAllQueue-info.txt")) {
RunAllQueuedString = File.openAsRawString(TempDisk + ":\\ANALYSIS DUMP\\RunAllQueue-info.txt");
Index = indexOf(RunAllQueuedString, "RunAllQueued_");
RunAllQueuedPrevious = substring(RunAllQueuedString, Index + 13, Index + 14);
if (RunAllQueuedPrevious) {
Index = indexOf(RunAllQueuedString, "current_Exp_");
ExpWhenPreviousGotStuck = substring(RunAllQueuedString, Index + 12, Index + 13);
Index = indexOf(RunAllQueuedString, "nExp_");
nExp = substring(RunAllQueuedString, Index + 5, Index + 6);
Index = indexOf(RunAllQueuedString, "QueueFinished_");
QueueFinished = substring(RunAllQueuedString, Index + 14, Index + 15);
}
}
QueueMultiple = 0;
Q = "";
nExp = 1;
Restart = 0;
QuitQueuing = 0;
ExpForRestart = 1;
RestartMessage = "";
// dialog
if (nQueuedExp == 0) {
Dialog.create("no queued experiments");
Dialog.addMessage("All Queued Experiments have been run !!");
Dialog.addCheckbox("Start adding experiment(s) to the queue ?", 1);
Dialog.setInsets(40, 10, 0);
Dialog.addMessage("***** BP & RO only ******");
Dialog.addNumber("Manipulate nQueuedExp ", nQueuedExp);
Dialog.addNumber("Manipulate QueueFinished ", QueueFinished);
//Dialog.show();
QueueMultiple = Dialog.getCheckbox();
nQueuedExp = Dialog.getNumber();
QueueFinished = Dialog.getNumber();
}
if (QueueMultiple) {
Q = "Queued ";
nExp = 1;
}
OptionArray = newArray("Add another experiment to the queue", "Run ALL queued experiments", "Start all over again setting experiments in queue", "Restart (the queue-run got stuck...)");
QueueFollowUp = "";
QuitQueuing = 0; // deze MOET 0 blijven
if (nQueuedExp == 1) {
Text = "1 Experiment Queued";
}
if (nQueuedExp > 1) {
Text = d2s(nQueuedExp, 0) + " Experiments Queued";
}
if (QueueFinished == 0) {
QueueFollowUp = OptionArray[3];
QuitQueuing = 0;
ExpForRestart = ExpWhenPreviousGotStuck;
RestartMessage = " \n \n previous run got stuck at Exp#" + ExpWhenPreviousGotStuck + " \n \n ";
}
if (nQueuedExp > 0) {
Dialog.create("some experiments queued");
Dialog.setInsets(0, 10, 0);
Dialog.addMessage(Text + RestartMessage);
if (run_mode == "queue") Dialog.addRadioButtonGroup("What do you want to do?", OptionArray, 4, 1, OptionArray[0]);
else if (run_mode == "process") Dialog.addRadioButtonGroup("What do you want to do?", OptionArray, 4, 1, OptionArray[1]);
Dialog.setInsets(20, 20, 0);
Dialog.addCheckbox("Single analysis (no queuing)", QuitQueuing);
Dialog.setInsets(-3, 20, 0);
Dialog.addMessage("(upon checking, queued data are perfectly safe)");
Dialog.setInsets(40, 10, 0);
Dialog.addMessage("***** BP & RO only ******");
Dialog.addNumber("Manipulate nQueuedExp ", nQueuedExp);
//Dialog.show();
QueueFollowUp = Dialog.getRadioButton;
QuitQueuing = Dialog.getCheckbox();
nQueuedExp = Dialog.getNumber();
}
// in all cases evaluate this :
a = QueueMultiple;
if (QueueFollowUp == OptionArray[0]) {
QueueMultiple = 1;
nExp = 1;
Q = "Queued ";
}
RunAllQueued = 0;
if (QueueFollowUp == OptionArray[1]) {
RunAllQueued = 1;
QueueMultiple = 1;
nExp = nQueuedExp;
Q = "Queued ";
Restart = 1;
}
RestartQueuing = 0;
if (QueueFollowUp == OptionArray[2]) {
RestartQueuing = 1;
QueueMultiple = 1;
nExp = 1;
Q = "Queued ";
nQueuedExp = 0;
}
RestartQueueRun = 0;
if (QueueFollowUp == OptionArray[3]) {
RestartQueueRun = 1;
QueueMultiple = 1;
nExp = nQueuedExp;
Q = "Queued ";
RunAllQueued = 1;
Restart = 1;
}
FirstRoundRestart = 1;
if (QuitQueuing) {
QueueMultiple = 0;
nExp = 1;
Q = "";
RunAllQueued = 0;
RestartQueuing = 0;
RestartQueueRun = 0;
}
if (RestartQueueRun) {
Dialog.create("Do a RESTART in the queued run");
Dialog.addMessage("Do a RESTART in the queued run" + RestartMessage);
Dialog.addNumber("Which experiment ?", ExpForRestart);
Dialog.show();
ExpForRestart = Dialog.getNumber();
}
print("");
if (RunAllQueued && LimitTimepointForDebugging > 0) {
print("");
waitForUser("LimitTimepointForDebugging is at " + LimitTimepointForDebugging + " \n \n do you want that ???");
print("");
} //bp37 vanwege de print's
// deze for-loop gaat over de GEHELE macro !!!
// deze for-loop gaat over de GEHELE macro !!!
// deze for-loop gaat over de GEHELE macro !!!
for (Exp = 1; Exp < nExp + 1; Exp++) {
if (Exp == 1 && RunAllQueued) {
QueueFinished = 0;
RunAllQueuedString = "RunAllQueued_" + RunAllQueued + " current_Exp_" + Exp + " ; nExp_" + nExp + " ; QueueFinished_" + QueueFinished;
File.saveString(RunAllQueuedString, TempDisk + ":\\ANALYSIS DUMP\\RunAllQueue-info.txt");
}
if (RunAllQueued) {
for (v = 0; v < 20; v++) {
print("#");
}
for (v = 0; v < 10; v++) {
print("RunAllQueued ; next Exp, namely Exp #" + Exp);
}
for (v = 0; v < 20; v++) {
print("#");
}
}
if (RestartQueueRun && FirstRoundRestart) {
Exp = ExpForRestart;
}
//GENERAL SETTINGS
while (isOpen("Exception")) {
selectWindow("Exception");
run("Close");
} //Reset things to prevent error
setOption("ExpandableArrays", true); //Makes expandable arrays possible
//run("Set Measurements...", "area mean limit redirect=None decimal=1"); //Set measurements to include mean gray
// for analysis
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\TEMP DUMP\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\Settings\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\Settings\\Settings Archive\\");
// deze hieronder kan toch weg?
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\RESULT\\"); //Make directories so the macro kan write away temp files and results (doesn't do anything if they alreadt exist)
if (QueueMultiple) {
Temp = nQueuedExp + 1;
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\Settings\\");
File.makeDirectory(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\RESULT\\");
} // altijd 1 folder vooruit maken ; beetje raar maar kan geen kwaad
// for output
// deze hieronder kan toch weg?
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\TEMP DUMP\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\Settings\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\Settings\\Settings Archive\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\RESULT\\"); //Make directories so the macro kan write away temp files and results (doesn't do anything if they alreadt exist)
if (QueueMultiple) {
Temp = nQueuedExp + 1;
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\Settings\\");
File.makeDirectory(OutputDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Temp + "\\RESULT\\");
} // altijd 1 folder vooruit maken ; beetje raar maar kan geen kwaad
// DB output image to better place
image_output_location = OutputDisk + ":\\ANALYSIS DUMP\\_Movies_" + prefix + File.separator;
File.makeDirectory(image_output_location);
ChannelColourOriginal = newArray("White", "Green", "Red", "Blue", "Cyan", "Magenta", "Yellow");
ChannelColour = newArray("None", "Green", "Red", "Blue", "Cyan", "Magenta", "Yellow");
AspectArray = newArray("no", "square", "4:3", "16:9");
ScreenWidth = screenWidth();
ScreenHeight = screenHeight();
FitWidthFactor = 0.8;
FitHeightFactor = 0.8; //RO 2204
FitWidth = FitWidthFactor * screenWidth; //RO 2204
FitHeight = FitHeightFactor * screenHeight; //RO 2204
WindowSeparateMarginX = 30; //RO 2204
//FIRST DIALOG (restart? transmitted? check position?)
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\Settings\\Settings_Previous_Exp.tif")) {
PresenceSettingsFile = 1;
open(TempDisk + ":\\ANALYSIS DUMP\\Settings\\Settings_Previous_Exp.tif"); //bpx
info = getMetadata("info");
close();
List.setList(info);
TransmittedChannelPresent = List.get("TransmittedChannelPresent");
CheckPositionNumber = List.get("CheckPositionNumber");
CheckPositionName = List.get("CheckPositionName");
ReadFileName = List.get("ReadFileName"); //bp33
} else {
PresenceSettingsFile = 0;
TransmittedChannelPresent = 1;
CheckPositionNumber = 1;
CheckPositionName = 1;
ReadFileName = 1; //bp33
}
if (RunAllQueued == 0 && Exp == 1) {
Dialog.create("Restart?");
Dialog.addCheckbox("Select box if this is a restart", 0);
Dialog.addCheckbox("Is there a Transmitted Channel?", TransmittedChannelPresent);
Dialog.addCheckbox("Check Position number?", CheckPositionNumber);
Dialog.addCheckbox("Check Position Name?", CheckPositionName);
Dialog.addCheckbox("Read file name from metadata ?", ReadFileName); //bp34
//Dialog.show();
Restart = Dialog.getCheckbox();
TransmittedChannelPresent = Dialog.getCheckbox();
TCPForOverruling = TransmittedChannelPresent;
CheckPositionNumber = Dialog.getCheckbox();
CheckPositionName = Dialog.getCheckbox();
ReadFileName = Dialog.getCheckbox(); // bp34
}
//RESTART, CHECK LAST POSITION
if (QueueMultiple == 0) {
WhereToSaveSettings = 1;
}
if (QueueMultiple) {
WhereToSaveSettings = nQueuedExp + 1;
}
if (Restart) {
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Settings_Exp" + Exp + ".tif")) {} else {
exit("No Settings File!, cannot restart!");
}
List.clear; //Start with retrieving last position sucessfully completed
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Progress.tif")) {
open(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Progress.tif"); //bpx
info = getMetadata("info");
List.setList(info);
Progress = parseFloat(List.get("Progress"));
} else {
Progress = -1;
}
}
List.clear; //Start with retrieving settings from a previous run (if there is one)
//LOAD SETTINGS
if (Restart) {
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Settings_Exp" + Exp + ".tif")) {
open(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Settings_Exp" + Exp + ".tif");
info = getMetadata("info");
close(); //print(info);
List.setList(info);
}
} else {
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\Settings\\Settings_Previous_Exp.tif")) {
open(TempDisk + ":\\ANALYSIS DUMP\\Settings\\Settings_Previous_Exp.tif");
info = getMetadata("info");
close(); //print(info);
List.setList(info);
}
}
SelectionX1 = newArray;
SelectionX2 = newArray;
SelectionY1 = newArray;
SelectionY2 = newArray;
TransmittedMin = newArray;
TransmittedMax = newArray;
TransmittedZslice = newArray;
NumberOfTimepoints = newArray;
LastTimepointBlack = newArray;
Singletimepoint = newArray;
ScaleBarYArray = newArray;
nPixelsScaleBarArray = newArray;
nMicronsScaleBarArray = newArray;
ArrayZResolution = newArray;
Threshold = newArray();
ArraySkipPositions = newArray(10000);
Array.fill(ArraySkipPositions, 0); //bp17
SplitZ = newArray(10000);
Array.fill(SplitZ, 0); //bp21 // 0 betekent geen splitting en 2 of 3 wil zeggen dat er gechopt wordt en het echte getal zegt in hoeveel delen
PileUpChunks = newArray(10000);
Array.fill(PileUpChunks, 0); //bp37
SplitAndUnsplit = newArray(10000);
Array.fill(SplitAndUnsplit, 0); //bp37
DefaultGamma = 0.55;
DefaultMultiply = 1.2;
SetLastTimepoint = 0;
CheckLastTimepointBlack = 0;
TimeProjectTransm = 0;
nFramesForTimeProject = 35; // = parameter for this function
ChannelColourOriginal = newArray("White", "Green", "Red", "Blue", "Cyan", "Magenta", "Yellow");
RedDeadChannelUse = newArray("Nuclei", "DeadStuff", "Other", "Other", "Other", "Other", "Other", "Other");
NucleiChannel = "None";
DeadChannel = "None";
oldhour = 0;
oldminute = 0;
oldsecond = 0;
olddayOfMonth = 0;
oldmonth = 0;
oldyear = 0;
SetBrightness = 150;
FluoOffset = 4;
RedDeadDye = false;
Hidewindows = 1;
Date = 20001231;
NameExperiment = "NameExperiment"; //ShiftPositions = 0;
ColourName = 1;
AddTime = 1;
AddScaleBar = 1;
AddScaleBarZ = 1;
ExtendedSettings = 0;
UseDepthcoding = "With";
Interval = 10;
ColorTime = "White";
FractionForText = 20;
FractionForBar = 0.15;
WriteBarDimensions = 1;
ScaleBarLineWidth = 2;
NumberOfTPTempStacks = 8;
NumberOfZsTempStacks = 5;
SaveProgressToNetwork = false;
DeleteZStacks = 1;
SkipGlow = 0;
TextInGlowIsWhite = 1;
SetMultiplyBeforeDepthcoding = 1;
WindowForPause = 0; //RO this failed if the settings file was not present!
AddPositionName = 1;
GuidedBC = 1;
TimeProjectTransm = 1;
TimeForPause = 250; // milliseconden
PauseInterval = 3; //bpm
PlaceScaleBarZ = "Top";
UnsplitStillToDo = 1;
NowDoTheUnsplit = 0;
SplitAndUnsplitFill = 1; //BP37
UpperLeft = 0;
GarbageInterval = 1;
AspectChoice = AspectArray[0];
DefineFrameRate = 0;
DefineAviLength = 0;
FrameRateAvi = 10;
AviLength = 20; // i.e. seconds
//End of Standard settings, only used if the Settings file is not in the right position (you need to start from somewhere...)
ChannelName = newArray("Max Project", "Max Project2", "Max Project3", "Max Project4", "Max Project5", "Max Project6", "Max Project7", "Max Project8", "Max Project9", "Max Project10"); //RO 2304
// GET Settings from file (if present) // GET Settings from file (if present) // GET Settings from file (if present)
if (PresenceSettingsFile) {
CodedFile = List.get("CodedFile");
file = replace(CodedFile, "SLASH", "\\\\");
SaveProgressToNetwork = List.get("SaveProgressToNetwork");
CodedNetworkDirectory = List.get("CodedNetworkDirectory");
NetworkDirectory = replace(CodedNetworkDirectory, "SLASH", "\\\\");
PositionNumber = newArray;
PositionName = newArray;
PositionChannelAmount = newArray;
TopZ = newArray;
BottomZ = newArray;
TransmittedChannelNumber = newArray(PositionNumber.length);
MultiplyBeforeDepthcoding = newArray;
GammaCorr = newArray; //Singletimepoint=newArray;
//PositionNumber=corresponding position in LIF file, PositionName=Name as given in LASAF, PositionChannelAmount=amount of channels in said position
TransmittedChannelPresent = List.get("TransmittedChannelPresent");
if (TCPForOverruling != TransmittedChannelPresent) {
TransmittedChannelPresent = TCPForOverruling;
}
CheckPositionNumber = List.get("CheckPositionNumber"); //RO2906 wrong position!
CheckPositionName = List.get("CheckPositionName");
if (nd2File || tiffFile) {
CheckPositionName = 0;
} //RO2906 wrong position!
AmountOfPositions = List.get("AmountOfPositions");
WindowForPause = List.get("WindowForPause");
for (l = 0; l < AmountOfPositions; l++) {
PositionNumber[l] = List.get("PositionNumber" + l);
PositionName[l] = List.get("PositionName" + l);
TopZ[l] = List.get("TopZ_" + l);
BottomZ[l] = List.get("BottomZ_" + l);
MultiplyBeforeDepthcoding[l] = List.get("MultiplyBeforeDepthcoding" + l);
GammaCorr[l] = List.get("GammaCorr" + l);
SetLastTimepoint = List.get("SetLastTimepoint");
Threshold[l] = List.get("Threshold" + l);
}
ArraySizeForChannelUseandColour = parseFloat(List.get("ArraySizeForChannelUseandColour"));
maxNumberOfChannels = parseFloat(List.get("maxNumberOfChannels"));
UseChannel = newArray;
ChannelColour = newArray; //ChannelName=newArray;
for (l = 0; l < ArraySizeForChannelUseandColour; l++) {
if (PresenceSettingsFile) {
UseChannel[l] = List.get("UseChannel" + l);
ChannelName[l] = List.get("ChannelName" + l);
} else {
UseChannel[l] = 1;
ChannelName[l] = "Ch" + l;
}
}
RedDeadDye = List.get("RedDeadDye");
Hidewindows = List.get("Hidewindows");
UpperLeft = List.get("UpperLeft");
Date = List.get("Date");
NameExperiment = List.get("NameExperiment");
ColourName = List.get("ColourName");
AddTime = List.get("AddTime");
AddScaleBar = List.get("AddScaleBar");
FractionForBar = List.get("FractionForBar");
ScaleBarLineWidth = List.get("ScaleBarLineWidth");
WriteBarDimensions = List.get("WriteBarDimensions");
AddScaleBarZ = List.get("AddScaleBarZ");
PlaceScaleBarZ = List.get("PlaceScaleBarZ");
ExtendedSettings = List.get("ExtendedSettings");
UseDepthcoding = List.get("UseDepthcoding");
Interval = List.get("Interval");
ColorTime = List.get("ColorTime");
GuidedBC = List.get("GuidedBC");
RedDeadDye = List.get("RedDeadDye");
SkipGlow = List.get("SkipGlow"); // AspectChoice = List.get("AspectChoice");
FractionForText = List.get("FractionForText");
NumberOfTPTempStacks = List.get("NumberOfTPTempStacks");
NumberOfZsTempStacks = List.get("NumberOfZsTempStacks");
SaveProgressToNetwork = List.get("SaveProgressToNetwork");
WindowForPause = List.get("WindowForPause");
TimeForPause = List.get("TimeForPause");
PauseInterval = List.get("PauseInterval");
GarbageInterval = List.get("GarbageInterval");
if (CheckPositionName) {
AddPositionName = List.get("AddPositionName");
} else {
AddPositionName = 0;
}
DeleteZStacks = List.get("DeleteZStacks");
TextInGlowIsWhite = List.get("TextInGlowIsWhite");
SetMultiplyBeforeDepthcoding = List.get("SetMultiplyBeforeDepthcoding");
maxNumberOfChannels = parseFloat(List.get("maxNumberOfChannels"));
DefineFrameRate = List.get("DefineFrameRate");
DefineAviLength = List.get("DefineAviLength");
FrameRateAvi = List.get("FrameRateAvi");
AviLength = List.get("AviLength");
for (l = 0; l < maxNumberOfChannels; l++) {
UseChannel[l] = List.get("UseChannel" + l);
ChannelName[l] = List.get("ChannelName" + l);
RedDeadChannelUse[l] = List.get("RedDeadChannelUse" + l);
NucleiChannel = List.get("NucleiChannel");
DeadChannel = List.get("DeadChannel");
}
ChromaticAberration = List.get("ChromaticAberration");
FeasableRib = List.get("FeasableRib");
DefaultGamma = List.get("DefaultGamma");
DefaultGamma = parseFloat(DefaultGamma);
if (isNaN(DefaultGamma)) {
DefaultGamma = 0.55;
} // the isNaN is a trik to make sure that also the very first time the macro is used, there is a default setting
DefaultMultiply = List.get("DefaultMultiply");
DefaultMultiply = parseFloat(DefaultMultiply);
if (isNaN(DefaultMultiply)) {
DefaultMultiply = 1.2;
}
SetLastTimepoint = List.get("SetLastTimepoint");
if (isNaN(parseFloat(SetLastTimepoint))) {
SetLastTimepoint = 0;
}
CheckLastTimepointBlack = List.get("CheckLastTimepointBlack");
if (isNaN(parseFloat(CheckLastTimepointBlack))) {
CheckLastTimepointBlack = 0;
}
TimeProjectTransm = List.get("TimeProjectTransm");
AddScaleBarZLeft = 0;
if (AddScaleBarZ && PlaceScaleBarZ == "Left") {
AddScaleBarZLeft = 1;
}
AddScaleBarZTop = 0;
if (AddScaleBarZ && PlaceScaleBarZ == "Top") {
AddScaleBarZTop = 1;
}
}
if (Restart) { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< RESTART BEGIN >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// This part is to retreive the positional data in the case of a restart.
// Note we are not opening any file yet as we don't need to ask for settings, the positions will be opened as required!
//RESTART, SETTINGS
CodedFile = List.get("CodedFile");
file = replace(CodedFile, "SLASH", "\\\\");
SaveProgressToNetwork = List.get("SaveProgressToNetwork");
CodedNetworkDirectory = List.get("CodedNetworkDirectory");
NetworkDirectory = replace(CodedNetworkDirectory, "SLASH", "\\\\");
PositionNumber = newArray;
PositionName = newArray;
PositionChannelAmount = newArray;
TopZ = newArray;
BottomZ = newArray;
TransmittedChannelNumber = newArray(PositionNumber.length);
MultiplyBeforeDepthcoding = newArray;
GammaCorr = newArray; //Singletimepoint=newArray;
BottomZ_1 = newArray;
TopZ_1 = newArray;
GammaCorr_1 = newArray;
MultiplyBeforeDepthcoding_1 = newArray;
BottomZ_2 = newArray;
TopZ_2 = newArray;
GammaCorr_2 = newArray;
MultiplyBeforeDepthcoding_2 = newArray;
BottomZ_3 = newArray;
TopZ_3 = newArray;
GammaCorr_3 = newArray;
MultiplyBeforeDepthcoding_3 = newArray;
//PositionNumber=corresponding position in LIF file, PositionName=Name as given in LASAF, PositionChannelAmount=amount of channels in said position
TransmittedChannelPresent = List.get("TransmittedChannelPresent");
TCPForOverruling = TransmittedChannelPresent;
CheckPositionNumber = List.get("CheckPositionNumber");
CheckPositionName = List.get("CheckPositionName");
AmountOfPositions = List.get("AmountOfPositions");
WindowForPause = List.get("WindowForPause");
SetLastTimepoint = List.get("SetLastTimepoint");
DefineFrameRate = List.get("DefineFrameRate");
DefineAviLength = List.get("DefineAviLength");
FrameRateAvi = List.get("FrameRateAvi");
AviLength = List.get("AviLength");
for (l = 0; l < AmountOfPositions; l++) {
ArraySkipPositions[l] = List.get("ArraySkipPositions_" + l); //bp17
PileUpChunks[l] = List.get("PileUpChunks_" + l);
if (isNaN(PileUpChunks[l])) {
PileUpChunks[l] = 1;
} //bp37
SplitAndUnsplit[l] = List.get("SplitAndUnsplit_" + l);
if (isNaN(SplitAndUnsplit[l])) {
SplitAndUnsplit[l] = 0;
} //bp37
PositionNumber[l] = List.get("PositionNumber" + l);
PositionName[l] = List.get("PositionName" + l);
PositionChannelAmount[l] = List.get("PositionChannelAmount" + l);
TransmittedChannelNumber[l] = List.get("TransmittedChannelNumber" + l);
TopZ[l] = List.get("TopZ_" + l);
BottomZ[l] = List.get("BottomZ_" + l);
MultiplyBeforeDepthcoding[l] = List.get("MultiplyBeforeDepthcoding" + l);
GammaCorr[l] = List.get("GammaCorr" + l);
SplitZ[l] = List.get("SplitZ" + l);
if (SplitZ[l] > 0) {
BottomZ_1[l] = List.get("BottomZ_1_" + l);
TopZ_1[l] = List.get("TopZ_1_" + l);
GammaCorr_1[l] = List.get("GammaCorr_1_" + l);
MultiplyBeforeDepthcoding_1[l] = List.get("MultiplyBeforeDepthcoding_1_" + l);
BottomZ_2[l] = List.get("BottomZ_2_" + l);
TopZ_2[l] = List.get("TopZ_2_" + l);
GammaCorr_2[l] = List.get("GammaCorr_2_" + l);
MultiplyBeforeDepthcoding_2[l] = List.get("MultiplyBeforeDepthcoding_2_" + l);
}
if (SplitZ[l] == 3) {
BottomZ_3[l] = List.get("BottomZ_3_" + l);
TopZ_3[l] = List.get("TopZ_3_" + l);
GammaCorr_3[l] = List.get("GammaCorr_3_" + l);
MultiplyBeforeDepthcoding_3[l] = List.get("MultiplyBeforeDepthcoding_3_" + l);
}
}
ArraySizeForChannelUseandColour = parseFloat(List.get("ArraySizeForChannelUseandColour"));
maxNumberOfChannels = parseFloat(List.get("maxNumberOfChannels"));
UseChannel = newArray;
ChannelColour = newArray;
ChannelName = newArray;
for (l = 0; l < ArraySizeForChannelUseandColour; l++) {
ChannelColour[l] = List.get("ChannelColour" + l);
if (PresenceSettingsFile) {
UseChannel[l] = List.get("UseChannel" + l);
ChannelName[l] = List.get("ChannelName" + l);
} else {
UseChannel[l] = 1;
ChannelName[l] = "Ch" + l;
}
}
PreviousRunWasDone = false;
if (Progress == -1) {
Progress = 0;
} else {
Progress = Progress + 1;
}
print("Progress " + Progress);
if (Progress >= AmountOfPositions) {
Progress = 0;
PreviousRunWasDone = true;
}
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Progress.tif")) {
selectWindow("Progress.tif");
}
//RESTART, DIALOG, CHOOSE POSITION
AskFromWichPos = 0;
if (RunAllQueued == 0 && Exp == 1) {
AskFromWichPos = 1;
}
if (RestartQueueRun && FirstRoundRestart) {
AskFromWichPos = 1;
}
// now the FirstRoundRestart can be set at 0, because not necessary anymore
FirstRoundRestart = 0;
if (AskFromWichPos) {
ArrayWithSkippedPositions = newArray(0);
Temp = newArray(1);
for (h = 0; h < AmountOfPositions; h++) {
if (ArraySkipPositions[h] == 1) {
Temp[0] = h;
ArrayWithSkippedPositions = Array.concat(ArrayWithSkippedPositions, Temp);
print("ArraySkipPositions :");
Array.print(ArraySkipPositions);
print(" :");
print("");
}
}
Dialog.create("Restart from which position?")
if (PreviousRunWasDone) {
Dialog.addMessage("!======================! ATTENTION: !======================!");
Dialog.addMessage("Last run was completed or progress file doesn't match the settings file");
Dialog.addMessage("!======================!===========!=====================!");
}
Dialog.addMessage("Please choose from which position the macro should restart");
Dialog.addMessage("The suggested start is already selected");
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Progress.tif")) {
Dialog.addMessage("The Progress window shows the last postion completed successfully");
} else {
Dialog.addMessage("Could not complete the first position!");
}
Dialog.addRadioButtonGroup("Please choose position to start from", PositionNumber, AmountOfPositions, 1, PositionNumber[Progress]);
for (h = 0; h < ArrayWithSkippedPositions.length; h++) {
Dialog.addMessage("#" + ArraySkipPositions[h] + " was skipped");
}
Dialog.show();
StartfromPositionNumber = Dialog.getRadioButton();
} else {
StartfromPositionNumber = PositionNumber[Progress];
}
for (l = 0; l < AmountOfPositions; l++) {
if (PositionNumber[l] == StartfromPositionNumber) {
StartFromi = l;
print("StartFromi: " + StartFromi);
}
}
if (RunAllQueued && RestartQueueRun == 0) {
StartFromi = 0;
} // bp37
if (File.exists(TempDisk + ":\\ANALYSIS DUMP\\" + Q + "Exp" + Exp + "\\Settings\\Progress.tif")) {
selectWindow("Progress.tif");
close();
}
} else { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< RESTART ELSE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//NORMAL, SETTINGS
StartFromi = 0;
//file = File.openDialog("Choose LIF-file to process");
file = inputfilename; // ##DB## picked up from input arguments
CodedFile = replace(file, "\\\\", "SLASH");
liffFile = 0;
if (endsWith(file, ".lif")) {
liffFile = 1;
}
tiffFile = 0;
if (endsWith(file, ".tif")) {
tiffFile = 1;
}
if (tiffFile) {
TransmittedChannelPresent = 0;
CheckPositionNumber = 0;
CheckPositionName = 0;
ReadFileName = 0;
}
nd2File = 0;
if (endsWith(file, ".nd2")) {
nd2File = 1;
}
if (nd2File) {
TransmittedChannelPresent = 0;
CheckPositionNumber = 0;
CheckPositionName = 0;
ReadFileName = 0;
}
BioFormatImporter(file);
setLocation(1,1);
print("CURRENT TIME -", makeDateOrTimeString("time"));
FilePathForInCase = File.directory;
if (Timo == 3) {
waitForUser("open tif");
pre = nImages;
run("Bio-Formats Importer", "open=[] color_mode=Default split_channels view=Hyperstack stack_order=XYCZT");
file = File.directory + getTitle();
if (nImages > pre+1 ) closeWrongChannels(pre);
}
//Chose a file to process, this way we also set which file to use for the open commands
//The CodedFile is required as \ marks disappear when saved to a file (required for Restart)
//MetadataLIF = getImageInfo(); // is a large string containing all info about the opened images // DB turned this off
//print(MetadataLIF); // DB turned this off
if (Timo == 3) {
waitForUser("print(MetadataLIF)");
}
PositionNumber = newArray;
if (PresenceSettingsFile) {
TimeProjectTransm = List.get("TimeProjectTransm");
} else {
TimeProjectTransm = 0;
}
nFramesForTimeProject = 35; // = parameter for this function
//NORMAL, POSITION NUMBER
if (CheckPositionNumber) { // Added this if-loop in case the metadata is such that the search is incorrect i.e. giving an error...
AmountOfPositions = 0;
Start = 0;
Name = "0";
continueW = 1;
while (continueW == 1) { //This while loop is to determine how many and which postions were opened and to add them to an array
continueW = 0;
IndexPos = indexOf(MetadataLIF, "Name ", Start) - 9; //RO 0204 changed this to be able to process positions larger than 99...
IndexPos = indexOf(MetadataLIF, " ", IndexPos); //RO 0204 changed this to be able to process positions larger than 99...
Start = IndexPos + 10;
IndexPosEnd = indexOf(MetadataLIF, " ", IndexPos + 1); //RO 0204 changed this to be able to process positions larger than 99...
Name = substring(MetadataLIF, IndexPos, IndexPosEnd); //RO 0204 changed this to be able to process positions larger than 99...
PositionNumber[AmountOfPositions] = parseFloat(Name) + 1;
AmountOfPositions = AmountOfPositions + 1;
Name = parseFloat(Name);
if (Name >= 0) {
continueW = 1;
}; // !!##DB this semi colon is very weird, but the macro currently runs so I'm hesitant to remove it
}
PositionNumber = Array.trim(PositionNumber, PositionNumber.length - 1);
//Remove the last point in the Array as this is not a number!
PositionNumber = Array.sort(PositionNumber); //Sort the array as he order in the metadata is 0-1-10-11-...-2-3 etc. this doesnot correspond to the order the images are opened!
AmountOfPositions = AmountOfPositions - 1;
//Correct for loop going 1 to far (asigning LD as a position number) Need this variable to make determine array.length when retreiving data from the settings file
} else {
if (tiffFile == 0) {
Dialog.create("How many positions were opened?") // I added this in case the check positions doesn't work and the user opted to switch it off
Dialog.addNumber("Amount of positions", 1); // and I needed a way to find out how many positions were opened PS I haven;t really tested this...
//Dialog.show();
AmountOfPositions = Dialog.getNumber();
} else {
AmountOfPositions = 1;
}
PositionNumber = newArray(AmountOfPositions);
for (PositionNumberFill = 0; PositionNumberFill < PositionNumber.length; PositionNumberFill++){
PositionNumber[PositionNumberFill] = PositionNumberFill + 1;
}
}
PositionName = newArray(PositionNumber.length);
PositionChannelAmount = newArray(PositionNumber.length);
TransmittedChannelNumber = newArray(PositionNumber.length);
Transmittedfound = newArray(PositionNumber.length);
Array.fill(Transmittedfound, 0);
print("AmountOfPositions" + AmountOfPositions);
// Counts the number of channels and determines the name for each postion
// The name for each position is derived from the title of the window (is always 'filename'.lif - 'Positionname' - C='channelnumber')