-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpet_Process_PETspace.m
138 lines (121 loc) · 4.67 KB
/
pet_Process_PETspace.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
function outDataset = pet_Process_PETspace(source, destination, varargin)
basepath = fileparts(mfilename('fullpath'));
args = inputParser();
args.addParameter('subjects', '.*');
args.addParameter('name', 'pet_Process');
args.addParameter('config', fullfile(basepath, 'config', 'pet.json'));
args.parse(varargin{:});
if ischar(args.Results.config)
params = spm_jsonread(args.Results.config);
else
params = args.Results.config;
end
% activating logging
log_path = fullfile(destination, args.Results.name, 'code');
if ~exist(log_path, 'dir')
mkdir(log_path);
end
outDataset = fullfile(destination, args.Results.name);
try
% Extracting Carotides
generate_log(log_path, 'pet_Carotides');
pet_Carotides(source, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
% Extracting IDIF
generate_log(log_path, 'pet_IDIF');
pet_IDIF(outDataset, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
%{
% Creating and applying brain mask
generate_log(log_path, 'pet_makeBrainMask');
pet_makeBrainMask(...
seg_ds, anat_ds, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
% Coregistering probability maps to PET image
generate_log(log_path, 'pet_Coregister_PET');
pet_Coregister(...
outDataset, outDataset, outDataset,...
destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params, ...
'configsection', 'registration_pet'...
);
% Re-creating brain masks from coregistered images
generate_log(log_path, 'pet_makeBrainMask_Coreg');
pet_makeBrainMask(...
outDataset, '', destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params, ...
'configsection', 'brainmask_coreg'...
);
% Partial volume correction
generate_log(log_path, 'pet_PVC');
pet_PVC(outDataset, outDataset, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
% Calculating Logan plot (with PVC)
generate_log(log_path, 'pet_Modelling');
pet_Modelling(outDataset, outDataset, outDataset, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
% Calculating Logan plot (without PVC)
generate_log(log_path, 'pet_Modellingi_noPVC');
pet_Modelling(outDataset, outDataset, outDataset, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params, ...
'configsection', 'modelling_noPVC'...
);
% Coregistering PET images to mri
generate_log(log_path, 'pet_Coregister_MRI');
pet_Coregister(outDataset, outDataset, outDataset, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params, ...
'configsection', 'registration_mri'...
);
% Normalizing to MNI space
generate_log(log_path, 'pet_Normalisation');
pet_Normalisation(...
outDataset, seg_ds, destination, ...
'subjects', args.Results.subjects, ...
'name', args.Results.name, ...
'config', params ...
);
%}
catch ME
fprintf('Error:\n%s\n', ME.getReport);
diary off;
rethrow(ME);
end
diary off;
end
function generate_log(log_path, name)
log_name = fullfile(log_path, [name '.log']);
if exist(log_name, 'file')
delete(log_name)
end
diary(log_name);
len = 30;
char = '#';
format_str = sprintf('%c %%-%ds%c\n', char, len - 3, char);
fprintf('%s\n', pad('', len, char));
fprintf(format_str, name);
fprintf(format_str, datestr(now(), 'dd/mm/YYYY - HH:MM:SS'));
fprintf('%s\n', pad('', len, char));
end