Skip to content

Commit 542a68d

Browse files
committed
deal with unwarp and segment modified suffix output
1 parent 7219728 commit 542a68d

File tree

4 files changed

+62
-38
lines changed

4 files changed

+62
-38
lines changed

src/defaults/Mapping.m

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,33 +165,35 @@
165165
%
166166

167167
prfx_spec = { ...
168-
{ obj.bias_cor }, obj.cfg.segment.bias_corrected; ...
169-
{ 'c1' }, obj.cfg.segment.gm; ...
170-
{ 'c2' }, obj.cfg.segment.wm; ...
171-
{ 'c3' }, obj.cfg.segment.csf
172-
{ 'iy_' }, obj.cfg.segment.deformation_field.from_mni
173-
{ 'y_' }, obj.cfg.segment.deformation_field.to_mni
174-
{ obj.stc, [obj.unwarp, obj.stc]}, obj.cfg.stc
175-
{ obj.unwarp }, obj.cfg.realign_unwarp
176-
{ 'rp_', ['rp_' obj.stc] }, obj.cfg.real_param
168+
{ obj.bias_cor }, obj.cfg.segment.bias_corrected; ...
169+
{ 'c1' }, obj.cfg.segment.gm; ...
170+
{ 'c2' }, obj.cfg.segment.wm; ...
171+
{ 'c3' }, obj.cfg.segment.csf; ...
172+
{ 'iy_' }, obj.cfg.segment.deformation_field.from_mni; ...
173+
{ 'y_' }, obj.cfg.segment.deformation_field.to_mni; ...
174+
{ 'segparam_' }, obj.cfg.segment.param; ...
175+
{ obj.stc, [obj.unwarp, obj.stc]}, obj.cfg.stc; ...
176+
{ 'unwarpparam_' }, obj.cfg.realign_unwarp_param; ...
177+
{ obj.unwarp }, obj.cfg.realign_unwarp; ...
178+
{ 'rp_', ['rp_' obj.stc] }, obj.cfg.real_param; ...
177179
{ 'mean', ...
178180
['mean' obj.unwarp], ...
179-
['mean' obj.unwarp, obj.stc] }, obj.cfg.mean
181+
['mean' obj.unwarp, obj.stc] }, obj.cfg.mean; ...
180182
{ obj.norm, ...
181183
[obj.norm, obj.bias_cor], ...
182184
[obj.norm, obj.unwarp, obj.stc], ...
183185
[obj.norm, obj.realign, obj.stc], ...
184186
[obj.norm, obj.unwarp], ...
185-
[obj.norm, obj.realign] }, obj.cfg.preproc_norm
186-
{ [obj.norm, 'mean', obj.unwarp] }, obj.cfg.normalized_mean
187-
{ [obj.norm, 'c1'] }, obj.cfg.segment.gm_norm
188-
{ [obj.norm, 'c2'] }, obj.cfg.segment.wm_norm
189-
{ [obj.norm, 'c3'] }, obj.cfg.segment.csf_norm
187+
[obj.norm, obj.realign] }, obj.cfg.preproc_norm; ...
188+
{ [obj.norm, 'mean', obj.unwarp] }, obj.cfg.normalized_mean; ...
189+
{ [obj.norm, 'c1'] }, obj.cfg.segment.gm_norm; ...
190+
{ [obj.norm, 'c2'] }, obj.cfg.segment.wm_norm; ...
191+
{ [obj.norm, 'c3'] }, obj.cfg.segment.csf_norm; ...
190192
{[obj.smooth, obj.norm], ...
191193
[obj.smooth, obj.norm, obj.unwarp, obj.stc], ...
192194
[obj.smooth, obj.norm, obj.realign, obj.stc], ...
193195
[obj.smooth, obj.norm, obj.unwarp], ...
194-
[obj.smooth, obj.norm, obj.realign] }, obj.cfg.smooth_norm
196+
[obj.smooth, obj.norm, obj.realign] }, obj.cfg.smooth_norm; ...
195197
{ obj.smooth, ...
196198
[obj.smooth, obj.unwarp, obj.stc], ...
197199
[obj.smooth, obj.realign, obj.stc], ...

src/defaults/check_cfg.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,15 @@
122122
'mode', 'image'), ...
123123
'suffix', 'xfm');
124124

125+
segment.param = struct('label', 'TBD', 'suffix', 'segparam');
126+
125127
fields_to_set.segment = segment;
126128

127129
% Preprocessed data
128130
fields_to_set.stc = desc_gen('stc');
129131

130132
fields_to_set.realign_unwarp = desc_gen('realignUnwarp');
133+
fields_to_set.realign_unwarp_param = struct('label', 'TBD', 'suffix', 'unwarpparam');
131134
fields_to_set.real_param = struct('entities', ...
132135
struct('desc', 'confounds'), ...
133136
'suffix', 'regressors', ...

src/spm_2_bids.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,29 @@
3333

3434
mapping = map.mapping;
3535
cfg = map.cfg;
36+
37+
use_suffix_as_label = false;
38+
39+
% deal with suffixes modified by SPM
40+
% turns them into prefixes that can be handled by the default mapping
41+
if strfind(file, '_uw.mat') %#ok<*STRIFCND>
42+
file = spm_file(file, 'prefix', 'unwarpparam_');
43+
file = strrep(file, '_uw.mat', '.mat');
44+
use_suffix_as_label = true;
45+
end
46+
if strfind(file, '_seg8.mat') %#ok<*STRIFCND>
47+
file = spm_file(file, 'prefix', 'segparam_');
48+
file = strrep(file, '_seg8.mat', '.mat');
49+
use_suffix_as_label = true;
50+
end
3651

3752
pth = spm_fileparts(file);
3853
new_filename = spm_file(file, 'filename');
3954
json = [];
4055

4156
p = bids.internal.parse_filename(file);
4257

58+
% TO DO allow renaming even if there is no prefix ?
4359
if isempty(p.prefix)
4460
return
4561
end
@@ -111,6 +127,10 @@
111127
spec = add_fwhm_to_smooth_label(spec, cfg);
112128

113129
spec = adapt_from_label_to_input(spec, p);
130+
131+
if use_suffix_as_label
132+
spec.entities.label = p.suffix;
133+
end
114134

115135
spec = use_config_spec(spec, cfg);
116136

@@ -134,7 +154,8 @@
134154
% adds the FWHM to the description label for smoothing
135155
%
136156

137-
if isfield(spec.entities, 'desc') && ...
157+
if isfield(spec, 'entities') && ...
158+
isfield(spec.entities, 'desc') && ...
138159
strcmp(spec.entities.desc, 'smth') && ...
139160
~isempty(cfg.fwhm)
140161
spec.entities.desc = sprintf('smth%i', cfg.fwhm);

tests/test_spm_2_bids.m

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88
initTestSuite;
99
end
1010

11+
function test_spm_2_bids_suffix()
12+
13+
input_output = {
14+
'sub-01_T1w_seg8.mat', 'sub-01_label-T1w_segparam.mat';
15+
'sub-01_task-auditory_bold_uw.mat', 'sub-01_task-auditory_label-bold_unwarpparam.mat'};
16+
17+
for i = 1:numel(size(input_output, 1))
18+
19+
print_here('%s\n', input_output{i,1});
20+
21+
filename = spm_2_bids(input_output{i,1});
22+
23+
expected = input_output{i, 2};
24+
assertEqual(filename, expected);
25+
26+
end
27+
28+
end
29+
1130
function test_spm_2_bids_new_mapping()
1231

1332
map = Mapping();
@@ -53,27 +72,6 @@ function test_spm_2_bids_new_mapping()
5372

5473
end
5574

56-
% Not yet implemented as this makes the filename parsing crash
57-
58-
% function test_spm_2_bids_suffix()
59-
%
60-
% input_output = {
61-
% 'sub-01_T1w_seg8.mat', 'sub-01_label-T1w_segparam.mat';
62-
% 'sub-01_task-auditory_bold_uw.mat', 'sub-01_task-auditory_label-bold_unwarpparam.mat'};
63-
%
64-
% for i = 1:numel(size(input_output, 1))
65-
%
66-
% print_here('%s\n', input_output{i,1});
67-
%
68-
% filename = spm_2_bids(input_output{i,1});
69-
%
70-
% expected = input_output{i, 2};
71-
% assertEqual(filename, expected);
72-
%
73-
% end
74-
%
75-
% end
76-
7775
function test_spm_2_bids_order_entities()
7876

7977
file = 'wmsub-01_desc-skullstripped_T1w.nii';

0 commit comments

Comments
 (0)