Skip to content

Commit 52be622

Browse files
committed
refactor and verbosity options
1 parent 622deb8 commit 52be622

File tree

6 files changed

+59
-44
lines changed

6 files changed

+59
-44
lines changed

src/defaults/Mapping.m

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,29 @@
196196
{[obj.norm, 'c3'] }, obj.cfg.segment.csf_norm
197197
};
198198

199-
smooth = {{ obj.smooth, ...
200-
[obj.smooth, obj.unwarp, obj.stc], ...
201-
[obj.smooth, obj.stc, obj.unwarp], ...
202-
[obj.smooth, obj.realign, obj.stc], ...
203-
[obj.smooth, obj.unwarp], ...
204-
[obj.smooth, obj.realign] }, obj.cfg.smooth};
205-
206-
smooth_norm = {{[obj.smooth, obj.norm], ...
207-
[obj.smooth, obj.norm, obj.unwarp, obj.stc], ...
208-
[obj.smooth, obj.norm, obj.stc, obj.unwarp], ...
209-
[obj.smooth, obj.norm, obj.realign, obj.stc], ...
210-
[obj.smooth, obj.norm, obj.unwarp], ...
211-
[obj.smooth, obj.norm, obj.realign] }, obj.cfg.smooth_norm};
212-
213-
preproc_norm = {{obj.norm, ...
214-
[obj.norm, obj.bias_cor], ...
215-
[obj.norm, obj.stc, obj.unwarp], ...
216-
[obj.norm, obj.unwarp, obj.stc], ...
217-
[obj.norm, obj.realign, obj.stc], ...
218-
[obj.norm, obj.unwarp], ...
219-
[obj.norm, obj.realign] }, obj.cfg.preproc_norm};
220-
221-
spec = cat(1, spec, smooth, smooth_norm, preproc_norm);
199+
spec_smooth = {{ obj.smooth, ...
200+
[obj.smooth, obj.unwarp, obj.stc], ...
201+
[obj.smooth, obj.stc, obj.unwarp], ...
202+
[obj.smooth, obj.realign, obj.stc], ...
203+
[obj.smooth, obj.unwarp], ...
204+
[obj.smooth, obj.realign] }, obj.cfg.smooth};
205+
206+
spec_smooth_norm = {{[obj.smooth, obj.norm], ...
207+
[obj.smooth, obj.norm, obj.unwarp, obj.stc], ...
208+
[obj.smooth, obj.norm, obj.stc, obj.unwarp], ...
209+
[obj.smooth, obj.norm, obj.realign, obj.stc], ...
210+
[obj.smooth, obj.norm, obj.unwarp], ...
211+
[obj.smooth, obj.norm, obj.realign] }, obj.cfg.smooth_norm};
212+
213+
spec_preproc_norm = {{obj.norm, ...
214+
[obj.norm, obj.bias_cor], ...
215+
[obj.norm, obj.stc, obj.unwarp], ...
216+
[obj.norm, obj.unwarp, obj.stc], ...
217+
[obj.norm, obj.realign, obj.stc], ...
218+
[obj.norm, obj.unwarp], ...
219+
[obj.norm, obj.realign] }, obj.cfg.preproc_norm};
220+
221+
spec = cat(1, spec, spec_smooth, spec_smooth_norm, spec_preproc_norm);
222222

223223
for i_map = 1:size(spec, 1)
224224
obj = obj.add_mapping('prefix', spec{i_map, 1}, ...

src/spm_2_bids.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [new_filename, pth, json] = spm_2_bids(file, map)
1+
function [new_filename, pth, json] = spm_2_bids(file, map, verbose)
22
%
33
% Provides a bids derivatives name for a file preprocessed with SPM
44
%
@@ -26,11 +26,15 @@
2626
%
2727
% (C) Copyright 2021 spm_2_bids developers
2828

29-
if nargin < 2
29+
if nargin < 2 || isempty(map)
3030
map = Mapping();
3131
map = map.default();
3232
end
3333

34+
if nargin < 3
35+
verbose = true;
36+
end
37+
3438
mapping = map.mapping;
3539
cfg = map.cfg;
3640

@@ -111,7 +115,7 @@
111115
spec = mapping(idx).name_spec;
112116
end
113117

114-
if isempty(spec)
118+
if isempty(spec) && verbose
115119
% TODO this warning should probably go in the find_mapping methods
116120
msg = sprintf('Unknown prefix: %s', bf.prefix);
117121
warning('spm_2_bids:unknownPrefix', msg); %#ok<SPWRN>
@@ -136,7 +140,9 @@
136140
new_filename = bf.filename;
137141

138142
json = bids.derivatives_json(bf.filename);
139-
json.content.RawSources{1} = identify_rawsources(file, false);
143+
144+
json.content.RawSources{1} = identify_rawsources(file, verbose);
145+
json.content.Sources{1} = identify_sources(file, map, verbose);
140146

141147
end
142148

src/utils/identify_sources.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function sources = identify_sources(derivatives)
1+
function sources = identify_sources(derivatives, map, verbose)
22
%
33
% finds the most likely files in the detrivatives that was used to create
44
% this file
@@ -37,6 +37,15 @@
3737
return
3838
end
3939

40+
if nargin < 2 || isempty(map)
41+
map = Mapping();
42+
map = map.default();
43+
end
44+
45+
if nargin < 3
46+
verbose = true;
47+
end
48+
4049
if endsWith(derivatives, '_seg8.mat')
4150

4251
prefix_based = false;
@@ -51,7 +60,7 @@
5160

5261
end
5362

54-
bf = bids.File(derivatives);
63+
bf = bids.File(derivatives, 'verbose', verbose);
5564

5665
if prefix_based
5766
if numel(bf.prefix) < 2
@@ -83,7 +92,7 @@
8392
end
8493

8594
% call spm_2_bids what is the filename from the previous step
86-
[new_filename] = spm_2_bids(bf.filename);
95+
[new_filename] = spm_2_bids(bf.filename, map, verbose);
8796

8897
sources = fullfile(bf.bids_path, new_filename);
8998

tests/test_identify_sources.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function test_identify_sources_anat()
2020

2121
for i = 1:size(prefix_output, 1)
2222

23-
sources = identify_sources([prefix_output{i, 1} anat_file]);
23+
sources = identify_sources([prefix_output{i, 1} anat_file], [], false);
2424

2525
assertEqual(sources, prefix_output{i, 2});
2626

@@ -47,7 +47,7 @@ function test_identify_sources_func()
4747

4848
for i = 1:size(prefix_output, 1)
4949

50-
sources = identify_sources([prefix_output{i, 1} func_file]);
50+
sources = identify_sources([prefix_output{i, 1} func_file], [], false);
5151

5252
assertEqual(sources, fullfile('sub-01', prefix_output{i, 2}));
5353

@@ -64,7 +64,7 @@ function test_identify_sources_suffix()
6464

6565
for i = 1:size(input_output, 1)
6666

67-
sources = identify_sources(input_output{i, 1});
67+
sources = identify_sources(input_output{i, 1}, [], false);
6868

6969
assertEqual(sources, ['sub-01/' input_output{i, 2}]);
7070

tests/test_spm_2_bids.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
function test_spm_2_bids_order_entities()
1212

1313
file = 'wmsub-01_desc-skullstripped_T1w.nii';
14-
new_filename = spm_2_bids(file);
14+
new_filename = spm_2_bids(file, [], false);
1515
assertEqual(new_filename, 'sub-01_space-IXI549Space_desc-preproc_T1w.nii');
1616

1717
end
@@ -25,7 +25,7 @@ function test_spm_2_bids_suffix()
2525

2626
print_here('%s\n', input_output{i, 1});
2727

28-
filename = spm_2_bids(input_output{i, 1});
28+
filename = spm_2_bids(input_output{i, 1}, [], false);
2929

3030
expected = input_output{i, 2};
3131
assertEqual(filename, expected);
@@ -70,7 +70,7 @@ function test_spm_2_bids_new_mapping()
7070

7171
print_here('%s\n', input_output{i, 1});
7272

73-
filename = spm_2_bids(input_output{i, 1}, map);
73+
filename = spm_2_bids(input_output{i, 1}, map, false);
7474

7575
expected = input_output{i, 2};
7676
assertEqual(filename, expected);
@@ -82,7 +82,7 @@ function test_spm_2_bids_new_mapping()
8282
function test_spm_2_bids_no_prefix()
8383

8484
file = 'sub-01_ses-02_T1w.nii';
85-
new_filename = spm_2_bids(file);
85+
new_filename = spm_2_bids(file, [], false);
8686
assertEqual(new_filename, file);
8787

8888
end
@@ -103,7 +103,7 @@ function test_spm_2_bids_unknown_prefix()
103103
function test_spm_2_bids_json()
104104

105105
file = 'c1sub-01_ses-02_T1w.nii';
106-
[new_filename, pth, json] = spm_2_bids(file);
106+
[new_filename, pth, json] = spm_2_bids(file, [], false);
107107

108108
end
109109

@@ -135,7 +135,7 @@ function test_spm_2_bids_defor_field()
135135

136136
print_here('%s\n', file);
137137

138-
filename = spm_2_bids(file);
138+
filename = spm_2_bids(file, [], false);
139139

140140
expected = prefix_input_output{i, 3};
141141
assertEqual(filename, expected);
@@ -169,7 +169,7 @@ function test_spm_2_bids_smooth_fwhm()
169169

170170
print_here('%s\n', file);
171171

172-
filename = spm_2_bids(file, map);
172+
filename = spm_2_bids(file, map, false);
173173

174174
expected = prefix_and_output{i, 2};
175175
assertEqual(filename, expected);
@@ -208,7 +208,7 @@ function test_spm_2_bids_anat()
208208

209209
print_here('%s\n', file);
210210

211-
filename = spm_2_bids(file);
211+
filename = spm_2_bids(file, [], false);
212212

213213
expected = prefix_and_output{i, 2};
214214
assertEqual(filename, expected);
@@ -253,7 +253,7 @@ function test_spm_2_bids_func()
253253

254254
print_here('%s\n', file);
255255

256-
filename = spm_2_bids(file);
256+
filename = spm_2_bids(file, [], false);
257257

258258
expected = prefix_and_output{i, 2};
259259
assertEqual(filename, expected);

tests/test_spm_2_bids_metadata.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function test_spm_2_bids_metadata_basic()
1212

1313
file = 'wmsub-01_T1w.nii';
1414

15-
[~, ~, json] = spm_2_bids(file);
15+
[~, ~, json] = spm_2_bids(file, [], false);
1616

1717
assertEqual(fieldnames(json), {'filename'; 'content'});
1818
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii');
19-
assertEqual(json.content.Sources{1}, {'sub-01_desc-biasCorected_T1w.nii'});
19+
assertEqual(json.content.Sources{1}, 'sub-01/sub-01_space-individual_desc-biascor_T1w.nii');
2020

2121
end

0 commit comments

Comments
 (0)