|
11 | 11 | % |
12 | 12 | % |
13 | 13 | % See test_createFilename in the test folder for more details on how to use it. |
14 | | - |
| 14 | + |
15 | 15 | cfg = checkCFG(cfg); |
16 | | - |
| 16 | + |
17 | 17 | cfg.fileName.pattern = ['%0' num2str(cfg.fileName.zeroPadding) '.0f']; |
18 | 18 | cfg.fileName.date = datestr(now, cfg.fileName.dateFormat); |
19 | | - |
| 19 | + |
20 | 20 | if ~isfield(cfg, 'task') |
21 | 21 | error('createFilename: missing a task name. i.e cfg.task.name'); |
22 | 22 | end |
23 | | - |
| 23 | + |
24 | 24 | cfg = getModality(cfg); |
25 | | - |
| 25 | + |
26 | 26 | cfg = createDirectories(cfg); |
27 | | - |
| 27 | + |
28 | 28 | cfg = setSuffixes(cfg); |
29 | | - |
| 29 | + |
30 | 30 | cfg = setFilenames(cfg); |
31 | | - |
| 31 | + |
32 | 32 | talkToMe(cfg); |
33 | | - |
| 33 | + |
34 | 34 | cfg = orderfields(cfg); |
35 | 35 | cfg.fileName = orderfields(cfg.fileName); |
36 | 36 | cfg.dir = orderfields(cfg.dir); |
37 | | - |
| 37 | + |
38 | 38 | end |
39 | 39 |
|
40 | 40 | function cfg = getModality(cfg) |
41 | | - |
| 41 | + |
42 | 42 | switch lower(cfg.testingDevice) |
43 | 43 | case 'pc' |
44 | 44 | modality = 'beh'; |
|
53 | 53 | otherwise |
54 | 54 | modality = 'beh'; |
55 | 55 | end |
56 | | - |
| 56 | + |
57 | 57 | cfg.fileName.modality = modality; |
58 | | - |
| 58 | + |
59 | 59 | end |
60 | 60 |
|
61 | 61 | function [subjectGrp, subjectNb, sessionNb, modality, taskName] = extractInput(cfg) |
62 | | - |
| 62 | + |
63 | 63 | subjectGrp = cfg.subject.subjectGrp; |
64 | 64 | subjectNb = cfg.subject.subjectNb; |
65 | 65 | sessionNb = cfg.subject.sessionNb; |
66 | 66 | modality = cfg.fileName.modality; |
67 | 67 | taskName = cfg.fileName.task; |
68 | | - |
| 68 | + |
69 | 69 | if isempty(sessionNb) |
70 | 70 | sessionNb = 1; |
71 | 71 | end |
72 | | - |
| 72 | + |
73 | 73 | end |
74 | 74 |
|
75 | 75 | function cfg = createDirectories(cfg) |
76 | | - |
| 76 | + |
77 | 77 | [subjectGrp, subjectNb, sessionNb, modality] = extractInput(cfg); |
78 | | - |
| 78 | + |
79 | 79 | pattern = cfg.fileName.pattern; |
80 | | - |
| 80 | + |
81 | 81 | % output dir |
82 | 82 | cfg.dir.outputSubject = fullfile ( ... |
83 | 83 | cfg.dir.output, ... |
84 | 84 | 'source', ... |
85 | 85 | ['sub-' subjectGrp, sprintf(pattern, subjectNb)], ... |
86 | 86 | ['ses-', sprintf(pattern, sessionNb)]); |
87 | | - |
| 87 | + |
88 | 88 | [~, ~, ~] = mkdir(cfg.dir.output); |
89 | 89 | [~, ~, ~] = mkdir(cfg.dir.outputSubject); |
90 | 90 | [~, ~, ~] = mkdir(fullfile(cfg.dir.outputSubject, modality)); |
91 | | - |
| 91 | + |
92 | 92 | if cfg.eyeTracker.do |
93 | 93 | [~, ~, ~] = mkdir(fullfile(cfg.dir.outputSubject, 'eyetracker')); |
94 | 94 | end |
95 | | - |
| 95 | + |
96 | 96 | end |
97 | 97 |
|
98 | 98 | function cfg = setSuffixes(cfg) |
99 | | - |
| 99 | + |
100 | 100 | cfg.fileName.suffix.run = ['_run-' sprintf(cfg.fileName.pattern, cfg.subject.runNb)]; |
101 | | - |
| 101 | + |
102 | 102 | % set values for the suffixes for the different fields in the BIDS name |
103 | 103 | fields2Check = { ... |
104 | 104 | 'contrastEnhancement', ... |
|
107 | 107 | 'echo', ... |
108 | 108 | 'acquisition' |
109 | 109 | }; |
110 | | - |
| 110 | + |
111 | 111 | for iField = 1:numel(fields2Check) |
112 | 112 | if isempty (cfg.mri.(fields2Check{iField})) %#ok<*GFLD> |
113 | 113 | cfg.fileName.suffix.mri.(fields2Check{iField}) = ''; %#ok<*SFLD> |
|
116 | 116 | ['_' fields2Check{iField} '-' getfield(cfg.mri, fields2Check{iField})]; |
117 | 117 | end |
118 | 118 | end |
119 | | - |
| 119 | + |
120 | 120 | cfg.fileName.suffix = orderfields(cfg.fileName.suffix); |
121 | | - |
| 121 | + |
122 | 122 | end |
123 | 123 |
|
124 | 124 | function cfg = setFilenames(cfg) |
125 | | - |
| 125 | + |
126 | 126 | [subjectGrp, subjectNb, sessionNb, modality, taskName] = extractInput(cfg); |
127 | | - |
| 127 | + |
128 | 128 | pattern = cfg.fileName.pattern; |
129 | | - |
| 129 | + |
130 | 130 | runSuffix = cfg.fileName.suffix.run; |
131 | 131 | acqSuffix = cfg.fileName.suffix.mri.acquisition ; |
132 | 132 | ceSuffix = cfg.fileName.suffix.mri.contrastEnhancement ; |
133 | 133 | dirSuffix = cfg.fileName.suffix.mri.phaseEncodingDirection ; |
134 | 134 | recSuffix = cfg.fileName.suffix.mri.reconstruction ; |
135 | 135 | echoSuffix = cfg.fileName.suffix.mri.echo; |
136 | | - |
| 136 | + |
137 | 137 | thisDate = cfg.fileName.date; |
138 | | - |
| 138 | + |
139 | 139 | cfg.fileName.datasetDescription = fullfile ( ... |
140 | 140 | cfg.dir.output, ... |
141 | 141 | 'dataset_description.json'); |
142 | | - |
| 142 | + |
143 | 143 | % create base fileName |
144 | 144 | fileNameBase = ... |
145 | 145 | ['sub-', subjectGrp, sprintf(pattern, subjectNb), ... |
146 | 146 | '_ses-', sprintf(pattern, sessionNb), ... |
147 | 147 | '_task-', taskName]; |
148 | 148 | cfg.fileName.base = fileNameBase; |
149 | | - |
| 149 | + |
150 | 150 | switch modality |
151 | | - |
| 151 | + |
152 | 152 | case 'func' |
153 | | - |
| 153 | + |
154 | 154 | cfg.fileName.events = ... |
155 | 155 | [fileNameBase, ... |
156 | 156 | acqSuffix, ceSuffix, ... |
157 | 157 | dirSuffix, recSuffix, ... |
158 | 158 | runSuffix, echoSuffix, ... |
159 | 159 | '_events_date-' thisDate '.tsv']; |
160 | | - |
| 160 | + |
161 | 161 | otherwise |
162 | | - |
| 162 | + |
163 | 163 | cfg.fileName.events = ... |
164 | 164 | [fileNameBase, runSuffix, '_events_date-' thisDate '.tsv']; |
165 | | - |
| 165 | + |
166 | 166 | end |
167 | | - |
| 167 | + |
168 | 168 | cfg.fileName.stim = strrep(cfg.fileName.events, 'events', 'stim'); |
169 | | - |
| 169 | + |
170 | 170 | if cfg.eyeTracker.do |
171 | 171 | cfg.fileName.eyetracker = ... |
172 | 172 | [fileNameBase, acqSuffix, ... |
173 | 173 | runSuffix, '_eyetrack_date-' thisDate '.edf']; |
174 | 174 | end |
175 | | - |
| 175 | + |
176 | 176 | end |
177 | 177 |
|
178 | 178 | function talkToMe(cfg) |
179 | | - |
180 | | - fprintf(1, '\nData will be saved in this directory:\n\t%s\n', ... |
181 | | - fullfile(cfg.dir.outputSubject, cfg.fileName.modality)); |
182 | | - |
183 | | - fprintf(1, '\nData will be saved in this file:\n\t%s\n', ... |
184 | | - cfg.fileName.events); |
185 | | - |
186 | | - if cfg.eyeTracker.do |
187 | | - |
188 | | - fprintf(1, '\nEyetracking data will be saved in this directory:\n\t%s\n', ... |
189 | | - fullfile(cfg.dir.outputSubject, 'eyetracker')); |
190 | | - |
191 | | - fprintf(1, '\nEyetracking data will be saved in this file:\n\t%s\n', ... |
192 | | - cfg.fileName.eyetracker); |
193 | | - |
| 179 | + |
| 180 | + if cfg.verbose |
| 181 | + |
| 182 | + fprintf(1, '\nData will be saved in this directory:\n\t%s\n', ... |
| 183 | + fullfile(cfg.dir.outputSubject, cfg.fileName.modality)); |
| 184 | + |
| 185 | + fprintf(1, '\nData will be saved in this file:\n\t%s\n', ... |
| 186 | + cfg.fileName.events); |
| 187 | + |
| 188 | + if cfg.eyeTracker.do |
| 189 | + |
| 190 | + fprintf(1, '\nEyetracking data will be saved in this directory:\n\t%s\n', ... |
| 191 | + fullfile(cfg.dir.outputSubject, 'eyetracker')); |
| 192 | + |
| 193 | + fprintf(1, '\nEyetracking data will be saved in this file:\n\t%s\n', ... |
| 194 | + cfg.fileName.eyetracker); |
| 195 | + |
| 196 | + end |
| 197 | + |
194 | 198 | end |
195 | | - |
| 199 | + |
196 | 200 | end |
0 commit comments