attachment:batch_spm5_eeg_preproc.m of SpmBatch5 - MRC CBU Imaging Wiki
location: attachment:batch_spm5_eeg_preproc.m of SpmBatch5

Attachment 'batch_spm5_eeg_preproc.m'

Download

   1 %-----------------------------------------------------------------------
   2 %Design specific parameters
   3 %-----------------------------------------------------------------------
   4 
   5 clear
   6 spm_defaults;
   7 
   8 subs = {'030093' '050637' '050636' '040317' '050714' '040630' '030721' '041031' '050715' '050716' '050717' '050718' '050719' '040700' '040858'};
   9 nsubs = length(subs);
  10 nsess = 2;
  11 ntot = nsubs*nsess;
  12 cnames{1} = {'S-nc' 'S-cs' 'S-cc' 'S-test' 'S-first'};
  13 cnames{2} = {'C-nc' 'C-cs' 'C-cc' 'C-test' 'C-first'};
  14 ncond = length(cnames{1});
  15 TR = 1.1005;
  16 dataroot = '/imaging/russell/expt456';
  17 batchroot = '/imaging/russell/test5';
  18 statsdir = fullfile(batchroot,'stats');
  19 border = [2 1 2 1 2 1 2 1 2 1 1 2 1 2 2];
  20 hpf = 60;
  21 incmoves = 1;
  22 modeldur = 0;
  23 imgfilt = '^snuraW.*\.img$';
  24 movefilt = '^rp_.*\.txt';
  25 evdir = fullfile(dataroot,'stats/e6/change/m2/events');
  26 mnames = {'x_trans' 'y_trans' 'z_trans' 'x_rot' 'y_rot' 'z_rot'};
  27 debug=0;
  28 
  29 cname = 'An example contrast';
  30 cons{1} = [repmat([-1 0 1 0 0 0 0 0 0 0 0],1,2) 0 0];
  31 
  32 
  33 
  34 %-----------------------------------------------------------------------
  35 %Design setup
  36 %-----------------------------------------------------------------------
  37 
  38 % basis functions and timing parameters
  39 %---------------------------------------------------------------------------
  40 % OPTIONS:'hrf'
  41 %         'hrf (with time derivative)'
  42 %         'hrf (with time and dispersion derivatives)'
  43 %         'Fourier set'
  44 %         'Fourier set (Hanning)'
  45 %         'Gamma functions'
  46 %         'Finite Impulse Response'
  47 %---------------------------------------------------------------------------
  48 
  49 %MD No slice timing, therefore using temporal-derivates to shift HRF forward and back in time
  50 
  51 xBF.name       = 'hrf';
  52 xBF.length     = 32.2;              % length in seconds
  53 xBF.order      = 1;                 % order of basis set
  54 xBF.T          = 16;                % number of time bins per scan
  55 xBF.T0         = 1;                 % first time bin (see slice timing) - middle of TA
  56 xBF.UNITS      = 'scans';           % OPTIONS: 'scans'|'secs' for onsets
  57 xBF.Volterra   = 1;                 % OPTIONS: 1|2 = order of convolution
  58 
  59 
  60 
  61 
  62 tc = 0;
  63 allfiles = '';
  64 for sub = 1:2%nsubs
  65     clear SPM
  66     disp(subs{sub})
  67     SPM.xY.RT = TR;
  68     SPM.xGX.iGXcalc = 'None';
  69     SPM.xVi.form = 'AR(1)';
  70     SPM.xBF = xBF;
  71     csub = subs{sub};
  72     subdata = fullfile(dataroot, csub);
  73     anadir = fullfile(statsdir,csub);
  74     if exist(anadir)~=7; mkdir(statsdir,csub);end
  75     cd(anadir);
  76     
  77     tc = 0;
  78     allfiles='';
  79     condtog = border(sub);
  80     
  81     for sess = 1:nsess
  82         tc = tc+1;
  83         sessdata = fullfile(subdata,['E6-Sess' num2str(sess)]);
  84         ons = spm_load(fullfile(evdir,['ev_' csub '_' num2str(sess) '.txt']));
  85         files = spm_select('List', sessdata, imgfilt);
  86         if incmoves==1
  87             mfname = spm_select ('List', sessdata, movefilt);
  88             moves = load(fullfile(sessdata,mfname));
  89         end
  90         SPM.nscan(tc) = size(files,1);
  91         for f =1:size(files,1)
  92             ffiles(f,:) = fullfile(sessdata,files(f,:));
  93         end
  94         allfiles = strvcat(allfiles,ffiles);
  95         
  96         for c = 1:ncond
  97             cidx = find(ons(:,2)==c);
  98             
  99             if modeldur==1
 100                 durs = ons(cidx,3);
 101             else
 102                 durs = zeros(length(cidx),1);
 103             end
 104             
 105             SPM.Sess(tc).U(c) = struct(...
 106                 'ons',ons(cidx,1),...
 107                 'dur',durs,...
 108                 'name',{cnames{condtog}(c)},...
 109                 'P',struct('name','none'));
 110         end
 111         
 112         SPM.xX.K(tc).HParam = hpf;
 113         if condtog == 1
 114             condtog = 2;
 115         elseif condtog == 2
 116             condtog = 1;
 117         end
 118         
 119         if incmoves==1
 120             SPM.Sess(tc).C.C    = moves;     % [n x c double] covariates
 121             SPM.Sess(tc).C.name = mnames; % [1 x c cell]   names
 122         else
 123             SPM.Sess(tc).C.C = [];
 124             SPM.Sess(tc).C.name = {};
 125         end
 126     end
 127     
 128     if debug==0
 129         SPM.xY.P = allfiles;
 130         SPMdes = spm_fmri_spm_ui(SPM);
 131         spm_unlink(fullfile('.', 'mask.img')); % avoid overwrite dialog
 132         SPMest = spm_spm(SPMdes);
 133         for i = 1:size(cons,2)
 134             if length(SPMest.xCon)==0
 135                 SPMest.xCon = spm_FcUtil('Set',cname,'T','c',cons{i}',SPMest.xX.xKXs);
 136             else
 137                 SPMest.xCon(end+1) = spm_FcUtil('Set',cname,'T','c',cons{i}',SPMest.xX.xKXs);
 138             end
 139         end
 140         spm_contrasts(SPMest);
 141     end
 142 end

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-01-21 10:41:39, 5.0 KB) [[attachment:batch_spm5_1stlevel.m]]
  • [get | view] (2008-01-21 10:42:26, 4.6 KB) [[attachment:batch_spm5_eeg_preproc.m]]
  • [get | view] (2008-01-21 10:41:17, 7.3 KB) [[attachment:batch_spm5_preproc.m]]
  • [get | view] (2008-11-07 13:11:51, 7.3 KB) [[attachment:batch_spm5_stats_2ndlevel_mixed_ANOVA.m]]
  • [get | view] (2008-02-19 15:34:16, 4.7 KB) [[attachment:batch_spm5_stats_2ndlevel_within_ANOVA.m]]
  • [get | view] (2007-07-25 11:33:40, 2.3 KB) [[attachment:spm2batch.tar.gz]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.