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

📄 pet_plot_brain_scores.m

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

   slider_hdl = findobj(gcf,'Tag','LVButtonSlider');
   total_rows = round(get(slider_hdl,'Max'));

   slider_value = total_rows - top_lv_button + 1;
   set(slider_hdl,'Value',slider_value);

   setappdata(gcf,'TopLVButton',top_lv_button);

   DisplayLVButtons;

   return;                                              % SetTopLVButton


%----------------------------------------------------------------------------
function SetupSlider()


   top_lv_button = getappdata(gcf,'TopLVButton');
   rows = getappdata(gcf,'NumLVRows');

   curr_lv_state = getappdata(gcf,'CurrLVState');
   num_lvs = length(curr_lv_state);

   total_rows = num_lvs;
   slider_hdl = findobj(gcf,'Tag','LVButtonSlider');

   if (total_rows > 1)           % don't need to update when no condition
      set(slider_hdl,'Min',1,'Max',total_rows, ...
                  'Value',total_rows-top_lv_button+1, ...
                  'Sliderstep',[1/(total_rows-1)-0.00001 1/(total_rows-1)]);
   end;

   return;                                              % UpdateSlider


%---------------------------------------------------------------------------
function SelectLV(selected_lv)

   lv_state = getappdata(gcf,'CurrLVState');
   LV_hlist = getappdata(gcf,'LV_hlist');
   top_lv = getappdata(gcf,'TopLVButton');
   rows = getappdata(gcf,'NumLVRows');
   bottom_lv = top_lv + rows - 1;


   %  remove the previous selection
   %
   prev_selected_lv = find(lv_state == 1);
   if (prev_selected_lv >= top_lv & prev_selected_lv <= bottom_lv),
      row_idx = prev_selected_lv - top_lv + 1;
      set(LV_hlist(row_idx),'Value',0);
   end;

   UpdateLVButtonList = 0;
   if ~exist('selected_lv','var')	 % select LV interactively
      curr_row = get(gcbo,'Userdata');
      curr_lv = top_lv + curr_row -1;
      set(LV_hlist(curr_row),'Value',1);
   else					 % select LV by specifying the index
      curr_lv = selected_lv;
      if (selected_lv >= top_lv & selected_lv <= bottom_lv),
         row_idx = selected_lv - top_lv + 1;
         set(LV_hlist(row_idx),'Value',1);
      else
         UpdateLVButtonList = 1;
      end;
   end;

   lv_state = zeros(1,length(lv_state));
   lv_state(curr_lv) = 1;

   setappdata(gcf,'CurrLVState',lv_state);

   if (UpdateLVButtonList)
      SetTopLVButton(curr_lv);
   end;

   return;                                              % SelectLV


%--------------------------------------------------------------------------
%
function h = delete_fig()

  pet_detail_hdl = getappdata(gcbf,'pet_detail_hdl');
  if exist('pet_detail_hdl','var') & ishandle(pet_detail_hdl)
     try
        delete(pet_detail_hdl);
     catch
     end
  end

  pet_allerr_hdl = getappdata(gcbf,'pet_allerr_hdl');
  if exist('pet_allerr_hdl','var') & ishandle(pet_allerr_hdl)
     try
        delete(pet_allerr_hdl);
     catch
     end
  end

  pet_dlv_hdl = getappdata(gcbf,'pet_dlv_hdl');
  if exist('pet_dlv_hdl','var') & ishandle(pet_dlv_hdl)
     try
        delete(pet_dlv_hdl);
     catch
     end
  end

  link_figure = getappdata(gcbf,'LinkFigureInfo');

  try 
     rmappdata(link_figure.hdl,link_figure.name);
  end;

  try
     load('pls_profile');
     pls_profile = which('pls_profile.mat');

     pet_plot_brain_scores_pos = get(gcbf,'position');

     save(pls_profile, '-append', 'pet_plot_brain_scores_pos');
  catch
  end

  return; 					% delete_fig


%--------------------------------------------------------------------------
function set_combine_plot()

  curr_state = get(gcbo,'Userdata');
  if (curr_state == 1),		% currently combining plots
     new_state = 0;
     set(gcbo,'Label','Combine plots within conditions');
  else
     new_state = 1;
     set(gcbo,'Label','Separate plots within conditions');
  end;

  set(gcbo,'Userdata',new_state);
  pet_plot_cond_stim_ui('COMBINE_PLOTS',new_state);

  return; 					% set_combine_plot

%--------------------------------------------------------------------------
function make_datamat_popup(data_option)
%  data_option = 1  - plot individual ST datamat
%  data_option = 2  - plot group data
%  data_option = 3  - plot all data

   popup_h = findobj(gcf,'Tag','STDatamatPopup');
   curr_option = get(popup_h,'Userdata');

   if ~isempty(curr_option) & (curr_option == data_option)
      return;				% no change, do nothing
   end;

   datamat_filenames = getappdata(gcf,'datamat_filename');

   switch (data_option)

     case {1}					% plot individual data
        num_datamat = length(datamat_filenames);
        popup_list = cell(1,num_datamat);
        for i=1:num_datamat,
           %  get rid of ".mat" extension if there is any 
           if strcmp(datamat_filenames{i}.name(end-3:end),'.mat')==1
              popup_list{i} = sprintf('[%d] %s', ...
                        datamat_filenames{i}.group, datamat_filenames{i}.name(1:end-4));
           else
              popup_list{i} = sprintf('[%d] %s', ...
                        datamat_filenames{i}.group, datamat_filenames{i}.name);
           end;
        end;
        alignment = 'left';

     case {2}					% plot group data
        num_group = datamat_filenames{end}.group;
        popup_list = cell(1,num_group);
	for i=1:num_group,
           popup_list{i} = sprintf('[ Group #%d ]',i);
	end;
        alignment = 'center';

     case {3}					% plot all data
        popup_list{1} = '< All Data >';
        alignment = 'center';
   end;

   set(popup_h,'String',popup_list,'Userdata',data_option, ...
               'HorizontalAlignment', alignment,'Value',1);

   msg = 'Press "Plot" Button or select datamat to see the response function';
   set(findobj(gcf,'Tag','MessageLine'),'String',msg);

   return; 					% make_datamat_popup


%--------------------------------------------------------------------------
function condition_update(sessionFileList,with_path)
%
   h = findobj(gcf,'Tag', 'CondSlider');
   rows = get(h,'UserData');
   max_page = get(h,'Max');
   slider_value = round(get(h,'Value'));
   page = max_page - slider_value +1;
   set(h,'Value',slider_value);

   chk_box_hlist = get(findobj(gcf,'Tag','ConditionLabel'),'UserData');
   num_cond = length(chk_box_hlist);

   visible_list = zeros(1,num_cond);
   visible_list((page-1)*rows+1:page*rows) = 1;

   for i=1:num_cond,
      if(visible_list(i) == 0)
          set(chk_box_hlist(i),'Visible','off');
      else
          set(chk_box_hlist(i),'Visible','on');
      end;
   end;
   
   return;
%


%--------------------------------------------------------------------------
function get_datamat_filename(datamat_files)
%
%
  result_file = getappdata(gcf,'result_file');
  num_groups = length(datamat_files);
  behav = [];
  behavcol = 99999;

  warning off;
  try
     load(result_file,'behavdata','behavname','behavdata_lst','behav_row_idx');
  catch
  end
  warning on;

  if exist('behavdata_lst','var')
     oldbehav = 0;
%     behav = behavdata;
     behav = [];

     for i=1:num_groups
        behavdata = behavdata_lst{i};
        behav = [behav; behavdata];
     end
  else
     oldbehav = 1;
     behav = [];
  end

  for i=1:num_groups
     [tmp, fn] = fileparts(datamat_files{i});

     datamat_filename{i}.name = fn;
     datamat_filename{i}.fullname = datamat_files{i};
     datamat_filename{i}.group = i;

     if oldbehav

        warning off;
        load(datamat_files{i},'behavdata','behavname');
        warning on;

        [r c] = size(behavdata);

        if c < behavcol
           behavcol = c;
        end

        if ~exist('behavname','var')
            behavname = {};
            for i=1:c
               behavname = [behavname, {['behav', num2str(i)]}];
            end
        end

        behavdata = behavdata(:,[1:behavcol]);
        if ~isempty(behav)
           behav = behav(:,[1:behavcol]);
        end

        behav = [behav; behavdata];
        behavname = behavname(1:behavcol);
     end
  end

%  if ~exist('behav_row_idx','var')
 %    behav_row_idx = 1:size(behav,1);
  %end

%  behav = behav(behav_row_idx, :);

  setappdata(gcf,'behavname',behavname);
  setappdata(gcf,'behavdata',behav);
  setappdata(gcf,'datamat_filename',datamat_filename);

  return;                                       % get_datamat_filename


%--------------------------------------------------------------------------
%
function  [st_datamat,st_coords,st_win_size,st_evt_list] =  ...
                                         load_plotted_datamat(selected_idx)

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

   st_filename = getappdata(gcf,'datamat_filename');

   h = findobj(gcf,'Tag','STDatamatPopup');
   selected_idx = get(h,'Value');
   data_option = get(h,'Userdata');

   switch (data_option)
      case {1}, 
         selected_files{1} = st_filename{selected_idx}.fullname;
      case {2},
         cnt = 0;
         for i=1:length(st_filename),
            if (st_filename{i}.group == selected_idx)
               cnt = cnt+1;
               selected_files{cnt} = st_filename{i}.fullname;
            end;
         end;
      case {3},
         cnt = 0;
         for i=1:length(st_filename),
            selected_files{i} = st_filename{i}.fullname;
         end;
   end; 


   %  merge files together
   [st_datamat,st_coords,st_win_size,st_evt_list] =  ...
                                   merge_st_datamat(selected_files);
   nr = length(st_evt_list);
   nc = length(st_coords);
   st_datamat = reshape(st_datamat,[nr,st_win_size,nc]);

   pls_coords = getappdata(gcf,'PLSCoords');
   dims = getappdata(gcf,'Dims');
   m = zeros(dims);
   m(pls_coords) = 1;

   coord_idx = find (m(st_coords) == 1);
   nc = length(coord_idx);
   st_coords = st_coords(coord_idx);
   st_datamat = st_datamat(:,:,coord_idx);

   set(gcf,'Pointer',old_pointer);

   if ~isequal(st_coords(:),pls_coords(:)),
      st_datamat = [];
      msg = 'ERROR: Incompatible coords for the st_datamat and the PLS result';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      return;
   end;

   return;                                       % load_plotted_datamat


%--------------------------------------------------------------------------
%
function  [grp_st_datamat,coords,win_size,evt_list] =  ...
                                   merge_st_datamat(selected_files),

   num_files = length(selected_files);

   %  compute the common coords first and the total number of events
   %  
   load(selected_files{1},'st_dims','st_win_size'); 
   total_num_evt = 0;
   m = zeros(st_dims);
   for i=1:num_files,
      load(selected_files{i},'st_coords','st_evt_list');
      total_num_evt = total_num_evt + length(st_evt_list); 
      m(st_coords) = m(st_coords) + 1; 
   end;
   coords = find(m == num_files); 


   %  ready to merge the st_datamat together now ...
   %
   win_size = st_win_size;
   num_voxels = length(coords);
   num_cols = win_size * num_voxels;
   grp_st_datamat = zeros(total_num_evt,num_cols);
   evt_list = [];
   first_row = 1;
   for i=1:num_files,

      load(selected_files{i});

      coord_idx = find(m(st_coords) == num_files);
      nr = length(st_evt_list);
      nc = length(st_coords);
      last_row = nr + first_row - 1;

      tmp_datamat = reshape(st_datamat,[nr,win_size,nc]); 
      tmp_datamat = reshape(tmp_datamat(:,:,coord_idx),[nr,num_cols]);

      grp_st_datamat(first_row:last_row,:) = tmp_datamat;
      evt_list = [evt_list st_evt_list];

      first_row = last_row + 1;

      clear st_datamat tmp_datamat;
   end; 

   return;                               	% merge_st_datamat


%---------------------------------------------------------------------------
function [brainscores,behavlv,s,conditions,selected_conditions, ...
	num_cond_lst,num_subj_lst,lvcorrs,boot_result,perm_result, ...
	session_info,datamat_files,cond_selection] = ...
		load_pls_brainscores(fname,cond_selection)

   brainscores = [];
   session_info = [];
   conditions = [];

%   cond_selection = getappdata(gcf,'cond_selection');

   % the following part will not get called during plsgui
   %
   if ~exist('fname','var') | isempty(fname),
     f_pattern = '*_PETresult.mat';
     [PLSresultFile,PLSresultFilePath] = uigetfile(f_pattern,'Load PLS scores');

     if isequal(PLSresultFile,0), 
        return;
     end;

     fname = [PLSresultFilePath,PLSresultFile];
   end;

   try 
      warning off;
      load( fname,'ismultiblock','brainscores','behavlv','s','perm_result','boot_result', ...
	'num_cond_lst','num_subj_lst','lvcorrs','datamat_files','behavname','bscan' );
      warning on;
   catch
      msg = sprintf('Cannot load the PLS result from file: %s',fname);
      disp(['ERROR: ' msg]);
      return;
   end;

   if exist('bscan','var') & ~isempty(bscan)
      kk = length(bscan);
   else
      kk = num_cond_lst(1);
   end

   if 0 % exist('ismultiblock','var')
      num_groups = length(num_subj_lst);
      k = num_cond_lst(1);
      t = length(behavname);

      lvcorr = [];

      for g = 1:num_groups
         lvcorr = [lvcorr; lvcorrs((g-1)*k+(g-1)*kk*t+k+1:(g-1)*k+(g-1)*kk*t+k+kk*t,:)];
      end

      lvcorrs = lvcorr;      

      if exist('boot_result','var') & ~isempty(boot_result)
         orig_corr = [];
         ulcorr = [];
         llcorr = [];

⌨️ 快捷键说明

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