-
Notifications
You must be signed in to change notification settings - Fork 43
/
icatb_setup_analysis.m
2176 lines (1652 loc) · 72.9 KB
/
icatb_setup_analysis.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
function varargout = icatb_setup_analysis(inputFile)
%% Setup ICA analysis
%
% Inputs are:
% inputFile - Input file for batch analysis.
%
% Outputs:
% ICA Parameter file.
if exist('inputFile', 'var')
[pathstr, fileN, extn] = fileparts(inputFile);
if ~strcmpi(extn, '.mat')
varargout{1} = icatb_read_batch_file(inputFile);
return;
else
sub_file = inputFile;
end
end
% Define input parameters
inputText = icatb_define_parameters;
[modalityType] = icatb_get_modality;
matchedIndex = strmatch('prefix', str2mat(inputText.tag), 'exact');
output_prefix = inputText(matchedIndex).answerString;
% Tags to be plotted in main figure window
if strcmpi(modalityType, 'fmri')
tagsTobePlotted = {'prefix', 'files', 'TR', 'estimate_components', 'numComp', 'autofill', 'algorithm', 'which_analysis', 'parallel_info'};
elseif strcmpi(modalityType, 'eeg')
tagsTobePlotted = {'prefix', 'files', 'numComp', 'autofill', 'algorithm', 'which_analysis', 'parallel_info'};
else
tagsTobePlotted = {'prefix', 'files', 'estimate_components', 'numComp', 'algorithm', 'which_analysis'};
end
if strcmpi(modalityType, 'fmri')
helpLabel = 'GIFT-Help';
figTitle = 'GIFT Setup ICA GUI';
htmlFile = 'icatb_setup_ica.htm';
elseif strcmpi(modalityType, 'smri')
helpLabel = 'SBM-Help';
figTitle = 'SBM Setup ICA GUI';
htmlFile = 'icatb_setup_ica.htm';
else
helpLabel = 'EEGIFT-Help';
figTitle = 'EEGIFT Setup ICA GUI';
htmlFile = 'icatb_eeg_setup_ica.htm';
end
if ~exist('sub_file', 'var')
% Select analysis output directory
[oldDir] = icatb_selectEntry('typeEntity', 'directory', 'title', 'Select Analysis Output Directory');
else
% set the prefix automatically
formStr = 'Subject.mat';
[oldDir, fileNN, file_extn] = fileparts(sub_file);
if (isempty(oldDir))
oldDir = pwd;
end
inputString = [fileNN, file_extn];
matchIndex = icatb_findstr(inputString, formStr);
output_prefix = inputString(1:matchIndex(1)-1);
clear fileNN; clear file_extn;
clear matchIndex; clear inputString;
end
handle_visibility = 'on';
drawnow;
% put a check for selecting the output directory
if isempty(oldDir)
error('Output directory is not selected');
end
% Change working directory
cd(oldDir);
%%%%%%%%% Draw figure and set up the controls %%%%%%%%
figureTag = 'setup_ICAGUI';
figHandle = findobj('tag', figureTag);
if ~isempty(figHandle)
delete(figHandle);
end
% Setup figure for GUI
[InputHandle] = icatb_getGraphics(figTitle, 'normal', figureTag, handle_visibility);
% store the directory information to sesInfo
sesInfo.userInput.pwd = oldDir;
handles_data.sesInfo = sesInfo;
% set figure data
set(InputHandle, 'userdata', handles_data, 'Menubar', 'none');
% set up menus (on click display an input dialog box)
setupDefaults = uimenu('parent', InputHandle, 'label', 'SetupICA-Defaults', 'tag', 'SetupICA-Defaults');
% help on setup ICA
giftHelpTitle = uimenu('parent', InputHandle, 'label', helpLabel);
giftHelpMenu = uimenu(giftHelpTitle, 'label', 'Setup-ICA', 'callback', ...
['icatb_openHTMLHelpFile(''', htmlFile, ''');']);
algoIndex = strmatch('algoType', char(inputText.tag), 'exact');
inputText(algoIndex).tag = 'algorithm';
countTags_menu = 0;
% total tags in menu
tagsVec = zeros(1, length(inputText) - length(tagsTobePlotted));
% store the tags that need to be plotted in a menu
for ii = 1:length(inputText)
strIndex = strmatch(inputText(ii).tag, tagsTobePlotted, 'exact');
if isempty(strIndex)
countTags_menu = countTags_menu + 1;
tagsInMenu{countTags_menu} = inputText(ii).tag;
tagsVec(countTags_menu) = ii;
end
end
% plot the input parameters to the parameter figure
icatb_plotInputPara('input_prefix', inputText, 'controls_to_plot', tagsTobePlotted, 'handles', ...
InputHandle);
%%%%%%%%% End for drawing the figure and setting up the controls %%%%
%%%%%%%%%% Set up function callbacks %%%%%%%%%%%%%%%%%
% setup defaults data
setupDefaultsData.tagsTobePlotted = tagsInMenu; setupDefaultsData.inputText = inputText;
setupDefaultsData.tagsVec = tagsVec;
%% Open figure window when SetupICA-Defaults menu is clicked
set(setupDefaults, 'callback', {@setupDefaultsCallback, InputHandle}, 'userdata', setupDefaultsData);
%% Answer function callbacks
set(findobj(InputHandle, 'tag', 'prefix'), 'callback', {@editboxCallback, InputHandle});
%% Load the functional files (data callback)
set(findobj(InputHandle, 'tag', 'files'), 'callback', ...
{@dataCallback, InputHandle, setupDefaults});
%% Set callback for cancel button
set(findobj(InputHandle, 'tag', 'Cancel'), 'callback', {@closeCallback, InputHandle});
estimateCompHandle = findobj(InputHandle, 'tag', 'estimate_components');
if ~isempty(estimateCompHandle)
% set callback for estimate components callback
set(estimateCompHandle, 'callback', {@estimateCompCallback, InputHandle});
end
componentHandle = findobj(InputHandle, 'tag', 'numComp');
autofillHandle = findobj(InputHandle, 'tag', 'autofill');
%% Component callback
set(componentHandle, 'callback', {@setCompCallback, InputHandle, autofillHandle});
%% Autofill handle
set(autofillHandle, 'callback', {@autoFillCallback, InputHandle, componentHandle});
%% Done callback
okHandle = findobj(InputHandle, 'tag', 'Done');
set(okHandle, 'callback', {@applyCallback, InputHandle, setupDefaults});
%% Which Analysis Callback
WhichAnalysisH = findobj(InputHandle, 'tag', 'which_analysis');
set(WhichAnalysisH, 'callback', {@WhichAnalysisCallback, InputHandle});
%% ICA Algorithm callback
set(findobj(InputHandle, 'tag', 'algorithm'), 'callback', {@icaTypeCallback, InputHandle});
% %% Group ica type callback
% groupICATypeTag = 'group_ica_type';
% groupICAAnalysisHandle = findobj(InputHandle, 'tag', groupICATypeTag);
% if (~isempty(groupICAAnalysisHandle))
% set(groupICAAnalysisHandle, 'callback', {@group_ica_typeCallback, InputHandle});
% end
%% Parallel analysis callback
parallelH = findobj(InputHandle, 'tag', 'parallel_info');
if (~isempty(parallelH))
set(parallelH, 'callback', {@parallelCallback, InputHandle});
end
%%%%%%%%%% End for setting up the function callbacks %%%%%%%%%%%%%%%%%
if exist('output_prefix', 'var')
prefixH = findobj(InputHandle, 'tag', 'prefix');
set(prefixH, 'string', output_prefix);
end
TRH = findobj(InputHandle, 'tag', 'TR');
if (~isempty(TRH))
cm = uicontextmenu;
TRmenu = uimenu(cm, 'Label', 'TR', 'callback', {@openTRWindow, InputHandle});
set(TRH, 'uicontextmenu', cm);
end
% Execute this function for GUI
editboxCallback(findobj(InputHandle, 'tag', 'prefix'), [], InputHandle);
%%%%%%%%% Sub Functions %%%%%%%%%
function varargout = icatb_plotInputPara(varargin)
% sub function to plot the input parameters
tagsTobePlotted = {};
figureTag = 'Input Parameters';
windowStyle = 'normal';
varargout = {};
% loop over arguments
for ii = 1:2:nargin
if strcmpi(varargin{ii}, 'input_prefix')
inputText = varargin{ii + 1};
elseif strcmpi(varargin{ii}, 'controls_to_plot')
tagsTobePlotted = varargin{ii + 1};
elseif strcmpi(varargin{ii}, 'handles')
InputHandle = varargin{ii + 1};
elseif strcmpi(varargin{ii}, 'tag_figure')
figureTag = varargin{ii + 1};
elseif strcmpi(varargin{ii}, 'windowstyle')
windowStyle = varargin{ii + 1};
end
% end for checking the input args
end
% end for loop
if ~exist('inputText', 'var')
error('inputText variable does not exist');
end
% tags to plot
if isempty(tagsTobePlotted)
disp('No controls to plot');
return;
end
if ~exist('InputHandle', 'var')
% Setup figure for GUI
[InputHandle] = icatb_getGraphics(figureTag, 'normal', figureTag);
% Set no menu bar for the figure
set(InputHandle, 'Menubar', 'none');
end
% end for checking the input handle
if ~ispc
windowStyle = 'normal';
end
set(InputHandle, 'windowStyle', windowStyle);
[InputHandle] = icatb_plot_controls_fig(inputText, figureTag, 'on', 'Done', 'Cancel', tagsTobePlotted, ...
InputHandle);
function set_data_para(handles, menuH)
% transfer figure data to menu
% sesInfo structure
handles_data = get(handles, 'userdata');
sesInfo = handles_data.sesInfo;
% menu data
menuData = get(menuH, 'userdata');
% input text structure
inputText = menuData.inputText;
numOfSub = 0; numOfSess = 0;
if isfield(sesInfo.userInput, 'numOfSub')
% Number of subjects and sessions
numOfSub = sesInfo.userInput.numOfSub;
end
if isfield(sesInfo.userInput, 'numOfSess')
% Number of subjects and sessions
numOfSess = sesInfo.userInput.numOfSess;
end
algoH = findobj(handles, 'tag', 'algorithm');
icaStr = get(algoH, 'string');
icaVal = get(algoH, 'value');
%% group ica type
groupICATypeTag = 'group_ica_type';
group_icaIndex = strmatch(groupICATypeTag, cellstr(char(inputText.tag)), 'exact');
useTemporalICA = 0;
if (~isempty(group_icaIndex))
groupICATypeOpts = lower(cellstr(inputText(group_icaIndex).answerString));
groupICATypeVal = inputText(group_icaIndex).value;
useTemporalICA = strcmpi('temporal', groupICATypeOpts{groupICATypeVal});
end
backReconTag = 'backReconType';
backReconIndex = strmatch(backReconTag, cellstr(char(inputText.tag)), 'exact');
if (~isempty(backReconIndex))
inputText(backReconIndex).enable = 'on';
if (strcmpi(deblank(icaStr(icaVal, :)), 'iva-gl') || strcmpi(deblank(icaStr(icaVal, :)), 'iva-l') ...
|| strcmpi(deblank(icaStr(icaVal, :)), 'iva-l-sos') || strcmpi(deblank(icaStr(icaVal, :)), 'moo-icar') || strcmpi(deblank(icaStr(icaVal, :)), 'moo-icar') || strcmpi(deblank(icaStr(icaVal, :)), 'constrained ica (spatial)'))
inputText(backReconIndex).enable = 'inactive';
end
end
if numOfSub*numOfSess > 0
% get the number of components from the textbox in main figure window
numCompH = findobj(handles, 'tag', 'numComp');
compIndex = strmatch('numComp', char(inputText.tag), 'exact');
% set component number to sesInfo
sesInfo.userInput.numComp = str2num(deblank(get(numCompH, 'string')));
% set the component number to the input text
inputText(compIndex).answerString = num2str(sesInfo.userInput.numComp);
% get the data reduction tag
dataRedIndex = strmatch('numReductionSteps', char(inputText.tag), 'exact');
inputText(dataRedIndex).enable = 'off';
numReductionSteps = 1;
if (~strcmpi(deblank(icaStr(icaVal, :)), 'iva-gl') && ~strcmpi(deblank(icaStr(icaVal, :)), 'iva-l') && ~strcmpi(deblank(icaStr(icaVal, :)), 'iva-l-sos') && ~strcmpi(deblank(icaStr(icaVal, :)), 'moo-icar') ...
&& ~strcmpi(deblank(icaStr(icaVal, :)), 'moo-icar') && ~strcmpi(deblank(icaStr(icaVal, :)), 'moo-icar') && ~strcmpi(deblank(icaStr(icaVal, :)), 'constrained ica (spatial)'))
% Number of data reduction steps
if(numOfSub == 1 && numOfSess == 1)
numReductionSteps = 1;
else
if (~useTemporalICA)
inputText(dataRedIndex).enable = 'on';
end
% get the value from the data reduction control
getStr = inputText(dataRedIndex).answerString; getVal = inputText(dataRedIndex).value;
if isfield(sesInfo.userInput, 'numReductionSteps')
numReductionSteps = sesInfo.userInput.numReductionSteps;
if (numReductionSteps == 3)
numReductionSteps = 2;
end
getVal = strmatch(num2str(numReductionSteps), getStr, 'exact');
% set the value to the data reduction tag
inputText(dataRedIndex).value = getVal;
else
numReductionSteps = str2num(deblank(getStr(getVal, :)));
end
end
% end for checking data reduction steps
end
% set reduction steps to sesInfo
sesInfo.userInput.numReductionSteps = numReductionSteps;
prefix1 = 'numOfPC1'; prefix2 = 'numOfPC2';
% get the index of the PC1, PC2
PC1Index = strmatch(prefix1, char(inputText.tag), 'exact');
PC2Index = strmatch(prefix2, char(inputText.tag), 'exact');
PCBefore = sesInfo.userInput.numComp;
[minTp, minTpInd] = min(sesInfo.userInput.diffTimePoints);
if (minTp == 1)
error('Error:TimePoints', 'Please re-select the data as the no of selected files is found to be 1 (%s)\n', deblank(sesInfo.userInput.files(minTpInd).name(1, :)));
end
PCBefore = round(min([minTp, 1.5*PCBefore]));
if numReductionSteps == 1
%% PC1
inputText(PC1Index).promptString = 'Number Of PC/IC (Step 1)';
inputText(PC1Index).enable = 'inactive';
sesInfo.userInput.numOfPC1 = sesInfo.userInput.numComp;
inputText(PC1Index).answerString = num2str(sesInfo.userInput.numOfPC1);
%% PC2
inputText(PC2Index).promptString = 'Number Of PC (Step 2)';
inputText(PC2Index).enable = 'inactive';
sesInfo.userInput.numOfPC2 = 0;
inputText(PC2Index).answerString = num2str(sesInfo.userInput.numOfPC2);
elseif numReductionSteps == 2
% display the object with PC1 and set the string to PC/IC
%% PC1
inputText(PC1Index).promptString = 'Number Of PC (Step 1)';
inputText(PC1Index).enable = 'on';
if ~isfield(sesInfo.userInput, 'numOfPC1')
sesInfo.userInput.numOfPC1 = PCBefore; %sesInfo.userInput.numComp;
else
if isempty(sesInfo.userInput.numOfPC1)
sesInfo.userInput.numOfPC1 = PCBefore; %sesInfo.userInput.numComp;
end
end
inputText(PC1Index).answerString = num2str(sesInfo.userInput.numOfPC1);
%% PC2
inputText(PC2Index).promptString = 'Number Of PC/IC (Step 2)';
inputText(PC2Index).enable = 'inactive';
sesInfo.userInput.numOfPC2 = sesInfo.userInput.numComp;
inputText(PC2Index).answerString = num2str(sesInfo.userInput.numOfPC2);
end
menuData.inputText = inputText;
% set the updated data
set(menuH, 'userdata', menuData);
handles_data.sesInfo = sesInfo;
set(handles, 'userdata', handles_data);
end
% end for checking the data
function [varOut] = check_var_integer(currentVar)
% check whether the variable in the string is integer or not
[varOut] = icatb_check_variable_integer(currentVar);
function [varOut, status, message] = check_var_character(currentVar)
% check whether the variable is a valid character or not
[varOut] = icatb_check_char(currentVar);
[status, message] = icatb_errorCheck(currentVar, 'output_prefix', 'prefix');
%%%%%%%%%% Function Callbacks %%%%%%%%
function editboxCallback(handleObj, event_data, handles)
% callback for output prefix text box
% Execute this function when prefix is entered
icatb_defaults;
global PARAMETER_INFO_MAT_FILE; %Holds information for group session parameters
% get the string for the text box
getString = get(handleObj, 'string'); %(output file prefixes)
if ~isempty(getString)
% check if it is a valid prefix
[getString, status, message] = check_var_character(getString);
if status == 0
error(message);
end
end
% Get the figure data
handles_data = get(handles, 'userdata');
% sesInfo structure
sesInfo = handles_data.sesInfo;
% directory where the information will be stored
oldDir = sesInfo.userInput.pwd;
% get the prefix of the output string
sesInfo.userInput.prefix = getString;
% All the entered parameters are going to be stored in this file
sesInfo.userInput.param_file = [sesInfo.userInput.prefix, PARAMETER_INFO_MAT_FILE, '.mat'];
sesInfo.userInput.param_file = fullfile(oldDir, sesInfo.userInput.param_file);
% estimateComponents callback
set(findobj(handles, 'tag', 'estimate_components'), 'enable', 'off');
% number of components callback
set(findobj(handles, 'tag', 'numComp'), 'enable', 'inactive');
% subject file
subjectFile = [getString, 'Subject.mat']; % check if the subjects file exist or not
% full file path for the subject file
subjectFile = fullfile(oldDir, subjectFile);
% find the setup ICA defaults menu
menuH = findobj(handles, 'tag', 'SetupICA-Defaults');
handles_data.sesInfo = sesInfo;
% set the figure data
set(handles, 'userdata', handles_data);
% check if the subjects file exists
if exist(subjectFile)
set(findobj(handles, 'tag', 'files'), 'style', 'popup', 'string', ...
char('Yes', 'No'));
% data callback
dataCallback(findobj(handles, 'tag', 'files'), [], handles, menuH);
else
set(findobj(handles, 'tag', 'files'), 'style', 'pushbutton', 'string', ...
'Select');
end
% Data callback for selecting the functional files
function dataCallback(handleObj, event_data, handles, menuH)
try
% handles data
handles_data = get(handles, 'userdata');
sesInfo = handles_data.sesInfo;
oldDir = sesInfo.userInput.pwd;
icatb_defaults;
global PARAMETER_INFO_MAT_FILE; %Holds information for group session parameters
global FUNCTIONAL_DATA_FILTER;
% Screen Color Defaults
global BG_COLOR;
global FONT_COLOR;
global AXES_COLOR;
global EXPERIMENTAL_TR;
% disable the estimate components and the data reduction parameters
set(findobj(handles, 'tag', 'estimate_components'), 'enable', 'off');
set(findobj(handles, 'tag', 'numReductionSteps'), 'enable', 'off');
% number of components callback
set(findobj(handles, 'tag', 'numComp'), 'enable', 'inactive');
% get the prefix of the output string
sesInfo.userInput.prefix = get(findobj(handles, 'tag', 'prefix'), 'string');
% get the subject matrix file
subjectFile = [sesInfo.userInput.prefix, 'Subject.mat'];
subjectFile = fullfile(oldDir, subjectFile);
% All the entered parameters are going to be stored in this file
sesInfo.userInput.param_file = [sesInfo.userInput.prefix, PARAMETER_INFO_MAT_FILE, '.mat'];
sesInfo.userInput.param_file = fullfile(oldDir, sesInfo.userInput.param_file);
newParamFile = sesInfo.userInput.param_file; % get the new parameter file
% get the style of the UIcontrol
getStyle = get(handleObj, 'style');
if strcmp(lower(getStyle), 'pushbutton')
getSubjects = 'no';
else
getPopValue = get(handleObj, 'value');
getPopString = get(handleObj, 'string');
getSubjects = lower(deblank(getPopString(getPopValue, :)));
end
% First determine whether the subjects file exists or not
% If it doesn''t exist then show the user the error dialog
% else load the subject file
if strcmp(getSubjects, 'yes') %getSubjects == 2
if ~exist(subjectFile, 'file')
icatb_errorDialog('Subject File doesn''t exist. Please use the other option', 'File not found');
else
load(subjectFile);
end
end
%%%%%% Check if the files doesn't exist %%%%%%%%%%%%%%%%%
if ~exist('modalityType', 'var')
[modalityType] = icatb_get_modality;
else
[modalityType2] = icatb_get_modality;
if ~strcmpi(modalityType, modalityType2)
delete(handles);
if strcmpi(modalityType, 'fmri')
disp('fMRI subject file already exists. Use GIFT toolbox to set up analysis');
elseif strcmpi(modalityType, 'smri')
disp('sMRI subject file already exists. Use SBM toolbox to set up analysis');
else
disp('EEG subject file already exists. Use EEGIFT toolbox to set up analysis');
end
return;
end
end
% store these fields regarding dataType, complex naming
dataType = 'real'; read_complex_images = 'real&imaginary'; write_complex_images = 'real&imaginary';
sesInfo.userInput.dataType = lower(dataType);
sesInfo.userInput.read_complex_images = lower(read_complex_images);
sesInfo.userInput.write_complex_images = lower(write_complex_images);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~strcmp(getSubjects, 'yes')
[sesInfo] = icatb_name_complex_images(sesInfo, 'read');
set(handles, 'pointer', 'watch');
[files, designMatrix, numOfSub, numOfSess, dataSelMethod, diffTimePoints, spmMatFlag, bids_info] = icatb_dataSelection(...
[], sesInfo.userInput.pwd, sesInfo.userInput.prefix, ...
sesInfo.userInput.read_complex_file_naming, sesInfo.userInput.read_complex_images);
setappdata(0, 'create_mask_gica',1);
drawnow;
sesInfo.userInput.files = files;
SPMFiles = designMatrix;
sesInfo.userInput.dataSelMethod = dataSelMethod;
sesInfo.userInput.designMatrix = designMatrix;
sesInfo.userInput.spmMatFlag = spmMatFlag;
sesInfo.userInput.diffTimePoints = diffTimePoints;
if (~isempty(bids_info))
sesInfo.userInput.bids_info = bids_info;
end
icatb_save(subjectFile, 'files', 'numOfSub', 'numOfSess', 'SPMFiles', 'modalityType');
%%%%%%%%%% Adjust the autofill popup box %%%%%%%%%%%
% set the autofill popup to yes
autoFillH = findobj(handles, 'tag', 'autofill');
% auto fill string
autoFillString = get(autoFillH, 'string');
% auto fill value
matchIndex = strmatch('yes', lower(autoFillString), 'exact');
% set the autofill popup to yes
set(autoFillH, 'value', matchIndex);
%%%%%%%%%% End for adjusting the autofill popup box %%%%%%%%%%%
% Create mask
%[sesInfo] = create_mask(sesInfo);
set(handles, 'pointer', 'arrow');
end
% end for selecting the data
% Initialise all the variables
sesInfo.userInput.modality = modalityType;
sesInfo.userInput.files = files;
sesInfo.userInput.designMatrix = SPMFiles;
sesInfo.userInput.numOfSub = numOfSub;
sesInfo.userInput.numOfSess = numOfSess;
numOfDataSets = numOfSub * numOfSess;
sesInfo.userInput.numOfGroups1 = numOfDataSets;
% If the subjects data exist
% Update the files and the numbers for the data reduction steps
if strcmp(getSubjects, 'yes') %getSubjects == 2
% Update the parameter field
if exist(newParamFile, 'file')
% load the parameter file
load(newParamFile);
% make sure to update the new parameter file
sesInfo.userInput.param_file = newParamFile;
end
% check time points
if ~isfield(sesInfo.userInput, 'diffTimePoints')
set(handles, 'pointer', 'watch');
if (strcmpi(modalityType, 'fmri') || strcmpi(modalityType, 'smri'))
% get the count for time points
diffTimePoints = icatb_get_countTimePoints(files);
else
diffTimePoints = icatb_get_num_electrodes(files);
end
% end for getting time points
sesInfo.userInput.diffTimePoints = diffTimePoints;
set(handles, 'pointer', 'arrow');
else
diffTimePoints = sesInfo.userInput.diffTimePoints;
end
% end for checking the time points
end
% number of scans
numberOfScans = diffTimePoints(1);
if ~isfield(sesInfo.userInput, 'numComp')
numComp = 20;
else
numComp = sesInfo.userInput.numComp;
end
% can't extract more components than time points
if min(diffTimePoints) < numComp
numComp = min(diffTimePoints);
end
% set the number of components
sesInfo.userInput.numComp = numComp;
algoHandle = findobj(handles, 'tag', 'algorithm');
tmpAlgVal = get(algoHandle, 'value');
tmpAlgStr = cellstr(get(algoHandle, 'string'));
numCompH = findobj(handles, 'tag', 'numComp');
set(numCompH, 'enable', 'on', 'string', num2str(sesInfo.userInput.numComp));
if (strcmpi(tmpAlgStr{tmpAlgVal}, 'moo-icar') || strcmpi(tmpAlgStr{tmpAlgVal}, 'moo-icar') || strcmpi(tmpAlgStr{tmpAlgVal}, 'constrained ica (spatial)'))
set(numCompH, 'enable', 'inactive');
end
%% make sure these two vars exist
sesInfo.userInput.pwd = oldDir;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
handles_data.sesInfo = sesInfo;
% set the user data
set(handles, 'userdata', handles_data);
clear inputText;
menuData = get(menuH, 'userdata');
inputText = menuData.inputText;
if strcmp(getSubjects, 'yes')
%% ICA algorithm
algoTag = 'algorithm';
if isfield(sesInfo.userInput, algoTag)
algoHandle = findobj(handles, 'tag', algoTag);
algoVal = getfield(sesInfo.userInput, algoTag);
algoStr = cellstr(get(algoHandle, 'string'));
set(algoHandle, 'value', algoVal);
if (strcmpi(algoStr{algoVal}, 'iva-gl') || strcmpi(algoStr{algoVal}, 'iva-l') || strcmpi(algoStr{algoVal}, 'iva-l-sos') || strcmpi(algoStr{algoVal}, 'moo-icar') || ....
strcmpi(algoStr{algoVal}, 'moo-icar') || strcmpi(algoStr{algoVal}, 'constrained ica (spatial)'))
icaTypeCallback(algoHandle, [], handles);
end
end
%% TR
trH = findobj(handles, 'tag', 'TR');
try
set(trH, 'enable', 'on', 'string', num2str(sesInfo.userInput.TR));
catch
set(trH, 'enable', 'on', 'string', num2str(EXPERIMENTAL_TR));
end
%% stability Type
whichAnalysisTag = 'which_analysis';
if isfield(sesInfo.userInput, whichAnalysisTag)
whichAnalysisHandle = findobj(handles, 'tag', whichAnalysisTag);
whichAnalysisVal = getfield(sesInfo.userInput, whichAnalysisTag);
set(whichAnalysisHandle, 'value', whichAnalysisVal);
end
%% group ica type
groupICATypeTag = 'group_ica_type';
group_icaIndex = strmatch(groupICATypeTag, cellstr(char(inputText.tag)), 'exact');
if ~isempty(group_icaIndex)
if (isfield(sesInfo.userInput, groupICATypeTag))
group_ica_type = getfield(sesInfo.userInput, groupICATypeTag);
else
group_ica_type = 'spatial';
end
group_ica_val = strmatch(group_ica_type, lower(cellstr(inputText(group_icaIndex).answerString)), 'exact');
inputText(group_icaIndex).value = group_ica_val;
end
% groupICAAnalysisHandle = findobj(handles, 'tag', groupICATypeTag);
%
% if (~isempty(groupICAAnalysisHandle))
% if isfield(sesInfo.userInput, groupICATypeTag)
% groupICATypeOpts = cellstr(get(groupICAAnalysisHandle, 'string'));
% tmpgroupICAVal = 'spatial';
% try
% tmpgroupICAVal = lower(getfield(sesInfo.userInput, groupICATypeTag));
% catch
% end
%
% if (~isnumeric(tmpgroupICAVal))
% tmpgroupICAVal = strmatch(tmpgroupICAVal, lower(groupICATypeOpts), 'exact');
% end
% set(groupICAAnalysisHandle, 'value', tmpgroupICAVal);
% end
% end
%% Run Parallel?
parallelTag = 'parallel_info';
if isfield(sesInfo.userInput, parallelTag)
parallelH = findobj(handles, 'tag', parallelTag);
opts = {'serial', 'parallel'};
parallelMode = 'serial';
try
parallelMode = sesInfo.userInput.parallel_info.mode;
catch
end
parallelVal = strmatch(parallelMode, opts, 'exact');
%parallelVal = lower(getfield(sesInfo.userInput, parallelTag));
set(parallelH, 'value', parallelVal);
end
%% Back-reconstruction
backReconTag = 'backReconType';
if (isfield(sesInfo.userInput, backReconTag))
backReconType = getfield(sesInfo.userInput, backReconTag);
else
backReconType = 'regular';
end
if (strcmpi(backReconType, 'str'))
backReconType = 'spatial-temporal regression';
end
backReconType = lower(backReconType);
backReconIndex = strmatch(backReconTag, cellstr(char(inputText.tag)), 'exact');
if ~isempty(backReconIndex)
backReconVal = strmatch(backReconType, lower(inputText(backReconIndex).answerString), 'exact');
if (~isempty(backReconVal))
inputText(backReconIndex).value = backReconVal;
else
backReconStrings = cellstr(inputText(backReconIndex).answerString);
sesInfo.userInput.backReconType = lower(deblank(backReconStrings{inputText(backReconIndex).value}));
handles_data.sesInfo = sesInfo;
% set the user data
set(handles, 'userdata', handles_data);
end
end
%% Data Pre-processing
preprocTag = 'preproc_type';
if (isfield(sesInfo.userInput, preprocTag))
preprocType = getfield(sesInfo.userInput, preprocTag);
else
preprocType = 'remove mean per timepoint';
end
preprocType = lower(preprocType);
preprocIndex = strmatch(preprocTag, cellstr(char(inputText.tag)), 'exact');
if ~isempty(preprocIndex)
preprocVal = strmatch(preprocType, lower(inputText(preprocIndex).answerString), 'exact');
inputText(preprocIndex).value = preprocVal;
end
%% Group PCA Type
groupPCATag = 'group_pca_type';
if (isfield(sesInfo.userInput, groupPCATag))
group_pca_type = getfield(sesInfo.userInput, groupPCATag);
else
group_pca_type = 'subject specific';
end
group_pca_type = lower(group_pca_type);
group_pcaIndex = strmatch(groupPCATag, cellstr(char(inputText.tag)), 'exact');
if ~isempty(group_pcaIndex)
group_pca_val = strmatch(group_pca_type, lower(inputText(group_pcaIndex).answerString), 'exact');
inputText(group_pcaIndex).value = group_pca_val;
end
%% PCA Type
pcaTag = 'pcaType';
if (isfield(sesInfo.userInput, pcaTag))
pcaType = getfield(sesInfo.userInput, pcaTag);
else
pcaType = 'standard';
end
pcaType = lower(pcaType);
pcaIndex = strmatch(pcaTag, cellstr(char(inputText.tag)), 'exact');
if ~isempty(pcaIndex)
pcaVal = strmatch(pcaType, lower(inputText(pcaIndex).answerString), 'exact');
inputText(pcaIndex).value = pcaVal;
end
if isfield(sesInfo.userInput, 'convertToZ')
sesInfo.userInput = rmfield(sesInfo.userInput, 'convertToZ');
end
% check the calibration step
if isfield(sesInfo.userInput, 'scaleType') %& isfield(sesInfo.userInput, 'convertToZ')
adjustVal = sesInfo.userInput.scaleType + 1;
scale_opts = icatb_scaleICA;
scaleStr = deblank(scale_opts(adjustVal, :));
% get the adjust information
adjustTag = 'scaleType';
adjustIndex = strmatch(adjustTag, char(inputText.tag), 'exact');
adjustVal = strmatch(lower(scaleStr), lower(inputText(adjustIndex).answerString), 'exact');
if (isempty(adjustVal))
adjustVal = 1;
end
inputText(adjustIndex).value = adjustVal;
end
% set mask information also
maskTag = 'maskFile';
if isfield(sesInfo.userInput, maskTag)
maskVal = getfield(sesInfo.userInput, maskTag);
if ~isempty(maskVal)
if (strcmpi(maskVal, 'average'))
maskVal = 2;
else
maskVal = 3;
end
else
maskVal = 1;
end
maskIndex = strmatch(maskTag, char(inputText.tag), 'exact');
if ~isempty(maskIndex)
inputText(maskIndex).value = maskVal;
end
end
end
% set input text to menu
menuData.inputText = inputText;
% set menu data
set(menuH, 'userdata', menuData);
% set data reduction parameters
set_data_para(handles, menuH);
set(findobj(handles, 'tag', 'files'), 'style', 'popup', 'string', ...
char('Yes', 'No'));
set(findobj(handles, 'tag', 'files'), 'value', 1);
% disable the estimate components and the data reduction parameters
set(findobj(handles, 'tag', 'estimate_components'), 'enable', 'on');
catch
set(handles, 'pointer', 'arrow');
% Prints line number information along with the error message
icatb_displayErrorMsg;
% change to old directory
%cd(oldDir);
end
function setupDefaultsCallback(hObject, event_data, handles)
% setup ICA defaults callback
% transfer data from sesInfo to menu
set_data_para(handles, hObject);
% get the user data for the menu
menuData = get(hObject, 'userdata');
% get the figure data
handles_data = get(handles, 'userdata');
sesInfo = handles_data.sesInfo;
inputText = menuData.inputText;
handles_visibility = 'on';
% tags to be plotted
tagsTobePlotted = menuData.tagsTobePlotted;
% tag vector
tagVec = menuData.tagsVec;
figureTag = 'SetupDefaults';
% Setup figure for GUI
InputH = icatb_getGraphics(figureTag, 'normal', figureTag, handles_visibility);
% Set no menu bar for the figure
set(InputH, 'Menubar', 'none');
modalityType = icatb_get_modality;
if strcmpi(modalityType, 'fmri')
helpLabel = 'GIFT-Help';
htmlFile = 'icatb_setup_ica_defaults.htm';
elseif strcmpi(modalityType, 'smri')
helpLabel = 'SBM-Help';
htmlFile = 'icatb_setup_ica_defaults.htm';
else