📄 erp_analysis_ui.m
字号:
PLSoptions.BehavDataCol = ''; % no need to select column (done by common_behav)
if max(PLSoptions.BehavDataCol) > num_behavdata_col
msg = ['ERROR: Maximum column value can not exceed ', ...
num2str(num_behavdata_col),'.'];
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
elseif isempty(PLSoptions.BehavDataCol)
PLSoptions.BehavDataCol = 1:num_behavdata_col;
end
PLSoptions.BehavDataCol = 1:num_behavdata_col;
% posthoc data file
%
posthoc_data_file = getappdata(gcf, 'posthoc_data_file');
if ~isempty(posthoc_data_file)
try
PLSoptions.posthoc = load(posthoc_data_file);
catch
msg = sprintf('Invalid posthoc data file.');
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
return;
end
[r_posthoc,c_posthoc] = size(PLSoptions.posthoc);
% if r_posthoc ~= length(PLSoptions.BehavDataCol) * getappdata(gcf,'num_selected_cond') * num_groups
if r_posthoc ~= getappdata(gcf,'num_selected_behav') * getappdata(gcf,'num_selected_cond') * num_groups
msg = sprintf('Rows in Posthoc data file do not match.');
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
return;
end
else
PLSoptions.posthoc = [];
end
end
% number of permutation
%
h = findobj(gcf,'Tag','NumPermutationEdit');
PLSoptions.num_perm = str2num(get(h,'String'));
if isempty(PLSoptions.num_perm)
msg = 'ERROR: Invalid number of permutation specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
% number of bootstrap
%
h = findobj(gcf,'Tag','NumBootstrapEdit');
PLSoptions.num_boot = str2num(get(h,'String'));
if isempty(PLSoptions.num_boot)
msg = 'ERROR: Invalid number of bootstrap specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
% upper limit of confidence interval estimated
%
h = findobj(gcf,'Tag','ClimEdit');
PLSoptions.Clim = str2num(get(h,'String'));
if isempty(PLSoptions.Clim)
msg = 'ERROR: Invalid upper limit of confidence specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
% if (PLSoptions.num_boot > 0)
% min_subj_required = 3;
% for i=1:num_groups,
% if (length(PLSoptions.profiles{i}) < min_subj_required)
% msg = 'All groups must have at least 3 subjects for bootstrap.';
% set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ' msg]);
% return;
% end
% end
% end;
% everything should be alright, save the option now
%
setappdata(gcf,'PLSoptions',PLSoptions);
% save PLSoptions PLSoptions;
status = 1;
return; % SavePLSOptions
%----------------------------------------------------------------------------
function total_profiles = ValidateProfiles(group_profiles,conditions),
num_groups = length(group_profiles);
cell_buffer = [];
for i=1:num_groups,
cell_buffer = [cell_buffer; group_profiles(i)];
end;
% check for duplicated profile
%
total_profiles = length(cell_buffer);
for i=1:total_profiles-1,
for j=i+1:total_profiles,
if isequal(cell_buffer{i},cell_buffer{j}),
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('"%s" has been used for more than 1 group',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
else
set(findobj(gcf,'Tag','MessageLine'),'String','');
end;
end;
end;
% make sure all conditions are the same
%
s = load(cell_buffer{1},'session_info','selected_conditions');
prev_condition = s.session_info.condition;
cond_selection = getappdata(gcf,'cond_selection');
selected_conditions_idx = find(s.selected_conditions);
new_cond_selection = zeros(1, length(s.selected_conditions));
new_cond_selection(selected_conditions_idx(find(cond_selection))) = 1;
prev_select = new_cond_selection; % s.selected_conditions;
prev_chan_order = s.session_info.chan_order;
if ~isfield(s.session_info,'system')
prev_system.class = 1;
prev_system.type = 1;
else
prev_system = s.session_info.system;
end
for i=2:total_profiles,
s = load(cell_buffer{i},'session_info','selected_conditions');
if sum(cond_selection) > sum(s.selected_conditions)
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('Incompatible conditions found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
end
if isfield(s.session_info,'system') & ~isequal(s.session_info.system,prev_system)
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('Incompatible electrode system found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
end
if ~isequal(s.session_info.chan_order,prev_chan_order)
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('Incompatible electrode order found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
end
curr_condition = s.session_info.condition;
selected_conditions_idx = find(s.selected_conditions);
new_cond_selection = zeros(1, length(s.selected_conditions));
new_cond_selection(selected_conditions_idx(find(cond_selection))) = 1;
curr_select = new_cond_selection; % s.selected_conditions;
if ~isequal(curr_condition,prev_condition)...
| ~isequal(curr_select, prev_select)
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('Incompatible conditions found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
else
prev_condition = curr_condition;
prev_select = curr_select;
end;
end;
setappdata(gcf,'num_selected_cond',length(find(prev_select)));
isbehav = get(findobj(gcf,'Tag','SelectBehavData'),'Value');
ismultiblock = get(findobj(gcf,'Tag','SelectMultiblockData'),'Value');
if (isbehav | ismultiblock) & isempty(getappdata(gcf,'behavdata_lst')) % behavdata not input from run
% make sure all behaviors are the same
%
s = load(cell_buffer{1},'session_info','selected_behav');
if(~isfield(s.session_info,'behavname'))
s.session_info.behavname = {};
for i=1:size(s.session_info.behavdata, 2)
s.session_info.behavname = [s.session_info.behavname, {['behav', num2str(i)]}];
end
s.selected_behav = ones(1, size(s.session_info.behavdata, 2));
end
prev_behavname = s.session_info.behavname;
prev_select = s.selected_behav;
for i=2:total_profiles,
s = load(cell_buffer{i},'session_info','selected_behav');
if(~isfield(s.session_info,'behavname'))
s.session_info.behavname = {};
for j=1:size(s.session_info.behavdata, 2)
s.session_info.behavname = [s.session_info.behavname, {['behav', num2str(j)]}];
end
s.selected_behav = ones(1, size(s.session_info.behavdata, 2));
end
curr_behavname = s.session_info.behavname;
curr_select = s.selected_behav;
if ~isequal(curr_behavname,prev_behavname)...
| ~isequal(curr_select, prev_select)
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('Incompatible behaviors found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
else
prev_behavname = curr_behavname;
prev_select = curr_select;
end;
end;
setappdata(gcf,'num_selected_behav',length(find(prev_select)));
end
% PLSoptions = getappdata(gcf,'PLSoptions');
% num_common_conditions = light_get_common(PLSoptions.profiles);
% setappdata(gcf,'num_selected_cond', sum(num_common_conditions));
return; % ValidateProfiles
%----------------------------------------------------------------------------
function ExecutePLS()
tic
PLSoptions = getappdata(gcf,'PLSoptions');
progress_hdl = rri_progress_ui('initialize','Loading datamat');
if exist('plslog.m','file')
if PLSoptions.ismultiblock
plslog('ERP Multiblock Analysis');
elseif PLSoptions.isbehav
plslog('ERP Behavior Analysis');
elseif PLSoptions.iscontrast
plslog('ERP Non-Rotated Analysis');
else
plslog('ERP Mean-Centering Analysis');
end
end
[resultFile, elapsed_time] = erp_analysis(PLSoptions.ismean, ...
PLSoptions.ishelmert, PLSoptions.iscontrast, PLSoptions.isbehav, ...
PLSoptions.BehavDataCol, PLSoptions.ContrastDataCol, ...
PLSoptions.posthoc, PLSoptions.profiles, PLSoptions.save_datamat, ...
PLSoptions.num_perm, PLSoptions.num_boot, PLSoptions.Clim, ...
PLSoptions.system, PLSoptions.ContrastFile, PLSoptions.cond_selection, ...
PLSoptions.behavdata_lst, PLSoptions.behavname, ...
PLSoptions.ismultiblock, PLSoptions.bscan);
if exist('progress_hdl','var') & ishandle(progress_hdl)
close(progress_hdl);
end
msg1 = ['Result file "',resultFile,'" has been created and saved on your hard drive.'];
msg2 = ['The total elapse time to build this datamat is ',num2str(elapsed_time),' seconds.'];
if 0 % ~isempty(resultFile)
uiwait(msgbox({msg1;'';msg2},'Completed','modal'));
% uiwait(msgbox(msg1,'Completed','modal'));
end
% uiresume;
close(gcf);
return; % ExecutePLS
%----------------------------------------------------------------------------
function EditPosthocDataFile
posthoc_data_file = deblank(strjust(get(gcbo,'String'),'left'));
set(gcbo,'String',posthoc_data_file);
if ~isempty(posthoc_data_file)
if ( exist(posthoc_data_file,'file') == 2 ) % specified file exists
setappdata(gcf,'posthoc_data_file',posthoc_data_file);
return;
end;
if ( exist(posthoc_data_file,'dir') == 7 ) % it is a directory!
msg = 'ERROR: The specified file is a direcotry!';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
setappdata(gcf,'posthoc_data_file','');
return;
end;
else
% msg = 'ERROR: Invalid input file!';
% set(findobj(gcf,'Tag','MessageLine'),'String',msg);
setappdata(gcf,'posthoc_data_file','');
return;
end;
return; % EditPosthocDataFile
%----------------------------------------------------------------------------
function SelectPosthocDataFile
h = findobj(gcf,'Tag','PosthocDataEdit');
[filename,pathname]=uigetfile('*.*','Select Posthoc Data File');
if isequal(filename,0) | isequal(pathname,0)
return;
end;
posthoc_data_file = [pathname, filename];
set(h,'String',posthoc_data_file);
set(h,'TooltipString',posthoc_data_file);
setappdata(gcf,'posthoc_data_file',posthoc_data_file);
return; % SelectPosthocDataFile
%----------------------------------------------------------------------------
function num_cond = light_get_common(datamat_files)
common_conditions = [];
num_files = length(datamat_files);
for i=1:num_files
load(datamat_files{i}, 'selected_conditions');
% initially, common_conditions is empty, init it with zero array
%
if isempty(common_conditions)
common_conditions = zeros(1,length(selected_conditions));
end
common_conditions = common_conditions + selected_conditions;
end
% find only the overlap parts of common conditions
%
idx = find(common_conditions == num_files);
common_conditions = zeros(1,length(selected_conditions));
common_conditions(idx) = 1;
num_cond = sum(common_conditions);
return;
%----------------------------------------------------------------------------
function deselect_condition
curr_profiles = getappdata(gcf,'CurrGroupProfiles');
if isempty(curr_profiles)
msg = 'Group need to be added before you can deselect condition';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
% tmp = load(curr_profiles{1});
cond_selection = getappdata(gcf,'cond_selection');
for i = 1:length(curr_profiles)
tmp = load(curr_profiles{i});
if sum(cond_selection) > sum(tmp.selected_conditions)
[p_path, p_name, p_ext] = fileparts(curr_profiles{i});
msg = sprintf('Incompatible conditions found in "%s".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
return;
end
end
condition = tmp.session_info.condition(find(tmp.selected_conditions));
new_cond_selection = rri_deselect_cond_ui(condition, cond_selection);
if ~isequal(new_cond_selection, cond_selection)
setappdata(gcf,'cond_selection',new_cond_selection);
setappdata(gcf,'behavname',{});
setappdata(gcf,'behavdata',[]);
setappdata(gcf,'behavdata_lst',{});
setappdata(gcf, 'bscan', []);
end
return; % deselect_condition
%----------------------------------------------------------------------------
function modify_behavdata
curr_profiles = getappdata(gcf,'CurrGroupProfiles');
if isempty(curr_profiles)
msg = 'Group need to be added before you can modify behavior data';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
cond_selection = getappdata(gcf,'cond_selection');
behavname = getappdata(gcf,'behavname');
behav
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -