-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalize_COMPLETE_paris.m
355 lines (304 loc) · 12.8 KB
/
localize_COMPLETE_paris.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
% function localize_COMPLETE_paris(a_path,task,stim,facteur,frequence,smoothing,do_erp,do_gamma)
a_path='E:\ALIZEE\EPILEPSY\DATA_SAFE\02135\02135';
task=1;
stim='Faces';
facteur='Age';
frequence=50:10:150;
smoothing=0;
do_erp=0;
do_gamma=1;
% try
% a_todo = 'tall';
% % a_elecdat = '/home/bastinj/MATLAB/tb_grenoble/localizer/elec.dat';
% % a_base =['/home/bastinj/Documents/BVS/'];
% a_elecdat = 'E:\ALIZEE\EPILEPSY\ALIZEE\elec.dat';
% a_base =['E:\ALIZEE\EPILEPSY\ALIZEE\'];
% cd(a_base);
% a_path = uigetdir(a_base, 'Select Folder to Analyze');
if task==1
dir_to_safe=[a_path '\Preproc_age'];
elseif task==2
dir_to_safe=[a_path '\Preproc_ratings'];
elseif task==3
dir_to_safe=[a_path '\Preproc_choices'];
end
mkdir(dir_to_safe)
v_f = findstr(a_path,filesep);
s_3 = v_f(length(v_f));
s_2 = v_f(length(v_f)-1);
a_exp_task = a_path(s_3+1:length(a_path));
a_exp = a_path(s_2+1:s_3-1);
a_task = strrep(a_exp_task,[a_exp '_'],'');
FILESEP=filesep;
%%%%%%%%%%%%%%%%%
% XX. PREF
%%%%%%%%%%%%%%%%
if task==1
name_task='age';
elseif task==2
name_task='rating';
elseif task==3
name_task='choice';
end
diary([a_exp_task '_' name_task '_smoothing' num2str(smoothing) '_erp' num2str(do_erp) '_gamma' num2str(do_gamma)]);
disp('-----------------------------------------------------------------------------------------')
disp([' ################# ' a_exp_task ' ##################'])
disp('-----------------------------------------------------------------------------------------')
disp(' ################# Loading pos file... ##################')
% oldpos=dir([a_path FILESEP '*BVS_raw.pos']);
% a_oldposfile = [a_path FILESEP oldpos.name];
% a_newposfile = [dir_to_safe FILESEP oldpos.name([1:end-8 end-3:end])];
%
% loc_chg_pos(a_oldposfile,a_newposfile);
a_newposfile_name=dir([dir_to_safe '*complete.pos']);
a_newposfile=[dir_to_safe a_newposfile_name.name];
% if task==1 % Age, indices 10 et 20
% %% Fusionne log files pour chaque tâche
% a_logfile_part{1}=[a_path FILESEP 'Copy_of_BVS_1b.log'];
% a_logfile_part{2}=[a_path FILESEP 'Copy_of_BVS_2b.log'];
%
% a_logfile=[a_path FILESEP 'Loca_preferences1.log'];
% Merge_logfiles( a_logfile_part, a_logfile)
%
% chg_pos_complete_age(a_newposfile,a_logfile);
% % OK, I created a new posfile 'named': PAT_CODE_locapref.pos
% a_new_pos_file_for_eeg=a_newposfile;
% a_newposfile = strrep(a_newposfile,'.pos','_locapref1.pos');
% % create .conf and .par
% % a_name = [a_path FILESEP a_exp '_' a_task];
% % a_name = [a_path FILESEP a_task];
% [index_preproc, ind_end]=regexp((a_newposfile),'\Preproc_age\');
%
% if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D1.eeg.ent'),'file')
%
% a_name = [a_oldposfile([1:end-8]) '_D1'];
% a_new_name=[a_newposfile([1:end-14]) '_D1'];
% else
% a_name = [a_oldposfile([1:end-8])];
% a_new_name=[a_newposfile([1:end-14])];
% end
% v_code = [12 13]; %these event code need to be created in the posfile !
%
% elseif task==2 % Age, indices 10 et 20
% %% Fusionne log files pour chaque tâche
% a_logfile_part{1}=[a_path FILESEP 'Copy_of_BVS_3b.log'];
% a_logfile_part{2}=[a_path FILESEP 'Copy_of_BVS_4b.log'];
% a_logfile_part{3}=[a_path FILESEP 'Copy_of_BVS_5b.log'];
%
% a_logfile=[a_path FILESEP 'Loca_preferences2.log'];
% Merge_logfiles( a_logfile_part, a_logfile)
%
% chg_pos_complete_ratings(a_newposfile,a_logfile);
% % OK, I created a new posfile 'named': PAT_CODE_locapref.pos
% a_new_pos_file_for_eeg=a_newposfile;
% a_newposfile = strrep(a_newposfile,'.pos','_locapref2.pos');
% % create .conf and .par
% % a_name = [a_path FILESEP a_exp '_' a_task];
% % a_name = [a_path FILESEP a_task];
% [index_preproc, ind_end]=regexp((a_newposfile),'\Preproc_ratings\');
%
% if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D1.eeg.ent'),'file')
%
% a_name = [a_oldposfile([1:end-8]) '_D1'];
% a_new_name=[a_newposfile([1:end-14]) '_D1'];
% else
% a_name = [a_oldposfile([1:end-8])];
% a_new_name=[a_newposfile([1:end-14])];
% end
% v_code = [32 33]; %these event code need to be created in the posfile !
%
% elseif task==3
% %% Fusionne log files pour chaque tâche
% a_logfile_part{1}=[a_path FILESEP 'Copy_of_BVS_6b.log'];
% a_logfile_part{2}=[a_path FILESEP 'Copy_of_BVS_7b.log'];
% a_logfile_part{3}=[a_path FILESEP 'Copy_of_BVS_8b.log'];
%
% a_logfile=[a_path FILESEP 'Loca_preferences3.log'];
% Merge_logfiles( a_logfile_part, a_logfile)
%
% chg_pos_complete_choices(a_newposfile,a_logfile);
% % OK, I created a new posfile 'named': PAT_CODE_locapref.pos
% a_new_pos_file_for_eeg=a_newposfile;
% a_newposfile = strrep(a_newposfile,'.pos','_locapref3.pos');
% % create .conf and .par
% % a_name = [a_path FILESEP a_exp '_' a_task];
% % a_name = [a_path FILESEP a_task];
% [index_preproc, ind_end]=regexp((a_newposfile),'\Preproc_choices\');
%
% if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D2.eeg.ent'),'file')
%
% a_name = [a_oldposfile([1:end-8]) '_D2'];
% a_new_name=[a_newposfile([1:end-14]) '_D2'];
% else
% a_name = [a_oldposfile([1:end-8])];
% a_new_name=[a_newposfile([1:end-14])];
% end
% v_code = [62 63]; %these event code need to be created in the posfile !
%
% end
% loc2_e2cp_pref(a_name,a_elecdat); %VUTILE POUR PRE-PARAMETER DES FICHIERS QUI SERVENT A FAIRE DU
% TEMPS-FREQUENCE AVEC L'OUTIL "ELAN" développé à LYON
disp('################# Processing of pos and log file done ! #################')
disp('-----------------------------------------------------------------------------------------')
disp('-----------------------------------------------------------------------------------------')
%PERMET AUSSI DE DETECTER QUAND LES CLINICIENS METTENT DES "zeros" partout
%dans le nom des électrodes : à corriger pour les scripts de JP par
%après...
%STEP 1 : FILTER the signal and then extract gamma band activity :)
%UNCOMMENT HERE (I already computed GAMMA)
% EXTRACT SAMPLING RATE INFO FROM ENT FILE
a_entfile =[dir_to_safe '02135' '.eeg.ent'];
f_old=fopen([a_entfile ],'r');
for s_i=1:9
a_line=fgetl(f_old);
end;
s_fs = 1/str2num(a_line);
s_fs = round(s_fs); % sampling frequency
fclose(f_old);
% we will downsample the data to 64 samples per second
if (s_fs==512)
s_downsamp = 8;
elseif (s_fs==1024)
s_downsamp = 16;
elseif (s_fs==2048)
s_downsamp = 32;
else
s_downsamp = 4; % 256 Hz
end;
a_name=[dir_to_safe];
smooth_val=smoothing; %0
v_freq=frequence; % (50:10:150)
if do_gamma==1%~exist(new_file,'file')
disp('############### Start filter and extract gamma band activity ################')
eeg2env2(a_name,a_newposfile,v_freq,smooth_val);%gamma = done !
else
disp('############### Filter and extract gamma band activity not asked ################')
end
% eeg2env2_theta(a_name,(4:8),a_newposfile);%for theta analyses, we modified the way LFP signal is filtered before hilbert transfrom with
% % Karim Jerbi.
% eeg2env2_theta(a_name,(8:12),a_newposfile);%for theta analyses, we
% modified the way LFP signal is filtered before hilbert transfrom with
% eeg2env2(a_name,(15:5:30),a_newposfile);%7BETA = done !
a_code = strvcat('Pref_score (low)','Pref_score (high)');
v_window_ms = [-500 3000];
if do_erp==1
disp('-----------------------------------------------------------------------------------------')
disp('############### Start evoked response activity ################')
loc_eeg2erp([a_name '.eeg'],a_newposfile,v_code,a_code,v_window_ms,20); %evoked response plots
end
% display correlations based on gamma enveloppes & pref_scores for different temporal
% smoothing (sorry alizee, it will indeed create many files in the same
% folder...BUT...everything is in the file names !
%NEXT: draw correlation values we just need sf_s to adjust the downsampling
%value (in JP LAchaux lab, we downsample gamma time serie to 64 Hz to
%increase the speed of all computations ; of course we can re-extrcat gamma
%at higher resolution if needed (theoretically grounded); not the case for
%LOCA_PREF...
%before everything, We will need the sampling rate of the EEGfile
%DONE :%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('-----------------------------------------------------------------------------------------')
disp(' ################# Start regressing eeg signal #################')
a_eeg = [a_new_name,'_f' int2str(min(v_freq)) 'f' int2str(max(v_freq)) '_ds' int2str(s_downsamp) '_sm' num2str(smooth_val) '.eeg'];%try not to smooth to see the results !!
% v_code = [51];
v_window_ms = [-500 2500];vt_stats=v_window_ms;
if task==1
if strcmp(stim,'Faces')
v_code = [21];
elseif strcmp(stim,'Paintings')
v_code = [11];
end
if strcmp(facteur,'Pref')
ind_betas=2;
elseif strcmp(facteur,'Age')
ind_betas=1;
elseif strcmp(facteur,'Conf')
ind_betas=3;
elseif strcmp(facteur,'RT')
ind_betas=4;
end
a_code = strvcat(['Age_task_on_' stim '_' facteur]);
if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D1.eeg.ent'),'file')
a_pos =[ a_new_name(1:end-3) '_locapref1_' 'ds' int2str(s_downsamp) '.pos'];
else
a_pos =[ a_new_name(1:end) '_locapref1_' 'ds' int2str(s_downsamp) '.pos'];
end
options.GLM_facteurs={facteur};
options.GLM_facteurs_index=[ind_betas];
options.folder_to_save_figures=['\GLM_' facteur '_on_age_' stim];
mkdir([dir_to_safe options.folder_to_save_figures])
loc_env2plot_rvalues_loca_AGE_GLM(a_eeg,a_pos,v_code,a_code,v_window_ms,20,options);
elseif task==2
if strcmp(stim,'Faces')
v_code = [41];
elseif strcmp(stim,'Paintings')
v_code = [31];
elseif strcmp(stim,'Food')
v_code = [51];
end
if strcmp(facteur,'Pref')
ind_betas=1;
elseif strcmp(facteur,'Conf')
ind_betas=2;
elseif strcmp(facteur,'RT')
ind_betas=3;
end
a_code = strvcat(['Rating_task_on_' stim '_' facteur]);
if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D1.eeg.ent'),'file')
a_pos =[ a_new_name(1:end-3) '_locapref2_' 'ds' int2str(s_downsamp) '.pos'];
else
a_pos =[ a_new_name(1:end) '_locapref2_' 'ds' int2str(s_downsamp) '.pos'];
end
options.GLM_facteurs={facteur};
options.GLM_facteurs_index=[ind_betas];
options.folder_to_save_figures=['\GLM_' facteur '_on_Rating_' stim];
mkdir([dir_to_safe options.folder_to_save_figures])
loc_env2plot_rvalues_loca_AGE_GLM(a_eeg,a_pos,v_code,a_code,v_window_ms,20,options);
elseif task==3
if strcmp(stim,'Faces')
v_code = [71];
elseif strcmp(stim,'Paintings')
v_code = [61];
elseif strcmp(stim,'Food')
v_code = [81];
end
if strcmp(facteur,'Vleft')
ind_betas=1;
elseif strcmp(facteur,'Vright')
ind_betas=2;
elseif strcmp(facteur,'Vchosen')
ind_betas=3;
elseif strcmp(facteur,'Vunchosen')
ind_betas=4;
elseif strcmp(facteur,'DVside')
ind_betas=5;
elseif strcmp(facteur,'DVchoice')
ind_betas=6;
elseif strcmp(facteur,'SVside')
ind_betas=7;
elseif strcmp(facteur,'SVchoice')
ind_betas=8;
end
a_code = strvcat(['Choice_task_on_' stim '_' facteur]);
if exist(strrep(a_new_pos_file_for_eeg([1:index_preproc-1 (ind_end+1):end]),'.pos','_D2.eeg.ent'),'file')
a_pos =[ a_new_name(1:end-3) '_locapref3_' 'ds' int2str(s_downsamp) '.pos'];
else
a_pos =[ a_new_name(1:end) '_locapref3_' 'ds' int2str(s_downsamp) '.pos'];
end
options.GLM_facteurs={facteur};
options.GLM_facteurs_index=[ind_betas];
options.folder_to_save_figures=['\GLM_' facteur '_on_Choices_' stim];
mkdir([dir_to_safe options.folder_to_save_figures])
loc_env2plot_rvalues_loca_AGE_GLM(a_eeg,a_pos,v_code,a_code,v_window_ms,20,options);
end
disp('-----------------------------------------------------------------------------------------')
disp(' ################# Finish ! #################')
disp(['Figures have been saved for ' a_exp_task '_' name_task ' smoothing ' num2str(smoothing)])
diary off
% catch ME
% disp('-----------------------------------------------------------------------------------------')
% disp(' ################# Error ! #################')
% diary off
%
% rethrow(ME)
%
% end