Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 update #37

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions testing/SWAT/C_manual_check.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
Group_list={'cystinosis' 'adult_controls'};
for gr=1:length(Group_list)
if strcmpi(Group_list{gr},'adult_controls')
subject_list = {'12091' '12709' '12883'};
subject_list = {'12091' '12709' '12883'};
elseif strcmpi(Group_list{gr},'cystinosis')
subject_list = {'9109' '9182' '9182'};
else
subject_list = {'9109' '9182' '9182'};
else
disp('not possible')
pause()
end
home_path = 'C:\Users\douwe\Desktop\processed\'; %place data is (something like 'C:\data\')
home_path = 'C:\Users\douwe\Desktop\processed\'; %place data is (something like 'C:\data\')
%need to add the folder with the functions
file_loc=[fileparts(matlab.desktop.editor.getActiveFilename),filesep];
addpath(genpath(file_loc));%adding path to your scripts so that the functions are found

for s=1:length(subject_list)
if s==1
group_del_channel=[]; %needed for the plot_group_deleted_chan_location function
if s==1
group_del_channel=[]; %needed for the plot_group_deleted_chan_location function
end
clear bad_chan;
fprintf('\n******\nProcessing subject %s\n******\n\n', subject_list{s});
data_path = [home_path subject_list{s} '\'];
EEG = pop_loadset('filename', [subject_list{s} '_exchn.set'], 'filepath', data_path);
pop_eegplot( EEG, 1, 1, 1);
prompt = 'Delete channels? If yes, input them all as strings inside {}. If none hit enter ';
bad_chan = input(prompt); %
%% 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);
Expand All @@ -36,9 +36,9 @@

%% 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_list{gr},length(subject_list));
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_list{gr},length(subject_list));

%% group quality info, ID / % deleted data / seconds of data left / N - deleted channels
quality(s,:)=[str2double(subject_list{s}), str2double(Group_list{gr}) EEG.deleteddata_wboundries,round(EEG.xmax), length(EEG.del_chan)];
end
Expand Down
203 changes: 203 additions & 0 deletions testing/SWAT/F_building_dashboard_group.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
clear all
home_path = 'C:\Users\douwe\Desktop\processed\'; %place data is (something like 'C:\data\')
Group_list={'adult_controls'};
%if the Eye tracking (ET) files were not saved as PGN add here the path to
%the edf files:
edf_path = 'C:\Users\douwe\Desktop\DATA\' ;
task_name = 'SWAT';
for gr=1:length(Group_list)
if strcmpi(Group_list{gr},'cystinosis' )
subject_list = { '9182' '9182' '9109'};
elseif strcmpi(Group_list{gr},'adult_controls')
subject_list = {'12709' '12091' '12883'};
elseif strcmpi(Group_list{gr},'grn')
subject_list = {'id_1' 'id_2'};
else
disp('not possible')
pause()
end
channels_names={'Fcz' 'Fc4' 'Fc3'}; %channels that you want ERP plots for
plotting_bins=[1:3]; %numbers of the bins you want to plot if
colors={'b-' 'm-' 'g-' };%'k-' 'r-'
epoch_time = [-50 500];
load([home_path 'participant_info_' Group_list{gr}]);
participant_info_full=participant_info;
for s=1:length(subject_list)
for i=1:height(participant_info_full)
if strcmpi(participant_info_full.('ID')(i),subject_list{s})
badchan= participant_info_full.('Deleted channels')(i);
Hit_green= participant_info_full.('hit green ')(i);
Hit_red= participant_info_full.('hit red ')(i);
Hit_all= participant_info_full.('All Hits')(i);

end
end
data_path = [home_path subject_list{s} '/'];
EEG = pop_loadset('filename', [subject_list{s} '_excom.set'], 'filepath', data_path);
%figures to png
h1= openfig([data_path subject_list{s} '_deleted_channels.fig']);
print([data_path subject_list{s} '_deleted_channels.png'], '-dpng' ,'-r300');
h2= openfig([data_path subject_list{s} '_bridged_channels.fig']);
print([data_path subject_list{s} '_bridged_channels.png'], '-dpng' ,'-r300');
%creating erps
ERP = pop_loaderp( 'filename', [subject_list{s} '.erp'], 'filepath', data_path );

channels=zeros(1,length(channels_names));
for i = 1:length(channels_names)
for ii=1:length(ERP.chanlocs)
if strcmpi(channels_names(i), ERP.chanlocs(ii).labels)
channels(i)=ii;
end
end
end
for i=1:length(channels_names)
figure();
for ii=1:length(plotting_bins)
plot(ERP.times,ERP.bindata(plotting_bins(i),:,plotting_bins(ii))) %plotting_bins(channel),time,bin
hold on
%row=bins columns=channels inside those each row=1subject
end
legend(ERP.bindescr{plotting_bins(1)}, ERP.bindescr{plotting_bins(2)} , ERP.bindescr{plotting_bins(3)}) %if you want to plot more/less channels change this
title(channels_names(i))
xlim(epoch_time);
print([data_path subject_list{s} '_' strtrim(ERP.bindescr{i}) '_erp'], '-dpng' ,'-r300');
close all
end
%if the ET file was saved as a PGN then don't run this part
edf_path_ind=[edf_path subject_list{s} '\'];
edf_to_figure(edf_path_ind);
saveas(gcf,[edf_path_ind subject_list{s} '_ET'])
print([data_path subject_list{s} '_ET' ], '-dpng' ,'-r300');
close all

fig=figure('units','normalized','outerposition',[0 0 1 1]);
set(gcf,'color',[0.85 0.85 0.85])
%Deleted channels (topoplot if amount is >1)

%ERPS

for i=1:length(plotting_bins)
subplot(5,5,i+10);
imshow([data_path subject_list{s} '_' strtrim(ERP.bindescr{i}) '_erp.png']);
title('ERPs')
end
%information boxes
annotation('textbox', [0.1, 0.825, 0.1, 0.1], 'String', [EEG.date; EEG.age; EEG.sex; EEG.Hand; EEG.glasses; EEG.Exp;EEG.Externals;EEG.Light; EEG.Screen; EEG.Cap;])
annotation('textbox', [0.25, 0.825, 0.1, 0.1], 'String', [EEG.vision_info; EEG.vision; EEG.hearing_info; EEG.hz500; EEG.hz1000; EEG.hz2000; EEG.hz4000]);
annotation('textbox', [0.25, 0.65, 0.1, 0.1], 'String', EEG.Medication);
annotation('textbox', [0.1, 0.6, 0.1, 0.1], 'String', [...
"Lowpass filter: " + EEG.filter.lowpass_filter_hz(1) + "Hz";...
"Highpass filter: " + EEG.filter.highpass_filter_hz(1) + "Hz";...
"Data deleted: " + num2str(EEG.deleteddata_wboundries) + "%";...
"Bad chan: " + badchan;...
"Amount bridged chan: " + string(length(EEG.bridged));...
]);
annotation('textbox', [0.10, 0.345, 0.1, 0.1], 'String',EEG.notes)
annotation('textbox', [0.10, 0.15, 0.1, 0.1], 'String',[...
"N Hit Green trials " + Hit_green...
"N Hit Red trials " + Hit_red...
"N Hit all trials " + Hit_all...
])

%Bridged channels (topoplot if amount is >1)
subplot(10,10,[5:6 15:16 25:26]);
if ~isempty(EEG.bridged)
imshow([data_path subject_list{s} '_bridged_channels.png']);
title('Bridged channels')
else
title('There are NO bridged channels')
end
subplot(10,10,[7:10 17:20 27:30]);
imshow([data_path subject_list{s} '_deleted_channels.png']);
title('Deleted channels')

subplot(10,10,[71:75 81:85 91:95]);
imshow([data_path subject_list{s} '_Bad_ICs_topos.png']);
title('Bad components')

subplot(10,10,[75:76 85:86 95:96]);
imshow([data_path subject_list{s} '_remaining_ICs_topos.png']);
title('Remaining components')

subplot(10,10,[77:80 87:90 97:100]);
imshow([data_path subject_list{s} '_ET.png']);
title('Eye Tracking')


%Final adjustments for the PDF
sgtitle(['Quality of ' subject_list{s} 's data while doing the ' task_name ' task']);
set(gcf, 'PaperSize', [16 10]);
% print(fig,[data_path subject_list{s} '_data_quality'],'-dpdf') % then print it
% print(fig,['D:\cystinosis\Flanker\Quality Check\' subject_list{s} '_data_quality'], '-dpdf');
close all
end %end of subject level
%% Start of group level plotting
%eye tracking at a group level
%input needs to be: edf_path=loctation with the participant folders (their names need to match the subject IDs,
%subject_list = list with all the subject IDs
edf_to_figure_group(edf_path,subject_list);
saveas(gcf,[home_path Group_list{gr} '_ET'])
print([home_path Group_list{gr} '_ET' ], '-dpng' ,'-r300');
close all
%ERP at group level needs to exist for this , this is identical to the
%individual level, but on the group erp
ERP = pop_loaderp( 'filename', [Group_list{gr} '.erp'], 'filepath', home_path );
for i=1:length(channels_names)
figure();
for ii=1:length(plotting_bins)
plot(ERP.times,ERP.bindata(plotting_bins(i),:,plotting_bins(ii))) %plotting_bins(channel),time,bin
hold on
%row=bins columns=channels inside those each row=1subject
end
legend(ERP.bindescr{plotting_bins(1)}, ERP.bindescr{plotting_bins(2)} , ERP.bindescr{plotting_bins(3)}) %if you want to plot more/less channels change this
title(channels_names(i))
xlim(epoch_time);
print([home_path Group_list{gr} '_' strtrim(ERP.bindescr{i}) '_erp'], '-dpng' ,'-r300');
close all
end
%starting the group dashboard
fig=figure('units','normalized','outerposition',[0 0 1 1]);
set(gcf,'color',[0.85 0.85 0.85])
full_group_name = strrep(Group_list{gr},'_',' ');
subplot(10,10,[4:6 14:16 24:26 34:36]);
imshow([home_path Group_list{gr} '_ET.png']);
title('Eye Tracking')
%If you want more than 3 ERPs than you need to change here the size
%of the subplots.
x=[0,3,6];
for i=1:length(plotting_bins)
subplot(10,10,[61+x(i):63+x(i) 71+x(i):73+x(i) 81+x(i):83+x(i) 91+x(i):93+x(i)]);%
imshow([home_path Group_list{gr} '_' strtrim(ERP.bindescr{i}) '_erp.png']);
title('ERPs')
end

subplot(10,10,[7:10 17:20 27:30 37:40]);
imshow([home_path Group_list{gr} '_deleted_channels.png']);
title('Deleted channels')
%looking for some info to write down
main_folder=dir(home_path);
for l=1:length(main_folder)
%looking for the group ERP date
if strcmpi([Group_list{gr} '.erp'],main_folder(l).name)
create_date=['The grand average ' full_group_name '.erp was created on ' main_folder(l).date];
end
end
group_size= ['There are ' num2str(length(ERP.workfiles)) ' participants in this group'];
date_dashboard = ["This group dashboard was created on " + datestr(datetime("today"))];
%Here you can add more info per group
annotation('textbox', [0.1, 0.800, 0.1, 0.1], 'String', [date_dashboard; ...
create_date; ...
group_size;...
"Lowpass filter: " + EEG.filter.lowpass_filter_hz(1) + "Hz";...
"Highpass filter: " + EEG.filter.highpass_filter_hz(1) + "Hz";...
"During the experiment (based on last participant):";...
EEG.Light;...
EEG.Screen])


%Final adjustments for the PDF
sgtitle(['Quality of the ' full_group_name ' group data while doing the ' task_name ' task']);
set(gcf, 'PaperSize', [16 10]);
print(fig,[home_path Group_list{gr} '_data_quality'],'-dpdf') % then print it
print(fig,['D:\cystinosis\Flanker\Quality Check\' Group_list{gr} '_data_quality'], '-dpdf');
end
4 changes: 2 additions & 2 deletions testing/SWAT/G_grandmeans.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
clear variables
eeglab
%% Subject info for each script
Group_list={ 'adult_controls' };
Group_list={ 'adult_controls' 'cystinosis' };
for gr=1:length(Group_list)
if strcmpi(Group_list{gr},'cystinosis' )
subject_list = { '9182' '9182' '9109'};
Expand All @@ -28,5 +28,5 @@
ERP = pop_savemyerp(ERP, 'erpname', Group_list{gr},...
'filename', [Group_list{gr} '.erp'], 'filepath', home_path, 'Warning', 'on');
%% plotting grandmean
ERP = pop_ploterps( ERP,1:3,1:64 , 'Axsize', [ 0.05 0.08], 'BinNum', 'on', 'Blc', 'pre', 'Box', [ 8 8], 'ChLabel', 'on', 'FontSizeChan',10, 'FontSizeLeg',12, 'FontSizeTicks',10, 'LegPos', 'bottom', 'Linespec', {'k-' , 'r-' , 'b-' , 'g-' , 'c-' }, 'LineWidth',1, 'Maximize', 'on', 'Position', [ 103.714 28 106.857 31.9412], 'Style', 'Classic', 'Tag', 'ERP_figure', 'Transparency',0, 'xscale', [ -50.0 394.0 -25 0:100:300 ], 'YDir', 'normal', 'yscale', [ -4.0 5 -10:2.5:5 ]);
% ERP = pop_ploterps( ERP,1:3,1:64 , 'Axsize', [ 0.05 0.08], 'BinNum', 'on', 'Blc', 'pre', 'Box', [ 8 8], 'ChLabel', 'on', 'FontSizeChan',10, 'FontSizeLeg',12, 'FontSizeTicks',10, 'LegPos', 'bottom', 'Linespec', {'k-' , 'r-' , 'b-' , 'g-' , 'c-' }, 'LineWidth',1, 'Maximize', 'on', 'Position', [ 103.714 28 106.857 31.9412], 'Style', 'Classic', 'Tag', 'ERP_figure', 'Transparency',0, 'xscale', [ -50.0 394.0 -25 0:100:300 ], 'YDir', 'normal', 'yscale', [ -4.0 5 -10:2.5:5 ]);
end
126 changes: 126 additions & 0 deletions testing/SWAT/functions/edf_to_figure_group.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
function [eyetrHeatMap] = edf_to_figure_group(data_path,id)
%% edf_to_figure is a combination of functions from @EDF2Mat.
% Edf2Mat is created by 'Adrian Etter, Marc Biedermann'
% edf_to_figure is created by Douwe John Horsthuis (2022)
% this is the followup where it combines the eyetracking of a group
% This function generates one figure with the heatmap of the gaze positions of all the data.
% It needs the data_path (where the .EDF files are of each participant)
% It needs the screen ratio of the screen the partiicpant was looking e.g. [16:10]

%% Merge all the data into one file
data_folder = dir(data_path);
obj = struct('Samples', struct('posX', [], 'posY', [])); % Initialize obj
amount = 0;
for s = 1:length(id) %length of all participants
for l=1:length(data_folder) %look at all the IDs in the datafolder dir
if strcmpi(id{s},data_folder(l).name)%if the id of the participant has a folder
data_folder_indv = dir([data_path id{s} '\']); %create a dir to the individual
amount = amount + 1;
for i = 1:length(data_folder_indv)
if endsWith(data_folder_indv(i).name, '.edf')
edf_temp = Edf2Mat([data_path id{s} filesep data_folder_indv(i).name]); % Reading the eye tracking files
obj.Samples.posX = [obj.Samples.posX; edf_temp.Samples.posX]; % Combining all of them
obj.Samples.posY = [obj.Samples.posY; edf_temp.Samples.posY]; % Combining all of them
end
end
end
end
end
exist edf_temp;
if ans == 0
disp('No EDF file, creating empty figure')
figure;

title(['This participant did not have an EDF file']);
xlabel(['This is an empty placeholder']);
elseif ans==1
%% Perform the rest (from Edf2Mat)
startIdx = 1;
endIdx = numel(obj.Samples.posX);
eye = 1;

range = startIdx:endIdx;
if numel(range) <= 0
error('Edf2Mat:plot:range', 'Start Index == End Index, nothing to be plotted');
end

%% Variables
gaussSize = 80;
gaussSigma = 20;

posX = obj.Samples.posX(range, eye);
posY = obj.Samples.posY(range, eye);

%% Generate data for heatmap
gazedata = [posY, posX];


% Set minimum x and y to zero
% for i = 1:size(gazedata, 2)
% gazedata(:, i) = gazedata(:, i) - min(gazedata(:, i));
% end

%finding screen size
for i = 1:length(edf_temp.RawEdf.FEVENT)
if contains(edf_temp.RawEdf.FEVENT(i).codestring, 'MESSAGEEVENT')
if contains(edf_temp.RawEdf.FEVENT(i).message, 'DISPLAY_COORDS')
display_coords= str2num(edf_temp.RawEdf.FEVENT(i).message(end-9:end));
end
end
end
%turning all gazes outsized of screen size to NaN
for i = 1:size(gazedata, 1)
if gazedata(i, 1) < 0 || gazedata(i, 2) < 0
gazedata(i, :) = [NaN, NaN];
elseif gazedata(i, :) > [display_coords(2),display_coords(1)]
gazedata(i, :) = [NaN, NaN];
elseif gazedata(i, 1) > [display_coords(2)]
gazedata(i, :) = [NaN, NaN];
elseif gazedata(i, 2) > [display_coords(1)]
gazedata(i, :) = [NaN, NaN];
end
end
gazedata = gazedata(~isnan(gazedata(:, 1)), :);

gazedata = ceil(gazedata) + 1;
data = accumarray(gazedata, 1, [max(gazedata(:, 1)), max(gazedata(:, 2))]);
data = flipud(data);

%% Smooth the Data
cut = mean(data(:));
data(data > cut) = cut;

size_1 = gaussSize;
sigma = gaussSigma;
[Xm, Ym] = meshgrid(linspace(-.5, .5, size_1));

s = sigma / size_1; % Gaussian width as fraction of imageSize
kernel = exp(-(((Xm.^2) + (Ym.^2)) ./ (2 * s^2))); % Formula for 2D gaussian

eyetrHeatMap = conv2(data, kernel, 'same');

% Map with gaze points on the value of the mean of the heatmap
gaze = mean(eyetrHeatMap(data > 0));
% Calculate percentage of eye tracking time
total_time = numel(range);
eye_tracking_time = sum(~isnan(posX));
eye_tracking_percentage = (eye_tracking_time / total_time) * 100;
if isempty(eyetrHeatMap)
disp('EDF File is empty')
figure;

title(['This participant has no data inside the eyetracking file']);
xlabel(['This is an empty placeholder']);
else
% Create figure
figure;
imagesc(eyetrHeatMap);
%changing range by using the pixel of the screen the subject looked at
plotRange=[0 display_coords(1) 0 display_coords(2)];
axis(plotRange);
colorbar;
title(['Heat map of the eye movement for ' num2str(amount) ' participants out of the ' num2str(length(id))]);
xlabel(['Percentage of Eye Tracking Time: ' num2str(eye_tracking_percentage) '%']);
end
end
end
Loading