Skip to content

Commit 051d63f

Browse files
Changing IClabel criteria and plotting
1 parent a4b0cd7 commit 051d63f

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ This script will double check and fix any potential trigger issue we encountered
9696
#### E_preprocces3
9797
This script will do an average reference.
9898
This is followed by an [Independent Component Analysis](https://eeglab.org/tutorials/06_RejectArtifacts/RunICA.html). We use the pca option to prevent rank-deficiencies.
99-
After his we delete only eye components by using [IClabel](https://github.com/sccn/ICLabel). IClabel will only delete the component if it has more than 80% eye data and less then 5% brain data.
99+
After his we delete only eye components by using [IClabel](https://github.com/sccn/ICLabel). IClabel will only delete the component if it has more than 80% eye data and less then 10% brain data. We arrived at this criteria after comparing (for a different dataset) how many components we (Ana, Douwe and Filip) would delete manually and what threshold would get the closesed to that.
100100
After that we use [pop_rejcont](https://github.com/wojzaremba/active-delays/blob/master/external_tools/eeglab11_0_4_3b/functions/popfunc/pop_rejcont.m). This function epochs the data temporatly and deletes the epochs that are noisy. We set this to a threshold of 8, because this would delete between 0-20% of the data. We save a matlab structure with how much data of each participant get's deleted.
101101

102102
**note** for the Aging group, we use the [pop_rejcont](https://github.com/wojzaremba/active-delays/blob/master/external_tools/eeglab11_0_4_3b/functions/popfunc/pop_rejcont.m) function also right before the ICA. This is because the data was too noisy for more than 50% of the participants to find eye components.
@@ -113,7 +113,7 @@ After that we use the the [pwelch function of Matlab](https://www.mathworks.com/
113113
# add here what channels we use, for now it's just indivual but we will change this to groups and averages of those groups
114114

115115
### Microstates
116-
this script follows the code as descibed in Poulsen, A. T., Pedroni, A., Langer, N., & Hansen, L. K. (2018). Microstate EEGlab toolbox: An introductory guide.
116+
this script follows the code as descibed in Poulsen, A. T., Pedroni, A., Langer, N., & Hansen, L. K. (2018). Microstate EEGlab toolbox: An introductory guide. [See their guide in bioRxiv for more information.](https://www.biorxiv.org/content/10.1101/289850v1)
117117

118118

119119

src/E_preprocces3.m

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
%clear variables
2-
%eeglab
3-
Group = {'Aging'}; %'Control'
1+
clear variables
2+
eeglab
3+
Group = {'Aging' 'Control' 'ASD'}; %'Control'
44

55
for g=1:length(Group)
66
switch Group{g}
@@ -15,8 +15,6 @@
1515
subject_list = {'12022' '12023' '12031' '12081' '12094' '12188' '12255' '12335' '12339' '12362' '12364' '12372' '12376' '12390' '12398' '12407' '12408' '12451' '12454' '12457' '12458' '12459' '12468' '12478' '12498' '12510' '12517' '12532' '12564' '12631' '12633' '12634' '12636' '12665' '12670' '12696' '12719' '12724' '12751' '12763' '12769' '12776' '12790' '12806' '12814' '12823' '12830' '12847' '12851' '12855' '12856' '12857' '12859' '12871' '12872' '12892'};
1616
deleted_data_before = num2cell(zeros(length(subject_list), 2)); %only this group wil have their data cleaned extra
1717
end
18-
19-
2018
figure_path = [home_path 'figures\'];
2119
participant_info = num2cell(zeros(length(subject_list),9));
2220
deleted_data = num2cell(zeros(length(subject_list), 2));
@@ -73,7 +71,7 @@
7371
ICA_components = EEG.etc.ic_classification.ICLabel.classifications ; %creates a new matrix with ICA components
7472
%Only the eyecomponent will be deleted, thus only components 3 will be put into the 8 component
7573
ICA_components(:,8) = ICA_components(:,3); %row 1 = Brain row 2 = muscle row 3= eye row 4 = Heart Row 5 = Line Noise row 6 = channel noise row 7 = other, combining this makes sure that the component also gets deleted if its a combination of all.
76-
bad_components = find(ICA_components(:,8)>0.80 & ICA_components(:,1)<0.05); %if the new row is over 80% of the component and the component has less the 5% brain
74+
bad_components = find(ICA_components(:,8)>0.80 & ICA_components(:,1)<0.10); %if the new row is over 80% of the component and the component has less the 5% brain
7775
%Still labeling all the other components so they get saved in the end
7876
brain_ic = length(find(ICA_components(:,1)>0.80));
7977
muscle_ic = length(find(ICA_components(:,2)>0.80 & ICA_components(:,1)<0.05));
@@ -82,21 +80,47 @@
8280
line_noise_ic = length(find(ICA_components(:,5)>0.80 & ICA_components(:,1)<0.05));
8381
channel_ic = length(find(ICA_components(:,6)>0.80 & ICA_components(:,1)<0.05));
8482
other_ic = length(find(ICA_components(:,7)>0.80 & ICA_components(:,1)<0.05));
85-
%will plot all the IC components that get deleted
83+
%Plotting all eye componentes and all remaining components
8684
if isempty(bad_components)~= 1 %script would stop if people lack bad components
8785
if ceil(sqrt(length(bad_components))) == 1
8886
pop_topoplot(EEG, 0, [bad_components bad_components] ,subject_list{s} ,0,'electrodes','on');
8987
else
9088
pop_topoplot(EEG, 0, [bad_components] ,subject_list{s},[ceil(sqrt(length(bad_components))) ceil(sqrt(length(bad_components)))] ,0,'electrodes','on');
9189
end
9290
title(subject_list{s});
93-
print([figure_path subject_list{s} '_Bad_ICs_topos'], '-dpng');
91+
print([figure_path subject_list{s} '_Bad_ICs_topos'], '-dpng' ,'-r300');
9492
EEG = pop_subcomp( EEG, [bad_components], 0); %excluding the bad components
93+
close all
9594
else %instead of only plotting bad components it will plot all components
95+
title(subject_list{s}); text( 0.2,0.5, 'there are no eye-components found')
9696
pop_topoplot(EEG, 0, 1:length(ICA_components) ,subject_list{s},[ceil(sqrt(length(ICA_components))) ceil(sqrt(length(ICA_components)))] ,0,'electrodes','on');
9797
title(subject_list{s});
98-
print([figure_path subject_list{s} '_no_bad_ICs_topos'], '-dpng');
98+
print([figure_path subject_list{s} '_Bad_ICs_topos'], '-dpng' ,'-r300');
9999
end
100+
title(subject_list{s});
101+
pop_topoplot(EEG, 0, 1:size(EEG.icaweights,1) ,subject_list{s},[ceil(sqrt(size(EEG.icaweights,1))) ceil(sqrt(size(EEG.icaweights,1)))] ,0,'electrodes','on');
102+
print([figure_path subject_list{s} '_remaining_ICs_topos'], '-dpng' ,'-r300');
103+
close all
104+
%putting both figures in 1 plot saving it, deleting the other 2.
105+
figure('units','normalized','outerposition',[0 0 1 1])
106+
if EEG.nbchan<65
107+
subplot(1,5,1);
108+
else
109+
subplot(1,10,1);
110+
end
111+
imshow([figure_path subject_list{s} '_Bad_ICs_topos.png']);
112+
title('Deleted components')
113+
if EEG.nbchan<65
114+
subplot(1,5,2:5);
115+
else
116+
subplot(1,10,2:10);
117+
end
118+
imshow([figure_path subject_list{s} '_remaining_ICs_topos.png']);
119+
title('Remaining components')
120+
print([figure_path subject_list{s} '_ICs_topos'], '-dpng' ,'-r300');
121+
%deleting two original files
122+
delete([figure_path subject_list{s} '_Bad_ICs_topos.png'])
123+
delete([figure_path subject_list{s} '_remaining_ICs_topos.png'])
100124
close all
101125
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_excom.set'],'filepath', data_path);%save
102126
%% extra cleaning
@@ -110,8 +134,5 @@
110134
components(s,:)=[subj_comps];
111135
end
112136
save([home_path 'components'], 'components');
113-
if strcmp(Group, 'Aging')
114-
save([home_path 'deleted_data_before_ica_160ch'], 'deleted_data_before');
115-
end
116-
save([home_path 'deleted_data_160ch'], 'deleted_data');
137+
save([home_path 'deleted_data'], 'deleted_data');
117138
end

0 commit comments

Comments
 (0)