Skip to content

Commit

Permalink
Merge pull request #28 from DouweHorsthuis/dashboard
Browse files Browse the repository at this point in the history
Major update 2022
  • Loading branch information
DouweHorsthuis authored Dec 1, 2022
2 parents 90e0d7d + 2271a83 commit 9fa3b26
Show file tree
Hide file tree
Showing 41 changed files with 3,103 additions and 125 deletions.
19 changes: 12 additions & 7 deletions src/A_merge_sets.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
% EEGLAB merge sets, and creates .set file
% by Douwe Horsthuis updated on 6/21/2021
% ------------------------------------------------
subject_list = {'some sort of ID' 'a different id for a different particpant'}; %all the IDs for the indivual particpants
filename = 'the_rest_of_the_file_name'; % if your bdf file has a name besides the ID of the participant (e.g. oddball_paradigm)
home_path = 'path_where_to_load_in_pc'; %place data is (something like 'C:\data\')
blocks = 5; % the amount of BDF files. if different participant have different amounts of blocks, run those participant separate
subject_list = {'ID_participant1' 'ID_participant2' 'ID_etc'}; %all the IDs for the indivual particpants
home_path = 'C:\Users\dohorsth\Desktop\cued-boss\'; %place data is (something like 'C:\data\')
save_path = 'C:\Users\dohorsth\Desktop\cystinosis\cued boss\data\'; %only for the first script, in case you load your data from somewhere special but want to save it somewhere else
filename = 'cued_boss'; % if your bdf file has a name besides the ID of the participant (e.g. oddball_paradigm)
blocks = 1; % the amount of BDF files. if different participant have different amounts of blocks, run those participant separate
readme_file ='yes';%'yes' or 'no', if yes using [EEG]= readme_to_EEG(EEG, data_path) to read readme file
eye_tracking ='no';%'yes' or 'no', if yes using edf_to_figure(data_path)to create a figure with avg gaze
if strcmpi(readme_file,'yes') || strcmpi(eye_tracking,'yes')% if yes we need to add the functions to the file path
Expand All @@ -17,15 +18,17 @@
close all
data_path = [home_path subject_list{s} '\'];
disp([data_path subject_list{s} '_' filename '.bdf'])
save_path_indv=[save_path subject_list{s} '\'];
if blocks == 1
%if participants have only 1 block, load only this one file
EEG = pop_biosig([data_path subject_list{s} '_' filename '.bdf']);
else
EEG = pop_biosig([data_path subject_list{s} '_' filename '_1.bdf']);
else
for bdf_bl = 1:blocks
%if participants have more than one block, load the blocks in a row
%your files need to have the same name, except for a increasing number at the end (e.g. id#_file_1.bdf id#_file_2)
EEG = pop_biosig([data_path subject_list{s} '_' filename '_' num2str(bdf_bl) '.bdf']);
[ALLEEG, ~] = eeg_store(ALLEEG, EEG, CURRENTSET);
mkdir(save_path_indv) %if individual folders do not exist
end
%since there are more than 1 files, they need to be merged to one big .set file.
EEG = pop_mergeset( ALLEEG, 1:blocks, 0);
Expand All @@ -37,7 +40,9 @@
EEG.subject = subject_list{s}; %subject ID
end
if strcmpi(eye_tracking,'yes')
edf_to_figure(data_path)
edf_to_figure(data_path);
saveas(gcf,[data_path subject_list{s} '_ET'])
close all
end
%save the bdf as a .set file

Expand Down
38 changes: 15 additions & 23 deletions src/B_downs_filter_chaninfo_exclchan.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
% Combination of EEGLAB downsample and filter, and reject channel script by Ana on 2017-07-11
% Combined and updated by Douwe Horsthuis last update 11/5/2021
% ------------------------------------------------

clear variables
% This defines the set of subjects
subject_list = {'some sort of ID' 'a different id for a different particpant'};
home_path = 'the main folder where you store your data';
scripts_location = 'C:\\Scripts\'; %needed if using 160channel data
subject_list = {'6209' '6239' '8103' '8110' '8110-01' '8113' '8117' '8119' '8121' '8121-01' '8128' '8128-01'}; %all the IDs for the indivual particpants
home_path = 'C:\Users\dohorsth\Desktop\cued-boss\'; %place data is (something like 'C:\data\')
downsample_to=256; % what is the sample rate you want to downsample to
lowpass_filter_hz=45; %45hz filter
highpass_filter_hz=1; %1hz filter
avg_deleted_data=zeros(1, length(subject_list));
clean_data={'y'}; % if 'y' not only channels but also noisy moments in thedata get cleaned
individual_plots='yes';
%% variables that need to be created
eeglab_location = fileparts(which('eeglab')); %needed if using a 10-5-cap
avg_deleted_data=zeros(1, length(subject_list));
% Loop through all subjects
for s=1:length(subject_list)
fprintf('\n******\nProcessing subject %s\n******\n\n', subject_list{s});
Expand All @@ -34,18 +31,20 @@
EEG = eeg_checkset( EEG );
EEG = pop_eegfiltnew(EEG, 'hicutoff',lowpass_filter_hz);
EEG = eeg_checkset( EEG );
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_downft.set'],'filepath', data_path);
%looking for bridged channels
if strcmpi(individual_plots,'yes')
EEG=plotting_bridged_channels(EEG, data_path); %plotting the location of bridged chan
end
close all
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_downft.set'],'filepath', data_path);

EEG.old_n_chan = EEG.nbchan;
old_samples=EEG.pnts;
%adding channel location
if EEG.nbchan >63 && EEG.nbchan < 95 %64chan cap (can be a lot of externals, this makes sure that it includes a everything that is under 96 channels, which could be an extra ribbon)
EEG=pop_chanedit(EEG, 'lookup',[eeglab_location '\plugins\dipfit\standard_BESA\standard-10-5-cap385.elp'],'rplurchanloc',[1]); %make sure you put here the location of this file for your computer
EEG=pop_chanedit(EEG, 'lookup',[fileparts(which('eeglab')) '\plugins\dipfit\standard_BESA\standard-10-5-cap385.elp'],'rplurchanloc',[1]); %make sure you put here the location of this file for your computer
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_info.set'],'filepath', data_path);
%looking for bridged channel
if strcmpi(individual_plots,'yes')
EEG=plotting_bridged_channels(EEG, data_path); %plotting the location of bridged chan
end
close all
%deleting bad channels
%EEG = pop_rejchan(EEG,'elec', [1:64],'threshold',5,'norm','on','measure','kurt');
EEG = pop_select( EEG, 'nochannel',{'EXG1','EXG2','EXG3','EXG4','EXG5','EXG6','EXG7','EXG8'});
Expand All @@ -56,7 +55,7 @@
end
EEG.deleteddata_wboundries=100-EEG.pnts/old_samples*100;
elseif EEG.nbchan >159 && EEG.nbchan < 191 %160chan cap
EEG=pop_chanedit(EEG, 'lookup',[scripts_location 'BioSemi160.sfp']); %make sure you put here the location of this file for your computer
EEG=pop_chanedit(EEG, 'lookup',[[fileparts(matlab.desktop.editor.getActiveFilename),filesep] 'BioSemi160.sfp']); %make sure you put here the location of this file for your computer
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_info.set'],'filepath', data_path);
%deleting bad channels
%EEG = pop_rejchan(EEG,'elec', [1:160],'threshold',5,'norm','on','measure','kurt');
Expand All @@ -68,15 +67,8 @@
end
EEG.deleteddata_wboundries=100-EEG.pnts/old_samples*100;
end
disp([num2str(EEG.deleteddata_wboundries) '% of the data got deleted for this participant']);
disp([num2str(EEG.deleteddata_wboundries) '% of the data got deleted for this participant']);
avg_deleted_data(s)=EEG.deleteddata_wboundries;


%% creating figures with deleted and bridged channels
if strcmpi(individual_plots,'yes')
EEG=plot_deleted_chan_location(EEG,data_path); %plotting the location of deleted chan
end
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_exchn.set'],'filepath', data_path);

EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_exchn.set'],'filepath', data_path);
end
disp(['on averages ' num2str(sum(avg_deleted_data)/length(subject_list)) ' % of the data got deleted']);
15 changes: 13 additions & 2 deletions src/C_manual_check.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
% ------------------------------------------------
subject_list = {'some sort of ID' 'a different id for a different particpant'};
home_path = 'the main folder where you store your data';

group_del_channel=[]; %needed for the plot_group_deleted_chan_location function
for s=1:length(subject_list)
clear bad_chan;
fprintf('\n******\nProcessing subject %s\n******\n\n', subject_list{s});
Expand All @@ -12,8 +14,17 @@
prompt = 'Delete channels? If yes, input them all as strings inside {}. If none hit enter ';
bad_chan = input(prompt); %
if isempty(bad_chan) ~=1
EEG = pop_select( EEG, 'nochannel',bad_chan);
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_exchn.set'],'filepath', data_path);
EEG = pop_select( EEG, 'nochannel',bad_chan);
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_exchn.set'],'filepath', data_path);
end
close all

%% creating figures with deleted and bridged channels
EEG=plot_deleted_chan_location(EEG,data_path); %plotting the location of deleted chan
% plotting a topoplot with how many channels get for everyone
[EEG, group_del_channel]=plot_group_deleted_chan_location(EEG,group_del_channel,home_path);
%% group quality info, ID / % deleted data / seconds of data left / N - deleted channels
quality(s,:)=[str2double(subject_list{s}), EEG.deleteddata_wboundries,round(EEG.xmax), length(EEG.del_chan)];
end
load([home_path 'participant_info']) %so we can add
save([home_path 'participant_info'], 'participant_badchan', 'quality');
27 changes: 3 additions & 24 deletions src/D_reref_exclextrn_interp_avgref_ica_autoexcom.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
clear variables
eeglab
%% Subject info for each script
subject_list = {'some sort of ID' 'a different id for a different particpant'};% This defines the set of subjects
home_path = 'the main folder where you store your data';% Path to the parent folder, which contains the data folders for all subjects
subject_list = {'some sort of ID' 'a different id for a different particpant'};
home_path = 'the main folder where you store your data';
%% info needed for this script specific
components = num2cell(zeros(length(subject_list), 8)); %prealocationg space for speed
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 (for example {'EXG3' 'EXG4'} or {'Cz'})
Expand Down Expand Up @@ -95,27 +95,6 @@
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');
print([data_path subject_list{s} '_remaining_ICs_topos'], '-dpng' ,'-r300');
close all
%putting both figures in 1 plot saving it, deleting the other 2.
figure('units','normalized','outerposition',[0 0 1 1])
if EEG.nbchan<65
subplot(1,5,1);
else
subplot(1,10,1);
end
imshow([data_path subject_list{s} '_Bad_ICs_topos.png']);
title('Deleted components')
if EEG.nbchan<65
subplot(1,5,2:5);
else
subplot(1,10,2:10);
end
imshow([data_path subject_list{s} '_remaining_ICs_topos.png']);
title('Remaining components')
print([data_path subject_list{s} '_ICs_topos'], '-dpng' ,'-r300');
%deleting two original files
delete([data_path subject_list{s} '_Bad_ICs_topos.png'])
delete([data_path subject_list{s} '_remaining_ICs_topos.png'])
close all
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_excom.set'],'filepath', data_path);%save
%this part saves all the bad channels + ID numbers
lables_del = setdiff(labels_all,labels_good); %only stores the deleted channels
Expand All @@ -124,4 +103,4 @@
data_subj = [ID, All_bad_chan]; %combines IDs and Bad channels
participant_badchan(s,:) = data_subj;%combine new data with old data
end
save([home_path 'participant_info'], 'participant_badchan');
save([home_path 'participant_info'], 'participant_badchan');
45 changes: 27 additions & 18 deletions src/E_epoching.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@
clear variables
eeglab
%% Subject info for each script
% This defines the set of subjects
subject_list = {'some sort of ID' 'a different id for a different particpant'};
% Path to the parent folder, which contains the data folders for all subjects
home_path = 'the main folder where you store your data';
home_path = 'the main folder where you store your data'; %place data is (something like 'C:\data\')
%% info needed for this script specific
name_paradigm = 'name'; % this is needed for saving the table at the end
name_paradigm = 'cued_boss'; % this is needed for saving the table at the end
%participant_info_temp = []; % needed for creating matrix at the end
binlist_location = 'the folder where you stored your binlist\'; %binlist should be named binlist.txt
epoch_time = [-50 400];
binlist_location = 'C:\Users\dohorsth\Documents\GitHub\EEG_to_ERP_pipeline_stats_R\testing\scripts\'; %binlist should be named binlist.txt
binlist_name='binlist_main_rts.txt';
epoch_time = [-50 800];
baseline_time = [-50 0];
n_bins=3;% enter here the number of bins in your binlist
participant_info_temp = string(zeros(length(subject_list), 2+n_bins)); %prealocationg space for speed
n_bins=9;% enter here the number of bins in your binlist
load([home_path 'participant_info'], 'participant_badchan');
participant_info_temp = string(zeros(length(subject_list), 3+n_bins)); %prealocationg space for speed
%% Loop through all subjects
for s=1:length(subject_list)
fprintf('\n******\nProcessing subject %s\n******\n\n', subject_list{s});
clear data_subj
% Path to the folder containing the current subject's data
data_path = [home_path subject_list{s} '/'];

% Load original dataset
fprintf('\n\n\n**** %s: Loading dataset ****\n\n\n', subject_list{s});
EEG = pop_loadset('filename', [subject_list{s} '_excom.set'], 'filepath', data_path);
%epoching
for i =1:length(EEG.event)%something odd, where eeg.event is irregular
if contains(EEG.event(i).type, 'boundary') %skipping the boundary events
continue
elseif ~isempty(EEG.event(i).edftype)
EEG.event(i).type = char(num2str(EEG.event(i).edftype)); %making sure that the edf are fixed first
else
new=EEG.event(i).type;
EEG.event(i).edftype=str2double(new); %fixing edftype
end
end
EEG = eeg_checkset( EEG );
EEG = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', 'BoundaryNumeric', { -99 }, 'BoundaryString', { 'boundary' } );
EEG = eeg_checkset( EEG );
EEG = pop_binlister( EEG , 'BDF', [binlist_location '\binlist.txt'], 'IndexEL', 1, 'SendEL2', 'EEG', 'Voutput', 'EEG' );
EEG = pop_binlister( EEG , 'BDF', [binlist_location binlist_name], 'IndexEL', 1, 'SendEL2', 'EEG', 'Voutput', 'EEG' );
EEG = eeg_checkset( EEG );
EEG = pop_epochbin( EEG , epoch_time, baseline_time); %epoch size and baseline size
EEG = eeg_checkset( EEG );
Expand All @@ -46,15 +54,16 @@
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_epoched.set'],'filepath', data_path);
ERP = pop_savemyerp(ERP, 'erpname', [subject_list{s} '.erp'], 'filename', [subject_list{s} '.erp'], 'filepath', data_path); %saving a.ERP file
%the following line creates an excel with RTs. For this to be possible make sure you have the right events in your eventlist.
%values = pop_rt2text(ERP, 'eventlist',1, 'filename', [home_path '\All RT files\' subject_list{s} '_rt.xls'], 'header', 'on', 'listformat', 'basic' );

ID = string(subject_list{s});
data_subj = [ID, percent_deleted, ERP.ntrials.accepted ]; %ERP.ntrials.accepted gives all the trials per bin
participant_info_temp(s,:) = data_subj;
RT = pop_rt2text(ERP, 'eventlist',1, 'filename', [data_path subject_list{s} '_rt.xls'], 'header', 'on', 'listformat', 'basic' );
for i=1:length(participant_badchan)
if strcmpi(participant_badchan(i,1),subject_list{s})
participant_info_temp(i,:)= [participant_badchan(i,:),percent_deleted, ERP.ntrials.accepted ];
end
end
end
colNames = [{'ID','%data deleted'} ERP.bindescr]; %adding names for columns [ERP.bindescr] adds all the name of the bins
colNames = [{'ID','Deleted channels', '%data deleted'} ERP.bindescr]; %adding names for columns [ERP.bindescr] adds all the name of the bins
participant_info = array2table( participant_info_temp,'VariableNames',colNames); %creating table with column names
save([home_path name_paradigm '_participant_epoching_cleaing_bin_info'], 'participant_info');
save([home_path name_paradigm '_participant_info'], 'participant_info');



Loading

0 comments on commit 9fa3b26

Please sign in to comment.