📄 bfm_analysis_ui.m
字号:
num_groups = length(curr_group_profiles);
total_rows = num_groups + 1;
slider_hdl = findobj(gcf,'Tag','GroupSlider');
if (total_rows > 1) % don't need to update when no group
set(slider_hdl,'Min',1,'Max',total_rows, ...
'Value',total_rows-top_group_idx+1, ...
'Sliderstep',[1/(total_rows-1)-0.00001 1/(total_rows-1)]);
end;
return; % UpdateSlider
%----------------------------------------------------------------------------
function ShowSlider()
slider_hdl = findobj(gcf,'Tag','GroupSlider');
set(slider_hdl,'visible','on');
return; % ShowSlider
%----------------------------------------------------------------------------
function HideSlider()
slider_hdl = findobj(gcf,'Tag','GroupSlider');
set(slider_hdl,'visible','off');
return; % HideSlider
%----------------------------------------------------------------------------
function SelectGroupAnalysis;
return;
h = findobj(gcf,'Tag','GroupAnalysisRadiobutton');
curr_value = get(h,'Value');
switch (get(h,'Value')),
case {1},
set(findobj(gcf,'Tag','BootstrapRequipementLabel'),'String', ...
'(require at least 3 subjs/group)');
case {0},
set(findobj(gcf,'Tag','BootstrapRequipementLabel'),'String', ...
'(require at least 3 subjs/group)');
end;
return; % SelectGrouopAnalysis
%----------------------------------------------------------------------------
function SelectContrastNone;
if get(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value') == 0 % click itself
set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',1);
else
set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');
end
return; % SelectContrastNone
%----------------------------------------------------------------------------
function SelectContrastHelmert
if get(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value') == 0
set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',1);
else
set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','off');
set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','off');
end
return; % SelectContrastHelmert
%----------------------------------------------------------------------------
function SelectContrastFile
if get(findobj(gcf,'Tag','ContrastFileChkBox'),'Value') == 0
set(findobj(gcf,'Tag','ContrastFileChkBox'),'Value',1);
else
set(findobj(gcf,'Tag','ContrastNoneChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastHelmertChkBox'),'Value',0);
set(findobj(gcf,'Tag','ContrastFileEdit'),'Enable','on');
set(findobj(gcf,'Tag','ContrastFileButton'),'Enable','on');
end
return; % SelectContrastFile
%----------------------------------------------------------------------------
function status = SavePLSOptions
ccurr_profiles = getappdata(gcf,'CurrGroupProfiles');
if isempty(ccurr_profiles)
msg = 'Group need to be added before you can modify behavior data';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
ccond_selection = getappdata(gcf,'cond_selection');
bbehavdata = getappdata(gcf,'behavdata');
if isempty(bbehavdata)
[status,behavname,behavdata,behavdata_lst,new_evt_list,newdata_lst] = ...
fmri_get_behavior(ccurr_profiles, ccond_selection);
setappdata(gcf,'behavname',behavname);
setappdata(gcf,'behavdata',behavdata);
setappdata(gcf,'behavdata_lst',behavdata_lst);
setappdata(gcf,'new_evt_list',new_evt_list);
setappdata(gcf,'newdata_lst',newdata_lst);
end
status = -1;
setappdata(gcf,'PLSoptions',[]);
% profiles
%
curr_profiles = getappdata(gcf,'CurrGroupProfiles');
num_groups = length(curr_profiles);
PLSoptions.profiles = cell(1,num_groups);
for i=1:num_groups,
PLSoptions.profiles{i} = curr_profiles{i}.name;
end;
if isempty(PLSoptions.profiles)
msg = 'Group need to be added before you can run analysis';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
if ( get(findobj(gcf,'Tag','SelectBehavData'),'Value') == 1 | ...
get(findobj(gcf,'Tag','SelectMultiblockData'),'Value') == 1 ) ...
& isempty(bbehavdata) & isempty(behavdata)
msg = 'No behavior data';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
h = findobj(gcf,'Tag','GroupAnalysisRadiobutton');
PLSoptions.group_analysis = get(h, 'Value');
% contrast
%
if (get(findobj(gcf,'Tag','SelectMean'),'Value') == 1)
PLSoptions.ContrastMethod = 1;
% elseif (get(findobj(gcf,'Tag','SelectHelmert'),'Value') == 1)
% PLSoptions.ContrastMethod = 2;
elseif (get(findobj(gcf,'Tag','SelectBehavData'),'Value') == 1)
PLSoptions.ContrastMethod = 4;
elseif (get(findobj(gcf,'Tag','SelectMultiblockData'),'Value') == 1)
PLSoptions.ContrastMethod = 5;
elseif (get(findobj(gcf,'Tag','SelectContrastData'),'Value') == 1)
PLSoptions.ContrastMethod = 3;
h = findobj(gcf,'Tag','ContrastFileEdit');
PLSoptions.ContrastFile = get(h,'String');
if isempty(PLSoptions.ContrastFile),
msg = 'ERROR: Contrast file is not specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
try
use_contrast = load(PLSoptions.ContrastFile,'conditions');
cond_selection = getappdata(gcf,'cond_selection');
if size(use_contrast,1) ~= sum(cond_selection)*num_groups
msg = 'ERROR: incompetible number of condition in contrast.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
catch
msg = 'ERROR: cannot load the contrast file.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
% check if the contrast matrix is rank deficient
%
if (rank(use_contrast) ~= size(use_contrast,2))
msg = 'Your Contrast matrix is rank deficient. Please check your contrasts and run the program again';
uiwait(msgbox(msg,'Warning: Contrasts are not linear independent','modal'));
% set(findobj(gcf,'Tag','MessageLine'),'String',msg);
% return;
end;
% check if the contrast matrix is orthogonal
%
% if abs(sum(sum(use_contrast'*use_contrast-diag(diag(use_contrast'*use_contrast))))) > 1e-6
check_orth = abs(triu(use_contrast'*use_contrast) - tril(use_contrast'*use_contrast));
if max(check_orth(:)) > 1e-6
msg = 'Effects expressed by each contrast are not independent. Check variable lvintercorrs in result file to see overlap of effects between LVs';
uiwait(msgbox(msg,'Warning: Contrasts are not orthogonal','modal'));
% set(findobj(gcf,'Tag','MessageLine'),'String',msg);
% return;
end
else
disp('ERROR : Unknown contrast method');
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;
if (PLSoptions.num_boot > 0)
min_subj_required = 3;
if (PLSoptions.group_analysis == 1), % for group analysis
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
else
if (PLSoptions.ContrastMethod == 4) % behav pls
num_behav_subj = 0;
for i=1:length(PLSoptions.profiles)
num_behav_subj = num_behav_subj + ...
get_repetition(PLSoptions.profiles{i});
end
if (num_behav_subj < min_subj_required)
msg = 'There must have at least 3 subjects for bootstrap.';
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ' msg]);
return;
end
else
if (get_repetition(PLSoptions.profiles{1}) < min_subj_required)
msg = 'There must have at least 3 subjects for bootstrap.';
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ' msg]);
return;
end
end
end
end;
% make sure the conditions in each profile are the same
%
if 0 % (PLSoptions.ContrastMethod == 3);
total_profiles = ValidateProfiles(PLSoptions.profiles, ...
use_contrast.conditions);
else
total_profiles = ValidateProfiles(PLSoptions.profiles);
end;
if (total_profiles == -1)
return;
end;
PLSoptions.TotalNumberProfiles = total_profiles;
% 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
else
PLSoptions.posthoc = [];
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;
% save datamat
%
save_datamat = get(findobj(gcf,'Tag','SaveDatamatChkbox'),'Value');
PLSoptions.save_datamat = save_datamat;
% cond_selection & behav_modify
%
PLSoptions.cond_selection = getappdata(gcf,'cond_selection');
PLSoptions.behavname = getappdata(gcf,'behavname');
PLSoptions.behavdata = getappdata(gcf,'behavdata');
PLSoptions.behavdata_lst = getappdata(gcf,'behavdata_lst');
PLSoptions.bscan = getappdata(gcf,'bscan');
PLSoptions.bscan = getappdata(gcf,'bscan');
if isempty(PLSoptions.bscan)
PLSoptions.bscan = 1:sum(PLSoptions.cond_selection);
end
% everything should be alright, save the option now
%
setappdata(gcf,'PLSoptions',PLSoptions);
% save PLSoptions PLSoptions;
status = 1;
return; % SavePLSoptions
%----------------------------------------------------------------------------
function num_rep = get_repetition(profile_list),
num_rep = 0;
for i=1:length(profile_list),
load(profile_list{i},'session_info');
rri_changepath('fmrisession');
datamat_prefix = session_info.datamat_prefix;
st_datamatFile = sprintf('%s_BfMRIdatamat.mat',datamat_prefix);
st_datamatFile = fullfile(session_info.pls_data_path,st_datamatFile);
load(st_datamatFile,'st_evt_list');
num_rep = num_rep + length(find(st_evt_list == 1));
end;
return; % get_repetition
%----------------------------------------------------------------------------
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');
prev_condition = s.session_info.condition;
first_profile_idx = 2;
for i=2:total_profiles,
s = load(cell_buffer{i},'session_info');
curr_condition = s.session_info.condition;
if ~isequal(curr_condition,prev_condition),
[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;
end;
end;
if exist('use_conditions','var')
if ~isequal(curr_condition,use_condition),
[p_path, p_name, p_ext] = fileparts(cell_buffer{i});
msg = sprintf('The contrast condition is not compatible.".',p_name);
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
total_profiles = -1;
return;
end;
end
return; % ValidateConditions
%----------------------------------------------------------------------------
function ExecutePLS(),
PLSoptions = getappdata(gcf,'PLSoptions');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -