Commit 3fb799b8 authored by Tyler Collins's avatar Tyler Collins
Browse files

Updates to quality control procedure.

parent 1aeeb3ce
......@@ -2,96 +2,81 @@
EEG = pop_loadset('filename','[batch_dfn]','filepath','[batch_dfp]');
EEG = eeg_checkset(EEG);
%% 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',[0.8,0.8,0]};
lookupTable = cell2struct(pairs, {'name', 'colour'}, 2);
% Below code is how to call proper label lookup
% [prob, classind] = max(EEG.etc.ic_classification.ICLabel.classifications(1, :));
% Below line should give you number of components
% length(EEG.etc.ic_classification.ICLabel.classifications);
% Run ICLabel
EEG = iclabel(EEG);
% 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, :));
rawLabels(index) = i;
% CHECK FOR IC CLASSIFICATION MARKS
if isempty(find(strcmp('brain',{EEG.marks.comp_info.label})));
%% 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',[0.8,0.8,0]};
lookupTable = cell2struct(pairs, {'name', 'colour'}, 2);
% Run ICLabel
EEG = iclabel(EEG);
% 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, :));
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
%RESET/INITIATE IC MARKS...
manual_ind=find(strcmp('manual',{EEG.marks.comp_info.label}));
brain_ind=find(strcmp('brain',{EEG.marks.comp_info.label}));
EEG.marks.comp_info(manual_ind).flags=~EEG.marks.comp_info(brain_ind).flags;
end
%ICLabel Exporting to marks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
logging_log('INFO','UPDATE MARKS STRUCTURE WITH ICLABEL BRAIN COMPS...');
tic;
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
logging_log('INFO','TIME TO: UPDATE MARKS STRUCTURE...');
toc
bfh=figure;
bar(EEG.etc.ic_classification.ICLabel.classifications,'stacked','Horizontal','on');
colormap(jet);
axis 'tight';
legend({ 'brain','muscle','eye','heart','line_noise','chan_noise','other'});
view(180,90);
set(gca,'ytick',[1:min(size(EEG.icasphere))])
%PLOT IC TOPOGRAPHIES...
%pop_topoplot(EEG,0, [1:min(size(EEG.icawinv))] , 'qc',0,1, 'electrodes', 'off', 'masksurf', 'on');
%for i=1;length([1:min(size(EEG.icawinv))]);
pop_viewprops(EEG,0);
%if i>35; tfh=pop_viewprops(EEG,0);
%end
%set(tfh,'Position',[ 1948 -9 1903 1049]);
%RESET/INITIATE IC MARKS...
manual_ind=find(strcmp('manual',{EEG.marks.comp_info.label}));
%neural_ind=marks_label2index(EEG.marks.comp_info,{'neural'},'indexes');
%EEG.marks.comp_info(manual_ind).flags(neural_ind)=0;
%bio_ind=marks_label2index(EEG.marks.comp_info,{'bio'},'indexes');
%EEG.marks.comp_info(manual_ind).flags(bio_ind)=1;
EEG.marks.comp_info(manual_ind).flags=zeros(size(EEG.marks.comp_info(manual_ind).flags));
%set mixed mark
% minx_ind=marks_label2index(EEG.marks.comp_info,{'neural','bio'},'flags','invert','on');
% EEG.marks=marks_add_label(EEG.marks,'comp_info', ...
% {'mix',[0,.3,.4],[0,.3,.4],1,minx_ind'});
%
%
% qc_cortical_flags=marks_label2index(EEG.marks.comp_info,{'neural'},'flags');
% EEG.marks=marks_add_label(EEG.marks,'comp_info', ...
% {'qc_cortical',[0,.6,0],[0,.6,0],1,zeros(size(qc_cortical_flags'))});
%PLOT CHAN DATA SCROLL PLOT USING VISED PLUGIN...
EEG_scalp = pop_vised(EEG,'data_type','EEG','pop_gui','off','spacing',80,'command','');
......@@ -111,9 +96,12 @@ disp(['Time taken to perform QC: ' qc_time 'sec.']);
tfh = findobj('Type', 'figure');
close(tfh(find(strcmp('View components properties - pop_viewprops() (dataset: filtLP - 1-s epochs - 1-s epochs - 1-s epochs)',{tfh.Name}))).Number);
%CLOSE/CLEAR ICLABEL BAR GRAPH
try close(bfh),clear bfh, catch clear bfh, end
%CLOSE/CLEAR EEG SCROLL PLOT HANDLES
try close(sfh),clear sfh, catch clear sfh, end
%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]');
\ No newline at end of file
%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