⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmri_plot_datamatcorrs_3v.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 5 页
字号:

   fmri_cluster_report(cluster_min_size,cluster_min_dist);


   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,'ContrastFile','SessionProfiles');

   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;

   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 ShowResult(action,update)
% action=0 - plot with the control figure
% action=1 - plot in a seperate figure
%

  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;

  h = findobj(gcf,'Tag','LagIndexEdit');  lag_idx = get(h,'Userdata');
  curr_lag_idx = getappdata(gcf,'CurrLagIdx');
  if (lag_idx ~= curr_lag_idx),
     lag_idx = curr_lag_idx;
     set(h,'String',num2str(lag_idx));
  end;

  h = findobj(gcf,'Tag','BSLVIndexEdit');  bs_lv_idx = get(h,'Userdata');
  curr_bs_lv_idx = getappdata(gcf,'CurrBSLVIdx');
  if (bs_lv_idx ~= curr_bs_lv_idx),
     bs_lv_idx = curr_bs_lv_idx;
     set(h,'String',num2str(bs_lv_idx));
  end;

  h = findobj(gcf,'Tag','GroupIndexEdit');  grp_idx = get(h,'Userdata');
  curr_grp_idx = getappdata(gcf,'CurrGroupIdx');
  if (grp_idx ~= curr_grp_idx),
     grp_idx = curr_grp_idx;
     set(h,'String',num2str(grp_idx));
  end;

  h = findobj(gcf,'Tag','BehavIndexEdit');  behav_idx = get(h,'Userdata');
  curr_behav_idx = getappdata(gcf,'CurrBehavIdx');
  if (behav_idx ~= curr_behav_idx),
     behav_idx = curr_behav_idx;
     set(h,'String',num2str(behav_idx));
  end;

  h = findobj(gcf,'Tag','FirstSlice'); first_slice = str2num(get(h,'String'));
  h = findobj(gcf,'Tag','SliceStep');  step = str2num(get(h,'String'));
  h = findobj(gcf,'Tag','LastSlice');  last_slice = str2num(get(h,'String'));

  if (first_slice < 1) | (first_slice > st_dims(4))
     msg =sprintf('ERROR: The first slice must be between 1 and %d.',st_dims(4));
     set(findobj(gcf,'Tag','MessageLine'),'String',msg);
     return;
  end;

  if (last_slice < 1) | (last_slice > st_dims(4))
     msg =sprintf('ERROR: The last slice must be between 1 and %d.',st_dims(4));
     set(findobj(gcf,'Tag','MessageLine'),'String',msg);
     return;
  end;

  slice_idx = [first_slice:step:last_slice];
  if isempty(slice_idx),
     msg = 'ERROR: Invalid slice range.';
     set(findobj(gcf,'Tag','MessageLine'),'String',msg);
     return;
  end;


  old_pointer = get(gcf,'Pointer');
  fig_hdl = gcf;
  set(fig_hdl,'Pointer','watch');

  setting = getappdata(gcf,'setting');

  if isempty(setting) | ~isfield(setting,'origin')
     setting.origin = getappdata(gcf,'STOrigin');
  else
     setappdata(gcf,'STOrigin',setting.origin);
     setappdata(gcf,'Origin',setting.origin);
  end;

  if (getappdata(gcf,'ViewBootstrapRatio') == 0),	% plot brain lv 

     h = findobj(gcf,'Tag','Threshold');  thresh = str2num(get(h,'String'));
     h = findobj(gcf,'Tag','MaxValue');   max_blv = str2num(get(h,'String'));
     h = findobj(gcf,'Tag','MinValue');   min_blv = str2num(get(h,'String'));

     if isempty(max_blv) | isempty(min_blv) | isempty(thresh) | ...
	   (abs(max_blv) < thresh) | (abs(min_blv) < thresh)
        msg = 'ERROR: Invalid threshold, minimum or maxinum value setting.';
        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        set(fig_hdl,'Pointer',old_pointer);
	return;
     end;

     range = [min_blv max_blv];
     switch action 
       case {0}
          plot_st_brainlv(PLSresultFile,grp_idx,behav_idx,lv_idx,lag_idx,[],thresh,range,0,[],update);
       case {1}
          plot_st_brainlv(PLSresultFile,grp_idx,behav_idx,lv_idx,lag_idx,[],thresh,range,1,[],update);
     end;

  else							% plot bootstrap ratio

     h = findobj(gcf,'Tag','Threshold');  thresh = str2num(get(h,'String'));
     h = findobj(gcf,'Tag','MaxValue');   max_blv = str2num(get(h,'String'));
     h = findobj(gcf,'Tag','MinValue');   min_blv = str2num(get(h,'String'));

     if isempty(max_blv) | isempty(min_blv) | isempty(thresh) | ...
	   (abs(max_blv) < thresh) | (abs(min_blv) < thresh)
        msg = 'ERROR: Invalid threshold, minimum or maxinum value setting.';
        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        set(fig_hdl,'Pointer',old_pointer);
	return;
     end;

     h = findobj(gcf,'Tag','BSThreshold'); 
     thresh_ratio = str2num(get(h,'String')); 
     h = findobj(gcf,'Tag','MaxRatio'); max_ratio = str2num(get(h,'String'));
     h = findobj(gcf,'Tag','MinRatio'); min_ratio = str2num(get(h,'String'));

     if isempty(max_ratio) | isempty(min_ratio) | isempty(thresh_ratio) | ...
	   (abs(max_ratio) < thresh_ratio) | (abs(min_ratio) < thresh_ratio)
        msg = 'ERROR: Invalid threshold, minimum or maxinum ratio setting.';
        set(findobj(gcf,'Tag','MessageLine'),'String',msg);
        set(fig_hdl,'Pointer',old_pointer);
	return;
     end;;

     range = [min_ratio max_ratio];
     switch action 
       case {0}
          plot_bs_ratio(PLSresultFile,grp_idx,behav_idx,lv_idx,lag_idx,[],thresh,range,0,[],update);
       case {1}
          plot_bs_ratio(PLSresultFile,grp_idx,behav_idx,lv_idx,lag_idx,[],thresh,range,1,[],update);
     end;

  end;

  set(fig_hdl,'Pointer',old_pointer);

  setting = getappdata(gcf,'setting');

  if isempty(setting) | ~isfield(setting,'origin')
     setting.origin = getappdata(gcf,'STOrigin');
  else
     setappdata(gcf,'STOrigin',setting.origin);
     setappdata(gcf,'Origin',setting.origin);
  end;

  setting.grp_idx = grp_idx;
  setting.lv_idx = lv_idx;
  setting.lag_idx = lag_idx;
  setting.bs_lv_idx = bs_lv_idx;
  setting.behav_idx = behav_idx;
  setting.rot_amount = getappdata(gcf,'RotateAmount');

  setting.first_slice = first_slice;
  setting.slice_step = step;
  setting.last_slice = last_slice;

  setting.thresh{grp_idx,lv_idx,behav_idx} = thresh;
  setting.min_blv{grp_idx,lv_idx,behav_idx} = min_blv;
  setting.max_blv{grp_idx,lv_idx,behav_idx} = max_blv;

  if getappdata(gcf,'ViewBootstrapRatio')		% plot bsr
     setting.bs_thresh{bs_lv_idx} = str2num(get(findobj(gcf,'Tag','BSThreshold'),'String'));
  end

  setappdata(gcf,'setting',setting);

if 0
  %  create / or re-create xhair
  %
  ax = getappdata(gcf,'BlvAxes');
  p_img = getappdata(gcf,'p_img');

  if isempty(p_img)
     p_img = [-1 -1];
  end

  img_xhair = getappdata(gcf,'img_xhair');
  img_xhair = rri_xhair(p_img,img_xhair,ax);


      %%%%%%%%%%%     update xhair      %%%%%%%%%%%%

  h_img = findobj(gcf,'tag','BLVImg');
  img_xlim = get(h_img, 'xdata');
  img_ylim = get(h_img, 'ydata');
  img_lx = img_xhair.lx;
  img_ly = img_xhair.ly;

  set(img_lx,'xdata', img_xlim, 'ydata', [p_img(2) p_img(2)]);
  set(img_ly,'xdata', [p_img(1) p_img(1)], 'ydata', img_ylim);


  xhair_color = get(findobj(gcf,'tag','XhairColorMenu'), 'user');
  set(img_xhair.lx, 'color', xhair_color);
  set(img_xhair.ly, 'color', xhair_color);

  setappdata(gcf,'img_xhair',img_xhair);
end

  % update the LV scores when needed
  %
  scores_fig = getappdata(gcf,'ScorePlotHdl'); 
  if isempty(scores_fig)		
      return;
  else
      fmri_plot_scores('UPDATE_LV_SELECTION',scores_fig,lv_idx);
  end;


  return;					% ShowResult


%-------------------------------------------------------------------------
%   
function plot_st_brainlv(PLSresultFile,grp_idx,behav_idx,lv_idx,lag_idx,slice_idx,thresh,range,new_fig,cluster_info,update)
% 
%  USAGE:  plot_st_brainlv(PLSresultFile,lv_idx,slice_idx,thresh,range,new_fig)
%
%
%  INPUT: 
%     PLSresultFile - file contains the PLS results
%     lv_idx - the index of brainlv to be displayed
%     slice_idx - (optional) the indices of the slices to be display
%     thresh - (optional) set up the cutoff value to be display in colour.
%               To show everything, set thresh = 0. 
%               [DEFAULT = 0.5 * (range of brainlv values)]  
%     range - (optional) 1x2 vector specifies the range of brainlv to be 
%             display, anything higher or lower will be clipped
%     new_fig - show images on a new figure
%                           
%  Example:
%
%      slice_idx = [50:70];
%      thresh = 0.01;
%      range = [-0.8 0.8];
%      plot_st_brainlv('PLSresult',slice_idx,0.4,range);
%
  if (new_fig)
     bg_img = getappdata(gcbf,'BackgroundImg');
     rot_amount = getappdata(gcbf,'RotateAmount');
  else
     bg_img = getappdata(gcf,'BackgroundImg');
     rot_amount = getappdata(gcf,'RotateAmount');
  end;

  rot_amount = 4;

  load(PLSresultFile,'st_dims','st_win_size','st_coords','st_voxel_size', ...
		'st_origin','num_conditions','behavdata');

%  if ~exist('slice_idx','var')
  if isempty(slice_idx)
     slice_idx = [1:st_dims(4)];
  end
  num_slices = length(slice_idx);

  num_lv = num_conditions;
  num_lag = st_win_size - 1;
  num_behav = size(behavdata,2);

  if ~exist('thresh','var') 
     thresh = [];
  end;

  h = findobj(gcf,'Tag','Threshold');  thresh = str2num(get(h,'String'));
  h = findobj(gcf,'Tag','MaxValue');   max_blv = str2num(get(h,'String'));
  h = findobj(gcf,'Tag','MinValue');   min_blv = str2num(get(h,'String'));

  if ~exist('range','var') | isempty(range)
     range = [min_blv max_blv];  
  else
     min_blv = range(1);
     max_blv = range(2);
  end

  win_size = st_win_size;

  if (mod(rot_amount,2) == 0) 
    img_height = st_dims(1);		  % rows 
    img_width  = st_dims(2);
  else
    img_height = st_dims(2);		  % rows - after 90 or 270 rotation
    img_width  = st_dims(1);
  end;

  mont_height = win_size * img_height;    
  mont_width = num_slices * img_width;     

  brainlv_lst = getappdata(gcf,'BLVData');
  brainlv = brainlv_lst{grp_idx,behav_idx};

  %  construct the brainlv images
  %
%  blv_imgs = zeros(win_size*img_height,mont_width);
  first_rows = 1; last_rows = img_height;

%  for i=1:win_size,
     i = lag_idx + 1;
     blv = brainlv(i:win_size:end,lv_idx);

        cluster_idx = st_coords;

     [img,cmap,cbar] = fmri_plot_brainlv(blv,st_coords,st_dims,slice_idx, ...
		thresh,range,rot_amount,bg_img,cluster_idx);

     blv_imgs = img;
%     blv_imgs(first_rows:last_rows,:) = reshape(img,[img_height, mont_width]);
     first_rows = last_rows + 1; last_rows = first_rows + img_height - 1;
%  end;

  %  display the images
  %
  if (new_fig)
      [axes_hdl,colorbar_hdl] = create_new_blv_figure;
  else 
%      axes_hdl = getappdata(gcf,'BlvAxes');
      colorbar_hdl = getappdata(gcf,'Colorbar');
  end;

%  axes(axes_hdl);			

if 0
  if update
     h_img = findobj(gcf,'tag','BLVImg');
     set(h_img,'CData',blv_imgs);
  else
     h_img = image(blv_imgs); 

     set(gca,'tickdir','out','ticklength',[0.001 0.001]);
     set(gca,'xlabel',text('String','Slice','FontSize',10,'Interpreter','none'));
     set(gca,'xtick',[img_width/2:img_width:mont_width]);
     set(gca,'xticklabel',slice_idx);
     set(gca,'ylabel',text('String','Lag','FontSize',10,'Interpreter','none'));
     set(gca,'ytick',[img_height/2:img_height:mont_height]);
     set(gca,'yticklabel',[0:win_size-1]); 
  end

  set(h_img,'Tag','BLVImg');
  colormap(cmap); 

  if (new_fig)
     create_colorbar(colorbar_hdl,cbar,min_blv,max_blv);
     return;
  end;

  set(h_img,'ButtonDownFcn','fmri_plot_datamatcorrs_3v(''SelectPixel'')');
end


    st_origin1 = getappdata(gcf,'STOrigin');
    if ~isempty(st_origin1)
       st_origin = st_origin1;
    end

    nii = make_nii(squeeze(img), st_voxel_size, st_origin);

    gui3view.figure = gcf;
    gui3view.area = [0.32 0.1 0.55 0.85];

    if update

        opt.command = 'updateimg';
        opt.usecolorbar = 0;
        view_nii(gcf,nii.img,opt);
        opt1.setcolormap = cmap;
        view_nii(gcf,opt1);

    else

        opt.setbuttondown = 'fmri_plot_datamatcorrs_3v(''SelectPixel'');';
        opt.setarea = [0.32 0.1 0.55 0.85];
        opt.setcolormap = cmap;
        opt.useimagesc = 0;
        opt.usepanel = 0;
        opt.usecolorbar = 0;
        tstfig = getappdata(gcf,'nii_view');
        if isempty(tstfig)
           opt.command = 'init';
        else
           opt.command = 'updatenii';
        end
        view_nii(gcf,nii,opt);

    end

    nii_view = getappdata(gcf,'nii_view');

    h = findobj(gcf,'Tag','XYZVoxel');
    set(h,'String',sprintf('%d %d %d %d',lag_idx,nii_view.imgXYZ.vox));

    h = findobj(gcf

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -