-
Notifications
You must be signed in to change notification settings - Fork 1
/
spm_bch_bchmat.m
180 lines (133 loc) · 5.24 KB
/
spm_bch_bchmat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function bch_mat = spm_bch_bchmat(bch_mfile,typeA)
% SPM batch system: Extract batch definitions from Mat file
% FORMAT bch_mat = spm_bch_bchmat(bch_mfile,typeA)
%
% bch_mfile -
% typeA - Type of analysis
% bch_mat -
%
%_______________________________________________________________________
%
% This function gets a m-file that describes the bach process and
% returns a .mat file containing the variables used during the batch.
%_______________________________________________________________________
% @(#)spm_bch_bchmat.m 2.11 Jean-Baptiste Poline & Stephanie Rouquette 01/01/30
%=======================================================================
% Programmers guide: Adding a new type of analysis
%=======================================================================
% When a new type of analysis is added, this file should be edited to
% define the variables that will be used by spm_input in BCH mode AND
% add them in the 'bch_names' variable. If you wish to check the
% consistency of the variables (errors in the m-file specifications),
% this should be done here and NOT in the function called in spm_bch to
% do the actual job.
% temporarily goes to the m file dir and comes back at the end
%-----------------------------------------------------------------------
cwd = pwd;
try
cd(spm_str_manip(bch_mfile,'H'));
catch
error([spm_str_manip(bch_mfile,'H') 'doesn''t exist']);
end
%-check that the m-file exists
%-----------------------------------------------------------------------
if ~(exist(spm_str_manip(bch_mfile,'rt')) == 2)
error(sprintf('%s not a m file in path', ...
spm_str_manip(bch_mfile,'rt')));
end
%-try to evaluate m-file
%-----------------------------------------------------------------------
try
feval(spm_str_manip(bch_mfile,'rt'));
catch
str = sprintf('cannot eval %s',spm_str_manip(bch_mfile,'rt'));
error([str ' : check your paths or parameter file']);
end
cd(cwd); %- come back here
clear cwd
switch typeA, case 'analyses'
%=======================================================================
bch_names = {typeA,'type','work_dir','mfile'};
case 'defaults_edit'
%=======================================================================
bch_names = {typeA, 'type_area' ...
'Misc','Printing','Hdr','Statistics', ...
'Normalisation','RealignCoreg','Reset'};
case {'headers','means','normalize','smooth','coreg','slicetime'}
%=======================================================================
bch_names = {typeA};
case 'realign'
%=======================================================================
bch_names = {typeA,'sessions'};
case 'model'
%=======================================================================
% missing fields added here for model
%-----------------------------------------------------------------------
% Added and modified fields are
% nodel(k).nscans
% model(k).remain
% model(k).interp (if not defined before)
% model(k).time_sampl (if not defined before)
%-----------------------------------------------------------------------
%
if exist('model') == 1,
%-
if ~isfield(model,'time_sampl')
for k =1:length(model)
model(k).time_sampl = cell(1,model(k).nsess);
end
[model.interp] = deal('');
end
for k = 1:length(model)
for l = 1:model(k).nsess
model(k).nscans(l) = model(k).nscans(l)+length(model(k).time_sampl{l});
model(k).remain{l} = setdiff(1:model(k).nscans(l),...
model(k).time_sampl{l});
end %- for k = 1:length(model)
end %- if ~isfield(model(k),'time_sampl')
end % if exist('model') == 1,
bch_names = {typeA,'conditions','stochastics',...
'regressors','parametrics','bf_ev','bf_ep'};
case 'contrasts'
%=======================================================================
% missing fields added here for contrasts
%-----------------------------------------------------------------------
% Added fields are
% contrasts(k).set_action
%-----------------------------------------------------------------------
if exist('contrasts') == 1
for k = 1:length(contrasts)
if ~isfield(contrasts(k),'set_action')
ncont = length(contrasts(k).names);
if ncont
tmp = cell(1,ncont);
[tmp{:}] = deal('c');
contrasts(k).set_action = tmp;
clear tmp;
end
end
end
end %- if exist('contrasts') == 1
bch_names = {typeA};
otherwise
%=======================================================================
warning(sprintf('unknown type of analyse %s',typeA))
end
%=======================================================================
%-create bch_names with existing variables only
%-----------------------------------------------------------------------
str = {};
names = {};
for i=1:length(bch_names),
if exist(bch_names{i}) == 1,
str = {str{:},bch_names{i}};
names{length(names)+1} = bch_names{i};
end
end
bch_names = names;
str = {str{:},'bch_names'};
% .mat saved here: here bch_mat does contain the path of the
% bch_mfile (because we are in the working dir).
%-----------------------------------------------------------------------
save(spm_str_manip(bch_mfile,'rp'),str{:});
bch_mat = spm_str_manip(bch_mfile,'rp'); %-here contains the path