0001 function D = fill(D, actions)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 2
0023 actions = '';
0024 end
0025 if ~is_fmri(D), return, end
0026 if isempty(actions), actions = {'defaults'}; end
0027 if ischar(actions), actions = {actions}; end
0028 fe = find(ismember(actions, 'for_estimation'));
0029 if ~isempty(fe)
0030 A = [];
0031 if is_fmri(D)
0032 if ~has_filter(D), A = {'filter'}; end
0033 end
0034 actions(fe) = [];
0035 actions = [actions(1:fe(1)-1) A actions(fe(1):end)];
0036 end
0037 actions = [{'defaults'}, actions];
0038
0039
0040 spmD = des_struct(D);
0041 xX = spmD.xX;
0042 if isfield(spmD, 'Sess')
0043 have_sess = 1;
0044 Sess = spmD.Sess;
0045 else
0046 have_sess = 0;
0047 end
0048
0049
0050
0051 row = block_rows(D);
0052 nsess = length(row);
0053 nscan = zeros(1,nsess);
0054 for i = 1:nsess
0055 nscan(i) = length(row{i});
0056 end
0057
0058 done_list = {};
0059 for a = 1:length(actions)
0060 if ismember(actions{a}, done_list), continue, end
0061 done_list = [actions(a) done_list];
0062 switch lower(actions{a})
0063 case 'defaults'
0064
0065
0066 xM = [];
0067 xGX = [];
0068 sGXcalc = 'none';
0069 sGMsca = 'none';
0070 Global = 'None';
0071
0072 BFstr = ''; DSstr = ''; ntr = [];
0073 if have_sess
0074 BFstr = Sess{1}.BFstr;
0075 DSstr = Sess{1}.DSstr;
0076 if ~length(xX.iC)
0077 DSstr = 'Block [session] effects only';
0078 end
0079
0080
0081 for i = 1:length(Sess)
0082 ntr(i) = length(Sess{i}.name);
0083 end
0084 end
0085
0086 xsDes = struct( 'Design', DSstr,...
0087 'Basis_functions', BFstr,...
0088 'Number_of_sessions', sprintf('%d',nsess),...
0089 'Conditions_per_session', sprintf('%-3d',ntr),...
0090 'Global_calculation', sGXcalc,...
0091 'Grand_mean_scaling', sGMsca,...
0092 'Global_normalisation', Global);
0093
0094 if isfield(spmD, 'xsDes')
0095 xsDes = mars_struct('fillafromb', spmD.xsDes, xsDes);
0096 end
0097
0098 spmD.xsDes = xsDes;
0099 spmD = mars_struct('merge', spmD, ...
0100 struct('xGX', xGX,...
0101 'xM', xM));
0102
0103 case 'images'
0104 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','fMRI stats model setup',0);
0105
0106 P = '';
0107 if nsess < 16
0108 for i = 1:nsess
0109 str = sprintf('select scans for session %0.0f',i);
0110 q = spm_get(nscan(i),mars_veropts('get_img_ext'),str);
0111 P = strvcat(P,q);
0112 end
0113 else
0114 str = sprintf('select scans for this study');
0115 P = spm_get(sum(nscan),mars_veropts('get_img_ext'),str);
0116 end
0117
0118
0119
0120 spm_help('!ContextHelp',mfilename)
0121 spm_input('Global intensity normalisation...',1,'d',mfilename);
0122
0123
0124
0125 str = 'remove Global effects';
0126 Global = spm_input(str,'+1','scale|none',{'Scaling' 'None'});
0127 if ischar(Global),
0128 Global = {Global};
0129 end
0130
0131
0132
0133 fprintf('%-40s: ','Mapping files')
0134 VY = spm_vol(P);
0135 fprintf('%30s\n','...done')
0136
0137
0138
0139 [samef msg] = mars_vol_check(VY);
0140 if ~samef, disp(char(msg)),error('Cannot use images'),end;
0141
0142
0143
0144 GM = 100;
0145 q = sum(nscan);
0146 g = zeros(q,1);
0147 fprintf('%-40s: %30s','Calculating globals',' ');
0148 for i = 1:q
0149 fprintf('%s%30s',repmat(sprintf('\b'),1,30),sprintf('%4d/%-4d',i,q));
0150 g(i) = spm_global(VY(i));
0151 end
0152 fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done')
0153
0154
0155
0156 gSF = GM./g;
0157 if strcmp(Global,'None')
0158 for i = 1:nsess
0159 j = row{i};
0160 gSF(j) = GM./mean(g(j));
0161 end
0162 end
0163
0164
0165
0166 for i = 1:q, VY(i).pinfo(1:2,:) = VY(i).pinfo(1:2,:)*gSF(i); end
0167
0168 sGXcalc = 'mean voxel value';
0169 sGMsca = 'session specific';
0170
0171
0172
0173 xM = struct('T', ones(q,1),...
0174 'TH', g.*gSF,...
0175 'I', 0,...
0176 'VM', {[]},...
0177 'xs', struct('Masking','analysis threshold'));
0178
0179
0180 xGX.iGXcalc = Global{1};
0181 xGX.sGXcalc = sGXcalc;
0182 xGX.rg = g;
0183 xGX.sGMsca = sGMsca;
0184 xGX.GM = GM;
0185 xGX.gSF = gSF;
0186
0187 xsDes = struct(...
0188 'Global_calculation', sGXcalc,...
0189 'Grand_mean_scaling', sGMsca,...
0190 'Global_normalisation', Global);
0191
0192 spmD.xsDes = mars_struct('ffillmerge',...
0193 spmD.xsDes,...
0194 xsDes);
0195 spmD = mars_struct('ffillmerge', ...
0196 spmD,...
0197 struct('xGX', xGX,...
0198 'VY', VY,...
0199 'xM', xM));
0200
0201 case 'filter'
0202
0203 if ~have_sess, return, end
0204
0205 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Set FMRI filter',0);
0206
0207
0208 if ~isfield(xX, 'RT')
0209 spmD.xX.RT = spm_input('Interscan interval {secs}','+1');
0210 end
0211
0212 spm_input('High and low pass filter','+1','d',mfilename)
0213 [spmD.xX.K HFstr LFstr] = pr_get_filter(spmD.xX.RT, Sess);
0214 xsDes = struct(...
0215 'Interscan_interval', sprintf('%0.2f',spmD.xX.RT),...
0216 'High_pass_Filter', LFstr,...
0217 'Low_pass_Filter', HFstr);
0218 spmD.xsDes = mars_struct('ffillmerge',...
0219 spmD.xsDes,...
0220 xsDes);
0221
0222 case 'autocorr'
0223 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','FMRI autocorrelation model',0);
0224
0225
0226 str = 'Model intrinsic correlations?';
0227 cVimenu = {'none','AR(1)'};
0228 cVi = spm_input(str,'+1','b',cVimenu);
0229
0230
0231
0232 Vi = speye(sum(nscan));
0233 xVi = struct('Vi',Vi,'Form',cVi);
0234 for i = 1:nsess
0235 xVi.row{i} = row{i};
0236 end
0237
0238
0239 spmD.xX.xVi = xVi;
0240 spmD.xsDes.Intrinsic_correlations = cVi;
0241
0242 otherwise
0243 error(['Unpredictable: ' actions{a}]);
0244 end
0245 end
0246
0247
0248 D = des_struct(D,spmD);
0249