|
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 |
|
|
92 | 92 | return |
93 | 93 | end |
94 | 94 |
|
| 95 | + sources = add_deformation_field(bf, sources, map, verbose); |
| 96 | + |
95 | 97 | % anything prefix based |
96 | 98 | if prefix_based |
97 | 99 |
|
98 | | - if length(bf.prefix) < 2 |
| 100 | + [status, bf] = update_prefix(bf); |
| 101 | + |
| 102 | + if status == 0 |
| 103 | + return |
99 | 104 |
|
100 | | - % TODO: files that have been realigned but not resliced have no |
101 | | - % "prefix" so we may miss some transformation |
| 105 | + elseif status == 1 |
| 106 | + sources = 'TODO'; |
102 | 107 | return |
103 | 108 |
|
104 | 109 | end |
105 | 110 |
|
106 | | - % remove the prefix of the last step |
107 | | - if startsWith(bf.prefix, 's') |
| 111 | + end |
108 | 112 |
|
109 | | - % in case the prefix includes a number to denotate the FXHM used |
110 | | - % for smoothing |
111 | | - starts_with_fwhm = regexp(bf.prefix, '^s[0-9]*', 'match'); |
112 | | - if ~isempty(starts_with_fwhm) |
113 | | - bf = shorten_prefix(bf, length(starts_with_fwhm{1})); |
114 | | - else |
115 | | - bf = shorten_prefix(bf, 1); |
116 | | - end |
| 113 | + % call spm_2_bids what is the filename from the previous step |
| 114 | + new_filename = spm_2_bids(bf.filename, map, verbose); |
117 | 115 |
|
118 | | - elseif startsWith(bf.prefix, 'u') |
119 | | - bf = shorten_prefix(bf, 1); |
| 116 | + sources{end + 1, 1} = fullfile(bf.bids_path, new_filename); |
120 | 117 |
|
121 | | - elseif startsWith(bf.prefix, 'w') |
122 | | - bf = shorten_prefix(bf, 1); |
123 | | - add_deformation_field = true; |
124 | | - |
125 | | - elseif startsWith(bf.prefix, 'rp_a') |
126 | | - bf = shorten_prefix(bf, 3); |
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 |
| 118 | +end |
138 | 119 |
|
139 | | - elseif ismember(bf.prefix(1:2), {'c1', 'c2', 'c3', 'c4', 'c5'}) |
140 | | - % bias corrected image |
141 | | - sources = 'TODO'; |
142 | | - return |
| 120 | +function sources = add_deformation_field(bf, sources, map, verbose) |
143 | 121 |
|
144 | | - else |
145 | | - % no idea |
146 | | - sources = 'TODO'; |
147 | | - return |
| 122 | + if ~startsWith(bf.prefix, 'w') |
| 123 | + return |
| 124 | + end |
148 | 125 |
|
149 | | - end |
| 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'; |
150 | 139 |
|
151 | 140 | end |
152 | 141 |
|
153 | | - % call spm_2_bids what is the filename from the previous step |
154 | | - new_filename = spm_2_bids(bf.filename, map, verbose); |
| 142 | + sources{end + 1, 1} = deformation_field; |
155 | 143 |
|
156 | | - sources{1, 1} = fullfile(bf.bids_path, new_filename); |
| 144 | +end |
157 | 145 |
|
158 | | - % for normalized images |
159 | | - if add_deformation_field |
| 146 | +function [status, bf] = update_prefix(bf) |
160 | 147 |
|
161 | | - % for anatomical data we assume that |
162 | | - % the deformation field comes from the anatomical file itself |
163 | | - if (~isempty(bf.modality) && ismember(bf.modality, {'anat'})) || ... |
164 | | - (~isempty(bf.suffix) && ~isempty(map.cfg.schema.find_suffix_group('anat', bf.suffix))) |
| 148 | + status = 2; |
165 | 149 |
|
166 | | - bf.prefix = 'y_'; |
167 | | - bf = bf.update; |
168 | | - new_filename = spm_2_bids(bf.filename, map, verbose); |
169 | | - deformation_field = fullfile(bf.bids_path, new_filename); |
| 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 |
170 | 156 |
|
171 | | - % otherwise we can't guess it just from the file name |
172 | | - else |
| 157 | + % remove the prefix of the last step |
| 158 | + if startsWith(bf.prefix, 's') |
173 | 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); |
174 | 167 | end |
175 | 168 |
|
176 | | - sources{2, 1} = deformation_field; |
| 169 | + elseif startsWith(bf.prefix, 'u') |
| 170 | + bf = shorten_prefix(bf, 1); |
| 171 | + |
| 172 | + elseif startsWith(bf.prefix, 'w') |
| 173 | + bf = shorten_prefix(bf, 1); |
| 174 | + |
| 175 | + elseif startsWith(bf.prefix, 'rp_a') |
| 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 |
177 | 198 |
|
178 | 199 | end |
179 | 200 |
|
|
0 commit comments