-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtfmri_session_prepilot_new.m
314 lines (236 loc) · 11.2 KB
/
rtfmri_session_prepilot_new.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
298
299
300
301
302
303
304
305
306
307
308
%% Preparatory part
clear all
clear classes
SubjectID='FATR';
UseASFV52;% CHECK FILE NAME !!
%% create 4 trds 1 for each session - you can configure the number of sessions
%COPY THEM TO THE STIMULATION MACHINE
% makeTRD_perception_rt(SubjectID, 1);
% makeTRD_perception_rt(SubjectID, 2);
% makeTRD_imagery_rt(SubjectID, 3);
% makeTRD_imagery_rt(SubjectID, 4);
%% Functional perception run 1 + retrain classifier
%Analyze output and show accuracy
%CHECK FILENAME IN THE PREPROC_CLASSIF FILE !!
cfg=[];
session=1;
disk='C:\Documents\RealTime\';
accessN='201507141030';
subjectCode='20150714FATR';
%%%%%%%%%%% paths 1st Run rakes from input run 1 puts into data path run 1
cfg.inputDir=sprintf('%s%s\\Ser%04d', disk, accessN, session); %'C:\Documents\RealTime\201509301130\Ser0001'; %'C:\Documents\RealTime\20150930MCBL\DiCo_1\'% % DISK Z:\
cfg.output=sprintf('%s%s\\', disk, subjectCode); %'C:\Documents\RealTime\20150930MCBL\'; %DISK C:\ NO RUN FOLDERS, THIS IS WHERE HISTORY AND PREDICTIONS ARE SAVED
cfg.dataPath=sprintf('%s%s\\', disk, subjectCode); % DISK C:\ ETC THIS ONE SHOULD HAVE RUNS IN IT !!! where the classifier takes them to be trained
%%%%%%%%%%%%% general session options
cfg.NrOfVols=305;
cfg.TimeOut=15.0;
cfg.TR=2;
cfg.numDummy=5;
cfg.blockDur=9;
Cfg.feedbackOnPage=nan;
%%%%%%%%%%%% preprocessing options
cfg.smoothFWHM = 0;
cfg.correctMotion = 1;
cfg.normalize2MNI = 0;
cfg.correctSliceTime = 1;
%%%%%%%%%%%
poll_for_data_preproc(SubjectID, 1, cfg);
%poll_for_data_preproc_ses1_version1(SubjectID, 1, cfg);
%% MASK
SubjectID='ANSN';
cfg=[];
session=2;
disk='C:\Documents\RealTime\';
accessN='201507171130';
subjectCode='20150717ANSN';
%%%%%%%%%%% paths 1st Run rakes from input run 1 puts into data path run 1
cfg.output=sprintf('%s%s\\', disk, subjectCode); %'C:\Documents\RealTime\20150930MCBL\'; %DISK C:\ NO RUN FOLDERS, THIS IS WHERE HISTORY AND PREDICTIONS ARE SAVED
cfg.dataPath=sprintf('%s%s\\', disk, subjectCode); % DISK C:\ ETC THIS ONE SHOULD HAVE RUNS IN IT !!! where the classifier takes them to be trained
cfg.maskpath=sprintf('%s%s\\', disk, subjectCode);
cfg.protocolpath=sprintf('%s%s\\', disk, subjectCode); %sprintf('%sPROTOCOLS\\'); 'C:\Documents\RealTime\20150930MCBL\';
cfg.numDummy=5;
cfg.TRtoTake= 3;
%cfg.subjBirthdate='19881016';
%obtain_mask_spm_epi(SubjectID, cfg);
%obtain_mask_spm_epi_test(SubjectID, cfg);
%obtain_mask_spm_epi_anat(SubjectID, cfg);
%if instead of mask we normalize
% 1 calculate mean image with Imcalc mean.hdr saved in the subj outputdir
% write data into matrix !!!!!!!!!
% normalize with est&write using mean as ref image
%TODO: online GLM and contrast analysis to identify voxels = mask
%here: 1) get onsets for each condition 2) run specify 1st level 3) results
%- estimate model - contrast threshold=0.03, voxels=30 save the file. but
%it is going to be saved in the session folder so in the mask path it is
%necessary to indicate the session folder no just the subject path
create_spm_design(SubjectID, 1, cfg);
cfg.saveClassifier=1;
%
if cfg.saveClassifier==1;
train_and_save_classifier(SubjectID, sessionN, cfg)
end
%% Functional perception run 2 + retrain classifier
SubjectID='FATR';
cfg.MultiSubjectID={'20150930MCBL', '20150717ANSN', '20150806PMMN'}; %'20150806MCBL','20150717OIFR',
UseASFV52;
%%%%%General experiment options
cfg.multiSubj=1;
cfg.Feedback=0;
cfg.voxelSelection=1; %1 for group maps, 2 for spm contrast clusters
%%%%%%%%%%%%% paths Run 2 rakes from input run 2 puts into data path run 2
session=2;
disk='C:\Documents\RealTime\';
accessN='201507141030';
subjectCode='20150714FATR';
%%%%%%%%%%% paths 1st Run rakes from input run 1 puts into data path run 1
cfg.inputDir=sprintf('%s%s\\Ser%04d', disk, accessN, session); %'C:\Documents\RealTime\201509301130\Ser0001'; %'C:\Documents\RealTime\20150930MCBL\DiCo_1\'% % DISK Z:\
cfg.output=sprintf('%s%s\\', disk, subjectCode); %'C:\Documents\RealTime\20150930MCBL\'; %DISK C:\ NO RUN FOLDERS, THIS IS WHERE HISTORY AND PREDICTIONS ARE SAVED
cfg.dataPath=sprintf('%s%s\\', disk, subjectCode); % DISK C:\ ETC THIS ONE SHOULD HAVE RUNS IN IT !!! where the classifier takes them to be trained
cfg.maskpath=sprintf('%s%s\\', disk, subjectCode);
cfg.protocolpath=sprintf('%s%s\\', disk, subjectCode); %sprintf('%sPROTOCOLS\\'); 'C:\Documents\RealTime\20150930MCBL\';
if cfg.multiSubj==1;
cfg.protocolpath='C:\Documents\RealTime\PROTOCOLS\'; % to put the current subject's protocols there too !!!!!!!!!
end
cfg.NrOfVols=305;
cfg.TimeOut=15.0;
cfg.TR=2;
cfg.numDummy=5;
cfg.blockDur=9;
if cfg.Feedback==1
cfg.FeedbackFolder='C:\Users\tbv\Documents\TBVData\NeuroFeedbackData\ATTEND';
mkdir(fullfile(cfg.FeedbackFolder, SubjectID));
else
cfg.FeedbackFolder='C:\Documents\RealTime\PROTOCOLS\';
end
%%%%%%%%%%%%normalization options %%%%%%%
cfg.mytemplate='C:\Users\eust_abbondanza\Documents\MATLAB\spm8\templates\EPI.nii';
cfg.matname=fullfile(cfg.dataPath, 'mean_sn.mat');
cfg.ref_image=fullfile(cfg.dataPath, 'mean.hdr');
%%%%%%%%%%%
%%%%%%%%%%%% preprocessing options
cfg.smoothFWHM = 0;
cfg.correctMotion = 1;
cfg.normalize2MNI = 1;
cfg.correctSliceTime = 1;
if cfg.multiSubj==1;
cfg.normalize2MNI = 1;
cfg.allSubjPath='C:\Documents\Realtime\';
cfg.mask_name=fullfile(cfg.maskpath, 'OSC.625.nii');
end
if cfg.normalize2MNI == 1;
cfg.mask_name=fullfile(cfg.maskpath, 'OSC.625.nii');
else
switch cfg.voxelSelection
case 1
cfg.mask_name=fullfile(cfg.maskpath, 'rwOSC.625.nii');
case 2
cfg.mask_name=fullfile(cfg.maskpath, 'Ser0001', 'spm_contrast.hdr');
end
end
cfg.maskThreshold= 0.01;
%%%%%%%%%%%%%%% classifier parameters
cfg.TRtoTake= 3;
%rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools'); %FOR
%%%%%%%%%%%%CLASSIFIER OPTIONS
cfg.Classifier=3; %1 for prtoolbox svm, 2 for EN logistic regression, 3 for libsvm 4 for glmnet 5 for cosmomvpa classifiers
%lassoglm is in the stats toolbox that is in conflict with other svms, so
%to switch between the classifiers you needd to pay attention to whether
%stats toolbox is on the path or not
%1 if you want to load a pre-trained classifier
if cfg.Classifier==2
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5\prtools');
addpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
else
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5');
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5\prtools');
rmpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
end
%%%%%%%%%%%%
%%%%%%%%%%%
%cfg.mask_name=fullfile(cfg.maskpath, 'OSC.625.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Occipital_Inf.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Occipital_Mid.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Fusiform.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Temporal_Inf.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Temporal_Mid.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'MNI_Temporal_Sup.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'rwOSC.625.nii');
%cfg.mask_name=fullfile(cfg.maskpath, 'Ser0001', 'contrast_mask.hdr');
%0.1; %0.001; %for native space to have more or less 1200 voxels
poll_for_data_preproc_classif(SubjectID, 2, 'Perc', cfg);
%just_classify(SubjectID, 2, 'Perc', cfg);
%poll_for_data_preproc_version1(SubjectID, 2, cfg)
%% Functional imagery run 1 + retrain classifier
%Analyze output and show accuracy
%%%%%%%%%%%%% paths Run 3 rakes from input run 3 puts into data path run 3
cfg.Classifier=3; %1 for prtoolbox svm, 2 for EN logistic regression, 3 for libsvm 4 for glmnet 5 for cosmomvpa classifiers
%lassoglm is in the stats toolbox that is in conflict with other svms, so
%to switch between the classifiers you needd to pay attention to whether
%stats toolbox is on the path or not
if cfg.Classifier==2
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5\prtools');
addpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
else
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
rmpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\shared' );
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5');
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools5\prtools');
rmpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
end
session=5;
disk='C:\Documents\RealTime\';
accessN='201509301130';
subjectCode='20150930MCBL';
%%%%%%%%%%% paths 1st Run rakes from input run 1 puts into data path run 1
cfg.inputDir=sprintf('%s%s\\Ser%04d', disk, accessN, session); %'C:\Documents\RealTime\201509301130\Ser0001'; %'C:\Documents\RealTime\20150930MCBL\DiCo_1\'% % DISK Z:\
cfg.output=sprintf('%s%s\\', disk, subjectCode); %'C:\Documents\RealTime\20150930MCBL\'; %DISK C:\ NO RUN FOLDERS, THIS IS WHERE HISTORY AND PREDICTIONS ARE SAVED
cfg.dataPath=sprintf('%s%s\\', disk, subjectCode); % DISK C:\ ETC THIS ONE SHOULD HAVE RUNS IN IT !!! where the classifier takes them to be trained
%%%%%%%%%%%
%train_and_save_classifier(SubjectID, 3, cfg);
%%%%
poll_for_data_preproc_classif(SubjectID, 3, 'Im', cfg);
%% Functional imagery run 2 + retrain classifier
%Analyze output and show accuracy
%%%%%%%%%%%%% paths Run 4 rakes from input run 4 puts into data path run 3
cfg.Classifier=3; %1 for prtoolbox svm, 2 for EN logistic regression, 3 for libsvm 4 for glmnet 5 for cosmomvpa classifiers
%lassoglm is in the stats toolbox that is in conflict with other svms, so
%to switch between the classifiers you needd to pay attention to whether
%stats toolbox is on the path or not
if cfg.Classifier==2
rmpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
addpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
else
addpath('C:\Users\eust_abbondanza\Documents\MATLAB\prtools');
rmpath('C:\Program Files (x86)\MATLAB\R2015a\toolbox\stats\stats');
end
session=4;
disk='C:\Documents\RealTime\';
accessN='201507141030';
subjectCode='20150714FATR';
%%%%%%%%%%% paths 1st Run rakes from input run 1 puts into data path run 1
cfg.inputDir=sprintf('%s%s\\Ser%04d', disk, accessN, session); %'C:\Documents\RealTime\201509301130\Ser0001'; %'C:\Documents\RealTime\20150930MCBL\DiCo_1\'% % DISK Z:\
cfg.output=sprintf('%s%s\\', disk, subjectCode); %'C:\Documents\RealTime\20150930MCBL\'; %DISK C:\ NO RUN FOLDERS, THIS IS WHERE HISTORY AND PREDICTIONS ARE SAVED
cfg.dataPath=sprintf('%s%s\\', disk, subjectCode); % DISK C:\ ETC THIS ONE SHOULD HAVE RUNS IN IT !!! where the classifier takes them to be trained
%%%%%%%%%%%
%train_and_save_classifier(SubjectID, 3, cfg);
%%%%%%%%%%%
poll_for_data_preproc_classif(SubjectID, 4, 'Im', cfg);
%% ANALYZE ses 2
analyze_pred_labels(SubjectID, 2, 'Perc', cfg);
%% ANALYZE ses 3
analyze_pred_labels(SubjectID, 3, 'Im', cfg);
%% ANALYZE ses 4
analyze_pred_labels(SubjectID, 4, 'Im', cfg);
%% ANALYZE all subjects session 2
%cfg.MultiSubjectID={};
SubjGroup={'MCBL', 'CARV'};
analyze_all(SubjGroup, 2, 'Perc', cfg);
%% ANALYZE all subjects session 3
%cfg.MultiSubjectID={};
analyze_all(SubjGroup, 3, 'Im', cfg);
%% ANALYZE all subjects session 4
%cfg.MultiSubjectID={};
analyze_all(SubjGroup, 4, 'Im', cfg);