Save SPM result as '.spm.mat' file format (VBMEG public function) % This function convert thresholded statistical values, obtained by SPM2/5/8 software, with its coordinate and save them as .spm.mat file, which is used in VBMEG to incorporate fMRI information in MEG current source estimation. [syntax] vb_job_convert_spm Note that you have to execute this function on the MATLAB console SPM2/5/8 is running. When you display statistical map of some kind of contrast, their value and its coordinate are stored in MATLAB workspace. This function just save these data in an appropriate format. [output] .spm.mat file is created. [history] Originally written by Naokazu Goda (for SPM99) 2004-12-11 Taku Yoshioka 2004-12-14 Naokazu Goda (backward coordinate transformation routine) 2005-02-23 Dai Kawawaki 2008-09-17 Dai Kawawaki 2008-10-27 Taku Yoshioka 2010-05-12 Takeda added spm8 support 2010-06-22 Taku Yoshioka Use 'spm_get_orig_coord.m' for SPM5/8 2010-10-06 Masa-aki Sato Use 'spm_get_orig_coord_spm5.m' for SPM5/8 Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function vb_job_convert_spm 0002 % Save SPM result as '.spm.mat' file format 0003 % (VBMEG public function) 0004 % 0005 % % This function convert thresholded statistical values, obtained by 0006 % SPM2/5/8 software, with its coordinate and save them as 0007 % .spm.mat file, which is used in VBMEG to incorporate fMRI 0008 % information in MEG current source estimation. 0009 % 0010 % [syntax] 0011 % vb_job_convert_spm 0012 % 0013 % Note that you have to execute this function on the MATLAB console 0014 % SPM2/5/8 is running. When you display statistical map of some kind of 0015 % contrast, their value and its coordinate are stored in MATLAB 0016 % workspace. This function just save these data in an appropriate 0017 % format. 0018 % 0019 % [output] 0020 % .spm.mat file is created. 0021 % 0022 % [history] 0023 % Originally written by Naokazu Goda (for SPM99) 0024 % 2004-12-11 Taku Yoshioka 0025 % 2004-12-14 Naokazu Goda (backward coordinate transformation routine) 0026 % 2005-02-23 Dai Kawawaki 0027 % 2008-09-17 Dai Kawawaki 0028 % 2008-10-27 Taku Yoshioka 0029 % 2010-05-12 Takeda added spm8 support 0030 % 2010-06-22 Taku Yoshioka 0031 % Use 'spm_get_orig_coord.m' for SPM5/8 0032 % 2010-10-06 Masa-aki Sato 0033 % Use 'spm_get_orig_coord_spm5.m' for SPM5/8 0034 % 0035 % Copyright (C) 2011, ATR All Rights Reserved. 0036 % License : New BSD License(see VBMEG_LICENSE.txt) 0037 0038 % 0039 % VBMEG constant 0040 % 0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0042 coord_const = vb_define_coordinate; 0043 0044 % 0045 % Get SPM result 0046 % 0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 try 0049 spm_ver = spm('ver'); 0050 catch 0051 error('You can use this function on result display of SPM analysis.'); 0052 end 0053 xSPM = get_important_struct(spm_ver); 0054 0055 % 0056 % Backward coordinate Transform from normalized to subject's native 0057 % 0058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0059 answer = questdlg('Normalized funtional data?','Convert SPM result', ... 0060 'Yes','No','Yes'); 0061 switch answer 0062 case 'Yes' 0063 [dir,fnames] = vb_file_select({'_sn.mat'},'Load SPM sn file'); 0064 if isempty(fnames), 0065 disp('Sn file was not selected.'); 0066 return; 0067 end; 0068 matname = [dir filesep fnames{1}]; 0069 0070 switch (lower(spm_ver)), 0071 case 'spm2', 0072 sn = load([dir filesep fnames{1}]); 0073 xSPM.XYZmm=vb_unsn(xSPM.XYZmm,sn); 0074 0075 case {'spm5','spm8'}, 0076 xSPM.XYZmm = spm_get_orig_coord_spm5((xSPM.XYZmm)',matname); 0077 xSPM.XYZmm = (xSPM.XYZmm)'; 0078 end; 0079 end; 0080 0081 % 0082 % Save 0083 % 0084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0085 [dir,fnames] = vb_file_select({'.spm.mat'},'Save .spm.mat file',true); 0086 if isempty(fnames), 0087 disp('.spm.mat file was not selected.'); 0088 return; 0089 end 0090 0091 SPM = xSPM; 0092 SPM.coord_type = coord_const.COORDINATE_SPM_RIGHT_MM; 0093 vb_fsave([dir filesep fnames{1}],'SPM'); 0094 0095 return; 0096 0097 % 0098 % Inner function 0099 % 0100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0101 function xSPM = get_important_struct(spm_ver) 0102 switch (lower(spm_ver)) 0103 case 'spm2' 0104 disp('Check SPM version: SPM2'); 0105 0106 command = 'exist(''xSPM'')'; 0107 if ~evalin('base',command) % execute command in base workspace 0108 error('Some contrast image must be displayed in SPM.'); 0109 else 0110 mSPM = evalin('base','xSPM'); 0111 nSPM.Z = mSPM.Z; 0112 nSPM.XYZmm = mSPM.XYZmm; 0113 nSPM.STAT = mSPM.STAT; 0114 xSPM = nSPM; 0115 clear mSPM; 0116 end 0117 clear command; 0118 0119 case 'spm5' 0120 disp('Check SPM version: SPM5'); 0121 0122 command = 'exist(''xSPM'')'; 0123 if ~evalin('base',command) % execute command in base workspace 0124 error('Some contrast image must be displayed in SPM.'); 0125 else 0126 mSPM = evalin('base','xSPM'); 0127 nSPM.Z = mSPM.Z; 0128 nSPM.XYZmm = mSPM.XYZmm; 0129 nSPM.STAT = mSPM.STAT; 0130 xSPM = nSPM; 0131 clear mSPM; 0132 end 0133 clear command; 0134 0135 case 'spm8' 0136 disp('Check SPM version: SPM8'); 0137 0138 command = 'exist(''xSPM'')'; 0139 if ~evalin('base',command) % execute command in base workspace 0140 error('Some contrast image must be displayed in SPM.'); 0141 else 0142 mSPM = evalin('base','xSPM'); 0143 nSPM.Z = mSPM.Z; 0144 nSPM.XYZmm = mSPM.XYZmm; 0145 nSPM.STAT = mSPM.STAT; 0146 xSPM = nSPM; 0147 clear mSPM; 0148 end 0149 clear command; 0150 0151 otherwise 0152 error('Sorry, this function does not accommodate to your spm version.'); 0153 end 0154 0155 return;