-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp_node_dmri_topup_b0.m
executable file
·131 lines (100 loc) · 3.87 KB
/
dp_node_dmri_topup_b0.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
classdef dp_node_dmri_topup_b0 < dp_node
% Estimate b0 using topup
methods
function obj = dp_node_dmri_topup_b0()
obj.output_test = {'fieldmap_fn'};
end
% construct names of output files
function output = i2o(obj, input)
% pass on the input
output = input;
% other files
output.topup_data_path = fullfile(input.op, 'topup_data');
output.fieldmap_fn = fullfile(input.op, 'fieldmap.nii.gz');
% input management of options
if (~isfield(input, 'topup_cnf'))
input.topup_cnf = 'b02bo';
end
if (isfield(input, 'topup_opt'))
input.topup_cnf = 'custom';
end
switch (input.topup_cnf)
case 'b02bo' % replicating b02bo.cnf
% https://github.com/ahheckel/FSL-scripts/blob/master/rsc/fsl/fsl4/topup/b02b0.cnf
topt.warpres = [20,16,14,12,10,6,4,4,4];
topt.subsamp = [2,2,2,2,2,1,1,1,1];
topt.fwhm = [8,6,4,3,3,2,1,0,0];
topt.miter = [5,5,5,5,5,10,10,20,20];
topt.lambda = [0.005,0.001,0.0001,0.000015,0.000005,0.0000005,0.00000005,0.0000000005,0.00000000001];
topt.estmov = [1,1,1,1,1,0,0,0,0];
topt.minmet = [0,0,0,0,0,1,1,1,1];
case 'none'
topt = struct();
case 'custom'
topt = input.topup_opt;
end
output.topt = topt;
end
function output = execute(obj, input, output)
% run topup ( all input files need to be present already)
f = @(x,y) sprintf(['--' x ' '], y);
cmd = {...
'topup ', ...
f('imain=%s', input.topup_nii_fn), ...
f('datain=%s', input.topup_spec_fn), ...
f('out=%s', output.topup_data_path), ...
f('fout=%s', output.fieldmap_fn) ...
};
% integer fields
opt_fields = {...
'warpres', ...
'subsamp', ...
'fwhm', ...
'miter', ...
'estmov', ...
'minmet', ...
'ssqlambda', ...
'splineorder', ...
'scale', ...
'nthr'};
h = @(x) [x(1:(end-1))];
p = @(x) h(sprintf('%i,',x));
g = @(y,z) sprintf('--%s=%s ', y,z);
for c = 1:numel(opt_fields)
if (~isfield(output.topt, opt_fields{c})), continue; end
cmd{end+1} = g(...
opt_fields{c}, ...
p(output.topt.(opt_fields{c})));
end
% float field
p = @(x) h(sprintf('%1.12f,',x));
if (isfield(output.topt, 'lambda'))
cmd{end+1} = g(...
'lambda', ...
p(output.topt.lambda));
end
% strings
opt_fields = {...
'regmod', ...
'numprec', ...
'intrep'};
for c = 1:numel(opt_fields)
if (~isfield(output.topt, opt_fields{c})), continue; end
cmd{end+1} = g(...
opt_fields{c}, ...
output.topt.(opt_fields{c}));
end
% verbose
if (obj.opt.verbose > 1)
cmd{end+1} = '--verbose ';
end
% now run it
cmd = sprintf('bash --login -c ''%s'' ', [cmd{:}]);
[status,cmdout] = system(cmd);
if (status > 0)
disp(cmd);
error(cmdout);
end
end
end
end