ET_PDToolkit/PDToolkit/GUI/PDToolkit_main.m

524 lines
19 KiB
Matlab

function varargout = PDToolkit_main(varargin)
% PDTOOLKIT_MAIN MATLAB code for PDToolkit_main.fig
% PDTOOLKIT_MAIN, by itself, creates a new PDTOOLKIT_MAIN or raises the existing
% singleton*.
%
% H = PDTOOLKIT_MAIN returns the handle to a new PDTOOLKIT_MAIN or the handle to
% the existing singleton*.
%
% PDTOOLKIT_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PDTOOLKIT_MAIN.M with the given input arguments.
%
% PDTOOLKIT_MAIN('Property','Value',...) creates a new PDTOOLKIT_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before PDToolkit_main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to PDToolkit_main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help PDToolkit_main
% Last Modified by GUIDE v2.5 22-Feb-2016 00:02:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @PDToolkit_main_OpeningFcn, ...
'gui_OutputFcn', @PDToolkit_main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before PDToolkit_main is made visible.
function PDToolkit_main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to PDToolkit_main (see VARARGIN)
% Choose default command line output for PDToolkit_main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes PDToolkit_main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = PDToolkit_main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in display_button.
function display_button_Callback(hObject, eventdata, handles)
% hObject handle to display_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
e = getappdata(handles.figure1, 'PDExperiment');
text = info(e);
[s,v] = listdlg('PromptString','Info',...
'SelectionMode','single',...
'ListString',text)
% --- Executes on button press in settings_button.
function settings_button_Callback(hObject, eventdata, handles)
% hObject handle to settings_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
e = getappdata(handles.figure1, 'PDExperiment');
options = {'<html><b>Dataset</b></html>', ...
' *) Initial directory readout',...
' *) Add subjects / sessions',...
' *) Remove subjects / sessions',...
'',...
'<html><b>Trial definitions</b></html',...
' *) Specify Trial start/end', ....
' *) Specify Stimulus start/end', ....
' *) Specify Baseline start/end', ....
' *) Specify Labels', ....
' *) Exclude Trials',...
'',...
'<html><b>Preprocessing settings</b></html',...
' *) Specify Blink extension', ....
' *) Specify Maximium Blink size', ....
' *) Specify Baseline correction type', ....
' *) Specify Quality threshold', ...
};
valid_choices = [ 2:4 7:10 13:16];
choice = 0; choice_is_valid = 0;
while ( ~choice_is_valid )
choice = listdlg('PromptString', 'Select an option', ...
'SelectionMode', 'single', ...
'ListSize', [200 200],...
'ListString', options);
choice_is_valid = ismember(choice, valid_choices);
if ~choice_is_valid
display('No setting selected. Please try again...');
end
end
current_settings = e.settings;
if choice > 0
switch choice
case 2
hObject = performDirectoryReadout(hObject, handles);
case 3
hObject = addSubjectsSessions(hObject, handles);
case 4
hObject = removeSubjectsSessions(hObject, handles);
case 6
hObject = PDTrialGUI(current_settings, 'trial');
case 7
hObject = PDTrialGUI(current_settings, 'stimulus');
case 8
hObject = PDTrialGUI(current_settings, 'baseline');
case 9
hObject = PDTrialGUI(current_settings, 'labels');
otherwise
end
end
function[hObject] = performDirectoryReadout(hObject, handles)
e = getappdata(handles.figure1, 'PDExperiment');
cwd = pwd;
directoryname = uigetdir(pwd, 'Select a folder to read');
if (ischar(directoryname) && exist(directoryname, 'dir'))
e = e.buildExperiment(directoryname);
cd(cwd);
nsubj = length(e.subjects); nsess = 0;
for i = 1:length(nsubj)
nsess = nsess + length(e.subjects(i).sessions);
end
status_line = sprintf('Found %d subjects (%d sessions)', nsubj, nsess);
pdlog(handles, status_line);
setappdata(handles.figure1, 'PDExperiment',e);
end
function [hObject] = addSubjectsSessions(hObject, handles)
e = getappdata(handles.figure1, 'PDExperiment');
answer = questdlg('Please select', 'Add datasets', 'Subjects', 'Sessions for a subject', 'Cancel', 'Cancel');
if strcmp(answer, 'Subjects')
performDirectoryReadout(hObject, handles);
end
% --- Executes on button press in rebuild_button.
function rebuild_button_Callback(hObject, eventdata, handles)
% hObject handle to rebuild_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in preprocess_button.
function preprocess_button_Callback(hObject, eventdata, handles)
% hObject handle to preprocess_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in import_button.
function import_button_Callback(hObject, eventdata, handles)
% hObject handle to import_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in setup_button.
function setup_button_Callback(hObject, eventdata, handles)
% hObject handle to setup_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in run_button.
function run_button_Callback(hObject, eventdata, handles)
% hObject handle to run_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in results_button.
function results_button_Callback(hObject, eventdata, handles)
% hObject handle to results_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in newexp_button.
function newexp_button_Callback(hObject, eventdata, handles)
% hObject handle to newexp_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Enter name for the experiment (without spaces):', 'Enter a description (optional)'};
dlg_title = 'New experiment';
num_lines = 1;
defaultans = {'PDExp1',''};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
if isempty(answer{1})
return
end
directoryname = uigetdir(pwd, 'Where do you want to save the experiment')
if (directoryname == 0)
return
end
filename = [directoryname filesep answer{1} '_PDExp.mat'];
%% create an empty PDExperiment object
e = PDExperiment('placeholder');
e.filename = filename;
e.name = answer{1};
e.description = answer{2};
write =0;
if (exist(filename, 'file'))
writeanswer = questdlg('File already exists, do you want to overwrite?','File exists', 'OK', 'Cancel', 'Cancel');
if strcmp(writeanswer, 'OK')
write =1;
end
else
write = 1;
end
if write
log_file = [directoryname filesep 'pdlog.txt'];
e.settings.Logfile = log_file;
save(filename, 'e');
setappdata(handles.figure1, 'PDExperiment', e);
handles.experiment_panel.Title = sprintf('Experiment : %s', e.name);
%% enable all basic buttons for experiment:
handles.settings_button.Enable = 'on';
handles.import_button.Enable = 'on';
handles.display_button.Enable = 'on';
pdlog(handles, sprintf('New Experiment ''%s'' succesfully created', e.name));
else
pdlog(handles, 'Operation aborted.');
end
% --- Executes on button press in loadexp_button.
function loadexp_button_Callback(hObject, eventdata, handles)
% hObject handle to loadexp_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,path,FilterIndex] = uigetfile('*_PDExp.mat','Select a PD Experiment file')
load([path filesep filename], 'e');
handles.experiment_panel.Title = sprintf('Experiment : %s', e.name);
log_file = [path filesep 'pdlog.txt'];
e.settings.Logfile = log_file;
setappdata(handles.figure1, 'PDExperiment', e);
%% enable all basic buttons for experiment:
handles.settings_button.Enable = 'on';
handles.import_button.Enable = 'on';
handles.display_button.Enable = 'on';
if exist(log_file, 'file')
fp = fopen(log_file, 'r'); l=1;
while(~feof(fp))
loglines{l} = fgetl(fp); l = l+1;
end
handles.loglist.String = loglines;
fclose(fp);
end
pdlog(handles, 'Experiment succesfully loaded');
% --- Executes on button press in saveexp_button.
function saveexp_button_Callback(hObject, eventdata, handles)
% hObject handle to saveexp_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in closeexp_button.
function closeexp_button_Callback(hObject, eventdata, handles)
% hObject handle to closeexp_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox2
% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function log_contextmenu_Callback(hObject, eventdata, handles)
% hObject handle to log_contextmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function show_log_Callback(hObject, eventdata, handles)
% hObject handle to show_log (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.loglist.Visible = 'on';
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_5_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_6_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_7_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_8_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_9_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_10_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_12_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_13_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_14_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_11_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function pdlog(handles, text)
logline = sprintf('%s\t%s', datestr(now, 'dd/mm/yy HH:MM'), text);
handles.loglist.String{end} = logline;
handles.logline.String = logline;
%% -- save the logfile
e = getappdata(handles.figure1,'PDExperiment');
try
fp = fopen(e.settings.Logfile, 'a+');
fprintf(fp, '%s\n', logline);
fclose(fp);
catch
warning('Could not save logfile.');
end
% --- Executes on selection change in loglist.
function loglist_Callback(hObject, eventdata, handles)
% hObject handle to loglist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns loglist contents as cell array
% contents{get(hObject,'Value')} returns selected item from loglist
% --- Executes during object creation, after setting all properties.
function loglist_CreateFcn(hObject, eventdata, handles)
% hObject handle to loglist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over loglist.
function loglist_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to loglist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.loglist.Visible = 'off';