function analyze(runid,group,subj,tries) % Analyze investors using SPM2 % % input: % runid - unique run identifier % group - group identifier % subj - subject % tries - # of times to retry on failure % % Misha Koshelev % February 24th, 2010 % Montague Laboratory if ~exist('tries','var') tries=3; end if regexp(runid,'3.*') analyze3(runid,group,subj,tries); return; elseif strcmp(runid,'4') analyze4(runid,group,subj,tries); return; elseif regexp(runid,'6.*') analyze6(runid,group,subj,tries); return; elseif strcmp(runid,'7') analyze7(runid,group,subj,tries); return; elseif strcmp(runid,'8') analyze8(runid,group,subj,tries); return; end warning off; group subj % save paths paths=path;pwds=pwd; addpath(genpath(pwd)); succeed=false; try % load data target=['/mnt/nfs/proj/trust_agnostic',filesep,group,filesep,subj]; cd([target,filesep,'other']); load('FileInfo'); load('motion'); load('source'); source=[source,filesep,'GLMs',filesep,subj]; cd('..'); if exist(runid,'dir') system(['rm -rf ',runid]); end mkdir(runid); % image files cd([source,filesep,'run1']); f=spm_get('Files',pwd,'sw*.img'); cd([target,filesep,runid]); spm_defaults; global defaults; % HRF SPM.xBF.name='hrf'; %'hrf (with time derivative)'; SPM.xBF.order=1; SPM.xBF.length=32.1250; % length in seconds SPM.xBF.T=16; % number of time bins per scan SPM.xBF.T0=1; % middle slice/timebin SPM.xBF.UNITS='secs'; % OPTIONS: 'scans'|'secs' for onsets SPM.xBF.Volterra=1; % OPTIONS: 1|2=order of convolution % Trials sess=1;i=1; events=fieldnames(FileInfo.EventStruct{1}); for j=1:length(events) event=FileInfo.EventStruct{1}.(events{j}); if strcmp(events{j},'ScreenInvAmount') % 4359 SHOWING MESSAGE AND PIC <0> % rounds 1&2 only - no regressor SPM.Sess(sess).U(i).name={[events{j},'1-2']}; SPM.Sess(sess).U(i).ons=event.values(1:2); SPM.Sess(sess).U(i).dur=event.dur(1:2); SPM.Sess(sess).U(i).P(1).name='none'; i=i+1; % rounds 3-10 - regressed with i&r's at past 2 time points SPM.Sess(sess).U(i).name={[events{j},'3-10']}; SPM.Sess(sess).U(i).ons=event.values(3:10); SPM.Sess(sess).U(i).dur=event.dur(3:10); SPM.Sess(sess).U(i).P.name='r(t-1)'; SPM.Sess(sess).U(i).P.h=1; SPM.Sess(sess).U(i).P.P=FileInfo.TruRatio(2:end-1)'; SPM.Sess(sess).U(i).P(end+1).name='i(t-1)'; SPM.Sess(sess).U(i).P(end).h=1; SPM.Sess(sess).U(i).P(end).P=FileInfo.InvRatio(2:end-1)'; SPM.Sess(sess).U(i).P(end+1).name='r(t-2)'; SPM.Sess(sess).U(i).P(end).h=1; SPM.Sess(sess).U(i).P(end).P=FileInfo.TruRatio(1:end-2)'; SPM.Sess(sess).U(i).P(end+1).name='i(t-2)'; SPM.Sess(sess).U(i).P(end).h=1; SPM.Sess(sess).U(i).P(end).P=FileInfo.InvRatio(1:end-2)'; i=i+1; else SPM.Sess(sess).U(i).name={events{j}}; SPM.Sess(sess).U(i).ons=event.values; SPM.Sess(sess).U(i).dur=event.dur; SPM.Sess(sess).U(i).P(1).name='none'; i=i+1; end end if length(motion) == 0, % no movement parameters SPM.Sess(sess).C.C=[]; SPM.Sess(sess).C.name={}; elseif size(motion, 2) > 20; SPM.Sess(sess).C.name={'first scan', 'last scan'}; SPM.Sess(sess).C.C=motion; else % assume movement parameters SPM.Sess(sess).C.C=motion; SPM.Sess(sess).C.name={'X','Y','Z','x','y','z'}; end % global normalization: OPTIONS:'Scaling'|'None' SPM.xGX.iGXcalc='None'; % low frequency confound: high-pass cutoff (secs) [Inf=no filtering] SPM.xX.K(sess).HParam=128; % intrinsic autocorrelations: OPTIONS: 'none'|'AR(1) + w' SPM.xVi.form='AR(1) + w'; %'AR(1) + w'; SPM.nscan(sess)=size(f,1); SPM.xY.P=f; SPM.xY.RT=2; % Time between scans SPM=spm_fmri_spm_ui_m(SPM,''); SPM=spm_spm_m(SPM); succeed=true; catch e=lasterror; e.message e.identifier for i=1:length(e.stack) s=e.stack(i); s.file s.name s.line end end path(paths); cd(pwds); warning on; if ~succeed&&tries>1 system('sleep 10'); analyze(runid,group,subj,tries-1); end