0001 function H = pa_fmri_util(fig, command, parm)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if ~exist('fig', 'var') || isempty(fig) || ~ishandle(fig)
0019 error('invalid figure is specified.');
0020 end
0021 if ~exist('command', 'var') || isempty(command)
0022 error('command is a required parameter.');
0023 end
0024
0025
0026
0027
0028
0029
0030 data = guidata(fig);
0031
0032 switch(command)
0033 case 'update_exec_push_status'
0034 update_exec_push_status(data.H);
0035 case 'set_spm_result_file'
0036 spm_result_file = parm;
0037 set_spm_result_file(data, spm_result_file);
0038 case 'set_spm_type'
0039 mode = parm;
0040 set_spm_type(data.H, mode);
0041 case 'exec_fmri'
0042 exec_fmri(data);
0043 end
0044
0045 function set_spm_result_file(data, spm_result_file)
0046
0047
0048
0049
0050
0051
0052 if exist(spm_result_file, 'file') ~= 2
0053 return;
0054 else
0055 set(data.H.spm_edit, 'String', spm_result_file);
0056
0057
0058 a = warning('Query', 'MATLAB:unknownElementsNowStruc');
0059 if strcmpi(a.state, 'on')
0060 warning('off', 'MATLAB:unknownElementsNowStruc');
0061 s = load(spm_result_file);
0062 warning('on', 'MATLAB:unknownElementsNowStruc');
0063 end
0064 keys = {s.SPM.xCon.name}';
0065 Nkeys = length(keys);
0066
0067 area_keys = cell(Nkeys);
0068 act_keys = cell(Nkeys*2);
0069
0070 postfix = '';
0071 if isfield(data, 'keys_postfix') && ~isempty(data.keys_postfix)
0072 postfix = [data.keys_postfix];
0073 end
0074 for k=1:Nkeys
0075 act_keys{k} = [keys{k}, '_T', postfix];
0076 act_keys{Nkeys+k} = [keys{k}, '_PS', postfix];
0077 end
0078 for k=1:Nkeys
0079 area_keys{k} = [keys{k}, '_T', postfix];
0080 end
0081
0082 set(data.H.area_key_listbox, 'String', area_keys, 'Value', 1, 'ListboxTop', 1, 'Min', 0, 'Max', length(area_keys));
0083 set(data.H.act_key_listbox, 'String', act_keys, 'Value', 1, 'ListboxTop', 1, 'Min', 0, 'Max', length(act_keys));
0084 end
0085
0086 function set_spm_type(H, mode)
0087
0088
0089 radio_group = [H.spm_mni2subj_radiobutton, ...
0090 H.spm_mni2mni_radiobutton, ...
0091 H.spm_subj2subj_radiobutton];
0092 set(radio_group, 'Value', 0);
0093
0094
0095 spm_norm_group = [H.spm_normalization_file_text, ...
0096 H.spm_normalization_file_edit, ...
0097 H.spm_normalization_file_push];
0098
0099 switch(lower(mode))
0100 case {'mni2subj'}
0101 set(H.spm_mni2subj_radiobutton, 'Value', 1);
0102 set(spm_norm_group, 'Visible', 'on');
0103 case {'mni2mni'}
0104 set(H.spm_mni2mni_radiobutton, 'Value', 1);
0105 set(spm_norm_group, 'Visible', 'off');
0106 case {'subj2subj'}
0107 set(H.spm_subj2subj_radiobutton, 'Value', 1);
0108 set(spm_norm_group, 'Visible', 'off');
0109 otherwise
0110 error('Please check function usage.');
0111 end
0112
0113 function update_exec_push_status(H)
0114
0115
0116
0117
0118
0119 if ~isempty(get(H.spm_edit, 'String')) & ...
0120 ~isempty(get(H.brain_file_edit, 'String')) & ...
0121 ~isempty(get(H.area_file_edit, 'String')) & ...
0122 ~isempty(get(H.act_file_edit, 'String'))
0123 set(H.exec_push, 'Enable', 'on');
0124 else
0125 set(H.exec_push, 'Enable', 'off');
0126 end
0127
0128 function H = exec_fmri(data)
0129
0130
0131
0132
0133
0134
0135 H = data.H;
0136
0137
0138
0139
0140 proj_root = get(H.prjroot_edit, 'String');
0141
0142
0143 fmri_parm = data.fmri_parm;
0144
0145
0146 fmri_parm.brain_file = get(H.brain_file_edit, 'String');
0147
0148
0149 fmri_parm.SPMmat_file = get(H.spm_edit, 'String');
0150
0151
0152 fmri_parm.spm_normalization_file = get(H.spm_normalization_file_edit, 'String');
0153
0154
0155 if get(H.spm_mni2subj_radiobutton, 'Value')
0156 fmri_parm.SPMmapmode = 'mni2subj';
0157 elseif get(H.spm_mni2mni_radiobutton, 'Value')
0158 fmri_parm.SPMmapmode = 'mni2mni';
0159 elseif get(H.spm_subj2subj_radiobutton, 'Value')
0160 fmri_parm.SPMmapmode = 'subj2subj';
0161 end
0162
0163
0164 fmri_parm.keys_postfix = data.keys_postfix;
0165
0166
0167 fmri_parm.area_file = get(H.area_file_edit, 'String');
0168
0169
0170 fmri_parm.act_file = get(H.act_file_edit, 'String');
0171
0172
0173
0174
0175 spm_func = which('spm_vol');
0176 if isempty(spm_func)
0177 msgbox('Please add SPM8 path to your MATLAB.', 'SPM path is required.');
0178 return;
0179 end
0180
0181 str = get(H.exec_push, 'String');
0182 set(H.exec_push, 'String','Processing...');
0183 pause(0.01);
0184
0185 vb_job_fmri(proj_root, fmri_parm);
0186
0187 set(H.exec_push, 'String', 'Exec');