Home > vbmeg > functions > tool_box > spmtools > vb_job_convert_spm.m

vb_job_convert_spm

PURPOSE ^

Save SPM result as '.spm.mat' file format

SYNOPSIS ^

function vb_job_convert_spm

DESCRIPTION ^

 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
 2016-03-28 Masa-aki Sato
  Whole program is rewritten
 2016-05-31 rhayashi
   - SPM result(MNI) is saved as MNI coordinate value.
   - SPM result(Subject) : is saved as SPM_Right_mm.
                         : NIfTI format is supported.

 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 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 % 2016-03-28 Masa-aki Sato
0035 %  Whole program is rewritten
0036 % 2016-05-31 rhayashi
0037 %   - SPM result(MNI) is saved as MNI coordinate value.
0038 %   - SPM result(Subject) : is saved as SPM_Right_mm.
0039 %                         : NIfTI format is supported.
0040 %
0041 % Copyright (C) 2011, ATR All Rights Reserved.
0042 % License : New BSD License(see VBMEG_LICENSE.txt)
0043 
0044 %%%%%% DEBUG %%%%%%
0045 DEBUG = 0;
0046 
0047 %
0048 % VBMEG constant
0049 %
0050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051 coord_const = vb_define_coordinate;
0052 
0053 %
0054 % Get SPM result
0055 %
0056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0057 if DEBUG==0
0058 %%%% If DEBUG =1, SPM check is skipped %%%%%%%%
0059     try
0060       spm_ver = spm('ver');
0061     catch
0062       error('You can use this function on result display of SPM analysis.');
0063     end
0064     xSPM = get_important_struct(spm_ver);
0065 else
0066     xSPM = [];
0067 end
0068 
0069 savefile  = [];
0070 
0071 %
0072 % Select Standard brain or Subject brain
0073 %
0074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0075 mesg = {'Which coordinate is used in the current SPM result?'};
0076 title_txt = 'SPM data import';
0077 
0078 ansA = 'Normalised template brain(MNI)';
0079 ansB = 'Subject brain';
0080 
0081 STD_sw = questdlg(mesg, title_txt, ansA, ansB, ansA);
0082 switch STD_sw
0083 case ansA
0084     xSPM.coord_type = coord_const.COORDINATE_MNI_RIGHT_MM;
0085 case ansB
0086     % Select Image file to adjust position gap of fmri activity derived from image center position.
0087     imagefile = get_t1_image;
0088     if isempty(imagefile)
0089         disp('T1 image file was not selected.');
0090         return;
0091     end
0092     fprintf('Transform subject native to SPM-right-mm coordinate : ');
0093     fprintf('imagefile %s\n',imagefile);
0094 
0095     %
0096     % Transform from subject's native to SPM-right-mm coordinate
0097     %
0098     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0099     if DEBUG==0
0100         %%%% If DEBUG =1, this part is skipped %%%%%%%%
0101         xSPM = vb_nifti_mm_to_spm_right_mm(xSPM', imagefile)';
0102         xSPM.coord_type = coord_const.COORDINATE_SPM_RIGHT_MM;
0103     end %%%% DEBUG END
0104 
0105 otherwise
0106     error('Unknown coordinate is specified.');
0107 end
0108 
0109 %
0110 % Get Save file name
0111 %
0112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0113 [dir,fnames] = vb_file_select({'.spm.mat'},'Input Save filename(.spm.mat)',true);
0114 if isempty(fnames), 
0115   disp('.spm.mat file was not selected.');
0116   return;
0117 end
0118 savefile = [dir filesep fnames{1}];
0119 
0120 %
0121 % Save
0122 %
0123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0124 fprintf('Save file: %s\n',savefile)
0125 
0126 if DEBUG==1, return; end
0127     
0128 SPM = xSPM;
0129 vb_fsave(savefile,'SPM', 'spm_ver');
0130 
0131 return;
0132 
0133 %
0134 % Inner function
0135 %
0136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0137 function xSPM = get_important_struct(spm_ver)
0138 switch (lower(spm_ver))
0139  case 'spm2' 
0140   disp('Check SPM version: SPM2');
0141   
0142   command = 'exist(''xSPM'')';
0143   if ~evalin('base',command) % execute command in base workspace
0144     error('Some contrast image must be displayed in SPM.');
0145   else
0146     mSPM = evalin('base','xSPM');
0147     nSPM.Z = mSPM.Z;
0148     nSPM.XYZmm = mSPM.XYZmm;
0149     nSPM.STAT = mSPM.STAT;
0150     xSPM = nSPM;
0151     clear mSPM;
0152   end
0153   clear command;
0154 
0155  case 'spm5'
0156   disp('Check SPM version: SPM5');
0157 
0158   command = 'exist(''xSPM'')';
0159   if ~evalin('base',command) % execute command in base workspace
0160     error('Some contrast image must be displayed in SPM.');
0161   else
0162     mSPM = evalin('base','xSPM');
0163     nSPM.Z = mSPM.Z;
0164     nSPM.XYZmm = mSPM.XYZmm;
0165     nSPM.STAT = mSPM.STAT;
0166     xSPM = nSPM;
0167     clear mSPM;
0168   end
0169   clear command;
0170 
0171   case 'spm8'
0172    disp('Check SPM version: SPM8');
0173 
0174    command = 'exist(''xSPM'')';
0175    if ~evalin('base',command) % execute command in base workspace
0176      error('Some contrast image must be displayed in SPM.');
0177    else
0178      mSPM = evalin('base','xSPM');
0179      nSPM.Z = mSPM.Z;
0180      nSPM.XYZmm = mSPM.XYZmm;
0181      nSPM.STAT = mSPM.STAT;
0182      xSPM = nSPM;
0183      clear mSPM;
0184    end
0185    clear command;
0186    
0187  otherwise
0188   error('Sorry, this function does not accommodate to your spm version.');
0189 end
0190 
0191 function imagefile = get_t1_image
0192 imagefile = '';
0193 [dir,fnames] = vb_file_select({'.hdr','.nii'},'Input T1 image file(.hdr/.nii)');
0194 if ~isempty(fnames)
0195     imagefile = fullfile(dir, fnames{1});
0196 end
0197 
0198 function xSPM = backword_transform_normalized_to_subject_native(snfile, spm_ver, xSPM)
0199 switch (lower(spm_ver))
0200  case 'spm2', 
0201   sn = load(snfile);
0202   xSPM.XYZmm=vb_unsn(xSPM.XYZmm,sn);
0203   
0204  case {'spm5','spm8'}, 
0205   xSPM.XYZmm = spm_get_orig_coord_spm5((xSPM.XYZmm)',snfile);
0206   xSPM.XYZmm = (xSPM.XYZmm)';
0207 end
0208

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