📄 struct_cluster_report.m
字号:
coord_idx(i) = find(coord==cluster_info.data{1}.idx(i));
end
data = data(coord_idx);
xyz = double(xyz2xyzmm(xyz, result_file));
xyz2 = double([cnum' double(data) xyz]);
[filename, pathname] = ...
uiputfile('*_STRUCTcluster_all.txt','Export All Location');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_structcluster_all.txt')))
[tmp filename] = fileparts(filename);
filename = [filename, '_STRUCTcluster_all.txt'];
end
if isequal(filename,0)
status = 0;
return;
end;
report_file = fullfile(pathname,filename);
try
save (report_file, '-ascii', 'xyz' );
msg = ['File ', filename, ' has been saved'];
msgbox(msg, 'Info');
catch
msg = ['File ', filename, ' can not be open to write'];
msgbox(msg, 'Error');
% msg = sprintf('Cannot export all location to %s',report_file),
% set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
filename2 = strrep(filename,'_STRUCTcluster_all.txt','_STRUCTcluster_num.txt');
report_file2 = fullfile(pathname,filename2);
try
save (report_file2, '-ascii', 'xyz2' );
msg = ['File ', filename2, ' has been saved'];
msgbox(msg, 'Info');
catch
msg = ['File ', filename2, ' can not be open to write'];
msgbox(msg, 'Error');
% msg = sprintf('Cannot export all location to %s',report_file),
% set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
return; % save_all_location
%--------------------------------------------------------------------------
function cluster_fig = load_cluster_report(mainfig)
cluster_fig = [];
result_name = getappdata(gcbf, 'ResultName');
[filename, pathname] = ...
uigetfile('*_STRUCTcluster.mat','Load the cluster report');
if isequal(filename,0)
status = 0;
return;
end;
report_file = fullfile(pathname,filename);
try
load(report_file);
catch
msg = sprintf('Cannot open the cluster report file: %s',report_file),
set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
cluster_fig = show_cluster_report(cluster_info,report_type,mainfig);
return; % load_cluster_report
%--------------------------------------------------------------------------
function fig_h = create_report_figure(report_type,mainfig)
%
save_setting_status = 'on';
struct_cluster_report_pos = [];
try
load('pls_profile');
catch
end
if ~isempty(struct_cluster_report_pos) & strcmp(save_setting_status,'on')
pos = struct_cluster_report_pos;
else
w = 0.9;
h = 0.85;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
end
if isequal(get(gcbf,'Tag'),'ClusterReportFigure'),
fig_h = gcbf;
setappdata(gcf,'HdlList',[]);
clf(fig_h);
else
fig_h = figure('Color',[0.8 0.8 0.8], ...
'Units','normal', ...
'Name','PLS Active Clusters Report', ...
'NumberTitle', 'off', ...
'DoubleBuffer','on', ...
'MenuBar','none',...
'Position',pos, ...
'DeleteFcn','struct_cluster_report(''delete_fig'');', ...
'PaperPositionMode','auto', ...
'Tag','ClusterReportFigure', ...
'ToolBar','none');
end;
w = 0.94;
h = 0.94;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
axes_h = axes('Parent',fig_h, ...
'Units','normal', ...
'Box','on', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'Position',pos, ...
'XTick', [], ...
'XLim', [0 1], ...
'YTick', [], ...
'YLim', [0 1], ...
'Tag','ClusterReportAxes');
standard_text = text('Fontname','courier', ...
'FontWeight','Normal', ...
'FontAngle','Normal', ...
'FontUnit','point', ...
'FontSize',10, ...
'Units','normal', ...
'Color',[0 0 0], ...
'Visible','off','Interpreter','none');
% File submenu
%
h_file = uimenu('Parent',fig_h, ...
'Label','&File', ...
'Tag','FileMenu', ...
'Visible','on');
h2 = uimenu(h_file, ...
'Label','&Load', ...
'Tag','MenuLoad', ...
'Visible','off', ...
'Callback','struct_cluster_report(''LoadClusterReport'');');
h2 = uimenu(h_file, ...
'Label','Save to .mat file', ...
'Tag','MenuSave', ...
'Callback','struct_cluster_report(''SaveClusterReport'');');
h2 = uimenu(h_file, ...
'Label','Save to .txt file', ...
'Tag','MenuSaveTxt', ...
'Callback','struct_cluster_report(''SaveClusterTXT'');');
h2 = uimenu(h_file, ...
'Label','Export All Location', ...
'Tag','MenuSaveAllLocation', ...
'Callback','struct_cluster_report(''SaveAllLocation'');');
h2 = uimenu(h_file, ...
'Label','Export Peak Location', ...
'Tag','MenuSavePeakLocation', ...
'Callback','struct_cluster_report(''SavePeakLocation'');');
h2 = uimenu(h_file, ...
'Separator', 'on', ...
'Label','&Print...', ...
'Tag','MenuPrint', ...
'visible', 'off', ...
'Callback','printdlg');
h2 = uimenu(h_file, ...
'Label','Print Pre&view...', ...
'Tag','MenuPrintPreview', ...
'visible', 'off', ...
'Callback','printpreview(gcbf)');
h2 = uimenu(h_file, ...
'Label','Print Set&up...', ...
'Tag','MenuPrintSetup', ...
'visible', 'off', ...
'Callback','filemenufcn(gcbf,''FilePrintSetup'')');
h2 = uimenu(h_file, ...
'Label','Pa&ge Setup...', ...
'Tag','MenuPageSetup', ...
'visible', 'off', ...
'Callback','pagesetupdlg(gcbf)');
rri_file_menu(fig_h);
setappdata(gcf,'ResultName', get(gcbf,'name'));
setappdata(gcf,'LineHeight', 0.03);
setappdata(gcf,'TopMargin', 0.14);
setappdata(gcf,'BottomMargin', 0.11);
setappdata(gcf,'StandardTextObj', standard_text);
setappdata(gcf,'ReportType', report_type);
if ~isempty(mainfig) & ishandle(mainfig)
setappdata(gcf,'mainfig',mainfig);
end
return; % create_figure;
%--------------------------------------------------------------------------
function setup_header();
standard_text_obj = getappdata(gcf,'StandardTextObj');
report_type = getappdata(gcf,'ReportType');
axes_h = findobj(gcf,'Tag','ClusterReportAxes');
axes_pos = get(axes_h,'Position');
total_height = 1;
header_text = { ... % {label, [x y z], type}, where y is counted from top
{ 'Cluster #', [0.05 0.08 0], -1 }, ...
{ 'Voxel Mean', [0.17 0.08 0], -1 }, ...
{ 'Peak Location', [0.39 0.05 0], -1 }, ...
{ 'XYZ', [0.33 0.08 0], -1 }, ...
{ 'XYZ(mm)', [0.52 0.08 0], -1 }, ...
{ 'Brain LV', [0.71 0.05 0], 0 }, ...
{ 'Value', [0.73 0.08 0], 0 }, ...
{ 'Bootstrap', [0.71 0.05 0], 1 }, ...
{ 'Ratio', [0.69 0.08 0], 1 }, ...
{ 'Appro.P', [0.76 0.08 0], 1 }, ...
{ 'Cluster Size', [0.85 0.05 0], -1 }, ...
{ '(voxels)', [0.87 0.08 0], -1 }};
str_field = 1; pos_field = 2; type_field = 3;
for i=1:length(header_text),
if (header_text{i}{type_field}<0 | report_type==header_text{i}{type_field})
h = copyobj(standard_text_obj,axes_h);
text_pos = header_text{i}{pos_field};
text_pos(2) = total_height - text_pos(2); % text pos=[x height-y z]
set(h,'String', header_text{i}{str_field}, ...
'Position', text_pos, ...
'Visible','on');
end;
end;
% line is located at the 0.08 from top
%
y_pos = 1 - 0.11;
line_hdl = line( ...
'XData', [0.040 0.960], ...
'YData', [y_pos y_pos], ...
'LineStyle', '-', ...
'LineWidth', 1, ...
'Color', [0 0 0], ...
'Marker', 'none');
return; % setup_header;
%--------------------------------------------------------------------------
function setup_footer(),
axes_h = findobj(gcf,'Tag','ClusterReportAxes');
standard_text_obj = getappdata(gcf,'StandardTextObj');
cluster_info = getappdata(gcf,'ClusterInfo');
key_text = { ...
{ '<<prev.', [0.80 0.06 0], 'PrevPage'}, ...
{ 'next>>', [0.90 0.06 0], 'NextPage'}};
str_field = 1; pos_field = 2; tag_field = 3;
for i=1:length(key_text),
h = copyobj(standard_text_obj,axes_h);
bd_fn = sprintf('struct_cluster_report(''%s'');',key_text{i}{tag_field});
set(h,'String', key_text{i}{str_field}, ...
'Position',key_text{i}{pos_field}, ...
'ButtonDownFcn',bd_fn, ...
'Tag',key_text{i}{tag_field}, ...
'Visible','off');
end;
% display the footer
%
source_file = cluster_info.source;
len_str = length(source_file);
if (len_str > 80)
source_file = [ '...' source_file(len_str-76:end)];
end;
source_line = sprintf('Source: %s',source_file);
h = copyobj(standard_text_obj,axes_h);
x = 0.03;
y = 0.08;
pos = [x y 0];
set(h,'String', source_line, ...
'Interpreter','none', ...
'Fontname','courier', ...
'FontWeight','Normal', ...
'FontAngle','Normal', ...
'FontUnit','point', ...
'FontSize',10, ...
'Position',pos, ...
'Visible','on');
lv_str = sprintf('LV Idx: %d',cluster_info.lv_idx);
thresh_str = sprintf('Threshold: %2.4f',cluster_info.threshold);
min_size_str = sprintf('Min Size: %d(voxels)', ...
cluster_info.min_size);
min_dist_str = sprintf('Min Distance: %3.1fmm ', ...
cluster_info.min_dist);
parameters_line = sprintf('%s, %s, %s, %s', ...
lv_str,thresh_str,min_size_str,min_dist_str);
h = copyobj(standard_text_obj,axes_h);
y = 0.05;
pos = [x y 0];
set(h,'String', parameters_line, ...
'Position',pos, ...
'Fontname','courier', ...
'FontWeight','Normal', ...
'FontAngle','Normal', ...
'FontUnit','point', ...
'FontSize',10, ...
'Visible','on');
return; % setup_footer;
%--------------------------------------------------------------------------
function show_page_keys(page_num),
total_pages = getappdata(gcf,'TotalPages');
h = findobj(gcf,'Tag','PrevPage');
if (page_num ~= 1),
set(h,'Visible','on');
else
set(h,'Visible','off');
end;
h = findobj(gcf,'Tag','NextPage');
if (page_num ~= total_pages)
set(h,'Visible','on');
else
set(h,'Visible','off');
end;
return; % show_page_keys;
%--------------------------------------------------------------------------
function setup_cluster_data_idx(cluster_info),
%
standard_text_obj = getappdata(gcf,'StandardTextObj');
line_height = getappdata(gcf,'LineHeight');
top_margin = getappdata(gcf,'TopMargin');
bottom_margin = getappdata(gcf,'BottomMargin');
axes_h = findobj(gcf,'Tag','ClusterReportAxes');
axes_pos = get(axes_h,'Position');
total_height = 1;
num_rows = floor((total_height - top_margin - bottom_margin) / line_height);
lag_idx = [];
cluster_id = [];
cluster_idx = [];
start_cluster_id = 1;
cluster_data = cluster_info.data;
for i=1:length(cluster_data),
num_clusters = length(cluster_data{i}.id);
if (num_clusters ~= 0)
lag_idx = [lag_idx repmat(i,1,num_clusters+1)];
cluster_idx = [cluster_idx [1:num_clusters 0]];
last_cluster_id = start_cluster_id+num_clusters-1;
cluster_id = [cluster_id [start_cluster_id:last_cluster_id 0]];
start_cluster_id = last_cluster_id+1;
end;
end;
cluster_data_idx = [cluster_id; lag_idx; cluster_idx];
cluster_data_idx = cluster_data_idx(:,1:end-1);
total_clusters = size(cluster_data_idx,2);
total_pages = ceil(total_clusters / num_rows);
setappdata(gcf,'ClusterInfo',cluster_info);
setappdata(gcf,'ClusterDataIdx',cluster_data_idx);
setappdata(gcf,'TotalPages',total_pages);
setappdata(gcf,'NumRows',num_rows);
return; % setup_page_rows
%--------------------------------------------------------------------------
function p_value = ratio2p(x,mu,sigma)
p_value = (1 + erf((x - mu) / (sqrt(2)*sigma))) / 2;
p_value = (1 - p_value) * 2;
return; % ratio2p
%----------------------------------------------------------------------------
function delete_fig
link_figure = getappdata(gcbf,'LinkFigureInfo');
try
rmappdata(link_figure.hdl,link_figure.name);
end;
try
load('pls_profile');
pls_profile = which('pls_profile.mat');
struct_cluster_report_pos = get(gcbf,'position');
save(pls_profile, '-append', 'struct_cluster_report_pos');
catch
end
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -