Home > vbmeg > functions > gui > preAnalysis > fmri > pa_fmri_util.m

pa_fmri_util

PURPOSE ^

This function is subcontracting function of fMRI GUI.

SYNOPSIS ^

function H = pa_fmri_util(fig, command, parm)

DESCRIPTION ^

 This function is subcontracting function of fMRI GUI.
 [USAGE]
    pa_brain_util(<fig>, <command>);
 [IN]
        fig : figure handle of brain gui.
    command : command
       parm : parameter
 [OUT]
    none

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function H = pa_fmri_util(fig, command, parm)
0002 % This function is subcontracting function of fMRI GUI.
0003 % [USAGE]
0004 %    pa_brain_util(<fig>, <command>);
0005 % [IN]
0006 %        fig : figure handle of brain gui.
0007 %    command : command
0008 %       parm : parameter
0009 % [OUT]
0010 %    none
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 %
0016 % --- Previous check
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 % --- Main Procedure
0027 %
0028 
0029 % load data(@see pa_fmri_create)
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 % This function fmri activity keys from SPM result file(SPM.mat)
0047 % and set them to GUI.
0048 % [IN]
0049 %               data : GUI data
0050 %    spm_result_file : SPM result file(SPM.mat)
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         % Warning off when loading SPM result file
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 % This function changes GUI display according to SPM file type.
0088     % radio button all off
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     % spm normalization file components
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 % This function changes Exec button status.(clickable or not)
0115 % [IN]
0116 %    H : GUI component handles
0117 % [OUT]
0118 %    none
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 % This function execute vb_job_fmri with set parameter.
0130 % [IN]
0131 %    data : data of fmri gui(@see pa_fmri_create)
0132 % [OUT]
0133 %    none
0134 
0135     H = data.H;
0136 
0137     %%%%%%%%%%%%%%%%%%%%
0138     % Parameter setting
0139     %%%%%%%%%%%%%%%%%%%%
0140     proj_root = get(H.prjroot_edit, 'String');
0141 
0142     % advanced parameters are set here.
0143     fmri_parm = data.fmri_parm;
0144     
0145     % BRAIN file
0146     fmri_parm.brain_file  = get(H.brain_file_edit, 'String');
0147 
0148     % SPM file
0149     fmri_parm.SPMmat_file = get(H.spm_edit, 'String');
0150 
0151     % SPM normalization file
0152     fmri_parm.spm_normalization_file = get(H.spm_normalization_file_edit, 'String');
0153     
0154     % SPM mapmode
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     % Postfix of area key and act key
0164     fmri_parm.keys_postfix = data.keys_postfix;
0165 
0166     % AREA file
0167     fmri_parm.area_file = get(H.area_file_edit, 'String');
0168 
0169     % ACT file
0170     fmri_parm.act_file  = get(H.act_file_edit, 'String');
0171 
0172     %%%%%%%%%%%%%%%%%%%%
0173     % execute job
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);% for label string update
0184 
0185     vb_job_fmri(proj_root, fmri_parm);
0186 
0187     set(H.exec_push, 'String', 'Exec');

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005