-
Notifications
You must be signed in to change notification settings - Fork 1
/
spm_bch.m
211 lines (178 loc) · 7.01 KB
/
spm_bch.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
function spm_bch(varargin)
% SPM batch system: Batch running program.
% FORMAT spm_bch(bch_mfile);
%
% bch_mfile - m-file containing the description of the batch analyses
%
%__________________________________________________________________________
%
% bch_mfile has to contain a variable 'analyses' that describes
% the kind of analyses to perform in batch, and variables:
% 'type', 'work_dir', 'file'
% See spm_bch.man for indication on how to fill these and what they are.
%
% spm_bch will basically loop over different analyses (eg: 'smooth',
% ..). Each analyses inputs will be taken from an m-file, (file
% variable) and performed in the working directory describe in
% work_dir. m-file names can be relative to the working directory. If
% several analyses of the same kind are to be computed, this is
% resolved with the analyses.index
%
% The top m-file may also contain the structures for the input of one
% or several analyses
%
%_______________________________________________________________________
% @(#)spm_bch.m 2.8 Jean-Baptiste Poline & Stephanie Rouquette 01/01/29
%=======================================================================
% Programmer's notes
%=======================================================================
% To add a new kind of analysis, eg NEW_Analysis
% 1- include it in the switch,
% (with BCH.index0 = {'NEW_Analysis',iA(cA)})
% 2- modify spm_bch_bchmat.m (see its documentation)
% 3- include 'NEW_Analysis' in the variable 'type' in the
% description of the sequences of analyses (top m-file).
% 4- the m-file describing the entries for this new anlysis
% should contain a top level variable 'NEW_Analysis'
% Reset lasterr to null so it doesn't confuse any of the try..catch
% subroutines. (Suggested by Darren Gitelman)
%-----------------------------------------------------------------------
lasterr('');
%- Global batch variables
%-----------------------------------------------------------------------
global BCH
BCH = struct(...
'bch_mat', '', ... % mat file or structure in which inputs are read
'index0' ,{{'', 0}}, ... % index for the root level variable
'flag' ,1 ... % flag : 1 -> batch mode, 0 -> GUI mode
);
%- Inputs and Defaults
%-----------------------------------------------------------------------
global MODALITY;
if nargin == 0,
fprintf('FORMAT : spm_bch(bch_mfile [,''FMRI''|''PET'']\n');
return;
end
if nargin == 1,
MODALITY = 'FMRI';
bch_mfile = varargin{1};
end
if nargin == 2,
bch_mfile = varargin{1};
MODALITY = varargin{2};
if ~ismember(MODALITY,{'FMRI','PET'}),
fprintf('FORMAT : spm_bch(bch_mfile [,''FMRI''|''PET'']\n');
return;
end
end
%- launch spm defaults for that modality
%-----------------------------------------------------------------------
spm('defaults',MODALITY);
%- m->mat file for the upper level analysis
%-----------------------------------------------------------------------
try
%--------- put it in mat file
ana_mat = spm_bch_bchmat(bch_mfile,'analyses');
%--------- put it in memory. spm_input supports mat file or struct.
ana_mat = load(ana_mat);
catch
error(sprintf('\nCan''t evaluate %s of ''analyses'' ', bch_mfile));
fprintf('\n Try to execute %s in matlab', bch_mfile)
end
BCH.bch_mat = ana_mat;
BCH.index0 = {'analyses',1};
%- save current directory
%-----------------------------------------------------------------------
cwd = pwd;
%- get indexes for all analyses and the m-files,
%- working dir, type of analysis
%-----------------------------------------------------------------------
iA = spm_input('batch',{},'index');
try
wk_dir = spm_input('batch',{'work_dir',':'});
%- same as: for cA = 1:length(iA)
%- wk_dir{cA} = spm_input('batch',{'work_dir',cA},1); ...
typeA = spm_input('batch',{'type',':'});
mfileA = spm_input('batch',{'mfile',':'});
catch
error(['check the top mfile .... ' bch_mfile]);
end
for cA = 1:length(iA) % length(iA) == number of analyses to be done
% go back to current dir (useful if path are relative)
%---------------------------------------------------------------
eval(['cd ' cwd]);
%- go into working directory
%---------------------------------------------------------------
try
eval(['cd ' wk_dir{cA}]);
catch
pwd
error(['can''t go to work dir ' ...
wk_dir{cA} ' or can''t get in mfile']);
end
%- m->mat file for sub analyses
BCH.bch_mat = spm_bch_bchmat(mfileA{cA},typeA{cA});
switch typeA{cA}
%-----------------------------------------------------------
case 'defaults_edit'
BCH.index0 = {'defaults_edit',iA(cA)};
%- first, get the indexes of the default areas
%-------------------------------------------------------
index = spm_input('batch',{},'index');
%- get the list of defaults areas to work on
%-------------------------------------------------------
areas = {};
areas = spm_input('batch',{'type_area',':'});
% for i_area = 1:length(index)
% areas{i_area} = spm_input('batch',{'type_area',i_area},1);
% end
%-------------------------------------------------------
for i_area = 1:length(areas)
%--- little trick : the top variable changes here ...
%--- reading info from {areas{i_area},index(i_area)}
BCH.index0 = {areas{i_area},index(i_area)};
spm_defaults_edit(areas{i_area});
end
%-----------------------------------------------------------
case 'model'
BCH.index0 = {'model',iA(cA)};
spm_fmri_spm_ui;
%-----------------------------------------------------------
case 'contrasts'
BCH.index0 = {'contrasts',iA(cA)};
s = spm_bch_GetCont;
s = spm_bch_DoCont;
%-----------------------------------------------------------
case 'headers'
BCH.index0 = {'headers',iA(cA)};
s = spm_bch_headers;
%-----------------------------------------------------------
case 'means'
BCH.index0 = {'means',iA(cA)};
s = spm_means;
%-----------------------------------------------------------
case 'realign'
BCH.index0 = {'realign',iA(cA)};
spm_realign_ui;
%-----------------------------------------------------------
case 'coreg'
BCH.index0 = {'coreg',iA(cA)};
spm_coreg_ui;
%-----------------------------------------------------------
case 'normalize'
BCH.index0 = {'normalize',iA(cA)};
spm_sn3d;
%-----------------------------------------------------------
case 'smooth'
BCH.index0 = {'smooth',iA(cA)};
spm_smooth_ui;
%-----------------------------------------------------------
otherwise
warning(sprintf('unknown type of analyse %s',typeA{cA}))
end %- switch typeA{cA}
end %- for cA = 1:length(iA)
cd(cwd);
% If there is a BCH variable then things like dialog boxes don't
% always show up. (Suggested by Darren Gitelman)
%-----------------------------------------------------------------------
clear global BCH;