Home > marsbar > release > test_rig.m

test_rig

PURPOSE ^

runs tests on MarsBaR using specified designs

SYNOPSIS ^

function res = test_rig(design_paths, params)

DESCRIPTION ^

 runs tests on MarsBaR using specified designs
 FORMAT res = test(design_paths, params)
 
 Inputs
 design_paths     - path(s) to SPM design files
 params           - structure giving params to pass to estimate method,
                    see help for do_estimate methods for details
                    Default is
                    params = struct('redo_covar', 0, ...
                                'redo_whitening', 0);
 
 Outputs
 res              - 1 if all tests passed, 0 otherwise
 
 The function depends on the SPM design having estimated contrasts to
 play with.  It uses these to:
 Get the maximum voxel in the first F and first T contrast
 Records the T/F statistic value
 Makes an ROI out of this voxel
 Estimates in MarsBaR
 Checks the statistic value is that same.
 
 Along the way, it uses much of the MarsBaR machinery
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function res = test_rig(design_paths, params)
0002 % runs tests on MarsBaR using specified designs
0003 % FORMAT res = test(design_paths, params)
0004 %
0005 % Inputs
0006 % design_paths     - path(s) to SPM design files
0007 % params           - structure giving params to pass to estimate method,
0008 %                    see help for do_estimate methods for details
0009 %                    Default is
0010 %                    params = struct('redo_covar', 0, ...
0011 %                                'redo_whitening', 0);
0012 %
0013 % Outputs
0014 % res              - 1 if all tests passed, 0 otherwise
0015 %
0016 % The function depends on the SPM design having estimated contrasts to
0017 % play with.  It uses these to:
0018 % Get the maximum voxel in the first F and first T contrast
0019 % Records the T/F statistic value
0020 % Makes an ROI out of this voxel
0021 % Estimates in MarsBaR
0022 % Checks the statistic value is that same.
0023 %
0024 % Along the way, it uses much of the MarsBaR machinery
0025 %
0026 % $Id$
0027   
0028 if nargin < 1
0029   design_paths = spm_get([0 Inf], 'SPM*.mat', 'Select SPM designs');
0030 end
0031 if nargin < 2
0032   params = struct('redo_covar', 0, ...
0033           'redo_whitening', 0);
0034 end
0035 
0036 n_designs = size(design_paths, 1);
0037 res = zeros(n_designs, 1);
0038 for d = 1:n_designs
0039   d_path = deblank(design_paths(d,:));
0040   res(d) = sf_test_design(d_path, params);
0041 end
0042 return
0043 
0044 function res = sf_test_design(d_path, params)
0045 % tests one design
0046   
0047 % Check for SPM estimated design, with estimated contrasts
0048 D = mardo(d_path);
0049 if ~is_spm_estimated(D)
0050   error('Need an SPM estimated design');
0051 end
0052 if ~has_contrasts(D)
0053   error(['Design ' d_path ' does not contain contrasts']);
0054 end
0055 if ~has_images(D)
0056   error(['Design ' d_path ' does not contain images']);
0057 end
0058 
0059 % try to get one F and one T contrast
0060 Swd = fileparts(d_path);
0061 xCon = get_contrasts(D);
0062 stats = [xCon(:).STAT];
0063 Ic    = []; fnames = {};
0064 for t = 'TF'
0065   for c = fliplr(find(stats == t))
0066     F = xCon(c).Vspm;
0067     if ~isempty(F)
0068       % SPM99 = filename, SPM2 = vol_struct
0069       if isstruct(F), F = F.fname; end
0070       F = fullfile(Swd, F);
0071       if exist(F, 'file'), Ic = [Ic c]; fnames{end+1} = F; break, end
0072     end
0073   end
0074 end
0075 if isempty(Ic)
0076   error(['Could not find any contrast images for ' d_path]);
0077 end
0078 
0079 % find maximum voxel coordinate for contrasts and test
0080 res = 1;
0081 for c = 1:length(Ic)
0082   V = spm_vol(fnames{c});
0083   img = spm_read_vols(V);
0084   [mx(c) i] = max(img(:));
0085   xyz(:, c) = mars_utils('e2xyz', i, V.dim(1:3));
0086   mx_roi(c) = maroi_pointlist(struct('XYZ', xyz(:, c), ...
0087                      'mat', V.mat), 'vox');
0088   Y = get_marsy(mx_roi(c), D, 'mean');
0089   E = estimate(D, Y, params);
0090   [E n_Ic] = add_contrasts(E, D, Ic(c));
0091   marsS = compute_contrasts(E, n_Ic);
0092   fprintf('SPM statistic %7.4f; MarsBaR statistic %7.4f\n',...
0093       mx(c), marsS.stat(1));
0094   if abs(marsS.stat(1) - mx(c)) > 1e-5
0095     disp('MarsBaR gives a different result for contrast');
0096     res = 0;
0097   end
0098 end
0099 return
0100

Generated on Tue 21-Jul-2009 00:29:30 by m2html © 2003