📄 fmri_cluster_report.m
字号:
setappdata(mainfig,'cluster_bsr',cluster_bsr);
else
cluster_blv{curr_lv_idx} = cluster_info;
setappdata(mainfig,'cluster_blv',cluster_blv);
end
cluster_fig = create_report_figure(report_type,mainfig);
setup_cluster_data_idx(cluster_info);
setup_header;
setup_footer;
show_report_page(1);
return; % show_cluster_report
%-------------------------------------------------------------------------
function show_report_page(page_num),
%
report_type = getappdata(gcf,'ReportType');
num_rows = getappdata(gcf,'NumRows');
top_margin = getappdata(gcf,'TopMargin');
line_height = getappdata(gcf,'LineHeight');
cluster_info = getappdata(gcf,'ClusterInfo');
cluster_data_idx = getappdata(gcf,'ClusterDataIdx');
standard_text_obj = getappdata(gcf,'StandardTextObj');
h_list = getappdata(gcf,'HdlList');
axes_h = findobj(gcf,'Tag','ClusterReportAxes');
axes_pos = get(axes_h,'Position');
first_row_pos = 1 - top_margin;
last_row_pos = first_row_pos - (num_rows-1)*line_height;
if isempty(cluster_data_idx)
return;
end;
show_page_keys(page_num);
% display the cluster information for the current page
%
start_row = num_rows * (page_num - 1) + 1;
if (cluster_data_idx(1,start_row) == 0), % the first row is empty
start_row = start_row - 1;
num_rows = num_rows - 1;
end;
v_pos = [first_row_pos:-line_height:last_row_pos];
if (report_type == 0) % BLV value report
h_pos = [0.09 0.19 0.24 0.40 0.70 0.87];
h_pvalue_pos = 0;
else % Bootstrap ratio report
h_pos = [0.09 0.19 0.24 0.40 0.66 0.87];
h_pvalue_pos = 0.75;
end;
delete(h_list);
h_list = [];
last_row = min(size(cluster_data_idx,2),start_row+num_rows-1);
for idx=start_row:last_row,
v_idx = idx-start_row+1;
cluster_id = cluster_data_idx(1,idx);
if (cluster_id ~= 0),
cluster_lag = cluster_data_idx(2,idx);
cluster_idx = cluster_data_idx(3,idx);
c_data = cluster_info.data{cluster_lag};
h = copyobj(standard_text_obj,axes_h); % cluster #
cluster_num = sprintf('%3d',cluster_id);
set(h, 'String',cluster_num, ...
'Position',[h_pos(1) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
if (idx==start_row | cluster_idx==1)
h = copyobj(standard_text_obj,axes_h); % lag
set(h, 'String',num2str(cluster_lag-1), ...
'Position',[h_pos(2) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
end;
h = copyobj(standard_text_obj,axes_h); % peak xyz
peak_xyz_str = sprintf('[%3d %3d %3d]',c_data.peak_xyz(cluster_idx,:));
set(h, 'String',peak_xyz_str, ...
'Position',[h_pos(3) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
h = copyobj(standard_text_obj,axes_h); % peak loc
peak_loc_str = sprintf('[%6.1f %6.1f %6.1f]', ...
c_data.peak_loc(cluster_idx,:));
set(h, 'String',peak_loc_str, ...
'Position',[h_pos(4) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
h = copyobj(standard_text_obj,axes_h); % peak value
peak_value_str = sprintf('%8.4f',c_data.peak_values(cluster_idx));
set(h, 'String',peak_value_str, ...
'Position',[h_pos(5) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
if (h_pvalue_pos ~= 0)
h = copyobj(standard_text_obj,axes_h); % P value
p_value = ratio2p(abs(c_data.peak_values(cluster_idx)), ...
0,1 );
p_value_str = sprintf('(%6.4f)',p_value);
set(h, 'String',p_value_str, ...
'Position',[h_pvalue_pos v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
end;
h = copyobj(standard_text_obj,axes_h); % cluster size
size_str = sprintf('%4d',c_data.size(cluster_idx));
set(h, 'String',size_str, ...
'Position',[h_pos(6) v_pos(v_idx) 0], ...
'Visible','on');
h_list = [h_list h];
end;
end;
setappdata(gcf,'CurrPage',page_num);
setappdata(gcf,'HdlList',h_list);
return; % show_report_page
%--------------------------------------------------------------------------
function save_cluster_report()
report_type = getappdata(gcf,'ReportType');
cluster_info = getappdata(gcf,'ClusterInfo');
if (report_type == 0) % BLV value report
cluster_info.type = 'BLV Report';
else
cluster_info.type = 'Bootstrap Ratio Report';
end;
result_name = getappdata(gcbf, 'ResultName');
if findstr('BfMRIresult.mat', result_name)
[filename, pathname] = ...
uiputfile('*_BfMRIcluster.mat','Save to .mat file');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_bfmricluster')))
[tmp filename] = fileparts(filename);
filename = [filename, '_BfMRIcluster.mat'];
end
else
[filename, pathname] = ...
uiputfile('*_fMRIcluster.mat','Save to .mat file');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_fmricluster')))
[tmp filename] = fileparts(filename);
filename = [filename, '_fMRIcluster.mat'];
end
end
if isequal(filename,0)
status = 0;
return;
end;
report_file = fullfile(pathname,filename);
try
save (report_file, 'cluster_info', 'report_type' );
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 save cluster report to %s',report_file),
% set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
status = 0;
return;
end;
return; % save_cluster_report
%--------------------------------------------------------------------------
function save_cluster_txt()
result_name = getappdata(gcbf, 'ResultName');
if findstr('BfMRIresult.mat', result_name)
[filename, pathname] = ...
uiputfile('*_BfMRIcluster.txt','Save to .txt file');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_bfmricluster.txt')))
[tmp filename] = fileparts(filename);
filename = [filename, '_BfMRIcluster.txt'];
end
else
[filename, pathname] = ...
uiputfile('*_fMRIcluster.txt','Save to .txt file');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_fmricluster.txt')))
[tmp filename] = fileparts(filename);
filename = [filename, '_fMRIcluster.txt'];
end
end
if isequal(filename,0)
status = 0;
return;
end;
report_file = fullfile(pathname,filename);
fid = fopen(report_file, 'wt');
if fid == -1
msg = ['File ', filename, ' can not be open to write'];
msgbox(msg, 'Error');
return;
end
cluster_info = getappdata(gcf,'ClusterInfo');
cluster_data_idx = getappdata(gcf, 'ClusterDataIdx');
report_type = getappdata(gcf,'ReportType');
str = sprintf('Clu#\tLag\tX\tY\tZ\tX(mm)\tY(mm)\tZ(mm)\t');
if report_type
str = [str sprintf('BSR\tAppro.P\tClu_Size(voxels)\n')];
str = [str '--------------------------------------------------------'];
str = [str '----------------------------------------'];
else
str = [str sprintf('BLV\tClu_Size(voxels)\n')];
str = [str '--------------------------------------------------------'];
str = [str '--------------------------------'];
end
fprintf(fid, '\n%s\n\n', str);
for idx = 1 : size(cluster_data_idx, 2)
cluster_id = cluster_data_idx(1, idx);
if cluster_id ~= 0
cluster_lag = cluster_data_idx(2, idx);
cluster_idx = cluster_data_idx(3, idx);
c_data = cluster_info.data{cluster_lag};
cluster_num = sprintf('%d\t', cluster_id);
lag_num = sprintf('%d\t', cluster_lag-1);
peak_xyz_str = ...
sprintf('%d\t%d\t%d\t',c_data.peak_xyz(cluster_idx,:));
peak_loc_str = ...
sprintf('%.1f\t%.1f\t%.1f\t',c_data.peak_loc(cluster_idx,:));
peak_value_str = sprintf('%.4f\t',c_data.peak_values(cluster_idx));
if report_type
p_value = ...
ratio2p(abs(c_data.peak_values(cluster_idx)), 0, ...
1);
p_value_str = sprintf('%.4f\t',p_value);
else
p_value_str = '';
end
size_str = sprintf('%d\n',c_data.size(cluster_idx));
str = [cluster_num,lag_num,peak_xyz_str,peak_loc_str];
str = [str peak_value_str,p_value_str,size_str];
fprintf(fid, '%s', str);
end
end
% display the footer
%
source_file = cluster_info.source;
source_line = sprintf('Source: %s',source_file);
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);
if report_type
str = ['--------------------------------------------------------'];
str = [str '----------------------------------------'];
str = [str sprintf('\n%s\n%s',source_line,parameters_line)];
else
str = ['--------------------------------------------------------'];
str = [str '--------------------------------'];
str = [str sprintf('\n%s\n%s',source_line,parameters_line)];
end
fprintf(fid, '\n%s\n\n', str);
fclose(fid);
msg = ['File ', filename, ' has been saved'];
msgbox(msg, 'Info');
return; % save_cluster_txt
%--------------------------------------------------------------------------
function save_all_location()
result_name = getappdata(gcbf, 'ResultName');
result_file = get(findobj(getappdata(gcf,'mainfig'),'tag','ResultFile'),'UserData');
st_dims = getappdata(getappdata(gcf,'mainfig'),'STDims');
cluster_info = getappdata(gcf,'ClusterInfo');
data = cluster_info.data;
xyz = [];
for i = 1:length(data)
new_xyz = rri_coord2xyz(data{i}.idx, st_dims);
% if isempty(findstr('BfMRIresult.mat', result_name))
% new_xyz = [(i-1)*ones(size(new_xyz,1),1) new_xyz];
% end
xyz = [xyz; new_xyz];
end
% xyz = rri_coord2xyz(xyz, st_dims);
% xyz = unique(xyz, 'rows');
xyz2=[];
max_cnum=[];
for i = 1:length(data)
cnum = cluster_info.data{i}.mask;
for j=1:length(cluster_info.data{i}.id)
cnum(find(cluster_info.data{i}.mask==cluster_info.data{i}.id(j)))=j;
end;
if isempty(max_cnum),max_cnum=0;end;
xyz2 = [xyz2 cnum+max_cnum];
max_cnum=max(xyz2);
end
coord = getappdata(getappdata(gcf,'mainfig'),'BSRatioCoords');
if isempty(coord)
coord = getappdata(getappdata(gcf,'mainfig'),'BLVCoords');
end
if getappdata(gcf,'ReportType')
data = getappdata(getappdata(gcf,'mainfig'), 'BSRatio');
else
data = getappdata(getappdata(gcf,'mainfig'), 'BLVData');
end
data = data(:, cluster_info.lv_idx);
win_size = getappdata(getappdata(gcf,'mainfig'), 'WinSize');
data2=[];
for i = 1:win_size
coord_idx = ones(size(cluster_info.data{i}.idx));
voxels = data(i:win_size:end);
for j=1:length(coord_idx)
coord_idx(j) = find(coord==cluster_info.data{i}.idx(j));
end
data2 = [data2; voxels(coord_idx)];
end
xyz = double(xyz2xyzmm(xyz, result_file));
xyz2 = double([xyz2' double(data2) xyz]);
if findstr('BfMRIresult.mat', result_name)
[filename, pathname] = ...
uiputfile('*_BfMRIcluster_all.txt','Export All Location');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_bfmricluster_all.txt')))
[tmp filename] = fileparts(filename);
filename = [filename, '_BfMRIcluster_all.txt'];
end
else
[filename, pathname] = ...
uiputfile('*_fMRIcluster_all.txt','Export All Location');
if ischar(filename) & (length(filename)<9 | isempty(findstr(lower(filename),'_fmricluster_all.txt')))
[tmp filename] = fileparts(filename);
filename = [filename, '_fMRIcluster_all.txt'];
end
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,'fMRIcluster_all.txt','fMRIcluster_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 save_peak_location()
result_name = getappdata(gcbf, 'ResultName');
result_file = get(findobj(getappdata(gcf,'mainfig'),'tag','ResultFile'),'UserData');
cluster_info = getappdata(gcf,'ClusterInfo');
data = cluster_info.data;
xyz = [];
for i = 1:length(data)
new_xyz = data{i}.peak_xyz;
% if isempty(findstr('BfMRIresult.mat', result_name))
% new_xyz = [(i-1)*ones(size(new_xyz,1),1) new_xyz];
% end
xyz = [xyz; new_xyz];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -