Skip to content

Commit 8b54b64

Browse files
committed
make sure identify sources skip files with unknown suffixes
1 parent a2f5328 commit 8b54b64

File tree

2 files changed

+32
-48
lines changed

2 files changed

+32
-48
lines changed

src/utils/identify_sources.m

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,6 @@
3939
add_deformation_field = false;
4040
deformation_field = 'TODO: add deformation field';
4141

42-
% TODO? grab all the anat suffixes from BIDS schema?
43-
covered_suffixes = {'T1w', ...
44-
'T2w', ...
45-
'PDw', ...
46-
'T2starw', ...
47-
'inplaneT1', ...
48-
'inplaneT2', ...
49-
'PD', ...
50-
'PDT2', ...
51-
'T2star', ...
52-
'FLASH', ...
53-
'T1map', ...
54-
'T2map', ...
55-
'T2starmap', ...
56-
'R1map', ...
57-
'R2map', ...
58-
'R2starmap', ...
59-
'PDmap', ...
60-
'UNIT1'};
61-
6242
args = inputParser;
6343

6444
addOptional(args, 'derivatives', pwd, @ischar);
@@ -75,6 +55,7 @@
7555
return
7656
end
7757

58+
% deal with SPM's funky suffixes
7859
if endsWith(derivatives, '_seg8.mat')
7960

8061
prefix_based = false;
@@ -91,6 +72,11 @@
9172

9273
bf = bids.File(derivatives, 'verbose', verbose, 'use_schema', false);
9374

75+
if ~ismember(bf.suffix, fieldnames(map.cfg.schema.content.objects.suffixes))
76+
sources{1} = 'TODO';
77+
return
78+
end
79+
9480
% deal with surface data
9581
if strcmp(bf.extension, '.surf.gii')
9682
bf.extension = '.nii';
@@ -171,7 +157,7 @@
171157
% for anatomical data we assume that
172158
% the deformation field comes from the anatomical file itself
173159
if (~isempty(bf.modality) && ismember(bf.modality, {'anat'})) || ...
174-
(~isempty(bf.suffix) && ismember(bf.suffix, covered_suffixes))
160+
(~isempty(bf.suffix) && ~isempty(map.cfg.schema.find_suffix_group('anat', bf.suffix)))
175161

176162
bf.prefix = 'y_';
177163
bf = bf.update;

tests/test_spm_2_bids_metadata.m

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,91 +8,89 @@
88
initTestSuite;
99
end
1010

11-
function test_spm_2_bids_metadata_surface()
11+
function test_spm_2_bids_metadata_func()
1212

13-
file = 'wmsub-01_T1w.surf.gii';
13+
file = 'wuasub-01_task-foo_bold.nii';
1414

1515
[~, ~, json] = spm_2_bids(file, [], false);
1616

1717
assertEqual(fieldnames(json), {'filename'; 'content'});
18-
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
18+
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_task-foo_bold.nii.gz');
1919
assertEqual(json.content.Sources{1}, ...
20-
'sub-01/sub-01_space-IXI549Space_desc-preproc_T1w.nii');
20+
'sub-01/sub-01_task-foo_space-individual_desc-realignUnwarp_bold.nii');
21+
assertEqual(json.content.Sources{2}, 'TODO: add deformation field');
2122

2223
bids.util.jsonencode(json.filename, json.content);
2324

2425
end
25-
function test_spm_2_bids_metadata_probseg()
2626

27-
file = 'c1sub-01_T1w.nii';
27+
function test_spm_2_bids_non_raw_suffix()
28+
29+
file = 'wuasub-01_task-foo_mask.nii';
2830

2931
[~, ~, json] = spm_2_bids(file, [], false);
3032

3133
assertEqual(fieldnames(json), {'filename'; 'content'});
32-
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
33-
assertEqual(json.content.Manual, false);
34+
assertEqual(json.content.RawSources{1}, 'TODO');
35+
assertEqual(json.content.Sources{1}, 'TODO');
3436

3537
bids.util.jsonencode(json.filename, json.content);
3638

3739
end
3840

39-
function test_spm_2_bids_metadata_smoothed_data()
41+
function test_spm_2_bids_metadata_surface()
4042

41-
file = 's6wusub-01_task-auditory_bold.nii';
43+
file = 'wmsub-01_T1w.surf.gii';
4244

4345
[~, ~, json] = spm_2_bids(file, [], false);
4446

4547
assertEqual(fieldnames(json), {'filename'; 'content'});
46-
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_task-auditory_bold.nii.gz');
48+
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
4749
assertEqual(json.content.Sources{1}, ...
48-
'sub-01/sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii');
50+
'sub-01/sub-01_space-IXI549Space_desc-preproc_T1w.nii');
4951

5052
bids.util.jsonencode(json.filename, json.content);
5153

5254
end
5355

54-
function test_spm_2_bids_metadata_source_must_be_empty()
56+
function test_spm_2_bids_metadata_probseg()
5557

56-
file = 'msub-01_T1w.nii';
58+
file = 'c1sub-01_T1w.nii';
5759

5860
[~, ~, json] = spm_2_bids(file, [], false);
5961

6062
assertEqual(fieldnames(json), {'filename'; 'content'});
61-
assertEqual(fieldnames(json.content), {'Description'; 'RawSources'; 'SpatialReference'});
6263
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
64+
assertEqual(json.content.Manual, false);
6365

6466
bids.util.jsonencode(json.filename, json.content);
6567

6668
end
6769

68-
function test_spm_2_bids_metadata_anat()
70+
function test_spm_2_bids_metadata_smoothed_data()
6971

70-
file = 'wmsub-01_T1w.nii';
72+
file = 's6wusub-01_task-auditory_bold.nii';
7173

7274
[~, ~, json] = spm_2_bids(file, [], false);
7375

7476
assertEqual(fieldnames(json), {'filename'; 'content'});
75-
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
77+
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_task-auditory_bold.nii.gz');
7678
assertEqual(json.content.Sources{1}, ...
77-
'sub-01/sub-01_space-individual_desc-biascor_T1w.nii');
78-
assertEqual(json.content.Sources{2}, ...
79-
'sub-01/sub-01_from-T1w_to-IXI549Space_mode-image_xfm.nii');
79+
'sub-01/sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii');
8080

8181
bids.util.jsonencode(json.filename, json.content);
8282

8383
end
8484

85-
function test_spm_2_bids_metadata_func()
85+
function test_spm_2_bids_metadata_source_must_be_empty()
8686

87-
file = 'wuasub-01_task-foo_bold.nii';
87+
file = 'msub-01_T1w.nii';
8888

8989
[~, ~, json] = spm_2_bids(file, [], false);
9090

9191
assertEqual(fieldnames(json), {'filename'; 'content'});
92-
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_task-foo_bold.nii.gz');
93-
assertEqual(json.content.Sources{1}, ...
94-
'sub-01/sub-01_task-foo_space-individual_desc-realignUnwarp_bold.nii');
95-
assertEqual(json.content.Sources{2}, 'TODO: add deformation field');
92+
assertEqual(fieldnames(json.content), {'Description'; 'RawSources'; 'SpatialReference'});
93+
assertEqual(json.content.RawSources{1}, 'sub-01/sub-01_T1w.nii.gz');
9694

9795
bids.util.jsonencode(json.filename, json.content);
9896

0 commit comments

Comments
 (0)