-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcubric_physio_main.m
164 lines (123 loc) · 4.84 KB
/
cubric_physio_main.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
% Script cubric_physio_main
% Main preproc/analysis script lernit to create PhysIO regressors and
% assess them via a nuisance-only GLM
%
% cubric_physio_main
%
%
% See also
% Author: Lars Kasper
% Created: 2022-11-20
% Copyright (C) 2022
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setup paths - #MOD# Modify to your own environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subjectId = 'sub-01';
% if true, only the SPM batch jobs are loaded, but you have to run them manually in the batch editor (play button)
isInteractive = true;
hasStruct = false; % if false, uses (bias-corrected) mean of fmri.nii for visualizations
doSmooth = true;
pathProject = 'C:\Users\kasperla\OneDrive - UHN\Collaborations\PhysIO\CUBRICTalk';
pathCode = fullfile(pathProject, 'code');
pathResults = fullfile(pathProject, 'results');
pathSubject = fullfile(pathResults, subjectId);
switch subjectId
case 'sub-01'
nSlices = 96/4; % nSlicesTotal/MB factor
TR = 1.5; % seconds
nVolumes = 400;
case 'sub-02'
nSlices = 46; % nSlicesTotal/MB factor
TR = 9; % seconds
nVolumes = 150;
end
addpath(genpath(pathCode));
pathNow = pwd;
cd(pathSubject);
% folder structure created with in results folder of subject to hold
% different preprocessed data
mkdir('glm')
mkdir('nifti')
mkdir('glm_s3')
mkdir('physio_out')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setup SPM Batch editor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% spm_jobman('initcfg')
spm fmri
if isInteractive
jobMode = 'interactive';
else
jobMode = 'run';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Spatial Preproc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if hasStruct
fileJobPreproc = 'preproc_minimal_spm_job.m';
else
fileJobPreproc = 'preproc_minimal_no_struct_spm_job.m';
end
% loads matlabbatch and adapts subject-specific data
clear matlabbatch
run(fileJobPreproc)
matlabbatch{1}.spm.spatial.realign.estwrite.data{1} = ...
cellstr(spm_select('ExtFPList', 'nifti', '^fmri.*', 1:nVolumes));
spm_jobman(jobMode, matlabbatch)
if isInteractive, input('Press Enter to continue'); end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Physio
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% loads matlabbatch and adapts subject-specific data
clear matlabbatch
fileJobPhysio = 'physio_spm_job.m';
clear matlabbatch
run(fileJobPhysio)
matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = nVolumes;
matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = nSlices;
matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = TR;
matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = nSlices/2;
switch subjectId
case 'sub-01'
% defaults OK in file
case 'sub-02'
matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'first';
% only 150 volumes, we don't want to reduce degrees of freedom too much
matlabbatch{1}.spm.tools.physio.model.movement.yes.censoring_threshold = 2;
% too noisy cardiac data, has to be bandpass-filtered (default
% values)
matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter = rmfield(...
matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter, 'no');
matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.yes.type = 'cheby2';
matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.yes.passband = [0.3 9];
matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.yes.stopband = [];
end
spm_jobman(jobMode, matlabbatch)
if isInteractive, input('Press Enter to continue'); end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% GLM with or w/o smoothing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if doSmooth
fileJobGlm = 'glm_s3_spm_job.m';
else
fileJobGlm = 'glm_spm_job.m';
end
clear matlabbatch
run(fileJobGlm)
if doSmooth
matlabbatch{1}.spm.stats.fmri_spec.sess.scans = ...
cellstr(spm_select('ExtFPList', 'nifti', '^srfmri.*', 1:nVolumes));
else
matlabbatch{1}.spm.stats.fmri_spec.sess.scans = ...
cellstr(spm_select('ExtFPList', 'nifti', '^rfmri.*', 1:nVolumes));
end
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t = nSlices;
matlabbatch{1}.spm.stats.fmri_spec.timing.RT = TR;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t0 = nSlices/2;
spm_jobman(jobMode, matlabbatch)
if isInteractive, input('Press Enter to continue'); end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Visualize PhysIO contrasts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% automatic contrast creation using PhysIO
visualize_physio