-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_bidspm_copy.m
145 lines (107 loc) · 4.35 KB
/
test_bidspm_copy.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
function test_suite = test_bidspm_copy %#ok<*STOUT>
% (C) Copyright 2023 bidspm developers
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end
function test_copy_filter()
inputPath = fullfile(getMoaeDir(), 'inputs', 'fmriprep');
% add dummy aroma file to input folder
BIDS = bids.layout(inputPath, ...
'verbose', false, ...
'use_schema', false);
sourceFile = bids.query(BIDS, 'data', ...
'suffix', 'bold', ...
'desc', 'preproc', ...
'space', 'T1w');
bf = bids.File(sourceFile{1});
bf.entities.desc = 'smoothAROMAnonaggr';
bf = bf.update;
destFile = bids.internal.file_utils(sourceFile, 'filename', bf.filename);
if exist(destFile{1}, 'file')
delete(destFile{1});
end
copyfile(sourceFile{1}, destFile{1});
%% with simple filter file
bids_filter_file = fullfile(tmpName(), 'bids_filter_file.json');
bids.util.jsonencode(bids_filter_file, ...
struct('bold', struct('modality', 'func')));
% filter takes precedence over predefined opt.query
% so anat should not be copied
opt.query.modality = {'anat'};
outputPath = tmpName();
bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'task', {'auditory'}, ...
'space', {'MNI152NLin6Asym', 'T1w'}, ...
'bids_filter_file', bids_filter_file, ...
'verbosity', 0, ...
'options', opt);
BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
assertEqual(numel(bids.query(BIDS, 'data')), 5);
%% now with more complex filter as struct
bids_filter_file = struct('bold', struct('modality', 'func', ...
'suffix', 'bold', ...
'desc', {'smoothAROMAnonaggr'; ...
'preproc'}));
bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'task', {'auditory'}, ...
'space', {'MNI152NLin6Asym', 'T1w'}, ...
'bids_filter_file', bids_filter_file, ...
'verbosity', 0);
BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
assertEqual(numel(bids.query(BIDS, 'data')), 6);
delete(destFile{1});
end
function test_copy()
inputPath = fullfile(getMoaeDir(), 'inputs', 'fmriprep');
outputPath = tmpName();
bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'task', {'auditory'}, ...
'space', {'MNI152NLin6Asym', 'T1w'}, ...
'verbosity', 0);
BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
assertEqual(numel(bids.query(BIDS, 'data')), 7);
% check that do no overwrite by default
% TODO
% bids.matlab still copies nii.gz because the files were unzipped
% force should be able to detect unzipped versions of files
bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'task', {'auditory'}, ...
'space', {'MNI152NLin6Asym'}, ...
'verbosity', 0);
BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
assertEqual(numel(bids.query(BIDS, 'data')), 7);
end
function test_copy_anat_only()
inputPath = fullfile(getMoaeDir(), 'inputs', 'fmriprep');
outputPath = tmpName();
opt.query.modality = {'anat'};
bidspm(inputPath, outputPath, 'subject', ...
'action', 'copy', ...
'task', {'auditory'}, ...
'space', {'MNI152NLin6Asym', 'T1w'}, ...
'verbosity', 0, ...
'options', opt);
BIDS = bids.layout(fullfile(outputPath, 'derivatives', 'bidspm-preproc'), ...
'verbose', false, ...
'use_schema', false);
assertEqual(numel(bids.query(BIDS, 'data')), 2);
end
function pth = tmpName()
pth = tempname();
mkdir(pth);
end