forked from tkkarjal/magia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magia_check_specs.m
297 lines (271 loc) · 9.59 KB
/
magia_check_specs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
function magia_check_specs(specs)
%% specs.study: Mandatory fields
mandatory_study_fields = {'tracer' 'frames'};
empty_study_fields = cell(length(mandatory_study_fields),1);
missing_study_fields = empty_study_fields;
for i = 1:length(mandatory_study_fields)
field = mandatory_study_fields{i};
if(isfield(specs.study,field))
if(isempty(specs.study.(field)))
empty_study_fields{i} = field;
end
else
missing_study_fields{i} = field;
end
end
empty_study_fields(cellfun(@isempty,empty_study_fields)) = [];
if(~isempty(empty_study_fields))
msg1 = 'The following mandatory study fields were empty: ';
for i = 1:length(empty_study_fields)
field = empty_study_fields{i};
msg1 = sprintf('%s ''%s''',msg1,field);
end
else
msg1 = '';
end
missing_study_fields(cellfun(@isempty,missing_study_fields)) = [];
if(~isempty(missing_study_fields))
msg2 = 'The following mandatory study fields were missing: ';
for i = 1:length(missing_study_fields)
field = missing_study_fields{i};
msg2 = sprintf('%s ''%s''',msg2,field);
end
else
msg2 = '';
end
%% specs.magia: Mandatory fields
mandatory_magia_fields = {'model' 'input_type' 'roi_type' 'dc' 'rc' 'fwhm_pre' 'fwhm_post' 'fwhm_roi' 'cpi' 'cut_time' 'gu'};
empty_magia_fields = cell(length(mandatory_magia_fields),1);
missing_magia_fields = empty_study_fields;
for i = 1:length(mandatory_magia_fields)
field = mandatory_magia_fields{i};
if(isfield(specs.magia,field))
if(isempty(specs.magia.(field)))
empty_magia_fields{i} = field;
end
else
missing_magia_fields{i} = field;
end
end
empty_magia_fields(cellfun(@isempty,empty_magia_fields)) = [];
if(~isempty(empty_magia_fields))
msg3 = 'The following mandatory magia fields were empty: ';
for i = 1:length(empty_magia_fields)
field = empty_magia_fields{i};
msg3 = sprintf('%s ''%s''',msg3,field);
end
else
msg3 = '';
end
missing_magia_fields(cellfun(@isempty,missing_magia_fields)) = [];
if(~isempty(missing_magia_fields))
msg4 = 'The following mandatory magia fields were missing: ';
for i = 1:length(missing_magia_fields)
field = missing_magia_fields{i};
msg4 = sprintf('%s ''%s''',msg4,field);
end
else
msg4 = '';
end
%% ROI type
if(isfield(specs.magia,'roi_type'))
switch specs.magia.roi_type
case 'atlas'
if(isfield(specs.magia,'mni_roi_mask_dir'))
if(isempty(specs.magia.mni_roi_mask_dir))
msg5 = 'No ''mni_roi_mask_dir'' was specified even if ''roi_type'' is ''atlas''.';
else
msg5 = '';
end
else
msg5 = 'No ''mni_mni_roi_mask_dir'' was specified even if ''roi_type'' is ''atlas''.';
end
case 'freesurfer'
if(isfield(specs.magia,'roi_set'))
if(isempty(specs.magia.roi_set))
msg5 = 'No ''roi_set'' was specified even if ''roi_type'' is ''freesurfer''.';
else
if(isfield(specs.study,'mri_code'))
if(isempty(specs.study.mri_code))
msg5 = '''mri_code'' was not specified even if the ROIs are supposed to be defined using FreeSurfer.';
else
msg5 = '';
end
else
msg5 = '''mri_code'' was not specified even if the ROIs are supposed to be defined using FreeSurfer.';
end
end
else
msg5 = 'No ''roi_set'' was specified even if ''roi_type'' is ''freesurfer''.';
end
otherwise
msg5 = '''roi_type'' should be either ''atlas'' or ''freesurfer''.';
end
else
msg5 = '';
end
%% Model
if(isfield(specs.magia,'model'))
if(isempty(specs.magia.model))
msg6 = '''model'' was not specified.';
else
specified_model = specs.magia.model;
available_models = {'suv' 'suvr' 'srtm' 'two_tcm' 'logan' 'logan_ref' 'patlak' 'patlak_ref' 'ma1' 'fur'};
if(ismember(specified_model,available_models))
msg6 = '';
else
msg6 = sprintf('The model ''%s'' is not supported by magia.',specified_model);
end
end
else
msg6 = '''model'' was not specified.';
end
%% Input type
if(isfield(specs.magia,'input_type'))
if(isempty(specs.magia.input_type))
msg7 = '''input_type'' was not specified.';
else
specified_input_type = specs.magia.input_type;
supported_input_types = {'plasma' 'blood' 'plasma&blood' 'ref' 'sca_ref' 'no_input'};
if(ismember(specified_input_type,supported_input_types))
if(strcmp(specified_input_type,'sca_ref'))
if(isfield(specs.magia,'classfile'))
if(isempty(specs.magia.classfile))
msg7 = '''classfile'' was not specified even if ''input_type'' was specified as ''sca_ref''';
else
msg7 = '';
end
else
msg7 = '''classfile'' was not specified even if ''input_type'' was specified as ''sca_ref''';
end
else
msg7 = '';
end
else
msg7 = sprintf('The input_type ''%s'' is not supported by magia.',specified_input_type);
end
end
else
msg7 = '';
end
%% Normalization method
if(isfield(specs.magia,'norm_method'))
if(isempty(specs.magia.norm_method))
msg8 = '''norm_method'' was not specified.';
else
specified_norm_method = specs.magia.norm_method;
supported_norm_methods = {'pet' 'mri'};
if(ismember(specified_norm_method,supported_norm_methods))
if(strcmp(specified_norm_method,'mri'))
if(isfield(specs.study,'mri_code'))
if(isempty(specs.study.mri_code))
msg8 = '''mri_code'' was not specified even if normalization is supposed to be done via MRI.';
else
msg8 = '';
end
else
msg8 = '''mri_code'' was not specified even if normalization is supposed to be done via MRI.';
end
else
if(isfield(specs.magia,'template'))
if(isempty(specs.magia.template))
msg8 = '''template'' was not specified even if normalization is supposed to be done via PET.';
else
msg8 = '';
end
else
msg8 = '''template'' was not specified even if normalization is supposed to be done via PET.';
end
end
else
msg8 = sprintf('The ''norm_method'' ''%s'' is not supported by magia. It should be either ''mri'' or ''pet''.',specified_norm_method);
end
end
else
msg8 = '';
end
%% NaN check
msg9 = '';
specs_fields = fieldnames(specs);
for i = 1:length(specs_fields)
field = specs_fields{i};
s = specs.(field);
sub_spec_fields = fieldnames(s);
for j = 1:length(sub_spec_fields)
f = sub_spec_fields{j};
switch f
case {'cut_time' 'weight' 'scanner' 'dose' 'glucose'}
otherwise
v = s.(f);
if(isnan(v))
if(isempty(msg9))
msg9 = sprintf('The following fields were NaN: specs.%s.%s',field,f);
else
msg9 = sprintf('%s specs.%s.%s',msg9,field,f);
end
end
end
end
end
%% Glucose
if(isfield(specs.magia,'gu'))
if(isempty(specs.magia.gu) || isnan(specs.magia.gu))
msg10 = '''gu'' was not specified.';
else
specified_gu = specs.magia.gu;
if(specified_gu)
if(isfield(specs.study,'glucose'))
specified_glucose = specs.study.glucose;
if(strcmp(specified_glucose,'No Data'))
msg10 = 'Plasma glucose concentration (the field glucose) was not specified even if gu = 1.';
else
msg10 = '';
end
else
msg10 = 'Plasma glucose concentration (the field glucose) was not specified even if gu = 1.';
end
else
msg10 = '';
end
end
else
msg10 = '''gu'' was not specified.';
end
%% Print observations
if(isempty(msg1) && isempty(msg2) && isempty(msg3) && isempty(msg4) && isempty(msg5) && isempty(msg6) && isempty(msg7) && isempty(msg8) && isempty(msg9) && isempty(msg10))
fprintf('No problems found from the specs.\n');
else
msg = 'The following problems were observed:';
if(~isempty(msg1))
msg = sprintf('%s\n\n%s',msg,msg1);
end
if(~isempty(msg2))
msg = sprintf('%s\n\n%s',msg,msg2);
end
if(~isempty(msg3))
msg = sprintf('%s\n\n%s',msg,msg3);
end
if(~isempty(msg4))
msg = sprintf('%s\n\n%s',msg,msg4);
end
if(~isempty(msg5))
msg = sprintf('%s\n\n%s',msg,msg5);
end
if(~isempty(msg6))
msg = sprintf('%s\n\n%s',msg,msg6);
end
if(~isempty(msg7))
msg = sprintf('%s\n\n%s',msg,msg7);
end
if(~isempty(msg8))
msg = sprintf('%s\n\n%s',msg,msg8);
end
if(~isempty(msg9))
msg = sprintf('%s\n\n%s',msg,msg9);
end
if(~isempty(msg10))
msg = sprintf('%s\n\n%s',msg,msg10);
end
error('%s\n\nPlease correct the mistakes and try again.\n',msg);
end
end