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

📄 bfm_result_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 5 页
字号:
function fig = bfm_result_ui(action,varargin)
%
%  USAGE: fig = bfm_result_ui(action,varargin)
%

   if ~exist('action','var') | isempty(action)

      [PLSresultFile,PLSresultFilePath] =  ...
                        uigetfile('*_BfMRIresult.mat','Open PLS Result');
      if (PLSresultFilePath == 0), return; end;

      cd(PLSresultFilePath);
      PLSResultFile = fullfile(PLSresultFilePath,PLSresultFile);

      if exist('plslog.m','file')
         plslog('Show BfMRI Result');
      end

      try
         warning off;
         load(PLSResultFile, 'SessionProfiles', 'session_files_timestamp', 'datamat_files_timestamp', 'singleprecision');
         warning on;
      catch
         msgbox('Can not open file','Error');
         return
      end

      rri_changepath('bfmriresult');

      if exist('datamat_files_timestamp','var')

         session_files_timestamp_old = session_files_timestamp;
         datamat_files_timestamp_old = datamat_files_timestamp;

         change_timestamp = 0;

         for i = 1:length(SessionProfiles)
            for j = 1:length(SessionProfiles{i})
               tmp = dir(SessionProfiles{i}{j});
               session_files_ts = tmp.date;

               load(SessionProfiles{i}{j},'session_info');
               datamat_prefix = session_info.datamat_prefix;
               datamat_file = [datamat_prefix,'_BfMRIdatamat.mat'];

               tmp = dir(datamat_file);
               datamat_files_ts = tmp.date;

               if datenum(session_files_ts) > datenum(session_files_timestamp{i}{j})
                  change_timestamp = 1;
               end

               if datenum(datamat_files_ts) > datenum(datamat_files_timestamp{i}{j})
                  change_timestamp = 1;
               end
            end
         end

         if change_timestamp
            msg1 = ['One or more session files or datamat files are newer than their '];
            msg1 = [msg1, 'timestamp stored in the result file.'];
            msg2 = 'If you believe that the datamat files are just touched (e.g. due to copy) but not modified, you can click "Proceed All".';
            msg3 = 'Otherwise, please click "Stop", and re-create the result file.';

            quest = questdlg({msg1 '' msg2 '' msg3 ''}, 'Choose','Proceed All','Stop','Stop');

            if strcmp(quest,'Stop')
               return;
            end

            set(gcbf,'Pointer','watch');

            for i = 1:length(SessionProfiles)
               for j = 1:length(SessionProfiles{i})
                  tmp = dir(SessionProfiles{i}{j});
                  session_files_ts = tmp.date;
                  session_files_timestamp{i}{j} = session_files_ts;

                  load(SessionProfiles{i}{j},'session_info');
                  datamat_prefix = session_info.datamat_prefix;
                  datamat_file = [datamat_prefix,'_BfMRIdatamat.mat'];

                  tmp = dir(datamat_file);
                  datamat_files_ts = tmp.date;
                  datamat_files_timestamp{i}{j} = datamat_files_ts;
               end
            end
         end

         if ~isequal(session_files_timestamp, session_files_timestamp_old)
            try
               save(PLSResultFile, '-append', 'session_files_timestamp');
            catch
               uiwait(msgbox('Can not save new session timestamp','Error','modal'));
               return;
            end
         end

         if ~isequal(datamat_files_timestamp, datamat_files_timestamp_old)
            try
               save(PLSResultFile, '-append', 'datamat_files_timestamp');
            catch
               uiwait(msgbox('Can not save new datamat timestamp','Error','modal'));
               return;
            end
         end

      end


      v7 = version;
      if exist('singleprecision','var') & singleprecision & str2num(v7(1))<7
         uiwait(msgbox('MATLAB Version 7 (R14) above must be used to show this result file','Error','modal'));
         return;
      end


      warning off
      subj_name = {};
      try
         load(PLSResultFile,'subj_name');
      catch
         msgbox('Can not open file','Error');
         return
      end

      if isempty(subj_name)

         msg = 'This result file is created in old version and needs converted. Do you want the converted file to be saved as the same result file name?';
         ans = questdlg(msg,'Warning');

         switch ans
            case 'Yes'
               resultFile = PLSResultFile;
            case 'No'
               [result_file,result_path] = ...
			uiputfile(PLSResultFile,'Saving PLS Result');

               if isequal(result_file,0)			% Cancel was clicked
                  return;
               else
                  resultFile = fullfile(result_path,result_file);
               end;
            otherwise
               return;
         end

         [ContrastFile,SessionProfiles,b_scores,boot_result,brainlv, ...
          cond_name,cond_selection,create_ver,d_scores,designlv,lv_evt_list, ...
          num_conditions,num_subj_lst,perm_result,s,st_coords,st_datamat, ...
          st_dims,st_origin,st_voxel_size,st_win_size,subj_group,subj_name] = ...
		fmri_convert_task(PLSResultFile);

         saved_info=['brainlv s designlv perm_result boot_result st_coords ', ...
  	         'st_dims lv_evt_list st_win_size st_voxel_size st_origin ', ...
		 'SessionProfiles ContrastFile b_scores d_scores ', ...
		 'subj_group num_conditions cond_name cond_selection ', ...
		 'create_ver num_subj_lst st_datamat subj_name'];

         done = 0;
         while ~done
            try
               eval(['save ' resultFile ' ' saved_info]);
               done = 1;
            catch
               [result_file,result_path] = uiputfile('*BfMRIresult.mat', ...
			'Can not write file, please try again');

               if isequal(result_file,0)		% Cancel was clicked
                  return;
               else
                  resultFile = fullfile(result_path,result_file);
               end;
            end
         end

         PLSResultFile = resultFile;

      end
      warning on

      msg = 'Loading PLS results ...    Please wait!';
      h = rri_wait_box(msg, [0.5 0.1]);

      fig_h = init(PLSResultFile);

      setappdata(gcf,'CallingFigure',gcbf); 
      set(gcbf,'visible','off','Pointer','arrow');

      rot_amount = load_pls_result;
      bfm_result_ui('Rotation', rot_amount);

      if (nargout > 0),
        fig = fig_h;
      end;

      delete(h);

      dims = getappdata(gcf,'STDims');
      origin = getappdata(gcf,'STOrigin');
      if origin(1) < 1, origin(1) = 1; end
      if origin(2) < 1, origin(2) = 1; end
      if origin(3) < 1, origin(3) = 1; end
      if origin(1) > dims(1), origin(1) = dims(1); end
      if origin(2) > dims(2), origin(2) = dims(2); end
      if origin(3) > dims(4), origin(3) = dims(4); end
      h = findobj(gcf,'Tag','XYZVoxel');
      set(h, 'string', num2str(origin));
      h = findobj(gcf,'Tag','MessageLine');
      set(h,'String','');
      EditXYZ;

      return;
   end;

   %  clear the message line,
   %
   h = findobj(gcf,'Tag','MessageLine');
   set(h,'String','');

   if (strcmp(action,'PlotBnPress'))
     ShowResult(0,1);                % display brainlv inside the Plot BLV figure
   elseif (strcmp(action,'PlotOnNewFigure'))
     ShowResult(1,0);                % display brainlv in a new figure;
   elseif (strcmp(action,'Zooming'))
     zoom_on_state = get(gcbo,'Userdata');
     if (zoom_on_state == 1)
	zoom on;
        set(gcbo,'Userdata',0,'Label','&Zoom off');
        set(gcf,'pointer','crosshair');
     else
	zoom off;
        set(gcbo,'Userdata',1,'Label','&Zoom on');
        set(gcf,'pointer','arrow');
     end;
   elseif (strcmp(action,'ClusterMask'))
     cluster_mask_state = get(gcbo,'Userdata');

     isbsr = getappdata(gcbf,'ViewBootstrapRatio');
     if isbsr
        cluster_info = getappdata(gcbf, 'cluster_bsr');
     else
        cluster_info = getappdata(gcbf, 'cluster_blv');
     end

     curr_lv_idx = getappdata(gcbf,'CurrLVIdx');
     if length(cluster_info) < curr_lv_idx
        cluster_info = [];
     else
        cluster_info = cluster_info{curr_lv_idx};
     end

     if isempty(cluster_info)
        msgbox('Please either Load or Create a cluster report for this scenario');
        return;
     end

     if (cluster_mask_state == 1)
        set(gcbo,'Userdata',0,'check','on');
        ShowResult(0,1);
     else
        set(gcbo,'Userdata',1,'check','off');
        ShowResult(0,1);
     end;
   elseif (strcmp(action,'Toggle_View'))
     DeleteLinkedFigure;
     ToggleView;
     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');
     ShowResult(0,1);
   elseif (strcmp(action,'Rotation'))
     p_img = getappdata(gcf,'p_img');
     if ~isempty(p_img)
        p_img = [-1 -1];
        setappdata(gcf,'p_img',p_img);
     end
     setappdata(gcf,'img_xhair',[]);

     rot_amount = varargin{1};
     setappdata(gcf,'RotateAmount',rot_amount);
     switch mod(rot_amount,4)
        case {0},					% 0 degree
           h = findobj(gcf,'Tag','Rotate0Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate90Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate180Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate270Menu');
           set(h,'Checked','on');
        case {1},					% 90 degree by default
           h = findobj(gcf,'Tag','Rotate0Menu');
           set(h,'Checked','on');
           h = findobj(gcf,'Tag','Rotate90Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate180Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate270Menu');
           set(h,'Checked','off');
        case {2},					% 180 degree
           h = findobj(gcf,'Tag','Rotate0Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate90Menu');
           set(h,'Checked','on');
           h = findobj(gcf,'Tag','Rotate180Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate270Menu');
           set(h,'Checked','off');
        case {3},					% 270 degree
           h = findobj(gcf,'Tag','Rotate0Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate90Menu');
           set(h,'Checked','off');
           h = findobj(gcf,'Tag','Rotate180Menu');
           set(h,'Checked','on');
           h = findobj(gcf,'Tag','Rotate270Menu');
           set(h,'Checked','off');
     end;

     ShowResult(0,0);
     EditXYZ;
   elseif (strcmp(action,'EditLV'))
     EditLV;
     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');
     ShowResult(0,1);
   elseif (strcmp(action,'UpdatePValue'))
     UpdatePValue;
     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');
     isbsr = getappdata(gcbf,'ViewBootstrapRatio');
     if isappdata(gcbf,'cluster_blv') & ~isbsr
        rmappdata(gcbf,'cluster_blv');
     end
     if isappdata(gcbf,'cluster_bsr') & isbsr
        rmappdata(gcbf,'cluster_bsr');
     end
     ShowResult(0,1);
   elseif (strcmp(action,'EditThresh'))
     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');
     isbsr = getappdata(gcbf,'ViewBootstrapRatio');
     if isappdata(gcbf,'cluster_blv') & ~isbsr
        rmappdata(gcbf,'cluster_blv');
     end
     if isappdata(gcbf,'cluster_bsr') & isbsr
        rmappdata(gcbf,'cluster_bsr');
     end
     ShowResult(0,1);
   elseif (strcmp(action,'EditMin'))
     isbsr = getappdata(gcbf,'ViewBootstrapRatio');
     lv = getappdata(gcbf,'CurrLVIdx');
     if isbsr
        data = getappdata(gcbf,'BSRatio');
        thresh = getappdata(gcbf,'BSThreshold');
        setting = getappdata(gcbf,'setting');
        old_data = setting.min_ratio;
     else
        data = getappdata(gcbf,'BLVData');
        thresh = getappdata(gcbf,'BLVThreshold');
        setting = getappdata(gcbf,'setting');
        old_data = setting.min_blv;
     end
     if str2num(get(gco,'string')) < min(data(:,lv)) | str2num(get(gco,'string')) > thresh
        msg = ['Valid number should be within [' num2str([min(data(:,lv)) thresh]) ']'];
        set(findobj(gcbf,'Tag','MessageLine'),'String',msg);
        set(gco,'string',num2str(old_data{lv}));
        return;
     end

     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');
     if isappdata(gcbf,'cluster_blv') & ~isbsr
        rmappdata(gcbf,'cluster_blv');
     end
     if isappdata(gcbf,'cluster_bsr') & isbsr
        rmappdata(gcbf,'cluster_bsr');
     end
     ShowResult(0,1);
   elseif (strcmp(action,'EditMax'))
     isbsr = getappdata(gcbf,'ViewBootstrapRatio');
     lv = getappdata(gcbf,'CurrLVIdx');
     if isbsr
        data = getappdata(gcbf,'BSRatio');
        thresh = getappdata(gcbf,'BSThreshold');
        setting = getappdata(gcbf,'setting');
        old_data = setting.max_ratio;
     else
        data = getappdata(gcbf,'BLVData');
        thresh = getappdata(gcbf,'BLVThreshold');
        setting = getappdata(gcbf,'setting');
        old_data = setting.max_blv;
     end
     if str2num(get(gco,'string')) > max(data(:,lv)) | str2num(get(gco,'string')) < thresh
        msg = ['Valid number should be within [' num2str([thresh max(data(:,lv))]) ']'];
        set(findobj(gcbf,'Tag','MessageLine'),'String',msg);
        set(gco,'string',num2str(old_data{lv}));
        return;
     end

     set(findobj(gcbf,'tag','ClusterMask'),'Userdata',1,'check','off');     
     if isappdata(gcbf,'cluster_blv') & ~isbsr
        rmappdata(gcbf,'cluster_blv');
     end
     if isappdata(gcbf,'cluster_bsr') & isbsr
        rmappdata(gcbf,'cluster_bsr');
     end
     ShowResult(0,1);
   elseif (strcmp(action,'SelectPixel'))
     SelectPixel;
   elseif (strcmp(action,'DeleteNewFigure'))
      try
         load('pls_profile');
         pls_profile = which('pls_profile.mat');

         bfm_result_newfig_pos = get(gcbf,'position');

         save(pls_profile, '-append', 'bfm_result_newfig_pos');
      catch
      end
   elseif (strcmp(action,'DeleteFigure'))
      try
         load('pls_profile');
         pls_profile = which('pls_profile.mat');

         bfm_result_pos = get(gcbf,'position');

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

     old_setting = getappdata(gcbf,'old_setting');
     setting = getappdata(gcbf,'setting');


     save_display_status = 'off';
     try
        load('pls_profile');
     catch 
     end
     if strcmpi(save_display_status, 'off')
        setting = [];
     end


     if ~isequal(setting, old_setting) & strcmpi(save_display_status, 'on')
%        save_setting = ...
%           questdlg('Would you like to save the display setting?', ...
%			'Save current fields', 'yes', 'no', 'yes');
        if 1	% strcmp(save_setting, 'yes')
           try
              PLSresultFile = get(findobj(gcbf,'Tag','ResultFile'),'UserData');
              setting1 = setting;
              save(PLSresultFile, '-append', 'setting1');
           catch
              msg = 'Cannot save setting information';
              msgbox(msg,'ERROR','modal');
           end

⌨️ 快捷键说明

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