📄 bfm_result_ui.m
字号:
rf1_plot = getappdata(gcbf,'RF1PlotHdl');
if ~isempty(rf1_plot)
msg = 'ERROR: Response function plot is already been opened';
set(findobj(gcbf,'Tag','MessageLine'),'String',msg);
return;
end;
rf1_plot = bfm_plot_rf('LINK',PLSresultFile);
link_info.hdl = gcbf;
link_info.name = 'RF1PlotHdl';
setappdata(rf1_plot,'LinkFigureInfo',link_info);
setappdata(gcbf,'RF1PlotHdl',rf1_plot);
% make sure the Coord of the Response Function Plot contains
% the current point in the Response
%
cur_coord = getappdata(gcbf,'Coord');
setappdata(rf1_plot,'Coord',cur_coord);
return; %%%%%%
sessionFileList = getappdata(gcbf,'SessionFileList');
rf_plot = getappdata(gcf,'RFPlotHdl');
if ~isempty(rf_plot)
msg = 'ERROR: Response function plot is already been opened';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
rf_plot = fmri_plot_rf('LINK',sessionFileList);
link_info.hdl = gcbf;
link_info.name = 'RFPlotHdl';
setappdata(rf_plot,'LinkFigureInfo',link_info);
setappdata(gcbf,'RFPlotHdl',rf_plot);
% make sure the Coord of the Response Function Plot contains
% the current point in the Response
%
cur_coord = getappdata(gcf,'Coord');
setappdata(rf_plot,'Coord',cur_coord);
return; % OpenCorrelationPlot
%-------------------------------------------------------------------------
%
function SetClusterReportOptions()
st_origin = getappdata(gcbf,'Origin');
st_dims = getappdata(gcbf,'STDims');
setting = getappdata(gcf,'setting');
if isempty(setting) | ~isfield(setting,'cluster_mask_size')
cluster_mask_size = getappdata(gcbf,'ClusterMaskSize');
cluster_min_size = getappdata(gcbf,'ClusterMinSize');
cluster_min_dist = getappdata(gcbf,'ClusterMinDist');
else
cluster_mask_size = setting.cluster_mask_size;
cluster_min_size = setting.cluster_min_size;
cluster_min_dist = setting.cluster_min_dist;
end;
if isempty(st_origin) | all(st_origin == 0)
st_voxel_size = getappdata(gcf,'STVoxelSize');
if all(st_dims == [40 48 1 34]) & all(st_voxel_size == [4 4 4])
st_origin = [20 29 12];
elseif all(st_dims == [91 109 1 91]) & all(st_voxel_size == [2 2 2])
st_origin = [46 64 37];
else
% according to SPM: if the origin field contains 0, then the origin is
% assumed to be at the center of the volume.
%
st_origin = floor((dims([1 2 4])+1)/2);
% st_origin = round(st_dims([1 2 4])/2);
end;
end;
xyz = getappdata(gcf,'xyz');
% prompt = {'Cluster Mask marker size', ...
prompt = {'Minimum cluster size (in voxels)', ...
'Minimum distance (in mm) between cluster peaks', ...
'Origin location (in voxels)' };
% 'Current location (in voxels)' };
% defValues = { num2str(cluster_mask_size), ...
defValues = { num2str(cluster_min_size), ...
num2str(cluster_min_dist), ...
num2str(st_origin) };
% num2str(xyz) };
dlgTitle='Cluster Report Options';
lineNo = 1;
answer = inputdlg(prompt,dlgTitle,lineNo,defValues);
if isempty(answer),
return;
end;
invalid_options = 0;
% mask_size = str2num(answer{1});
min_size = str2num(answer{1});
min_dist = str2num(answer{2});
origin_xyz = str2num(answer{3});
% cur_xyz = str2num(answer{4});
%isempty(mask_size) | (mask_size <= 0) |
if isempty(min_size) | isempty(min_dist) | isempty(origin_xyz)
invalid_options = 1;
elseif (min_size <= 0) | (min_dist <= 0) | (sum(origin_xyz<= 0) ~= 0)
invalid_options = 1;
end;
if (invalid_options)
msg = 'Invalid cluster report options. Options did not changed';
set(findobj(gcbf,'Tag','MessageLine'),'String',msg);
return;
end;
setappdata(gcbf,'ClusterMaskSize',4); %mask_size);
setappdata(gcbf,'ClusterMinSize',min_size);
setappdata(gcbf,'ClusterMinDist',min_dist);
setappdata(gcbf,'Origin',origin_xyz);
setappdata(gcbf,'STOrigin',origin_xyz);
setting.cluster_mask_size = 4; %mask_size;
setting.cluster_min_size = min_size;
setting.cluster_min_dist = min_dist;
setting.origin = origin_xyz;
setappdata(gcf,'setting',setting);
if 0
if isempty(cur_xyz) | ~all(size(cur_xyz) == [1 3])
msg = 'Please use 3 numbers for xyz.';
set(findobj(gcbf,'Tag','MessageLine'),'String',msg);
return;
else
EditXYZ(cur_xyz);
end
end
% xyz = getappdata(gcf,'xyz'); % move ahead
if 0
if ~isempty(xyz)
EditXYZ;
end
end
if ~isempty(xyz)
voxel_size = getappdata(gcf,'STVoxelSize');
xyz_offset = xyz - origin_xyz;
xyz_mm = xyz_offset .* voxel_size;
h = findobj(gcbf,'Tag','XYZmm');
set(h,'String',sprintf('%2.1f %2.1f %2.1f',xyz_mm));
end;
return; % SetClusterReportOptions
%-------------------------------------------------------------------------
%
function OpenClusterReport()
% wait message
old_pointer = get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
msg = 'Generating Cluster Report ... please wait';
h = rri_wait_box(msg, [0.5 0.1]);
cluster_min_size = getappdata(gcbf,'ClusterMinSize');
cluster_min_dist = getappdata(gcbf,'ClusterMinDist');
cluster_hdl = getappdata(gcbf,'cluster_hdl');
if ~isempty(cluster_hdl)
msg = 'Please close any opening cluster report window';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
[tmp cluster_hdl] = fmri_cluster_report(cluster_min_size,cluster_min_dist);
link_info.hdl = gcbf;
link_info.name = 'cluster_hdl';
setappdata(cluster_hdl,'LinkFigureInfo',link_info);
setappdata(gcbf,'cluster_hdl',cluster_hdl);
set(gcbf,'Pointer',old_pointer);
set(findobj(gcbf,'Tag','MessageLine'),'String','');
delete(h);
return; % OpenClusterReport
%-------------------------------------------------------------------------
function OpenContrastWindow()
contrast_fig = getappdata(gcbf,'ContrastFigHdl');
if ~isempty(contrast_fig)
msg = 'ERROR: Constrasts information has already been dispalyed.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
h = findobj(gcbf,'Tag','ResultFile');
PLSresultFile = get(h,'UserData');
load(PLSresultFile,'cond_name','design');
num_groups = length(getappdata(gcf,'SessionFileList'));
% if length(cond_name) == size(design, 1)
% num_groups = 1;
% end
if num_groups * length(cond_name) ~= size(design, 1)
design = repmat(design, [num_groups 1]);
end
contrast_fig = rri_input_contrast_ui({'BfMRI'}, cond_name, [], num_groups, design, 1);
if 0
if isequal(ContrastFile,'NONE'),
msg = 'No contrast was used for this PLS analysis.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
if isequal(ContrastFile,'HELMERT'), % using Helmert matrix for contrasts
load(SessionProfiles{1}{1});
conditions = session_info.condition;
num_conditions = length(conditions);
helmert_contrasts = rri_helmert_matrix(num_conditions);
for i=1:num_conditions-1,
pls_contrasts(i).name = sprintf('Contrast #%d',i);
pls_contrasts(i).value = helmert_contrasts(:,i)';
end;
else
try
load(ContrastFile);
catch
msg = sprintf('ERROR: Cannot open contrast file "%s".',ContrastFile);
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
end;
end
% contrast_fig = fmri_input_contrast_ui(pls_contrasts,conditions,1);
link_info.hdl = gcbf;
link_info.name = 'ContrastFigHdl';
setappdata(contrast_fig,'LinkFigureInfo',link_info);
setappdata(gcbf,'ContrastFigHdl',contrast_fig);
return; % OpenContrastWindow
%-------------------------------------------------------------------------
%
function OpenDesignPlot()
scores_fig = getappdata(gcbf,'ScorePlotHdl');
if ~isempty(scores_fig)
msg = 'ERROR: Design Scores Plot is already been opened';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
h = findobj(gcbf,'Tag','ResultFile');
PLSresultFile = get(h,'UserData');
scores_fig = fmri_plot_scores('LINK',PLSresultFile);
lv_idx = getappdata(gcbf,'CurrLVIdx');
if (lv_idx ~= 1)
fmri_plot_scores('UPDATE_LV_SELECTION',scores_fig,lv_idx);
end;
link_info.hdl = gcbf;
link_info.name = 'ScorePlotHdl';
setappdata(scores_fig,'LinkFigureInfo',link_info);
setappdata(gcbf,'ScorePlotHdl',scores_fig);
return; % OpenDesignPlot
%-------------------------------------------------------------------------
%
function OpenBrainScoresPlot()
bs_plot = getappdata(gcf,'BSPlotHdl');
if ~isempty(bs_plot)
msg = 'ERROR: Brain score plot is already been opened';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
sessionFileList = getappdata(gcbf,'SessionFileList');
h = findobj(gcbf,'Tag','ResultFile');
PLSresultFile = get(h,'UserData');
bs_plot = fmri_plot_brain_scores('LINK',sessionFileList,PLSresultFile);
link_info.hdl = gcbf;
link_info.name = 'BSPlotHdl';
setappdata(bs_plot,'LinkFigureInfo',link_info);
setappdata(gcbf,'BSPlotHdl',bs_plot);
return; % OpenBrainScoresPlot
%-------------------------------------------------------------------------
%
function SaveResultToIMG(is_disp)
%
h = findobj(gcf,'Tag','ResultFile'); PLSresultFile = get(h,'Userdata');
try % load the dimension info of the st_datamat
load(PLSresultFile,'st_dims'),
catch
msg =sprintf('ERROR: Cannot load the PLS result file "%s".',PLSresultFile);
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
h = findobj(gcf,'Tag','LVIndexEdit'); lv_idx = get(h,'Userdata');
curr_lv_idx = getappdata(gcf,'CurrLVIdx');
if (lv_idx ~= curr_lv_idx),
lv_idx = curr_lv_idx;
set(h,'String',num2str(lv_idx));
end;
old_pointer = get(gcf,'Pointer');
fig_hdl = gcf;
set(fig_hdl,'Pointer','watch');
win_size = getappdata(gcf,'WinSize');
cluster_mask_state = get(findobj(gcf,'tag','ClusterMask'),'Userdata');
isbsr = getappdata(gcf,'ViewBootstrapRatio');
if isbsr
cluster_info = getappdata(gcf, 'cluster_bsr');
coords = getappdata(gcf,'BSRatioCoords');
else
cluster_info = getappdata(gcf, 'cluster_blv');
coords = getappdata(gcf,'BLVCoords');
end
if length(cluster_info) < curr_lv_idx
cluster_info = [];
else
cluster_info = cluster_info{curr_lv_idx};
end
if cluster_mask_state
cluster_info = [];
end
for i = 1:win_size
if isempty(cluster_info)
cluster_idx{i} = coords;
else
cluster_idx{i} = cluster_info.data{i}.idx;
end
if isequal(coords, cluster_idx{i})
non_cluster_coords{i} = [];
else
[tmp cluster_coords] = intersect(coords,cluster_idx{i});
non_cluster_coords{i} = ones(1,length(coords));
non_cluster_coords{i}(cluster_coords) = 0;
non_cluster_coords{i} = find(non_cluster_coords{i});
end
end
if (getappdata(gcf,'ViewBootstrapRatio') == 0), % save brain lv
thresh = getappdata(gcf,'BLVThreshold');
if is_disp
create_st_brainlv_disp(PLSresultFile,lv_idx,thresh,non_cluster_coords);
else
create_st_brainlv_img(PLSresultFile,lv_idx,thresh,non_cluster_coords);
end
else % save bootstrap ratio
thresh_ratio = getappdata(gcf,'BSThreshold');
if is_disp
create_bs_ratio_disp(PLSresultFile,lv_idx,thresh_ratio,non_cluster_coords);
else
create_bs_ratio_img(PLSresultFile,lv_idx,thresh_ratio,non_cluster_coords);
end
end;
set(fig_hdl,'Pointer',old_pointer);
return; % SaveResultToIMG
%--------------------------------------------------------------------------
function create_st_brainlv_disp(PLSresultFile,lv_idx,thresh_ratio,non_cluster_coords);
% get the output IMG filename first
%
[pn fn] = fileparts(PLSresultFile);
resultfile_prefix = fn(1:end-11);
image_fn = [resultfile_prefix, sprintf('BfMRIblv_disp_lv%d.img',lv_idx)];
[filename, pathname] = uiputfile(image_fn,'Brain LV IMG file');
img_file = [pathname, filesep, filename];
if isequal(filename,0)
return;
end;
% load the result file
%
load(PLSresultFile,'brainlv','s','st_dims','st_win_size','st_coords', ...
'st_voxel_size','st_origin');
is_rescale = get(findobj(gcf,'Tag','RESCALECheckbox'),'value');
if is_rescale
for i=1:length(s)
brainlv(:,i) = brainlv(:,i).*s(i);
end
end
newcoords = st_coords;
voxel_size = st_voxel_size;
origin = st_origin;
dims = st_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -