forked from hMRI-group/hMRI-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbx_scfg_hmri_proc_pipeline.m
237 lines (213 loc) · 9.36 KB
/
tbx_scfg_hmri_proc_pipeline.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
function proc_pipel = tbx_scfg_hmri_proc_pipeline
% Configuration file for the pipeline part of the processing modules of
% the "histological MRI" (hMRI) toolbox.
% -> Provides standard processign pipelines.
%
% For simplicity, 2 standard pipelines are also set up:
% - US+Smooth -> applies US, warps into MNI, then smoothes
% (weighted-average)
% - US+Dartel+Smooth -> applies US, builds Dartel template and warps into
% MNI, then smoothes (weighted-average)
% Most of the parameters are therefore pre-defined and hardcoded!
% For more flexibility, you ought to use the individual modules and build
% your own pipeline.
%_______________________________________________________________________
% Copyright (C) 2017 Cyclotron Research Centre
% Written by Christophe Phillips
% ---------------------------------------------------------------------
% indir Input directory as output directory
% ---------------------------------------------------------------------
indir = cfg_menu;
indir.tag = 'indir';
indir.name = 'Input directory';
indir.help = {['Output files will be written to the same folder as ',...
'each corresponding input file.']};
indir.labels = {'Yes'};
indir.values = {1};
indir.val = {1};
% ---------------------------------------------------------------------
% outdir Output directory for all data
% ---------------------------------------------------------------------
outdir = cfg_files;
outdir.tag = 'outdir';
outdir.name = 'Output directory, all together';
outdir.help = {['Select a directory where all output files from all '...
'subjects put together will be written to.']};
outdir.filter = 'dir';
outdir.ufilter = '.*';
outdir.num = [1 1];
% ---------------------------------------------------------------------
% outdir_ps Output directory for per-subject organisation
% ---------------------------------------------------------------------
outdir_ps = cfg_files;
outdir_ps.tag = 'outdir_ps';
outdir_ps.name = 'Output directory, with per-subject sub-directory';
outdir_ps.help = {['Select a directory where output files will be '...
'written to, in each subject''s sub-directory.']};
outdir_ps.filter = 'dir';
outdir_ps.ufilter = '.*';
outdir_ps.num = [1 1];
% ---------------------------------------------------------------------
% output Output choice
% ---------------------------------------------------------------------
output = cfg_choice;
output.tag = 'output';
output.name = 'Output choice';
output.help = {['Output directory can be the same as the input ',...
'directory for each input file or user selected (one for everything ',...
'or preserve a per-subject organisation).']};
output.values = {indir outdir outdir_ps };
output.val = {indir};
% -------------------------------------------------------------------------
% vols Volumes
% ---------------------------------------------------------------------
vols = cfg_files;
vols.tag = 's_vols';
vols.name = 'Structural images (T1w or MT) for segmentation';
vols.help = {['Select structural images, i.e. T1w or MT, for ',...
'"unified segmentation". They are used to create the individuam ',...
'tissue class maps, e.g. GM and WM posterior probability maps']};
vols.filter = 'image';
vols.ufilter = '.*';
vols.num = [1 Inf];
% ---------------------------------------------------------------------
% vols_pm Parametric maps
% ---------------------------------------------------------------------
vols_pm = cfg_files;
vols_pm.tag = 'vols_pm';
vols_pm.name = 'Maps (single type)';
vols_pm.help = {['Select whole brain parameter maps (e.g. MT, R2*, ',...
'FA, etc.) from all subjects for processing.']};
vols_pm.filter = 'image';
vols_pm.ufilter = '.*';
vols_pm.num = [1 Inf];
% ---------------------------------------------------------------------
% many_pams Parameter maps
% ---------------------------------------------------------------------
% used for 'many subjects', i.e. list the data per map type across subjects
many_pams = cfg_repeat;
many_pams.tag = 'maps';
many_pams.name = 'Parametric maps';
many_pams.values = {vols_pm };
many_pams.val = {vols_pm };
many_pams.num = [1 Inf];
many_pams.help = {['Select whole brain parameter maps (e.g. MT, ',...
'R2*, FA, etc.) from all subjects for processing, one type at a time.']};
% ---------------------------------------------------------------------
% pipe_c Pipeline choice
% ---------------------------------------------------------------------
pipe_c = cfg_menu;
pipe_c.tag = 'pipe_c';
pipe_c.name = 'Pipeline';
pipe_c.help = {
'Chose the predefined pipeline that you prefer:'
'- US+Smooth -> applies US, warps into MNI, then smoothes (weighted-average)'
['- US+Dartel+Smooth -> applies US, builds Dartel template and warps into' ...
'MNI, then smoothes (weighted-average)']
}';
pipe_c.labels = {
'US+smooth'
'US+Dartel+smooth'}';
pipe_c.values = {1 2};
pipe_c.val = {2};
% ---------------------------------------------------------------------
% Gaussian FWHM
% ---------------------------------------------------------------------
fwhm = cfg_entry;
fwhm.tag = 'fwhm';
fwhm.name = 'Gaussian FWHM';
fwhm.val = {[6 6 6]};
fwhm.strtype = 'e';
fwhm.num = [1 3];
fwhm.help = {['Specify the full-width at half maximum (FWHM) of the ',...
'Gaussian blurring kernel in mm. Three values should be entered',...
'denoting the FWHM in the x, y and z directions.']};
% ---------------------------------------------------------------------
% vox Voxel sizes
% ---------------------------------------------------------------------
vox = cfg_entry;
vox.tag = 'vox';
vox.name = 'Voxel sizes';
vox.num = [1 3];
vox.strtype = 'e';
vox.val = {[1 1 1]};
vox.help = {[...
'Specify the voxel sizes of the deformation field and tissue classes ',...
'to be produced. Non-finite values will default to the voxel sizes of ',...
'the template image that was originally used to estimate the deformation.']};
%--------------------------------------------------------------------------
% bb Bounding box
%--------------------------------------------------------------------------
bb = cfg_entry;
bb.tag = 'bb';
bb.name = 'Bounding box';
bb.help = {'The bounding box (in mm) of the volume which is to be written (relative to the anterior commissure).'};
bb.strtype = 'r';
bb.num = [2 3];
bb.def = @(val)spm_get_defaults('normalise.write.bb', val{:});
% ---------------------------------------------------------------------
% proc_pipel Preprocess maps -> pipelines
% ---------------------------------------------------------------------
proc_pipel = cfg_exbranch;
proc_pipel.tag = 'proc_pipel';
proc_pipel.name = 'Proc. hMRI -> Pipelines';
proc_pipel.help = {
['Parameter maps are spatially processed and brought into standard space',...
'for furhter statistical analysis. Only 2 tissue classes, GM & WM, '...
'are considered.']
[' ']
['For simplicity, 2 standard pipelines are also set up:']
['- US+Smooth -> applies US, warps into MNI, then smoothes (weighted-average)']
['- US+Dartel+Smooth -> applies US, builds Dartel template and warps' ...
'into MNI, then smoothes (weighted-average)']
}'; %#ok<*NBRAK>
proc_pipel.val = {output vols many_pams vox bb fwhm pipe_c};
proc_pipel.prog = @hmri_run_proc_pipeline;
proc_pipel.vout = @vout_proc_pipeline;
proc_pipel.check = @check_data;
end
%----------------------------------------------------------------------
%----------------------------------------------------------------------
%----------------------------------------------------------------------
%% =======================================================================
% VOUT function
% =======================================================================
% Collect and prepare output
function dep = vout_proc_pipeline(job)
% This depends on job contents, which may not be present when virtual
% outputs are calculated.
% There should be one series of images per parametric map and tissue class,
% e.g. in the usual case of 4 MPMs and GM/WM -> 8 series of image
n_pams = numel(job.vols_pm); % #parametric image types
n_TCs = 2; % #tissue classes = 2, by default
cdep = cfg_dep;
for ii=1:n_TCs
for jj=1:n_pams
cdep(end+1) = cfg_dep; %#ok<*AGROW>
cdep(end).sname = sprintf('c#%d, pMap #%d', ii, jj);
cdep(end).src_output = substruct('.', 'tc', '{}', {ii,jj});
cdep(end).tgt_spec = cfg_findspec({{'filter','image','strtype','e'}});
end
end
dep = cdep(2:end);
end
%% =======================================================================
% CHECKING the data
% ========================================================================
function t = check_data(job)
% Checking that the data are consistent.
t = {};
nSubj = numel(job.s_vols); % number of subjects from #struct images
nPara = numel(job.vols_pm); % number of maps type
% Check number of structurals matches the number of parametric maps per
% type
if nPara>0
for ii=1:nPara
if numel(job.vols_pm{ii})~=0 && numel(job.vols_pm{ii})~=nSubj
t{1} = 'Number of maps not matching number of structural images/subjects!';
warndlg(t,'Maps numbers');
return
end
end
end
end