|
1 | 1 | function MRS_struct = GannetCoRegister(MRS_struct, struc) |
2 | 2 | % Co-registration of MRS voxel volumes to imaging datasets, based on headers. |
3 | 3 |
|
4 | | -if nargin < 2 |
| 4 | +if nargin < 1 || ... |
| 5 | + (nargin < 2 && ~(isfield(MRS_struct, 'p') && isfield(MRS_struct.p, 'bids') && MRS_struct.p.bids)) |
5 | 6 | fprintf('\n'); |
6 | | - error('MATLAB:minrhs', 'Not enough input arguments.'); |
| 7 | + error('MATLAB:minrhs', ['Not enough input arguments. ' ... |
| 8 | + 'GannetCoRegister requires two arguments (MRS_struct, struc), ' ... |
| 9 | + 'unless processing a BIDS dataset, in which case only MRS_struct ' ... |
| 10 | + 'is required.']); |
7 | 11 | end |
8 | 12 |
|
9 | 13 | if ~isstruct(MRS_struct) |
10 | 14 | fprintf('\n'); |
11 | | - error('The first input argument ''%s'' must be a structure.', MRS_struct); |
| 15 | + error('The first input argument must be a structure, but received %s.', class(MRS_struct)); |
12 | 16 | end |
13 | 17 |
|
14 | | -if ~iscell(struc) |
15 | | - fprintf('\n'); |
16 | | - error('The second input argument ''%s'' must be a structure.', struc); |
| 18 | +if nargin == 2 |
| 19 | + if ~iscell(struc) |
| 20 | + fprintf('\n'); |
| 21 | + error('The second input argument ''%s'' must be a structure.', struc); |
| 22 | + end |
17 | 23 | end |
18 | 24 |
|
19 | | -MRS_struct.version.coreg = '250805'; |
| 25 | +MRS_struct.info.datetime.coreg = datetime('now'); |
| 26 | +MRS_struct.info.version.coreg = '250911'; |
20 | 27 |
|
21 | 28 | warning('off'); % temporarily suppress warning messages |
22 | 29 |
|
|
41 | 48 | vox = MRS_struct.p.vox(1); |
42 | 49 | end |
43 | 50 |
|
44 | | -struc = GetFullPath(struc); |
| 51 | +% Find MR images if processing a BIDS dataset |
| 52 | +if MRS_struct.p.bids |
| 53 | + struc = cell(MRS_struct.p.numScans,1); |
| 54 | + for ii = 1:MRS_struct.p.numScans |
| 55 | + bids_file = bids.File(MRS_struct.metabfile{ii}); |
| 56 | + if ~exist(fullfile(MRS_struct.out.BIDS.pth, 'derivatives', 'Gannet_output', bids_file.bids_path), 'dir') |
| 57 | + bids.util.mkdir(fullfile(MRS_struct.out.BIDS.pth, 'derivatives', 'Gannet_output', bids_file.bids_path)); |
| 58 | + end |
| 59 | + metadata = bids.internal.get_metadata(bids.internal.get_meta_list(MRS_struct.metabfile{ii})); |
| 60 | + try |
| 61 | + struc{ii} = bids.internal.resolve_bids_uri(metadata.AnatomicalImage, MRS_struct.out.BIDS); |
| 62 | + catch |
| 63 | + fprintf('\n'); |
| 64 | + error(['No valid structural images found for ''%s''.' ... |
| 65 | + '\nCheck that its JSON sidecar file has an entry for ''AnatomicalImage''.'], bids_file.filename); |
| 66 | + end |
| 67 | + end |
| 68 | +else |
| 69 | + struc = GetFullPath(struc); |
| 70 | +end |
45 | 71 |
|
46 | 72 | if MRS_struct.p.numScans ~= length(struc) |
47 | 73 | fprintf('\n'); |
|
154 | 180 | set(ha, 'Position', [0 pos(2) 1 pos(4)]); |
155 | 181 | axis off; |
156 | 182 |
|
157 | | - [~,tmp,tmp2] = fileparts(MRS_struct.mask.(vox{kk}).outfile{ii}); |
158 | | - fname = [tmp tmp2]; |
| 183 | + [~,name,ext] = fileparts(MRS_struct.mask.(vox{kk}).fname{ii}); |
| 184 | + fname = [name ext]; |
159 | 185 | if length(fname) > 30 |
160 | 186 | fname = [fname(1:12) '...' fname(end-11:end)]; |
161 | 187 | end |
|
165 | 191 | text(0.5, 0.63, 'Spatial parameters: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
166 | 192 | text(0.5, 0.63, ' [LR, PA, SI]', 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
167 | 193 |
|
168 | | - tmp = [' ' num2str(MRS_struct.p.voxdim(ii,1)) ' \times ' num2str(MRS_struct.p.voxdim(ii,2)) ' \times ' num2str(MRS_struct.p.voxdim(ii,3)) ' mm^{3}']; |
| 194 | + str = [' ' num2str(MRS_struct.p.voxdim(ii,1)) ' \times ' num2str(MRS_struct.p.voxdim(ii,2)) ' \times ' num2str(MRS_struct.p.voxdim(ii,3)) ' mm^{3}']; |
169 | 195 | text(0.5, 0.51, 'Dimensions: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
170 | | - text(0.5, 0.51, tmp, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13, 'Interpreter', 'tex'); |
| 196 | + text(0.5, 0.51, str, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13, 'Interpreter', 'tex'); |
171 | 197 |
|
172 | | - tmp = [' ' num2str(prod(MRS_struct.p.voxdim(ii,:))/1e3) ' mL']; |
| 198 | + str = [' ' num2str(prod(MRS_struct.p.voxdim(ii,:))/1e3) ' mL']; |
173 | 199 | text(0.5, 0.39, 'Volume: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
174 | | - text(0.5, 0.39, tmp, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
| 200 | + text(0.5, 0.39, str, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
175 | 201 |
|
176 | | - tmp = [' [' num2str(MRS_struct.p.voxoff(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxoff(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxoff(ii,3), '%3.1f') '] mm']; |
| 202 | + str = [' [' num2str(MRS_struct.p.voxoff(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxoff(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxoff(ii,3), '%3.1f') '] mm']; |
177 | 203 | text(0.5, 0.27, 'Position: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
178 | | - text(0.5, 0.27, tmp, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
| 204 | + text(0.5, 0.27, str, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
179 | 205 |
|
180 | 206 | if any(strcmp(MRS_struct.p.vendor, {'Philips', 'Philips_data'})) |
181 | | - tmp = [' [' num2str(MRS_struct.p.voxang(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,3), '%3.1f') '] deg']; |
| 207 | + str = [' [' num2str(MRS_struct.p.voxang(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,3), '%3.1f') '] deg']; |
182 | 208 | else |
183 | | - tmp = [' [' num2str(MRS_struct.p.voxang(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,3), '%3.1f') '] deg']; |
| 209 | + str = [' [' num2str(MRS_struct.p.voxang(ii,1), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,2), '%3.1f') ', ' num2str(MRS_struct.p.voxang(ii,3), '%3.1f') '] deg']; |
184 | 210 | end |
185 | 211 | text(0.5, 0.15, 'Angulation: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
186 | | - text(0.5, 0.15, tmp, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
| 212 | + text(0.5, 0.15, str, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
187 | 213 |
|
188 | 214 | text(0.5, 0.03, 'CoRegVer: ', 'Units', 'normalized', 'HorizontalAlignment', 'right', 'FontName', 'Arial', 'FontSize', 13); |
189 | | - text(0.5, 0.03, [' ' MRS_struct.version.coreg], 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
| 215 | + text(0.5, 0.03, [' ' MRS_struct.info.version.coreg], 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 13); |
190 | 216 |
|
191 | 217 | hb = subplot(2,3,1:3); |
192 | 218 |
|
193 | 219 | if strcmp(MRS_struct.p.vendor, 'Siemens_rda') |
194 | | - [~,tmp,tmp2] = fileparts(MRS_struct.metabfile{1,ii*2-1}); |
| 220 | + [~,name,ext] = fileparts(MRS_struct.metabfile{1,ii*2-1}); |
195 | 221 | else |
196 | | - [~,tmp,tmp2] = fileparts(MRS_struct.metabfile{1,ii}); |
| 222 | + [~,name,ext] = fileparts(MRS_struct.metabfile{1,ii}); |
197 | 223 | end |
198 | | - fname = [tmp tmp2]; |
| 224 | + fname = [name ext]; |
199 | 225 | if length(fname) > 30 |
200 | 226 | fname = [fname(1:12) '...' fname(end-11:end)]; |
201 | 227 | end |
202 | | - [~,tmp3,tmp4] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii}); |
203 | | - T1image = [tmp3 tmp4]; |
| 228 | + [~,name,ext] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii}); |
| 229 | + T1image = [name ext]; |
204 | 230 | if length(T1image) > 30 |
205 | 231 | T1image = [T1image(1:12) '...' T1image(end-11:end)]; |
206 | 232 | end |
|
0 commit comments