Home > fmri > utils > post_process_corrmat_fsl.m

post_process_corrmat_fsl

PURPOSE ^

plots design matrix and regressor covariance structure for FSL analyses

SYNOPSIS ^

function [cmat, X] = post_process_corrmat_fsl(fsldir,opt)

DESCRIPTION ^

 plots design matrix and regressor covariance structure for FSL analyses
 
   [cmat X] = post_process_corrmat_fsl(fsldir)
 
 REQUIRES
   fsldir - path to fsl analysis directory, within which should exist:
       design.mat, design.fsf, fsf.mat
   opt.printfig - flag, 1 or 0, to print or not print the figure to file
   opt.figstub - file name stub (w/o extension) for figure filenames
   opt.appendstr - cell array of strings of additional settings to send to
       print when printing the figures to file
   opt.title - figure title stub (to which will be appended 'design
       matrix' or 'regressor correlations'
   opt.plot_corr_txt - plot text labels on regressor correlations?
 
 RETURNS
   cmat - correlation matrix for design matrix regressors
   X - design matrix
 
 05/19/06 Petr Janata - modified from a 2004 version of the script.  Added
 support for SPM5 structure of the SPM.mat file.
 10/28/09 Fred Barrett - adapted from post_process_corrmat (SPM only) for
 use with FSL

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [cmat, X] = post_process_corrmat_fsl(fsldir,opt)
0002 % plots design matrix and regressor covariance structure for FSL analyses
0003 %
0004 %   [cmat X] = post_process_corrmat_fsl(fsldir)
0005 %
0006 % REQUIRES
0007 %   fsldir - path to fsl analysis directory, within which should exist:
0008 %       design.mat, design.fsf, fsf.mat
0009 %   opt.printfig - flag, 1 or 0, to print or not print the figure to file
0010 %   opt.figstub - file name stub (w/o extension) for figure filenames
0011 %   opt.appendstr - cell array of strings of additional settings to send to
0012 %       print when printing the figures to file
0013 %   opt.title - figure title stub (to which will be appended 'design
0014 %       matrix' or 'regressor correlations'
0015 %   opt.plot_corr_txt - plot text labels on regressor correlations?
0016 %
0017 % RETURNS
0018 %   cmat - correlation matrix for design matrix regressors
0019 %   X - design matrix
0020 %
0021 % 05/19/06 Petr Janata - modified from a 2004 version of the script.  Added
0022 % support for SPM5 structure of the SPM.mat file.
0023 % 10/28/09 Fred Barrett - adapted from post_process_corrmat (SPM only) for
0024 % use with FSL
0025 
0026 if nargin < 2
0027   opt = struct();
0028 end
0029 
0030 load new_seismic  % colormap
0031 
0032 if ~exist(fsldir,'dir')
0033   error('fsldir (%s) not found',fsldir);
0034 end
0035 
0036 matfname = fullfile(fsldir,'fsf.mat');
0037 fsffname = fullfile(fsldir,'design.fsf');
0038 desfname = fullfile(fsldir,'design.mat');
0039 
0040 % get FEAT fsf structure
0041 if ~exist(matfname,'file') && ~exist(fsffname,'file')
0042   error('FSL fsf FEAT structure not found in %s',fsldir);
0043 elseif exist(matfname,'file')
0044   load(matfname);
0045 elseif exist(fsffname,'file')
0046   error(['reading straight from design.fsf not yet supported ...\n' ...
0047       'please provide an fsf.mat file']);
0048   % otherwise, you may load the fsffname file here, and parse the file to
0049   % get an fsf structure
0050 end
0051 
0052 evnames = {fsf.ev.name};
0053 
0054 % get design matrix
0055 if exist(desfname,'file')
0056   desmat = loadtxt(desfname,'skipline',5);
0057   X = cell2mat(desmat);
0058 else
0059   error('could not find design matrix (%s)',desfname);
0060 end
0061 
0062 % % % % % % PLOT: design matrix
0063 
0064 % Initialize a figure
0065 figure
0066 
0067 % Plot the design matrix
0068 imagesc(X);
0069 
0070 % colormap(new_seismic)
0071 % colorbar
0072 
0073 set(gca,'xtick',[])
0074 set(gca,'ticklen',[0 0])
0075 
0076 for ic = 1:size(X,2)
0077   text(ic,size(X,1)+0.5,strrep(evnames{ic},'_','\_'),'rotation',-90,'horizontalalign','left')
0078 end
0079 
0080 % add title
0081 if isfield(opt,'title')
0082   title(sprintf('%s design matrix',opt.title),'fontsize',14)
0083 else
0084   title('design matrix','fontsize',14);
0085 end
0086 
0087 % %  print to file
0088 
0089 try 
0090   if opt.printfig
0091     print(sprintf('%s_desmat.ps',opt.figstub),'-dpsc','-adobecset', opt.append_str)
0092     
0093     %    unix_str = sprintf('ps2pdf %s.ps %s.pdf', opt.figstub, opt.figstub);
0094     %    unix(unix_str);
0095     %    unix(sprintf('rm %s.ps >> /dev/null', opt.figstub));
0096   end
0097 catch
0098 end
0099 
0100 % % % % % % PLOT: regressor correlations
0101 
0102 % Initialize a figure
0103 figure
0104 
0105 % If there is a constant column, remove it
0106 rem_col = find(sum(X) == size(X,1));
0107 if ~isempty(rem_col)
0108     X(:,rem_col) = [];
0109     evnames(rem_col) = [];
0110 end
0111   
0112 cmat = corrcoef(X);  % calculate the correlation matrix
0113 
0114 % Plot the matrix
0115 imagesc(cmat,[-1 1]), axis square
0116 
0117 % colormap(new_seismic)
0118 colorbar
0119 
0120 set(gca,'ytick',1:size(cmat,2))
0121 set(gca,'yticklabel',evnames)
0122 
0123 if isfield(opt,'plot_corr_txt') && opt.plot_corr_txt
0124   for ir = 1:size(cmat,1)
0125     for ic = 1:size(cmat,2)
0126       text(ic,ir,sprintf('%1.2f', cmat(ir,ic)),'horizontalalign','center')
0127     end
0128   end
0129 end
0130 
0131 set(gca,'xtick',[])
0132 set(gca,'ticklen',[0 0])
0133 
0134 for ic = 1:size(cmat,2)
0135   text(ic,size(cmat,1)+0.5,strrep(evnames{ic},'_','\_'),'rotation',-90,'horizontalalign','left')
0136 end
0137 
0138 if isfield(opt,'title')
0139   title(sprintf('%s regressor correlations',opt.title),'fontsize',14)
0140 else
0141   title('design matrix','fontsize',14);
0142 end
0143 
0144 % %  print to file
0145 
0146 try
0147   if opt.printfig
0148     print(sprintf('%s_desmat_corr.ps',opt.figstub),'-dpsc','-adobecset', opt.append_str)
0149     
0150     %    unix_str = sprintf('ps2pdf %s.ps %s.pdf', opt.figstub, opt.figstub);
0151     %    unix(unix_str);
0152     %    unix(sprintf('rm %s.ps >> /dev/null', opt.figstub));
0153   end
0154 catch
0155 end

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003