0001 function vb_job_fmri(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 spm_func = which('spm_vol');
0038 if isempty(spm_func)
0039 error('Please add SPM8 path to your MATLAB.');
0040 end
0041 if nargin == 1
0042 proj_root = [];
0043 parm = varargin{1};
0044 elseif nargin == 2
0045 proj_root = varargin{1};
0046 parm = varargin{2};
0047 else
0048 error('Invalid usage of vb_job_fmri.');
0049 end
0050
0051 proj_root = vb_rm_trailing_slash(proj_root);
0052
0053
0054
0055
0056
0057
0058
0059 SPMmat_file = parm.SPMmat_file;
0060 brain_file = fullfile(proj_root, parm.brain_file);
0061
0062
0063 act_file = fullfile(proj_root, parm.act_file);
0064 area_file = fullfile(proj_root, parm.area_file);
0065 keys_postfix = parm.keys_postfix;
0066
0067
0068 Tthres = parm.Tthres;
0069 Rthres = parm.Rthres;
0070 PSthres = parm.PSthres;
0071 SPMmapmode = parm.SPMmapmode;
0072
0073
0074 switch lower(SPMmapmode)
0075 case {'subj2subj'}
0076
0077
0078 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0079 vb_fmri_project_Tmap_cortex(brain_file,act_file,area_file,Tthres,Rthres,SPMimginfo);
0080
0081 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0082 vb_fmri_project_PSmap_cortex(brain_file,act_file,area_file,PSthres,Rthres,SPMimginfo);
0083
0084 case {'mni2subj'}
0085
0086
0087 sn_file = parm.spm_normalization_file;
0088 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0089 vb_fmri_unsn_project_Tmap_cortex(brain_file,act_file,area_file,sn_file,Tthres,Rthres,SPMimginfo);
0090
0091 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0092 vb_fmri_unsn_project_PSmap_cortex(brain_file,act_file,area_file,sn_file,PSthres,Rthres,SPMimginfo);
0093
0094 case {'mni2mni'}
0095
0096 fprintf(' SPM maps on MNI brain will projected to the MNI standard brain model ! \n');
0097
0098 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0099 vb_fmri_project_Tmap_cortex(brain_file,act_file,area_file,Tthres,Rthres,SPMimginfo,1);
0100
0101 SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0102 vb_fmri_project_PSmap_cortex(brain_file,act_file,area_file,PSthres,Rthres,SPMimginfo,1);
0103
0104 otherwise
0105 error('SPMmapmode must be either ''subj2subj'', ''mni2subj'' or ''mni2mni'' !');
0106 end
0107
0108
0109
0110
0111 proj_file = get_project_filename;
0112 if ~isempty(proj_file)
0113 project_file_mgr('load', proj_file);
0114 project_file_mgr('add', 'fmri_parm', parm);
0115 end
0116
0117
0118
0119
0120
0121
0122
0123 function SPMimginfo = SPMmat2SPMimginfo(SPMmatfile,postfix,flagT)
0124
0125 load(SPMmatfile);
0126
0127 spm_ver = SPM.SPMid(1:strfind(SPM.SPMid,':')-1);
0128
0129 for nn = 1 : length(SPM.xCon)
0130
0131
0132 labels{nn} = [SPM.xCon(nn).name postfix];
0133
0134
0135 if flagT
0136 filenames{nn} = [SPM.xCon(nn).Vspm.fname];
0137 else
0138 filenames{nn} = [SPM.xCon(nn).Vcon.fname];
0139 end
0140
0141
0142 ncon(nn) = sum(SPM.xCon(nn).c > 0);
0143
0144 ixreg = find(SPM.xCon(nn).c);
0145 X = SPM.xX.X(:,ixreg);
0146 peak(nn) = max(X(:));
0147
0148 a = strfind(SPM.xX.name, 'constant');
0149 for ii = 1 : length(a)
0150 if ~isempty(a{ii})
0151 ixreg = ii;
0152 end
0153 end
0154 baseimgfiles{nn} = ['beta_' num2str(ixreg, '%04d') '.img'];
0155
0156 end
0157
0158 spmdir = [fileparts(SPMmatfile) filesep];
0159
0160 for nn = 1 : length(SPM.xCon)
0161 SPMimginfo(nn) = struct('dirname', spmdir, 'imgfilename', filenames{nn}, 'imglabel', labels{nn},...
0162 'ncon',ncon(nn),'peak', peak(nn), 'baseimgfilename', baseimgfiles{nn},'spm_ver',spm_ver);
0163 end