qc_init.htb 5.05 KB
Newer Older
Tyler Collins's avatar
Tyler Collins committed
1
2
%LOAD DATASET FILE...
EEG = pop_loadset('filename','[batch_dfn]','filepath','[batch_dfp]');
3
4
5
6
7

if ~find(strcmpi({EEG.marks.chan_info.label},'ch_s_sd'));
    EEG.marks=marks_add_label(EEG.marks,'chan_info',{'ch_s_sd',[1,0,0],[]});
end;

Tyler Collins's avatar
Tyler Collins committed
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
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;
117
118
119
if ~isempty(ch_s_sd_ind); % skip study-wide criteria if not used
    EEG.marks.comp_info(ch_s_sd_ind).order=2;
end;
Tyler Collins's avatar
Tyler Collins committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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]');