127127 contrastsList , ...
128128 groups );
129129
130- % make sure there is no SPM.mat in the target dir
131- %
132- % folders where the model is to be specified have already been emptied
133- % if at this stage they are not, something has gone horribly wrong.
134- %
135- % also if we continued SPM would ask us to manually confirm the over-write
136- % by clicking buttons and no one has got time this
137- for j = 1 : numel(matlabbatch )
138-
139- if isfield(matlabbatch{j }.spm, ' stats' ) && ...
140- isfield(matlabbatch{j }.spm.stats, ' fmri_est' )
141- if exist(matlabbatch{j }.spm.stats.fmri_est.spmmat{1 }, ' file' )
142- error(' PANIC! About to overwrite a model. That should not happen' );
143- end
144- end
130+ checkDirIsEmpty(matlabbatch );
145131
146- end
132+ status = saveAndRunWorkflow(matlabbatch , ...
133+ ' group_level_model_specification_estimation' , ...
134+ opt );
147135
148- saveAndRunWorkflow( matlabbatch , ' group_level_model_specification_estimation ' , opt );
136+ renameDesignMatrixFigure( status , matlabbatch );
149137
150138 end
151139
163151 opt.pipeline.type = ' groupStats' ;
164152 initBids(opt , ' description' , description , ' force' , false );
165153 end
154+
166155end
167156
168157function checks(opt )
@@ -172,3 +161,41 @@ function checks(opt)
172161 errorHandling(mfilename(), ' tooManySpaces' , msg , false , opt .verbosity );
173162 end
174163end
164+
165+ function checkDirIsEmpty(matlabbatch )
166+
167+ % make sure there is no SPM.mat in the target dir
168+ %
169+ % folders where the model is to be specified have already been emptied
170+ % if at this stage they are not, something has gone horribly wrong.
171+ %
172+ % also if we continued SPM would ask us to manually confirm the over-write
173+ % by clicking buttons and no one has got time this
174+ for i = 1 : numel(matlabbatch )
175+
176+ if isfield(matlabbatch{i }.spm, ' stats' ) && ...
177+ isfield(matlabbatch{i }.spm.stats, ' fmri_est' )
178+ if exist(matlabbatch{i }.spm.stats.fmri_est.spmmat{1 }, ' file' )
179+ error(' PANIC! About to overwrite a model. That should not happen' );
180+ end
181+ end
182+
183+ end
184+
185+ end
186+
187+ function renameDesignMatrixFigure(status , matlabbatch )
188+
189+ if ~status
190+ return
191+ end
192+
193+ for j = 1 : numel(matlabbatch )
194+ if isfield(matlabbatch{j }.spm, ' stats' ) && ...
195+ isfield(matlabbatch{j }.spm.stats, ' fmri_est' )
196+ directory = fileparts(matlabbatch{j }.spm.stats.fmri_est.spmmat{1 });
197+ renamePng(directory , ' task' );
198+ end
199+ end
200+
201+ end
0 commit comments