|
25 | 25 | % 'wra' |
26 | 26 | % those will throw warnings |
27 | 27 |
|
| 28 | + % TODO adapt in case prefixes have been changed from SPM defaults |
| 29 | + |
28 | 30 | % TODO |
29 | 31 | % functional to anatomical coregistration |
30 | 32 | % anatomical to functional coregistration |
31 | 33 |
|
32 | 34 | default_map = Mapping(); |
33 | 35 | default_map = default_map.default(); |
34 | 36 |
|
35 | | - sources = ''; |
| 37 | + sources = {}; |
36 | 38 |
|
37 | 39 | prefix_based = true; |
38 | 40 |
|
39 | | - add_deformation_field = false; |
40 | | - deformation_field = 'TODO: add deformation field'; |
41 | | - |
42 | 41 | args = inputParser; |
43 | 42 |
|
44 | 43 | addOptional(args, 'derivatives', pwd, @ischar); |
|
72 | 71 |
|
73 | 72 | bf = bids.File(derivatives, 'verbose', verbose, 'use_schema', false); |
74 | 73 |
|
| 74 | + % unknown suffix |
75 | 75 | if ~ismember(bf.suffix, fieldnames(map.cfg.schema.content.objects.suffixes)) |
76 | | - sources{1} = 'TODO'; |
| 76 | + sources{1, 1} = 'TODO'; |
77 | 77 | return |
78 | 78 | end |
79 | 79 |
|
|
83 | 83 | prefix_based = false; |
84 | 84 | end |
85 | 85 |
|
86 | | - % anything prefix based |
87 | | - if prefix_based |
| 86 | + % unless this file already contains a derivative entity |
| 87 | + % it needs at least 2 characters for this file |
| 88 | + % to have some provenance in the derivatives |
| 89 | + if length(bf.prefix) == 1 && any(ismember(fieldnames(bf.entities), map.cfg.entity_order)) |
| 90 | + bf.prefix = ''; |
| 91 | + sources{1, 1} = fullfile(bf.bids_path, bf.filename); |
| 92 | + return |
| 93 | + end |
88 | 94 |
|
89 | | - if numel(bf.prefix) < 2 |
| 95 | + sources = add_deformation_field(bf, sources, map, verbose); |
90 | 96 |
|
91 | | - % needs at least 2 characters for this file to have some provenance in the |
92 | | - % derivatives |
| 97 | + % anything prefix based |
| 98 | + if prefix_based |
93 | 99 |
|
94 | | - % TODO: files that have been realigned but not resliced have no |
95 | | - % "prefix" so we may miss some transformation |
| 100 | + [status, bf] = update_prefix(bf, map); |
96 | 101 |
|
| 102 | + if status == 0 |
97 | 103 | return |
98 | 104 |
|
99 | | - else |
100 | | - % remove the prefix of the last step |
101 | | - |
102 | | - if startsWith(bf.prefix, 's') |
103 | | - |
104 | | - % in case the prefix includes a number to denotate the FXHM used |
105 | | - % for smoothing |
106 | | - starts_with_fwhm = regexp(bf.prefix, '^s[0-9]*', 'match'); |
107 | | - if ~isempty(starts_with_fwhm) |
108 | | - bf.prefix = bf.prefix(length(starts_with_fwhm{1}) + 1:end); |
109 | | - else |
110 | | - bf.prefix = bf.prefix(2:end); |
111 | | - end |
112 | | - |
113 | | - elseif ismember(bf.prefix(1:2), {'c1', 'c2', 'c3', 'c4', 'c5'}) |
114 | | - % bias corrected image |
115 | | - sources = 'TODO'; |
116 | | - return |
117 | | - |
118 | | - elseif startsWith(bf.prefix, 'u') |
119 | | - bf.prefix = bf.prefix(2:end); |
120 | | - |
121 | | - elseif startsWith(bf.prefix, 'w') |
122 | | - bf.prefix = bf.prefix(2:end); |
123 | | - add_deformation_field = true; |
124 | | - |
125 | | - elseif startsWith(bf.prefix, 'rp_a') |
126 | | - bf.prefix = bf.prefix(4:end); |
127 | | - |
128 | | - elseif startsWith(bf.prefix, 'mean') |
129 | | - % TODO mean may involve several files from the source (across runs |
130 | | - % and sessions |
131 | | - % prefixes = { |
132 | | - % 'mean' |
133 | | - % 'meanu' |
134 | | - % 'meanua' |
135 | | - % }; |
136 | | - sources = 'TODO'; |
137 | | - return |
138 | | - |
139 | | - else |
140 | | - % no idea |
141 | | - sources = 'TODO'; |
142 | | - return |
143 | | - |
144 | | - end |
| 105 | + elseif status == 1 |
| 106 | + sources = 'TODO'; |
| 107 | + return |
145 | 108 |
|
146 | 109 | end |
| 110 | + |
147 | 111 | end |
148 | 112 |
|
149 | 113 | % call spm_2_bids what is the filename from the previous step |
150 | 114 | new_filename = spm_2_bids(bf.filename, map, verbose); |
151 | 115 |
|
152 | | - sources{1, 1} = fullfile(bf.bids_path, new_filename); |
| 116 | + sources{end + 1, 1} = fullfile(bf.bids_path, new_filename); |
153 | 117 |
|
154 | | - % for normalized images |
155 | | - if add_deformation_field |
| 118 | +end |
156 | 119 |
|
157 | | - % for anatomical data we assume that |
158 | | - % the deformation field comes from the anatomical file itself |
159 | | - if (~isempty(bf.modality) && ismember(bf.modality, {'anat'})) || ... |
160 | | - (~isempty(bf.suffix) && ~isempty(map.cfg.schema.find_suffix_group('anat', bf.suffix))) |
| 120 | +function sources = add_deformation_field(bf, sources, map, verbose) |
161 | 121 |
|
162 | | - bf.prefix = 'y_'; |
163 | | - bf = bf.update; |
164 | | - new_filename = spm_2_bids(bf.filename, map, verbose); |
165 | | - deformation_field = fullfile(bf.bids_path, new_filename); |
| 122 | + if ~startsWith(bf.prefix, map.norm) |
| 123 | + return |
| 124 | + end |
166 | 125 |
|
167 | | - % otherwise we can't guess it just from the file name |
168 | | - else |
| 126 | + % for anatomical data we assume that |
| 127 | + % the deformation field comes from the anatomical file itself |
| 128 | + if (~isempty(bf.modality) && ismember(bf.modality, {'anat'})) || ... |
| 129 | + (~isempty(bf.suffix) && ~isempty(map.cfg.schema.find_suffix_group('anat', bf.suffix))) |
| 130 | + |
| 131 | + bf.prefix = 'y_'; |
| 132 | + bf = bf.update; |
| 133 | + new_filename = spm_2_bids(bf.filename, map, verbose); |
| 134 | + deformation_field = fullfile(bf.bids_path, new_filename); |
| 135 | + |
| 136 | + % otherwise we can't guess it just from the file name |
| 137 | + else |
| 138 | + deformation_field = 'TODO: add deformation field'; |
| 139 | + |
| 140 | + end |
| 141 | + |
| 142 | + sources{end + 1, 1} = deformation_field; |
169 | 143 |
|
| 144 | +end |
| 145 | + |
| 146 | +function [status, bf] = update_prefix(bf, map) |
| 147 | + |
| 148 | + status = 2; |
| 149 | + |
| 150 | + if length(bf.prefix) < 2 |
| 151 | + % TODO: files that have been realigned but not resliced have no |
| 152 | + % "prefix" so we may miss some transformation |
| 153 | + status = 0; |
| 154 | + return |
| 155 | + end |
| 156 | + |
| 157 | + % remove the prefix of the last step |
| 158 | + if startsWith(bf.prefix, map.smooth) |
| 159 | + |
| 160 | + % in case the prefix includes a number to denotate the FXHM used |
| 161 | + % for smoothing |
| 162 | + starts_with_fwhm = regexp(bf.prefix, '^s[0-9]*', 'match'); |
| 163 | + if ~isempty(starts_with_fwhm) |
| 164 | + bf = shorten_prefix(bf, length(starts_with_fwhm{1})); |
| 165 | + else |
| 166 | + bf = shorten_prefix(bf, 1); |
170 | 167 | end |
171 | 168 |
|
172 | | - sources{2, 1} = deformation_field; |
| 169 | + elseif startsWith(bf.prefix, map.unwarp) |
| 170 | + bf = shorten_prefix(bf, 1); |
| 171 | + |
| 172 | + elseif startsWith(bf.prefix, map.norm) |
| 173 | + bf = shorten_prefix(bf, 1); |
| 174 | + |
| 175 | + elseif startsWith(bf.prefix, ['rp_' map.stc]) |
| 176 | + bf = shorten_prefix(bf, 3); |
| 177 | + |
| 178 | + elseif startsWith(bf.prefix, 'mean') |
| 179 | + % TODO mean may involve several files from the source (across runs |
| 180 | + % and sessions |
| 181 | + % prefixes = { |
| 182 | + % 'mean' |
| 183 | + % 'meanu' |
| 184 | + % 'meanua' |
| 185 | + % }; |
| 186 | + status = 1; |
| 187 | + return |
| 188 | + |
| 189 | + elseif ismember(bf.prefix(1:2), {'c1', 'c2', 'c3', 'c4', 'c5'}) |
| 190 | + % bias corrected image |
| 191 | + status = 1; |
| 192 | + return |
| 193 | + |
| 194 | + else |
| 195 | + % no idea |
| 196 | + status = 1; |
| 197 | + return |
173 | 198 |
|
174 | 199 | end |
175 | 200 |
|
176 | 201 | end |
| 202 | + |
| 203 | +function bf = shorten_prefix(bf, len) |
| 204 | + bf.prefix = bf.prefix((len + 1):end); |
| 205 | +end |
0 commit comments