Commit 56e02817 authored by Tyler Collins's avatar Tyler Collins
Browse files

QC init for ICLabel

parent eb515d84
%LOAD DATASET FILE...
EEG = pop_loadset('filename','[batch_dfn]','filepath','[batch_dfp]');
EEG = eeg_checkset(EEG);
% CHECK FOR IC CLASSIFICATION MARKS
%% Use the ICLabel plugin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ICLabel is a database style plugin that classifies ICA components into the
% following seven categories
% (Brain)(Muscle)(Eye)(Heart)(Line Noise)(Channel Noise)(Other)
% ( 1 )( 2 )( 3 )( 4 )( 5 )( 6 )( 7 )
% Colour structure and groupings are as follows:
% ----------
% Brain -> [0, 0.4, 0]
% ----------
% Muscle -> [0.4, 0, 0]
% Eye -> [0.8, 0, 0]
% Heart -> [0.8, 0.4, 0]
% ----------
% Line Noise -> [0.2, 0.4, 0.8]
% Channel noise -> [0.4, 0, 0.8]
% ----------
% Other -> [0.8, 0.8, 0]
% ----------
% Create lookup table of the above information.
pairs = {'brain',[0, 0.4, 0];
'muscle',[0.4,0,0];
'eye',[0.8,0,0];
'heart',[0.8,0.4,0];
'line_noise',[0.2,0.4,0.8];
'chan_noise',[0.4,0,0.8];
'other',[.7 .4 0]};
lookupTable = cell2struct(pairs, {'name', 'colour'}, 2);
EEG = pop_marks_select_data(EEG,'time marks',[],'labels',{'manual'},'remove','on');
% Run ICLabel
%EEG = iclabel(EEG);
% extract features
disp 'ICLabel: extracting features...'
features = ICL_feature_extractor(EEG, 40);
% run ICL
disp 'ICLabel: calculating labels...'
labels = run_ICL(features{:});
% save into EEG
disp 'ICLabel: saving results...'
EEG.etc.ic_classification.ICLabel.classes = ...
{'Brain', 'Muscle', 'Eye', 'Heart', 'Line', 'Channel', 'Other'};
EEG.etc.ic_classification.ICLabel.classifications = labels;
tmp=EEG.etc.ic_classification;
EEG = pop_loadset('filename','[batch_dfn]','filepath','[batch_dfp]');
EEG = eeg_checkset(EEG);
EEG.etc.ic_classification=tmp;
% Extract labels from the structure.
rawLabels = zeros([1,length(EEG.etc.ic_classification.ICLabel.classifications)]);
for index = 1:length(EEG.etc.ic_classification.ICLabel.classifications)
[p,i] = max(EEG.etc.ic_classification.ICLabel.classifications(index,1:end-1));
if p<.3;
i=7;
end
rawLabels(index) = i;
end
%ICLabel Exporting to marks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
logging_log('INFO','UPDATE MARKS STRUCTURE WITH ICLABEL BRAIN COMPS...');
for compStage = 1:7
ICLabel_pass= zeros([1,length(rawLabels)]);
ICLabel_pass(find(rawLabels==compStage)) = 1;
ICLabel_pass = ICLabel_pass';
EEG.marks=marks_add_label(EEG.marks,'comp_info', ...
{lookupTable(compStage).name,lookupTable(compStage).colour, ...
lookupTable(compStage).colour,1,ICLabel_pass});
end
% make any brain components always on top:
EEG.marks.comp_info(1,find(strcmp({EEG.marks.comp_info.label},'brain'))).order=2;
%RESET/INITIATE CHAN MARKS...
manual_ind=find(strcmp('manual',{EEG.marks.chan_info.label}));
%RESET/INITIATE IC MARKS...
EEG.marks=marks_add_label(EEG.marks,'comp_info',{'ambig',[.3,.3,1],[.3,.3,1],3,zeros(min(size(EEG.icaweights)),1)});
manual_ind=find(strcmp('manual',{EEG.marks.comp_info.label}));
ch_s_sd_ind=find(strcmp('ch_s_sd',{EEG.marks.chan_info.label}));
ch_sd_ind=find(strcmp('ch_sd',{EEG.marks.chan_info.label}));
low_r_ind=find(strcmp('low_r',{EEG.marks.chan_info.label}));
bridge_ind=find(strcmp('bridge',{EEG.marks.chan_info.label}));
rank_ind=find(strcmp('rank',{EEG.marks.chan_info.label}));
icrt_ind=find(strcmp('ic_rt',{EEG.marks.comp_info.label}));
brain_ind=find(strcmp('brain',{EEG.marks.comp_info.label}));
muscle_ind=find(strcmp('muscle',{EEG.marks.comp_info.label}));
eye_ind=find(strcmp('eye',{EEG.marks.comp_info.label}));
heart_ind=find(strcmp('heart',{EEG.marks.comp_info.label}));
line_noise_ind=find(strcmp('line_noise',{EEG.marks.comp_info.label}));
chan_noise_ind=find(strcmp('chan_noise',{EEG.marks.comp_info.label}));
other_ind=find(strcmp('other',{EEG.marks.comp_info.label}));
ambig_ind=find(strcmp('ambig',{EEG.marks.comp_info.label}));
EEG.marks.comp_info(manual_ind).order=1;
EEG.marks.comp_info(ch_s_sd_ind).order=2;
EEG.marks.comp_info(ch_sd_ind).order=2;
EEG.marks.comp_info(low_r_ind).order=2;
EEG.marks.comp_info(bridge_ind).order=2;
EEG.marks.comp_info(rank_ind).order=2;
EEG.marks.comp_info(icrt_ind).order=1;
EEG.marks.comp_info(brain_ind).order=2;
EEG.marks.comp_info(muscle_ind).order=2;
EEG.marks.comp_info(eye_ind).order=2;
EEG.marks.comp_info(heart_ind).order=2;
EEG.marks.comp_info(line_noise_ind).order=2;
EEG.marks.comp_info(chan_noise_ind).order=2;
EEG.marks.comp_info(other_ind).order=2;
EEG.marks.comp_info(ambig_ind).order=3;
bioa_inds = marks_label2index(EEG.marks.comp_info,{'muscle','eye','heart','chan_noise'},'indexes');
EEG.marks.comp_info(manual_ind).flags=zeros(min(size(EEG.icaweights)),1);
EEG.marks.comp_info(manual_ind).flags(bioa_inds)=1;
%SAVE *_qc.SET DATASET FILE...
EEG = pop_saveset( EEG,'filename','[batch_dfn,_,-1]_qc.set','filepath','[batch_dfp]');
%init_bids_sub(EEG,'[batch_dfn,_,-2]','[_,-2,batch_dfn,.,-1]');
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment