1+ function expParameters = createFilename(expParameters , cfg )
2+ % create the BIDS compliant directories and filenames for the behavioral output for this subject /
3+ % session / run.
4+ % Will also create the right filename for the eyetracking data file.
5+ %
6+ % For the moment the date of acquisition is appreneded to the filename
7+ %
8+ % can work for behavioral experiment if cfg.device is set to 'PC'
9+ % can work for fMRI experiment if cfg.device is set to 'scanner'
10+ % can work for simple eyetracking data if cfg.eyeTracker is set to 1
11+ %
12+ % BOLD
13+ % sub-<label>[_ses-<label>]_task-<label>[_acq-<label>][_ce-<label>][_dir-<label>][_rec-<label>][_run-<index>][_echo-<index>]_<contrast_label>.nii[.gz]
14+ %
15+ % iEEG
16+ % sub-<label>[_ses-<label>]_task-<task_label>[_run-<index>]_ieeg.json
17+ %
18+ % EEG
19+ % sub-<label>[_ses-<label>]_task-<label>[_run-<index>]_eeg.<manufacturer_specific_extension>
20+ %
21+ % EYETRACKER
22+ % sub-<participant_label>[_ses-<label>][_acq-<label>]_task-<task_label>_eyetrack.<manufacturer_specific_extension>
23+
24+ zeroPadding = 3 ;
25+ pattern = [' %0' num2str(zeroPadding ) ' .0f' ];
26+
27+ dateFormat = ' yyyymmdd_HHMM' ;
28+
29+
30+
31+ % extract input
32+ subjectGrp = expParameters .subjectGrp ;
33+ subjectNb = expParameters .subjectNb ;
34+ sessionNb = expParameters .sessionNb ;
35+ runNb = expParameters .runNb ;
36+
37+ expParameters.date = datestr(now , dateFormat );
38+
39+ % output dir
40+ expParameters.outputDir = fullfile (...
41+ expParameters .outputDir , ...
42+ ' source' , ...
43+ [' sub-' subjectGrp , sprintf(pattern , subjectNb )], ...
44+ [' ses-' , sprintf(pattern , sessionNb )]);
45+
46+ % create base filename
47+ expParameters.fileName.base = ...
48+ [' sub-' , subjectGrp , sprintf(pattern , subjectNb ), ...
49+ ' _ses-' , sprintf(pattern , sessionNb ) , ...
50+ ' _task-' , expParameters .task ];
51+
52+ runSuffix = [' _run-' sprintf(pattern , runNb )];
53+
54+
55+ switch lower(cfg .device )
56+ case ' pc'
57+ modality = ' beh' ;
58+ case ' scanner'
59+ modality = ' func' ;
60+ otherwise
61+ modality = ' beh' ;
62+ end
63+
64+ expParameters.modality = modality ;
65+
66+
67+ % set values for the suffixes for the different fields in the BIDS name
68+ fields2Check = { ...
69+ ' ce' , ...
70+ ' dir' , ... % For BIDS file naming: phase encoding direction of acquisition for fMRI
71+ ' rec' , ... % For BIDS file naming: reconstruction of fMRI images
72+ ' echo' , ... % For BIDS file naming: echo fMRI images
73+ ' acq' % For BIDS file naming: acquisition of fMRI images
74+ };
75+
76+ for iField = 1 : numel(fields2Check )
77+ if isempty (getfield(expParameters , fields2Check{iField }) ) % #ok<*GFLD>
78+ expParameters = setfield(expParameters , [fields2Check{iField } ' Suffix' ], ...
79+ ' ' ); % #ok<*SFLD>
80+ else
81+ expParameters = setfield(expParameters , [fields2Check{iField } ' Suffix' ], ...
82+ [' _' fields2Check{iField } ' -' getfield(expParameters , fields2Check{iField })]);
83+ end
84+ end
85+
86+
87+ %% create directories
88+ [~ , ~ , ~ ] = mkdir(expParameters .outputDir );
89+ [~ , ~ , ~ ] = mkdir(fullfile(expParameters .outputDir , modality ));
90+
91+ if cfg .eyeTracker
92+ [~ , ~ , ~ ] = mkdir(fullfile(expParameters .outputDir , ' eyetracker' ));
93+ end
94+
95+
96+ %% create filenames
97+
98+ switch modality
99+
100+ case ' beh'
101+
102+ expParameters.fileName.events = ...
103+ [expParameters .fileName .base , runSuffix , ' _events_date-' expParameters .date ' .tsv' ];
104+
105+ case ' func'
106+
107+ expParameters.fileName.events = ...
108+ [expParameters .fileName .base , ...
109+ expParameters .acqSuffix , expParameters .ceSuffix , ...
110+ expParameters .dirSuffix , expParameters .recSuffix , ...
111+ runSuffix , expParameters .echoSuffix , ...
112+ ' _events_date-' expParameters .date ' .tsv' ];
113+
114+ end
115+
116+ if cfg .eyeTracker
117+
118+ expParameters.fileName.eyetracker = ...
119+ [expParameters .fileName .base , expParameters .acqSuffix , ...
120+ runSuffix , ' _eyetrack_date-' expParameters .date ' .edf' ];
121+
122+ end
123+
124+
125+ end
0 commit comments