-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathctmrGUI.m
1975 lines (1548 loc) · 104 KB
/
ctmrGUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
classdef ctmrGUI < handle
properties
mainFig
extraFig
controls
settings
alice_version
end
methods
function obj = ctmrGUI
% Create main window.
width = 1010; %increase
height = 750;
frameheight = 200;
global ALICE
obj.alice_version = ALICE.version;
%number lines in action log.
obj.settings.NUM_LINES = 8;
%no files loaded.
obj.settings.loaded = [0 0 0 0];
%initial values for 3dclustering
obj.settings.CV = 3999;
obj.settings.R = 3;
obj.settings.IS = 1;
%empty hemisphere:
obj.settings.Hemisphere = cell(1,3);
%empty method:
obj.settings.Method = cell(1,3);
%empty subject name:
obj.settings.subject = [];
%empty lay9ut/grid settings:
obj.settings.Layout = cell(1,3);
obj.settings.Tabnum = 1;
obj.settings.Grids = [];
obj.settings.Gridnum = 0;
%current number lines in action log
obj.settings.curr_num_lines = 0;
%by default do not save nii files
obj.settings.saveNii = 0;
% Get screen size.
screenSize = get(0,'ScreenSize');
% Starting point of each frame.
startingPointFrame = [10 round(width/3)+5 2*round(width/3)];
% Main window
windowPosition = [ round((screenSize(3)-width)/5), screenSize(4)-height-100, width, height+80];
obj.mainFig = figure( 'Name', 'ALICE','OuterPosition', windowPosition, 'Menu', 'none', ...
'NumberTitle', 'off', 'Color', get(0,'DefaultUIControlBackgroundColor'), 'Resize', 'off', 'CloseRequestFcn', @obj.figCloseRequest );
%two buttons for create directory or locate directory:
obj.controls.btnCreateDirectory = uicontrol( 'Parent', obj.mainFig, 'Style', 'pushbutton', 'Position', [295 718+36 200 35], ...
'String', 'Create Directory', 'Callback', @obj.btnCreateDirectory, 'FontSize', 11 , 'FontWeight', 'bold');
obj.controls.btnLocateDirectory = uicontrol( 'Parent', obj.mainFig, 'Style', 'pushbutton', 'Position', [505 718+36 200 35], ...
'String', 'Locate Directory', 'Callback', @obj.btnLocateDirectory, 'FontSize', 11 , 'FontWeight', 'bold');
%Frame 1
obj.controls.frame1 = uipanel( 'Parent', obj.mainFig, 'Units', 'pixels', 'Position', [startingPointFrame(1) frameheight+40 round(width/3)-20 height-250], ...
'Title', '1. CT-MR Co-registration', 'FontSize', 12,'Visible', 'off', 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [.5 .5 .5] );
%Frame 2
obj.controls.frame2 = uipanel( 'Parent', obj.mainFig, 'Units', 'pixels', 'Position', [startingPointFrame(2) frameheight+40 round(width/3)-20 height-250], ...
'Title', '2. Electrode Selection', 'FontSize', 12, 'Visible', 'off','FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [.5 .5 .5] );
%Frame 3
obj.controls.frame3 = uipanel( 'Parent', obj.mainFig, 'Units', 'pixels', 'Position', [startingPointFrame(3) frameheight+40 round(width/3)-20 height-250], ...
'Title', '3. Electrode Projection', 'FontSize', 12,'Visible', 'off', 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [.5 .5 .5] );
%% Inside frame 1:
% SubFrame 1 inside frame 1
obj.controls.subframe1 = uipanel( 'Parent', obj.controls.frame1, 'Units', 'pixels', 'Position', [10 360 293 100], ...
'Title', 'Select MRI scan from FS folder', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% SubFrame 2 inside frame 1
obj.controls.subframe2 = uipanel( 'Parent', obj.controls.frame1, 'Units', 'pixels', 'Position', [10 240 293 100], ...
'Title', 'Select FreeSurfer segmentation', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% SubFrame 3 inside frame 1
obj.controls.subframe3 = uipanel( 'Parent', obj.controls.frame1, 'Units', 'pixels', 'Position', [10 120 293 100], ...
'Title', 'Select CT scan', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% Button 1 inside frame 1
obj.controls.btnAlignCTtoMRI = uicontrol( 'Parent', obj.controls.frame1, 'Style', 'pushbutton', 'Position', [10 35 140 50], ...
'String', 'Align CT to MRI', 'Callback', @obj.btnAlignCTtoMRI, 'FontSize', 9, 'FontWeight', 'bold' );
% Button 2 inside frame 1
obj.controls.btnAlreadyAligned = uicontrol( 'Parent', obj.controls.frame1, 'Style', 'pushbutton', 'Position', [163 35 140 50], ...
'String', 'CT already aligned', 'Callback', @obj.btnAlreadyAligned, 'FontSize', 9, 'FontWeight', 'bold' );
%% Inside frame 2:
% SubFrame 1 inside frame 2
obj.controls.subframe4 = uipanel( 'Parent', obj.controls.frame2, 'Units', 'pixels', 'Position', [10 360 293 100], ...
'Title', 'Select file with electrode labels', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% SubFrame 2 inside frame 2
obj.controls.subframe5 = uipanel( 'Parent', obj.controls.frame2, 'Units', 'pixels', 'Position', [10 120 293 220], ...
'Title', '3D-Clustering settings', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% Button 1 inside frame 2
obj.controls.btnExtractClusters = uicontrol( 'Parent', obj.controls.frame2, 'Style', 'pushbutton', 'Position', [10 35 140 50], ...
'String', 'Extract Clusters', 'Callback', @obj.btnExtractClusters, 'FontSize', 9 , 'FontWeight', 'bold');
% Button 2 inside frame 2
obj.controls.btnSelectElectrodes = uicontrol( 'Parent', obj.controls.frame2, 'Style', 'pushbutton', 'Position', [163 35 140 50], ...
'String', 'Select Electrodes', 'Callback', @obj.btnSelectElectrodes, 'FontSize', 9 , 'FontWeight', 'bold');
%% Inside frame 3:
% SubFrame 1 inside frame 3
obj.controls.subframe6 = uipanel( 'Parent', obj.controls.frame3, 'Units', 'pixels', 'Position', [10 120 293 340], ...
'Title', 'Select Projection Method', 'FontSize', 10, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [0.8 .8 .8] );
% Checkbox inside frame 3
obj.controls.checkBoxSaveNii = uicontrol( 'Parent', obj.controls.frame3, 'Style', 'checkbox', 'Position', [109 35+55 140 20], ...
'String', 'Save Nifti files', 'Callback', @obj.checkBoxSaveNii, 'FontSize', 8 , 'FontWeight', 'normal');
% Button 1 inside frame 3
obj.controls.btnVisualize = uicontrol( 'Parent', obj.controls.frame3, 'Style', 'pushbutton', 'Position', [90 35 140 50], ...
'String', 'Visualize!', 'Callback', @obj.btnVisualize, 'FontSize', 9 , 'FontWeight', 'bold');
%% Inside Subframe 1 - frame 1
% Button 1 inside subframe 1
obj.controls.btnOpenMRI = uicontrol( 'Parent', obj.controls.subframe1, 'Style', 'pushbutton', 'Position', [10 25 100 40], ...
'String', 'Open', 'Callback', @obj.btnOpenMRI, 'FontSize', 9 , 'FontWeight', 'bold');
% text box inside subframe 1
obj.controls.txtMRI = uicontrol( 'Parent', obj.controls.subframe1, 'Style', 'edit', 'Position', [115 26 168 36], ...
'FontSize', 7, 'string', {' (.../FreeSurfer/mri/T1.mgz)'} , 'HorizontalAlignment', 'left', 'BackgroundColor', 'w' ,'enable','inactive');
%% Inside subframe 2 - frame 1
% Button 1 inside subframe 2
obj.controls.btnOpenFS = uicontrol( 'Parent', obj.controls.subframe2, 'Style', 'pushbutton', 'Position', [10 25 100 40], ...
'String', 'Open', 'Callback', @obj.btnOpenFS, 'FontSize', 9 , 'FontWeight', 'bold');
% text box inside subframe 2
obj.controls.txtFS= uicontrol( 'Parent', obj.controls.subframe2, 'Style', 'edit', 'Position', [115 26 168 36], ...
'FontSize',7, 'string', {' (.../FreeSurfer/mri/ribbon.mgz)'} , 'HorizontalAlignment', 'left', 'BackgroundColor', 'w' ,'enable','inactive');
%% Inside subframe 3 - frame 1
% Button 1 inside subframe 3
obj.controls.btnOpenCT1 = uicontrol( 'Parent', obj.controls.subframe3, 'Style', 'pushbutton', 'Position', [10 25 100 40], ...
'String', 'Open', 'Callback', @obj.btnOpenCT1, 'FontSize', 9 , 'FontWeight', 'bold');
% text box inside subframe 3
obj.controls.txtCT1= uicontrol( 'Parent', obj.controls.subframe3, 'Style', 'edit', 'Position', [115 26 168 36], ...
'FontSize', 7, 'string', {' (.../*.nii)'} , 'HorizontalAlignment', 'left', 'BackgroundColor', 'w' ,'enable','inactive');
%% Inside subframe 4 - frame 2
% text box inside subframe 4
obj.controls.txtLabels = uicontrol( 'Parent', obj.controls.subframe4, 'Style', 'edit', 'Position', [115 26 168 36], ...
'FontSize',7, 'string', {' (.../*.txt)'} , 'HorizontalAlignment', 'left', 'BackgroundColor', 'w' ,'enable','inactive');
% Button 1 inside subframe 4
obj.controls.btnOpenLabels = uicontrol( 'Parent', obj.controls.subframe4, 'Style', 'pushbutton', 'Position', [10 25 100 40], ...
'String', 'Open', 'Callback', @obj.btnOpenLabels, 'FontSize', 9 , 'FontWeight', 'bold');
%% Inside subframe 5 - frame 3
%text box
obj.controls.txtCV = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'text', 'Position', [10 145 213 25], ...
'FontSize', 10, 'string', {'Electrode max. intensity (-5)'} , 'HorizontalAlignment', 'left','enable','inactive');
%edit text box
obj.controls.edtCV = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'edit', 'Position', [223 145 60 36], ...
'FontSize', 10, 'string', {'3999'} ,'Callback', @obj.edtCV, 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%text box
obj.controls.txtR = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'text', 'Position', [10 85 213 25], ...
'FontSize', 10, 'string', {'Electrode volume (e.g., 3)'} , 'HorizontalAlignment', 'left','enable','inactive');
%edit text box
obj.controls.edtR = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'edit', 'Position', [223 85 60 36], ...
'FontSize', 10, 'string', {'3'} , 'Callback', @obj.edtR, 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%text box
obj.controls.txtIS = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'text', 'Position', [10 25 213 25], ...
'FontSize', 10, 'string', {'Interelectrode space (e.g., 1)'} , 'HorizontalAlignment', 'left','enable','inactive');
%edit text box
obj.controls.edtIS = uicontrol( 'Parent', obj.controls.subframe5, 'Style', 'edit', 'Position', [223 25 60 36], ...
'FontSize', 10, 'string', {'1'} , 'Callback', @obj.edtIS, 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%% Inside subframe 6 - frame 3
%select a method
obj.controls.Methods = uibuttongroup('Parent', obj.controls.subframe6, 'Visible', 'on', 'SelectionChangedFcn', @obj.radiobtnSelectionMethod, 'Position', [0 0.66 1 0.5], 'Bordertype', 'none');
obj.controls.radiobtn1 = uicontrol( obj.controls.Methods, 'Style', 'radiobutton', 'Position', [20 75 230 25], ...
'FontSize', 10, 'string', 'Method 1 (Hermes et al. 2010)' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn1.Value = 0;
obj.controls.radiobtn2 = uicontrol( obj.controls.Methods, 'Style', 'radiobutton', 'Position', [20 55 230 25], ...
'FontSize', 10, 'string', 'Method HD' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn2.Value = 0;
obj.controls.radiobtn5 = uicontrol( obj.controls.Methods, 'Style', 'radiobutton', 'Position', [20 35 230 25], ...
'FontSize', 10, 'string', 'Method sEEG or depth' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn5.Value = 0;
%enter subject name:
%text box
obj.controls.txtSbjName = uicontrol( obj.controls.subframe6, 'Style', 'text', 'Position', [10 205-10 150 40], ...
'FontSize', 10, 'string', {'Subject Name:'} , 'FontWeight', 'bold','HorizontalAlignment', 'left','enable','inactive');
%edit text box
obj.controls.edtSbjName = uicontrol( 'Parent', obj.controls.subframe6, 'Style', 'edit', 'Position', [130 224-10 155 25], ...
'FontSize', 8, 'string','name...' , 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%select an hemisphere
obj.controls.Hemisphere = uibuttongroup('Parent', obj.controls.subframe6, 'Visible', 'on', 'SelectionChangedFcn', ...
@obj.radiobtnSelectionHemisphere,'Position', [0 0.33 1 0.33],'Bordertype', 'none');
% text box select hemisphere
obj.controls.txtHemisphere = uicontrol( obj.controls.Hemisphere, 'Style', 'text', 'Position', [10 60-5 150 40], ...
'FontSize', 10, 'string', {'Implanted hemisphere:'} , 'FontWeight', 'bold','HorizontalAlignment', 'left','enable','inactive');
%radio button 3
obj.controls.radiobtn3 = uicontrol( obj.controls.Hemisphere, 'Style', 'radiobutton', 'Position', [120-2 75-5 230 25], ...
'FontSize', 10, 'string', 'Left' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn3.Value = 0;
%radio button 4
obj.controls.radiobtn4 = uicontrol( obj.controls.Hemisphere, 'Style', 'radiobutton', 'Position', [175-1 75-5 230 25], ...
'FontSize', 10, 'string', 'Right' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn4.Value = 0;
%radio button 6
obj.controls.radiobtn6 = uicontrol( obj.controls.Hemisphere, 'Style', 'radiobutton', 'Position', [238-2 75-5 230 25], ...
'FontSize', 10, 'string', 'Both' ,'HandleVisibility','off', 'HorizontalAlignment', 'left','enable','on');
obj.controls.radiobtn6.Value = 0;
% Tab group for each scheme
obj.controls.layout = uitabgroup('Parent', obj.controls.subframe6, 'Visible', 'on', 'SelectionChangedFcn', @obj.tabSelectScheme,...
'Position', [0.02 0.02 0.97 0.45], 'TabLocation', 'Top');
% Tab 1
obj.controls.tab(1) = uitab( obj.controls.layout, 'Title', 'Layout 1', 'HandleVisibility','off');
% Add tab
obj.controls.addTab = uicontrol( 'Parent', obj.controls.subframe6, 'Style', 'pushbutton', 'Position', [243 132 22 22], ...
'String', '+', 'Callback', @obj.btnAddTab, 'FontSize', 12 , 'FontWeight', 'bold','Enable', 'off');
% remove tab
obj.controls.removeTab = uicontrol( 'Parent', obj.controls.subframe6, 'Style', 'pushbutton', 'Position', [267 132 22 22], ...
'String', '-', 'Callback', @obj.btnRemoveTab, 'FontSize', 16, 'Enable', 'off' );
%% set grid settings:
%text box
obj.controls.txtGrid1(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [10 93 230 20], ...
'FontSize', 10, 'string', {'Grid settings:'} , 'FontWeight', 'bold', 'HorizontalAlignment', 'left','enable','inactive');
%text box label
obj.controls.txtGrid2(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [10+40 70 80 15], ...
'FontSize', 10, 'string', {'Label'} , 'HorizontalAlignment', 'center','enable','inactive');
%edit text box label
obj.controls.edtGrid2(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'edit', 'Position', [10+40 35 80 36], ...
'FontSize', 8, 'string','e.g.: C' , 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%text box grid size
obj.controls.txtGrid4(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [190-40 70 80 15], ...
'FontSize', 10, 'string', {'Size'} , 'HorizontalAlignment', 'center','enable','inactive');
%edit text box grid size
obj.controls.edtGrid4(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'edit', 'Position', [190-40 35 80 36], ...
'FontSize', 8, 'string','e.g.: 4, 8' , 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
% Add grid
obj.controls.addGrid(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'pushbutton', 'Position', [120 7 22 22], ...
'String', '+', 'Callback', @obj.btnAddGrid, 'FontSize', 12 , 'FontWeight', 'bold');
% remove grid
obj.controls.removeGrid(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'pushbutton', 'Position', [150 7 22 22], ...
'String', '-', 'Callback', @obj.btnRemoveGrid, 'FontSize', 16,'Enable','off' );
% previous grid
obj.controls.previousGrid(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'pushbutton', 'Position', [90 7 22 22], ...
'String', '<', 'Callback', @obj.btnPreviousGrid, 'FontSize', 11 , 'FontWeight', 'bold', 'Enable', 'off');
% next grid
obj.controls.nextGrid(1) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'pushbutton', 'Position', [180 7 22 22], ...
'String', '>', 'Callback', @obj.btnNextGrid, 'FontSize', 11 , 'FontWeight', 'bold', 'Enable', 'off');
%% Logging frame
obj.controls.logframe = uipanel( 'Parent', obj.mainFig, 'Units', 'pixels', 'Position', [10 10 980 frameheight-20+40], ...
'Title', 'Action Log:', 'FontSize', 12, 'FontWeight', 'bold', 'BorderType', 'line', 'HighlightColor', [.5 .5 .5] );
% Inside the Logging frame:
% text box
obj.controls.txtLog = uicontrol( 'Parent', obj.controls.logframe, 'Style', 'text','max',2, 'Position', [10 10 960 145+40], ...
'FontSize', 10, 'string', {'> Welcome to ALICE!', '> Please create a directory to start ALICE from scratch, or locate the existing directory.'}, 'HorizontalAlignment', 'left', 'BackgroundColor', 'w' ,'enable','inactive');
end
function CreateDirectory( obj )
obj.settings.originaldir = [pwd '/'];
obj.settings.scriptspath = [fileparts( mfilename('fullpath') ) '/'];
if exist([pwd '/ALICE'])==7
errordlg('A folder named ALICE already exists. Please choose another directory or rename the existing folder.');
else
%make panels visible
set(obj.controls.frame1,'Visible', 'on');
set(obj.controls.frame2,'Visible', 'on');
set(obj.controls.frame3,'Visible', 'on');
%create directories
mkdir('ALICE');
fileattrib ./ALICE +w g
cd ./ALICE;
obj.settings.currdir = [pwd '/'];
mkdir('log_info');
%data folder
mkdir('data');
cd ./data;
mkdir('3Dclustering');
mkdir('CT');
mkdir('coregistration')
mkdir('MRI');
mkdir('FreeSurfer');
cd(obj.settings.currdir);
%locate matlab scripts
addpath(genpath([ obj.settings.scriptspath 'MATLAB_scripts']));
%locate afni scripts
cd(obj.settings.currdir);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/alignCTtoT1_shft_res.csh'], [obj.settings.currdir 'data/coregistration/']);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/3dclustering.csh'], [obj.settings.currdir 'data/3Dclustering/']);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/select_electrode.csh'], [obj.settings.currdir 'data/3Dclustering/']);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/open_afni_suma.csh'], [obj.settings.currdir 'data/3Dclustering/']);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/indexify_electrodes.csh'], [obj.settings.currdir 'data/3Dclustering/']);
copyfile([obj.settings.scriptspath 'AFNI_scripts' '/delete_cluster.csh'], [obj.settings.currdir 'data/3Dclustering/']);
cd(obj.settings.currdir);
addpath(genpath(obj.settings.currdir));
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> ALICE successfully created. Please proceed to Step 1.'});
loggingActions(obj.settings.currdir,1,' > ALICE successfully created. Please proceed to Step 1.');
end
end
function LocateDirectory( obj )
folderName = uigetdir('.', 'Please locate ALICE folder.');
if sum(folderName)~=0 && strcmp(folderName(end-4:end), 'ALICE')
%make panels visible
set(obj.controls.frame1,'Visible', 'on');
set(obj.controls.frame2,'Visible', 'on');
set(obj.controls.frame3,'Visible', 'on');
obj.settings.currdir = [folderName '/'];
cd(folderName);
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},['> ALICE directory located: ' obj.settings.currdir],'> Please proceed to Step 1.'});
loggingActions(obj.settings.currdir,1,[' > ALICE directory located: ' obj.settings.currdir]);
loggingActions(obj.settings.currdir,1,' > Please proceed to Step 1.');
if exist([obj.settings.currdir '/log_info/settings.mat'])==2
oldsettings = load([obj.settings.currdir '/log_info/settings.mat']);
obj.settings = oldsettings.settings;
obj.settings.currdir = [folderName '/'];
%check for version differences:
if ~isfield(obj.settings,'version') || obj.settings.version < 6.5
obj.settings.version = obj.alice_version;
%add new fields
if ~isempty(obj.settings.Grids)
obj.settings.Layout{1} = obj.settings.Grids;
obj.settings.Grids = [];
else
obj.settings.Layout = cell(1,3);
end
obj.settings.Tabnum = 1;
obj.settings.Gridnum = 0;
end
%check if older version has not method/hemisphere per
%layout
%todo
if ~iscell(obj.settings.Hemisphere)
obj.settings.Hemisphere = {obj.settings.Hemisphere [] []};
end
if ~iscell(obj.settings.Method)
obj.settings.Method = {obj.settings.Hemisphere [] []};
end
try
set(obj.controls.edtCV, 'String',obj.settings.CV);
set(obj.controls.edtR, 'String',obj.settings.R);
set(obj.controls.edtIS, 'String',obj.settings.IS);
set(obj.controls.checkBoxSaveNii, 'value', obj.settings.saveNii);
end
try
set(obj.controls.edtSbjName, 'String',obj.settings.subject);
end
%delete tab if exist:
try
for t2 = length(obj.controls.tab):-1:1
obj.controls.tab(t2).Parent = [];
obj.controls.tab(t2) = [];
obj.controls.nextGrid(t2) = [];
obj.controls.previousGrid(t2) = [];
obj.controls.addGrid(t2) = [];
obj.controls.removeGrid(t2) = [];
obj.controls.edtGrid2(t2) = [];
obj.controls.edtGrid4(t2) = [];
obj.controls.txtGrid1(t2) = [];
obj.controls.txtGrid2(t2) = [];
obj.controls.txtGrid4(t2) = [];
end
end
%add new tabs
for t = 1:length(obj.settings.Layout)
if ~isempty(obj.settings.Layout{t}) || t==1
obj.controls.tab(t) = uitab( obj.controls.layout, 'Title', ['Layout ' num2str(t)], 'HandleVisibility','off');
%add elements inside tab
obj.controls.txtGrid1(t) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [10 93 230 20], ...
'FontSize', 10, 'string', {'Grid settings:'} , 'FontWeight', 'bold', 'HorizontalAlignment', 'left','enable','inactive');
%text box label
obj.controls.txtGrid2(t) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [10+40 70 80 15], ...
'FontSize', 10, 'string', {'Label'} , 'HorizontalAlignment', 'center','enable','inactive');
%edit text box label
obj.controls.edtGrid2(t) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'edit', 'Position', [10+40 35 80 36], ...
'FontSize', 8, 'string','e.g.: C' , 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
%text box grid size
obj.controls.txtGrid4(t) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'text', 'Position', [190-40 70 80 15], ...
'FontSize', 10, 'string', {'Size'} , 'HorizontalAlignment', 'center','enable','inactive');
%edit text box grid size
obj.controls.edtGrid4(t) = uicontrol( 'Parent', obj.controls.tab(1), 'Style', 'edit', 'Position', [190-40 35 80 36], ...
'FontSize', 8, 'string','e.g.: 4, 8' , 'HorizontalAlignment', 'center', 'BackgroundColor', 'w' ,'enable','on');
% Add grid
obj.controls.addGrid(t) = uicontrol( 'Parent', obj.controls.tab(t), 'Style', 'pushbutton', 'Position', [120 7 22 22], ...
'String', '+', 'Callback', @obj.btnAddGrid, 'FontSize', 12 , 'FontWeight', 'bold');
% remove grid
obj.controls.removeGrid(t) = uicontrol( 'Parent', obj.controls.tab(t), 'Style', 'pushbutton', 'Position', [150 7 22 22], ...
'String', '-', 'Callback', @obj.btnRemoveGrid, 'FontSize', 16,'Enable','off' );
% previous grid
obj.controls.previousGrid(t) = uicontrol( 'Parent', obj.controls.tab(t), 'Style', 'pushbutton', 'Position', [90 7 22 22], ...
'String', '<', 'Callback', @obj.btnPreviousGrid, 'FontSize', 11 , 'FontWeight', 'bold', 'Enable', 'off');
% next grid
obj.controls.nextGrid(t) = uicontrol( 'Parent', obj.controls.tab(t), 'Style', 'pushbutton', 'Position', [180 7 22 22], ...
'String', '>', 'Callback', @obj.btnNextGrid, 'FontSize', 11 , 'FontWeight', 'bold', 'Enable', 'off');
%set add and remove tab buttons
if t > 1
set(obj.controls.addTab,'enable','on');
set(obj.controls.removeTab,'enable','on');
else
set(obj.controls.addTab,'enable','on');
set(obj.controls.removeTab,'enable','off');
end
end
end
if ~isempty(obj.settings.Layout{obj.settings.Tabnum})
%highlight last used tab (works for Tabnum==1 and Tabnum>1)
set(obj.controls.layout, 'SelectedTab',obj.controls.tab(obj.settings.Tabnum));
obj.settings.Grids = obj.settings.Layout{obj.settings.Tabnum};
obj.settings.Gridnum = length(obj.settings.Grids);
%display last grid settings
auxgrids = split(obj.settings.Grids{end}, ';');
set(obj.controls.edtGrid2(obj.settings.Tabnum), 'enable', 'on');
set(obj.controls.edtGrid2(obj.settings.Tabnum), 'String', strtrim(auxgrids{1}));
set(obj.controls.edtGrid4(obj.settings.Tabnum), 'enable', 'on');
set(obj.controls.edtGrid4(obj.settings.Tabnum), 'String', strtrim(auxgrids{2}));
if length(obj.settings.Grids)==1
set(obj.controls.removeGrid(obj.settings.Tabnum),'enable','on');
set(obj.controls.addGrid(obj.settings.Tabnum),'enable','on');
set(obj.controls.nextGrid(obj.settings.Tabnum),'enable','off');
set(obj.controls.previousGrid(obj.settings.Tabnum),'enable','off');
else %more than 1
set(obj.controls.removeGrid(obj.settings.Tabnum),'enable','on');
set(obj.controls.addGrid(obj.settings.Tabnum),'enable','on');
set(obj.controls.nextGrid(obj.settings.Tabnum),'enable','off'); %set to last grid, so no next grid
set(obj.controls.previousGrid(obj.settings.Tabnum),'enable','on');
end
%log
LogInfo(obj, 3);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},['> Current grid settings: ' strjoin(obj.settings.Grids,' ')]});
loggingActions(obj.settings.currdir,3,[' > Current grid settings: ' strjoin(obj.settings.Grids,' ')]);
end
%set method
if strcmp(obj.settings.Method{obj.settings.Tabnum}, 'Method 1 (Hermes et al. 2010)')
set(obj.controls.radiobtn1,'Value', 1);
set(obj.controls.radiobtn2,'Value', 0);
set(obj.controls.radiobtn5,'Value', 0);
elseif strcmp(obj.settings.Method{obj.settings.Tabnum}, 'Method HD') %if HD method
set(obj.controls.radiobtn1,'Value', 0);
set(obj.controls.radiobtn2,'Value', 1);
set(obj.controls.radiobtn5,'Value', 0);
elseif strcmp(obj.settings.Method{obj.settings.Tabnum}, 'Method sEEG or depth') %if sEEG method
set(obj.controls.radiobtn1,'Value', 0);
set(obj.controls.radiobtn2,'Value', 0);
set(obj.controls.radiobtn5,'Value', 1);
set(obj.controls.radiobtn3, 'Value',0);
set(obj.controls.radiobtn3, 'Enable','off');
set(obj.controls.radiobtn4, 'Value',0);
set(obj.controls.radiobtn4, 'Enable','off');
set(obj.controls.radiobtn6, 'Value',1);
set(obj.controls.radiobtn6, 'Enable','off');
%disable grid size
set(obj.controls.edtGrid4, 'Enable', 'off');
set(obj.controls.edtGrid4, 'String', ' ');
end
%set hemisphere
if strcmp(obj.settings.Hemisphere{obj.settings.Tabnum}, 'Left')
set(obj.controls.radiobtn3,'Value', 1);
set(obj.controls.radiobtn4,'Value', 0);
set(obj.controls.radiobtn6,'Value', 0);
elseif strcmp(obj.settings.Hemisphere{obj.settings.Tabnum}, 'Right')
set(obj.controls.radiobtn3,'Value', 0);
set(obj.controls.radiobtn4,'Value', 1);
set(obj.controls.radiobtn6,'Value', 0);
elseif strcmp(obj.settings.Hemisphere{obj.settings.Tabnum}, 'Both')
set(obj.controls.radiobtn3,'Value', 0);
set(obj.controls.radiobtn4,'Value', 0);
set(obj.controls.radiobtn6,'Value', 1);
end
end
%log
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},['> Saved subject name, cluster settings and grid settings loaded.']});
loggingActions(obj.settings.currdir,1,[' > Saved subject name, cluster settings and grid settings loaded.']);
%if files in folder then read them:
%MRI
E = [obj.settings.currdir 'data/MRI/T1.nii'];
if exist(E)~=0
obj.settings.MRI = [obj.settings.currdir 'data/MRI/T1.nii'];
set(obj.controls.txtMRI, 'string',['...' obj.settings.MRI(end-18:end)]);
set(obj.controls.txtMRI, 'FontSize',10);
%log
LogInfo(obj, 2);
try
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> MRI scan selected: ',['... ', obj.settings.MRI(end-125:end)]});
catch
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> MRI scan selected: ',[obj.settings.MRI(1:end)]});
end
loggingActions(obj.settings.currdir,1,[' > MRI scan selected: ' obj.settings.MRI]);
end
%FS
E = [obj.settings.currdir 'data/FreeSurfer/t1_class.nii'];
if exist(E)~=0
obj.settings.FS = [obj.settings.currdir 'data/FreeSurfer/t1_class.nii'];
obj.settings.loaded(2) = 1;
set(obj.controls.txtFS, 'string',['...' obj.settings.FS(end-18:end)]);
set(obj.controls.txtFS, 'FontSize',10);
%log
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> FS segmentation selected: ', obj.settings.FS});
loggingActions(obj.settings.currdir,1,[' > FS segmentation selected: ' obj.settings.FS]);
end
%CT
E = [obj.settings.currdir 'data/CT/CT_highresRAI.nii'];
if exist(E)~=0
obj.settings.CT = [obj.settings.currdir 'data/CT/CT_highresRAI.nii'];
obj.settings.loaded(3) = 1;
set(obj.controls.txtCT1, 'string',['...' obj.settings.CT(end-18:end)]);
set(obj.controls.txtCT1, 'FontSize',10);
%log
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> CT scan selected: ', obj.settings.CT});
loggingActions(obj.settings.currdir,1,[' > CT scan selected: ' obj.settings.CT]);
end
%LABELS
E = [obj.settings.currdir 'data/3DClustering/electrode_labels.txt'];
if exist(E)~=0
obj.settings.Labels = [obj.settings.currdir 'data/3DClustering/electrode_labels.txt'];
obj.settings.loaded(4) = 1;
set(obj.controls.txtLabels, 'string', ['...' obj.settings.Labels(end-18:end)]);
set(obj.controls.txtLabels, 'FontSize',10);
%log
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> Electrode labels selected: ', obj.settings.Labels});
loggingActions(obj.settings.currdir,1,[' > Electrode labels selected: ' obj.settings.Labels]);
end
%update path info
addpath(genpath(obj.settings.currdir));
obj.settings.scriptspath = [fileparts( mfilename('fullpath') ) '/'];
addpath(genpath(obj.settings.scriptspath));
settings = obj.settings;
save([obj.settings.currdir '/log_info/settings'], 'settings');
else %if wrong directory is selected
errordlg('Please select an ''ALICE'' folder.')
disp('! ERROR: Please select an ''ALICE'' folder.');
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> ERROR: Please select an ''ALICE'' folder.'});
end
end
function AlignCTtoMRI( obj )
cd(obj.settings.currdir);
if obj.settings.loaded(1) == 1 && obj.settings.loaded(3) == 1
%log before
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> Aligning CT to MRI. This procedure might take several minutes. Please wait...'});
loggingActions(obj.settings.currdir,1,' > Aligning CT to MRI... This might take several minutes. Please wait...');
pause(1);
cd([obj.settings.currdir '/data/coregistration/']);
%clean directory if already run before:
system('rm CT_highresRAI_*');
system('rm *.1D');
system('rm temp_*');
%copy CT local
copyfile('../CT/CT_highresRAI.nii','.');
%select T1
t1_name = dir(obj.settings.MRI);
T1_path = ['../MRI/' t1_name.name];
%align:
system(['tcsh -x alignCTtoT1_shft_res.csh -CT_path CT_highresRAI.nii -T1_path ' T1_path]);
loggingActions(obj.settings.currdir,1, [' > tcsh -x alignCTtoT1_shft_res.csh -CT_path CT_highresRAI.nii -T1_path' T1_path]);
cd(obj.settings.currdir);
f = fopen('./data/coregistration/status.txt');
S = fscanf(f,'%s');
if strcmp(S(end-20:end),'alignmentsuccessfully')
%log after
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> CT and MRI have been co-registered. Please check the results before proceeding.'});
loggingActions(obj.settings.currdir,1,' > CT and MRI have been co-registered. Please check the results before proceeding.');
%display instruction box:
h = msgbox({['To check whether the alignment was successful,', ' please check the overlayed files in AFNI.'],...
['For that use the buttons OVERLAY and UNDERLAY ', 'to specify the CT and MRI, respectively. ', ...
'Use the intensity button on the volume windows,', ' to decrease/increase the intensity of the overlay.'],...
[' '],['- If the alignment is good, please close AFNI and proceed to Step 2.'],...
['- If the alignment is NOT good, please check the if the CT and MRI where correctly',...
' converted to *.nii. Check orientation and voxel sizes too.']},'How to check if alignment was successful?', 'help');
else
%display instruction box:
h = msgbox({['Alignment failed,', ' please check the input files.'],...
['Please check the if the CT and MRI where correctly',...
' converted to *.nii. Check orientation and voxel sizes too.']},'Alignment failed', 'error');
end
else
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '>! WARNING: CT and MRI scans are not loaded yet. Use the buttons in Step 1 to load them.'});
loggingActions(obj.settings.currdir,1,' >! WARNING: CT and MRI scans are not loaded yet. Use the buttons in Step 1 to load them.');
end
end
function AlreadyAligned( obj )
%create 1D files with identity matrices
Tmatrix = [1 0 0 0 0 1 0 0 0 0 1 0];
fileID = fopen([obj.settings.currdir '/data/coregistration/CT_highresRAI_res_shft_al_mat.aff12.1D'],'w');
fwrite(fileID, num2str(Tmatrix));
fclose(fileID);
Tmatrix2 = [1 0 0 0 0 1 0 0 0 0 1 0];
fileID = fopen([obj.settings.currdir '/data/coregistration/CT_highresRAI_shft.1D'],'w');
fwrite(fileID, num2str(Tmatrix2));
fclose(fileID);
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> Open selected: CT already aligned.'});
loggingActions(obj.settings.currdir,1,' > Open selected: CT already aligned.');
end
function ExtractClusters ( obj )
cd(obj.settings.currdir);
if obj.settings.loaded(3) == 1
system(['rm ' obj.settings.currdir '/data/coregistration/temp_ANAT.nii']);
system(['rm ' obj.settings.currdir '/data/coregistration/CT_highresRAI.nii']);
%3dclustering
cd([obj.settings.currdir '/data/3Dclustering/']);
if exist(['3dclusters_r' num2str(obj.settings.R) '_is' num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.nii'])==0 && exist('../CT/CT_highresRAI.nii')==2
%log before 3dclustering
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> Extracting electrode clusters. This procedure might take some minutes. Please wait...'});
loggingActions(obj.settings.currdir,2,' > Extracting electrode clusters. This procedure might take some minutes. Please wait...');
pause(1);
system(['tcsh -x 3dclustering.csh -CT_path ../CT/CT_highresRAI.nii -radius ' num2str(obj.settings.R) ' -interelectrode_space ' num2str(obj.settings.IS) ' -clip_value ' num2str(obj.settings.CV)]);
%log after 3dclustering
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> Electrode clusters extracted. Please check results and then close SUMA.'});
loggingActions(obj.settings.currdir,2,' > Electrode cluster extracted. Please check results and then close SUMA.');
%message box:
h = msgbox({['The electrode-clusters have been extracted,', ' please check the result in SUMA.'],...
['After revision, close SUMA.'],[' '], ['To extract new clusters, select new settings and click ''Extract clusters''.'], ...
['Otherwise, click ''Select Electrodes'' to continue.']},'Check electrode-clusters', 'help');
system(['suma -i 3dclusters_r' num2str(obj.settings.R) '_is' num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.gii']);
else
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '>! ERROR: delete any 3dclusters_rX_isX_thrX.nii files in the /3Dclustering directory. This function cannot overwrite files. Check if CT_highresRAI.nii is ','inside /data/CT folder.'});
loggingActions(obj.settings.currdir,2,' > ! ERROR: delete any 3dclusters_rX_isX_thrX.nii files in the /3Dclustering directory. This function cannot overwrite files. Check if CT_highresRAI.nii is inside /data/CT folder.');
end
cd(obj.settings.currdir);
else
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '>! WARNING: CT was not loaded yet. Use the button in Step 2 to load it.'});
loggingActions(obj.settings.currdir,2,' >! WARNING: CT was not loaded yet. Use the button in Step 2 to load it.');
cd(obj.settings.currdir);
end
end
function SelectElectrodes( obj )
cd(obj.settings.currdir);
if obj.settings.loaded(4)==0
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, ['>! WARNING: Please select a file with electrode labels first.']});
loggingActions(obj.settings.currdir,2,[' >! WARNING: Please select a file with electrode labels first.']);
return;
end
%check if file exists
if exist([obj.settings.currdir '/data/3Dclustering/3dclusters_r' num2str(obj.settings.R) '_is' num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.nii']) ~=0
%log before select electrodes
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '> Time to select the electrodes! Please select them according to the leads order.'});
loggingActions(obj.settings.currdir,2,' > Time to select the electrodes! Please select them according to the leads order.');
%move to 3dclustering folder
cd([obj.settings.currdir '/data/3Dclustering/']);
%define input file
clust_set = ['3dclusters_r' num2str(obj.settings.R) '_is'...
num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.nii'];
clust_surf = ['3dclusters_r' num2str(obj.settings.R) '_is' ...
num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.gii'];
%open afni and suma:
system(['tcsh -x open_afni_suma.csh -CT_path ../CT/CT_highresRAI.nii -clust_set ' clust_set ' -clust_surf ' clust_surf ], '-echo');
selectElGUI( obj.settings, obj.controls );
%display instruction box:
h = msgbox({['Time to select the electrodes!'], ['Please have the leads order (electrode layout) at hand.'],...
[' '],['AFNI and SUMA interfaces will open, ', 'and you will see the electrodes clusters both in the volume and the surface spaces.'], ...
[' '],['With right click you can select the electrode on the surface,', ' and with the left click on the volume space.'],...
['Use the click+drag to navigate in SUMA, scroll to zoom in and out and scroll-lock for panning.'],...
[' '],['Please use the matlab pop-up window to select the electrodes.'],...
},'Time to select electrodes!', 'help');
else
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, ['>! WARNING: There is no 3dclusters_r' num2str(obj.settings.R) '_is' num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.nii file in the /3Dclustering folder. Please check the settings above or extract clusters first.']});
loggingActions(obj.settings.currdir,2,[' >! WARNING: There is no 3dclusters_r' num2str(obj.settings.R) '_is' num2str(obj.settings.IS) '_thr' num2str(obj.settings.CV) '.nii file in the /3Dclustering folder. Please check the settings above or extract clusters first.']);
end
end
function LogInfo( obj, offset )
obj.settings.str = get(obj.controls.txtLog, 'string');
long_sentences = sum(cellfun(@length, obj.settings.str)>160);
long_sentences = long_sentences + sum(cellfun(@length, obj.settings.str)>2*160);
if length(obj.settings.str)+long_sentences > obj.settings.NUM_LINES
try
obj.settings.str = obj.settings.str( (end - (obj.settings.NUM_LINES-offset-long_sentences-1)) :end);
catch
obj.settings.str = obj.settings.str(offset+1:end);
end
end
end
end
methods % for callbacks
% Close request function for the main dialog.
function figCloseRequest( obj, hObject, ~ )
%set writing permissions to all files created with alice for
%group.
if isfield(obj.settings,'currdir')
cd(obj.settings.currdir);
L = dir('../ALICE');
if ~isempty(L)
listing = dir('**/*');
list = [{listing.folder}' {listing.name}'];
for k=1:length(list)
try
fileattrib([list{k,1} '/' list{k,2}],'+w','g');
end
end
end
%to double check permissions, since sometimes it doesnt
%work for some files..
try
system('chmod -R g+w ../ALICE');
end
end
if ~isempty(obj.settings.Grids)
%move all grids to layout for completeness
obj.settings.Layout{obj.settings.Tabnum} = obj.settings.Grids;
obj.settings.Grids = [];
end
%save changes in settings mat file
settings = obj.settings;
try
save([obj.settings.currdir '/log_info/settings'], 'settings');
end
delete( hObject );
clc;
disp(' ___ ');
disp(' | | _ ');
disp(' ___| __|__|_|__ ');
disp('| | | |_ ');
disp('|____| |________|_| | Together everyone achieves more | ');
disp(' ');
end
%locate directory
function btnLocateDirectory( obj, hObject, ~ )
obj.LocateDirectory
end
%create directory
function btnCreateDirectory( obj, hObject, ~ )
obj.CreateDirectory;
end
%open MRI
function btnOpenMRI( obj, hObject, ~ )
cd(obj.settings.currdir);
%clean up previous MRI
if length(dir([obj.settings.currdir '/data/MRI/']))>2
choice = questdlg({[' '],['Other MRI scan(s) have have been found in ./data/MRI folder.'], ...
['If you choose to delete file(s), the existing file(s) will be deleted and replaced by the new file!'],[' ']},...
'WARNING!', 'Delete old file(s)', 'Keep old file(s)', 'Delete old file(s)');
switch choice
case 'Delete old file(s)'
delete([obj.settings.currdir '/data/MRI/*.nii']);
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '>! WARNING: Deleting previously loaded MRI file.'});
loggingActions(obj.settings.currdir,1,[' >! WARNING: Deleting previously loaded MRI file.']);
end
end
[FileName, PathName] = uigetfile('../*.mgz;*.nii');
if FileName~=0
%if the file was already in the folder but was not loaded
%before, then do not copy-paste, else copy-paste
if ~strcmpi(PathName,[obj.settings.currdir 'Data/MRI/'])
%copy file to Alice folder
copyfile([PathName FileName], [obj.settings.currdir 'data/MRI/' FileName ]);
origdir = [PathName FileName];
LogInfo(obj, 2);
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> MRI scan selected: ',origdir});
loggingActions(obj.settings.currdir,1,[' > MRI scan selected: ' origdir]);
end
%if mgz --> convert to nii
if strcmpi(FileName(end-2:end), 'mgz')
system(['mri_convert ' obj.settings.currdir 'data/MRI/' FileName ' ' obj.settings.currdir 'data/MRI/T1.nii']);
FileName = [FileName(1:end-3) 'nii'];
end
obj.settings.MRI = [obj.settings.currdir 'data/MRI/' FileName];
obj.settings.loaded(1) = 1;
settings = obj.settings;
save([obj.settings.currdir '/log_info/settings'], 'settings');
set(obj.controls.txtMRI, 'string',['...' obj.settings.MRI(end-18:end)]);
set(obj.controls.txtMRI, 'FontSize',10);
%log
LogInfo(obj, 2);
try
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> MRI scan saved as: ',['... ', obj.settings.MRI(end-125:end)]});
catch
set(obj.controls.txtLog, 'string',{obj.settings.str{:},'> MRI scan saved as: ',[obj.settings.MRI(1:end)]});
end
loggingActions(obj.settings.currdir,1,[' > MRI scan saved as: ' obj.settings.MRI]);
else
disp('! WARNING: MRI scan not selected.');
%log
LogInfo(obj, 1);
set(obj.controls.txtLog, 'string',{obj.settings.str{:}, '>! WARNING: MRI scan not selected.'});
loggingActions(obj.settings.currdir,1,' >! WARNING: MRI scan not selected.');
end
end
%open FS
function btnOpenFS( obj, hObject, ~ )
cd(obj.settings.currdir);
[FileName, PathName] = uigetfile('../*.mgz;*.nii');
if FileName~=0