Skip to content

Commit 30191a9

Browse files
committed
improve suffix management
1 parent 65eda26 commit 30191a9

File tree

4 files changed

+157
-37
lines changed

4 files changed

+157
-37
lines changed

src/checkCFG.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151
function fieldsToSet = mriDefaults(fieldsToSet)
5252

5353
% for file naming and JSON
54-
fieldsToSet.mri.contrastEnhancement = [];
55-
fieldsToSet.mri.phaseEncodingDirection = [];
56-
fieldsToSet.mri.reconstruction = [];
57-
fieldsToSet.mri.echo = [];
58-
fieldsToSet.mri.acquisition = [];
59-
fieldsToSet.mri.repetitionTime = [];
60-
61-
fieldsToSet.mri = orderfields(fieldsToSet.mri);
54+
fieldsToSet.suffix.contrastEnhancement = [];
55+
fieldsToSet.suffix.phaseEncodingDirection = [];
56+
fieldsToSet.suffix.reconstruction = [];
57+
fieldsToSet.suffix.echo = [];
58+
fieldsToSet.suffix.acquisition = [];
59+
fieldsToSet.suffix.repetitionTime = [];
60+
fieldsToSet.suffix.recording = [];
61+
62+
fieldsToSet.suffix = orderfields(fieldsToSet.suffix);
6263

6364
end
6465

src/createFilename.m

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
'echo', ...
106106
'phaseEncodingDirection', ...
107107
'reconstruction', ...
108+
'recording', ...
108109
};
109110

110111
targetFields = { ...
@@ -113,21 +114,22 @@
113114
'echo', ...
114115
'dir', ...
115116
'rec', ...
117+
'recording', ...
116118
};
117119

118120
for iField = 1:numel(fields2Check)
119121

120-
if isempty (cfg.mri.(fields2Check{iField})) %#ok<*GFLD>
122+
if isempty (cfg.suffix.(fields2Check{iField})) %#ok<*GFLD>
121123

122-
cfg.fileName.suffix.mri.(fields2Check{iField}) = ''; %#ok<*SFLD>
124+
cfg.fileName.suffix.(fields2Check{iField}) = ''; %#ok<*SFLD>
123125

124126
else
125127

126128
% upper camelCase and remove invalid characters
127-
thisField = getfield(cfg.mri, fields2Check{iField});
129+
thisField = getfield(cfg.suffix, fields2Check{iField});
128130
[~, validFieldName] = createValidName(thisField);
129131

130-
cfg.fileName.suffix.mri.(fields2Check{iField}) = ...
132+
cfg.fileName.suffix.(fields2Check{iField}) = ...
131133
['_' targetFields{iField} '-' validFieldName];
132134

133135
end
@@ -144,11 +146,12 @@
144146
pattern = cfg.fileName.pattern;
145147

146148
runSuffix = cfg.fileName.suffix.run;
147-
acqSuffix = cfg.fileName.suffix.mri.acquisition ;
148-
ceSuffix = cfg.fileName.suffix.mri.contrastEnhancement ;
149-
dirSuffix = cfg.fileName.suffix.mri.phaseEncodingDirection ;
150-
recSuffix = cfg.fileName.suffix.mri.reconstruction ;
151-
echoSuffix = cfg.fileName.suffix.mri.echo;
149+
acqSuffix = cfg.fileName.suffix.acquisition ;
150+
ceSuffix = cfg.fileName.suffix.contrastEnhancement ;
151+
dirSuffix = cfg.fileName.suffix.phaseEncodingDirection ;
152+
recSuffix = cfg.fileName.suffix.reconstruction ;
153+
echoSuffix = cfg.fileName.suffix.echo;
154+
recordingSuffix = cfg.fileName.suffix.recording;
152155

153156
thisDate = cfg.fileName.date;
154157

@@ -167,26 +170,31 @@
167170

168171
case 'func'
169172

170-
cfg.fileName.events = ...
171-
[fileNameBase, ...
173+
basename = [fileNameBase, ...
172174
acqSuffix, ceSuffix, ...
173175
dirSuffix, recSuffix, ...
174-
runSuffix, echoSuffix, ...
175-
'_events_date-' thisDate '.tsv'];
176+
runSuffix, echoSuffix];
176177

178+
case 'beh'
179+
180+
basename = ...
181+
[fileNameBase, ...
182+
acqSuffix, ...
183+
runSuffix];
184+
177185
otherwise
178186

179-
cfg.fileName.events = ...
180-
[fileNameBase, runSuffix, '_events_date-' thisDate '.tsv'];
187+
basename = [fileNameBase, runSuffix];
181188

182189
end
190+
191+
cfg.fileName.events = [basename, '_events_date-' thisDate '.tsv'];
183192

184-
cfg.fileName.stim = strrep(cfg.fileName.events, 'events', 'stim');
193+
cfg.fileName.stim = [basename, recordingSuffix, '_stim_date-' thisDate '.tsv'];
185194

186195
if cfg.eyeTracker.do
187196
cfg.fileName.eyetracker = ...
188-
[fileNameBase, acqSuffix, ...
189-
runSuffix, '_recording-eyetracking_physio_date-' thisDate '.edf'];
197+
[basename, '_recording-eyetracking_physio_date-' thisDate '.edf'];
190198
end
191199

192200
end

tests/test_checkCFG.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ function test_checkCfgBasic()
9191

9292
expectedCfgStructure.eyeTracker.do = false;
9393

94-
expectedCfgStructure.mri.contrastEnhancement = [];
95-
expectedCfgStructure.mri.phaseEncodingDirection = [];
96-
expectedCfgStructure.mri.reconstruction = [];
97-
expectedCfgStructure.mri.echo = [];
98-
expectedCfgStructure.mri.acquisition = [];
99-
expectedCfgStructure.mri.repetitionTime = [];
94+
expectedCfgStructure.suffix.contrastEnhancement = [];
95+
expectedCfgStructure.suffix.phaseEncodingDirection = [];
96+
expectedCfgStructure.suffix.reconstruction = [];
97+
expectedCfgStructure.suffix.echo = [];
98+
expectedCfgStructure.suffix.acquisition = [];
99+
expectedCfgStructure.suffix.repetitionTime = [];
100+
expectedCfgStructure.suffix.recording = [];
100101

101102
expectedCfgStructure.bids.mri.RepetitionTime = [];
102103
expectedCfgStructure.bids.mri.SliceTiming = '';

tests/test_createFilename.m

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ function test_createFilenameMriSuffix()
107107
cfg.eyeTracker.do = false;
108108
cfg.testingDevice = 'mri';
109109

110-
cfg.mri.reconstruction = 'fast recon';
111-
cfg.mri.contrastEnhancement = 'test';
112-
cfg.mri.phaseEncodingDirection = 'y pos';
113-
cfg.mri.echo = '1';
114-
cfg.mri.acquisition = ' new tYpe';
110+
cfg.suffix.recording = 'respi pulse';
111+
cfg.suffix.reconstruction = 'fast recon';
112+
cfg.suffix.contrastEnhancement = 'test';
113+
cfg.suffix.phaseEncodingDirection = 'y pos';
114+
cfg.suffix.echo = '1';
115+
cfg.suffix.acquisition = ' new tYpe';
115116

116117
cfg = createFilename(cfg);
117118

@@ -125,6 +126,63 @@ function test_createFilenameMriSuffix()
125126
'_acq-newTYpe_ce-test_dir-yPos_rec-fastRecon', ...
126127
'_run-005_echo-1_events_date-' ...
127128
cfg.fileName.date '.tsv'];
129+
130+
stimFilename = ['sub-ssri003_ses-004_task-rest', ...
131+
'_acq-newTYpe_ce-test_dir-yPos_rec-fastRecon', ...
132+
'_run-005_echo-1_recording-respiPulse_stim_date-' ...
133+
cfg.fileName.date '.tsv'];
134+
135+
%% tests
136+
% make sure the func dir is created
137+
assertTrue(exist(funcDir, 'dir') == 7);
138+
139+
% make sure the right filenames are created
140+
assertEqual(cfg.fileName.base, baseFilename);
141+
assertEqual(cfg.fileName.events, eventFilename);
142+
assertEqual(cfg.fileName.stim, stimFilename);
143+
144+
end
145+
146+
function test_createFilenameBehSuffix()
147+
148+
outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
149+
150+
%% set up
151+
152+
cfg.verbose = true;
153+
cfg.subject.subjectGrp = 'ssri';
154+
cfg.subject.subjectNb = 2;
155+
cfg.subject.runNb = 3;
156+
cfg.task.name = 'rest';
157+
cfg.dir.output = outputDir;
158+
159+
cfg.eyeTracker.do = false;
160+
cfg.testingDevice = 'pc';
161+
162+
cfg.suffix.recording = 'respi pulse';
163+
cfg.suffix.reconstruction = 'fast recon';
164+
cfg.suffix.contrastEnhancement = 'test';
165+
cfg.suffix.phaseEncodingDirection = 'y pos';
166+
cfg.suffix.echo = '1';
167+
cfg.suffix.acquisition = ' new tYpe';
168+
169+
cfg = createFilename(cfg);
170+
171+
%% data to test against
172+
173+
funcDir = fullfile(outputDir, 'source', 'sub-ssri002', 'ses-001', 'beh');
174+
175+
baseFilename = 'sub-ssri002_ses-001_task-rest';
176+
177+
eventFilename = ['sub-ssri002_ses-001_task-rest', ...
178+
'_acq-newTYpe', ...
179+
'_run-003_events_date-' ...
180+
cfg.fileName.date '.tsv'];
181+
182+
stimFilename = ['sub-ssri002_ses-001_task-rest', ...
183+
'_acq-newTYpe', ...
184+
'_run-003_recording-respiPulse_stim_date-' ...
185+
cfg.fileName.date '.tsv'];
128186

129187
%% tests
130188
% make sure the func dir is created
@@ -133,6 +191,58 @@ function test_createFilenameMriSuffix()
133191
% make sure the right filenames are created
134192
assertEqual(cfg.fileName.base, baseFilename);
135193
assertEqual(cfg.fileName.events, eventFilename);
194+
assertEqual(cfg.fileName.stim, stimFilename);
195+
196+
197+
end
198+
199+
function test_createFilenameEegSuffix()
200+
201+
outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output');
202+
203+
%% set up
204+
205+
cfg.verbose = true;
206+
cfg.subject.subjectNb = 2;
207+
cfg.subject.runNb = 3;
208+
cfg.task.name = 'rest';
209+
cfg.dir.output = outputDir;
210+
211+
cfg.eyeTracker.do = false;
212+
cfg.testingDevice = 'eeg';
213+
214+
cfg.suffix.recording = 'respi pulse';
215+
cfg.suffix.reconstruction = 'fast recon';
216+
cfg.suffix.contrastEnhancement = 'test';
217+
cfg.suffix.phaseEncodingDirection = 'y pos';
218+
cfg.suffix.echo = '1';
219+
cfg.suffix.acquisition = ' new tYpe';
220+
221+
cfg = createFilename(cfg);
222+
223+
%% data to test against
224+
225+
funcDir = fullfile(outputDir, 'source', 'sub-002', 'ses-001', 'eeg');
226+
227+
baseFilename = 'sub-002_ses-001_task-rest';
228+
229+
eventFilename = ['sub-002_ses-001_task-rest', ...
230+
'_run-003_events_date-' ...
231+
cfg.fileName.date '.tsv'];
232+
233+
stimFilename = ['sub-002_ses-001_task-rest', ...
234+
'_run-003_recording-respiPulse_stim_date-' ...
235+
cfg.fileName.date '.tsv'];
236+
237+
%% tests
238+
% make sure the func dir is created
239+
assertTrue(exist(funcDir, 'dir') == 7);
240+
241+
% make sure the right filenames are created
242+
assertEqual(cfg.fileName.base, baseFilename);
243+
assertEqual(cfg.fileName.events, eventFilename);
244+
assertEqual(cfg.fileName.stim, stimFilename);
245+
136246

137247
end
138248

0 commit comments

Comments
 (0)