11% Restingstate pipepline (2021)
22% Final version of SRC code 12/6/2021
33% this script allows for re-reference (which we skip)
4+ % this script interpolates the bad channels
45% does an average reference
56% does ICA (using pop_runica) setting a PCA, of all chans minus 1. This is
67% not great. So it's changed to pca = rank(EEG.data), which also takes care of bridged channels)
1415for g= 1 : length(Group )
1516 switch Group{g }
1617 case ' Control'
17- % home_path = '\\data.einsteinmed.org\users\Filip Ana Douwe\Resting state data\Control\';
18+ home_path = ' \\ data.einsteinmed.org\users\Filip Ana Douwe\Resting state data\Control\' ;
1819 %% aged matched controls
19- % subject_list = {'10033' '10130' '10131' '10158' '10165' '10257' '10281' '10293' '10360' '10369' '10384' '10394' '10407' '10438' '10446' '10451' '10463' '10467' '10476' '10501' '10526' '10534' '10545' '10561' '10562' '10581' '10585' '10616' '10615' '10620' '10639' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '10844' '10956' '12005' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------
20+ subject_list = {' 10033' ' 10130' ' 10131' ' 10158' ' 10165' ' 10257' ' 10281' ' 10293' ' 10360' ' 10369' ' 10384' ' 10394' ' 10407' ' 10438' ' 10446' ' 10451' ' 10463' ' 10467' ' 10476' ' 10501' ' 10526' ' 10534' ' 10545' ' 10561' ' 10562' ' 10581' ' 10585' ' 10616' ' 10615' ' 10620' ' 10639' ' 10748' ' 10780' ' 10784' ' 10822' ' 10858' ' 10906' ' 10915' ' 10929' ' 10935' ' 10844' ' 10956' ' 12005' ' 12007' ' 12010' ' 12215' ' 12328' ' 12360' ' 12413' ' 12512' ' 12648' ' 12651' ' 12707' ' 12727' ' 12739' ' 12750' ' 12815' ' 12898' ' 12899' };% ------------------------------------------------
2021 %% extra controls
21- subject_list = {' 10297' ' 10331' ' 10385' ' 10399' ' 10497' ' 10553' ' 10590' ' 10640' ' 10867' ' 10906' ' 12002' ' 12004' ' 12006' ' 12122' ' 12139' ' 12177' ' 12188' ' 12197' ' 12203' ' 12206' ' 12230' ' 12272' ' 12415' ' 12474' ' 12482' ' 12516' ' 12534' ' 12549' ' 12588' ' 12632' ' 12735' ' 12746' ' 12755' ' 12770' ' 12852' ' 12870' };
22- home_path = ' C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\' ;
22+ % subject_list = {'10297' '10331' '10385' '10399' '10497' '10553' '10590' '10640' '10867' '10906' '12002' '12004' '12006' '12122' '12139' '12177' '12188' '12197' '12203' '12206' '12230' '12272' '12415' '12474' '12482' '12516' '12534' '12549' '12588' '12632' '12735' '12746' '12755' '12770' '12852' '12870'};
23+ % home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\';
2324 % did these again because need extra channels deleted
2425 % subject_list = {'12139' '10399'};
2526 % home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\';
3334 end
3435 figure_path = [home_path ' figures\' ];
3536 participant_info = num2cell(zeros(length(subject_list ),9 ));
36- deleted_data = num2cell(zeros(length(subject_list ), 2 ));
37+ % deleted_data = num2cell(zeros(length(subject_list), 2));
38+ participant_data_qt = string(zeros(length(subject_list ), 4 )); % prealocationg space for speed
3739 components = num2cell(zeros(length(subject_list ), 8 )); % prealocationg space for speed
3840 refchan = { }; % if you want to re-ref to a channel add the name of the channel here, if empty won't re-ref to any specific channel
3941 for s= 1 : length(subject_list )
4244 data_path = [home_path subject_list{s } ' \\ ' ];
4345 fprintf(' \n\n\n **** %s : Loading dataset ****\n\n\n ' , subject_list{s });
4446 EEG = pop_loadset(' filename' , [subject_list{s } ' _triggerfix.set' ], ' filepath' , data_path );
45- % re-referencing, if refchan is empty this get's skipped
47+ %% setting PCA for ICA (amount of ICs you want to be created)
48+ pca = EEG .nbchan - 1 ; % the PCA part of the ICA needs stops the rank-deficiency % pre 12/6/2021 , is not accurate but so far the best we can do. Does not take bridging in account, but neither would the normal ICA function, which misses the avg ref sometimes
49+ %% interpolation
50+ EEGinter = pop_loadset(' filename' , [subject_list{s } ' _info.set' ], ' filepath' , data_path );% loading participant file with 64 channels
51+ % saving the original amount of total channels
52+ labels_all = {EEGinter .chanlocs .labels }.' ; % stores all the labels in a new matrix
53+ % interpolating for 64 channels
54+ labels_good = {EEG .chanlocs .labels }.' ; % saves all the channels that are in the excom file
55+ disp(EEG .nbchan ); % writes down how many channels are there
56+ EEG = pop_interp(EEG , EEGinter .chanlocs , ' spherical' );% interpolates the data
57+ EEG = eeg_checkset( EEG );
58+ EEG = pop_saveset( EEG , ' filename' , [subject_list{s } ' _inter.set' ], ' filepath' , data_path ); % saves data
59+ disp(EEG .nbchan )
60+ %% re-referencing, if refchan is empty this get's skipped
4661 if isempty(refchan )~=1 % if no re-reference channels chose this gets skipped
4762 for j= 1 : length(EEG .chanlocs )
4863 if strcmp(refchan{1 }, EEG .chanlocs(j ).labels)
6075 EEG = pop_reref( EEG , [ref1 ref2 ]); % re-references to the average of 2 channels
6176 end
6277 end
63- EEG = eeg_checkset( EEG );
64- % another re-ref to the averages as suggested for the ICA
78+
79+
80+ %% Avg re-reference as suggested for the ICA
6581 EEG = pop_reref( EEG , []);
6682 EEG = eeg_checkset( EEG );
6783 EEG = pop_saveset( EEG , ' filename' ,[subject_list{s } ' _ref.set' ],' filepath' , data_path );
7591 end
7692 % Independent Component Analysis
7793 EEG = eeg_checkset( EEG );
78- pca = EEG . nbchan - 1 ; % the PCA part of the ICA needs stops the rank-deficiency % pre 12/6/2021 , is not accurate but so far the best we can do. Does not take bridging in account, but neither would the normal ICA function, which misses the avg ref sometimes
94+
7995 EEG = pop_runica(EEG , ' extended' ,1 ,' interupt' ,' on' ,' pca' ,pca ); % using runica function, with the PCA part
8096 EEG = eeg_checkset( EEG );
8197 EEG = pop_saveset( EEG , ' filename' ,[subject_list{s } ' _ica.set' ],' filepath' , data_path );
135151 delete([figure_path subject_list{s } ' _remaining_ICs_topos.png' ])
136152 close all
137153 EEG = pop_saveset( EEG , ' filename' ,[subject_list{s } ' _excom.set' ],' filepath' , data_path );% save
138- %% extra cleaning %was uses before 12/6/2021 for all projects, not needed after update to cleaning function
139- % orig_length=EEG.xmax;
140- % EEG = pop_rejcont(EEG, 'elecrange',[1:EEG.nbchan] ,'freqlimit',[20 40] ,'threshold',8 ,'epochlength',0.5,'contiguous',4,'addlength',0.25,'taper','hamming');
141- % clean_length=EEG.xmax;
142- % EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_clean.set'],'filepath', data_path);%save
143154 %% saving structures
144- deleted_data(s ,: )=[subject_list(s ), 100 -(clean_length / orig_length )*100 ];
145155 subj_comps= [subject_list(s ), num2cell(brain_ic ), num2cell(muscle_ic ), num2cell(eye_ic ), num2cell(hearth_ic ), num2cell(line_noise_ic ), num2cell(channel_ic ), num2cell(other_ic )];
146- components(s ,: )=[subj_comps ];
156+ lables_del = setdiff(labels_all ,labels_good ); % only stores the deleted channels
157+ All_bad_chan = strjoin(lables_del ); % puts them in one string rather than individual strings
158+ ID = string(subject_list{s });% keeps all the IDs
159+ data_subj = [ID , length(lables_del ), All_bad_chan , EEG .nbchan ]; % combines IDs and Bad channels, total channels at the end
160+ participant_data_qt(s ,: ) = data_subj ;% combine new data with old data
161+ components(s ,: ) = [subj_comps ];
162+ clear EEG_temp EEGinter
147163 end
148164 save([home_path ' components_' Group{g } ], ' components' );
149- save([home_path ' deleted_data_' Group{g }], ' deleted_data ' );
165+ save([home_path ' deleted_data_' Group{g }], ' participant_data_qt ' );
150166end
0 commit comments