attachment:ShowResults.m of SpmBatchPrintContrasts - MRC CBU Imaging Wiki
location: attachment:ShowResults.m of SpmBatchPrintContrasts

Attachment 'ShowResults.m'

Download

   1 % Displays first and second-level SPM results. First level results are displayed
   2 % with: ShowResults(subjectn, contrastn, [none/FDR/FWE],[treshold]).
   3 % For second-level results, set subjectn to 'rfx'. Use ShowResults('list') to 
   4 % list current first-level contrast names and numbers, or ('listrfx') to list 
   5 % second-level contrasts. You can skip specifying correction and treshold -
   6 % the script will use pre-specified default values instead.
   7 
   8 % Example 1: ShowResults(1, 3, 'FWE', .05) brings up the F>S contrast for
   9 % subject 1, FWE-corrected at p<.05.
  10 % Example 2: ShowResults('rfx', 6) brings up the F>S second-level contrast
  11 % at the default correction and treshold.
  12 
  13 % Requires csl_getRes and csl_getSPM2 on the path or in the same directory.
  14 % Based on print_results. See this page for files:
  15 % http://imaging.mrc-cbu.cam.ac.uk/imaging/SpmBatchPrintContrasts 
  16 % You will need to change some parameters below to run this on your data.
  17 
  18 % This script makes some assumptions regarding your folder structure, e.g.
  19 % a shared root for first- and second-level scripts, first-level results 
  20 % in each participant's folder, second-level results in folders by contrast etc). 
  21 % If things aren't working, this is where I'd look first.
  22 
  23 % J Carlin 20/2/2009
  24 % 24/2/2009 Updated for greater first-level contrast listing flexibility
  25 % via SPM.xCon.name.
  26 
  27 function ShowResults(subjectn,contrast,correction,treshold)
  28 
  29 % --- PARAMETERS TO CHANGE --- %
  30 addpath /imaging/jc01/UtilityScripts/BatchPrintSPMs/% Change to where this is saved
  31 subjroot ='/imaging/jc01/Gaze01/mrdata/analysis'; % All other paths build on this
  32 subjects = {'S01',... % Subject directories
  33 	'S02',...
  34 	'S03',...
  35 	'S04',...
  36 	'S05',...
  37 	'S06',...
  38 	'S07',...
  39 	'S08',...
  40 	% 'S09',...
  41 	};
  42 ana_dir = 'SPMsplitresults'; % First-level results directory within subject dir
  43 SLdir = 'SecondLevel'; % directory in subjroot
  44 
  45 % If correction and treshold aren't specified, use these defaults.
  46 if nargin == 2
  47 	correction = 'none';
  48 	treshold = 0.001;
  49 	display(['No correction or treshold specified. Default values are correction: ' correction ', p<' num2str(treshold)])
  50 end
  51 
  52 % --- END OF PARAMETERS --- %
  53 
  54 % List of second level condition names from directory names
  55 SLrawdirs = dir(fullfile(subjroot, SLdir));
  56 % Skipping unix . and ..
  57 % Adding some additional control by ensuring only directories are included
  58 ic = 0;
  59 for i=3:size(SLrawdirs,1)
  60 	if SLrawdirs(i).isdir == 1
  61 		ic=ic+1;
  62 		SLdirs{ic} = SLrawdirs(i).name;
  63 	end
  64 end
  65 SLcons = 1:1:size(SLdirs,2);
  66 
  67 
  68 % List conditions
  69 switch subjectn
  70 	case 'list' % Below, we happily assume that subject 1 is representative of all.
  71 		load(fullfile(subjroot,subjects{1},ana_dir,'SPM.mat'));
  72 		con_n = 1:1:length(SPM.xCon);
  73 		% This code could probably be made more efficient
  74 		D=struct2cell(SPM.xCon); %Condition list to string
  75 		E=D(1,1,:); %Take only name part
  76 		F=shiftdim(E,2); %Rotate dimensions to put names in rows
  77 		display(strcat(int2str(con_n'), ' = ', F))
  78 		return
  79 	case 'listrfx'
  80 		display(strcat(int2str(SLcons'), ' = ', SLdirs'))
  81 		return
  82 end
  83 
  84 
  85 
  86 spm_defaults;
  87 global defaults
  88 defaults.modality='FMRI';
  89 
  90 
  91 %--------------------------------------------------------------------
  92 %- xSPM is a structure for the parameters
  93 
  94 xSPM = struct( ...
  95       'swd', '', ...       % full path to SPM.mat file
  96       'Ic', [], ...        % no of contrast (or contrasts for conjunction)
  97       'Im', [],...         % no of contrast to mask with. Empty for no masking
  98       'pm', [],...         % masking contrast uncorrected p
  99       'Ex', [],...         % whether masking is inclusive or exclusive
 100       'title', '',...      % if empty results in default contrast title
 101       'Mcp', correction,...    % Mutiple comp method: FWE|FDR|none
 102       'u', treshold,...        % threshold (corrected or uncorrected, as above)
 103       'k', 0);             % extent threshold
 104 %--------------------------------------------------------------------
 105 
 106 if subjectn == 'rfx' % second-level analysis
 107 	contrastdir = SLdirs{contrast};
 108 	xSPM.swd = fullfile(subjroot, SLdir, contrastdir); %analysis directory
 109 	xSPM.spmmat = fullfile(subjroot, SLdir, contrastdir, 'SPM.mat'); % Get SPM path
 110 	xSPM.Ic=1; % The contrast number is always one for RFX.
 111 else % first-level analysis
 112 	% Index to the right subject
 113 	subj = subjects{subjectn};
 114 	xSPM.swd = fullfile(subjroot, subj, ana_dir); %analysis directory
 115 	xSPM.spmmat = fullfile(subjroot,subj,ana_dir, 'SPM.mat'); % Get SPM path
 116 	% Get contrast - now only by number.
 117 	xSPM.Ic=contrast; %Set the current contrast index	
 118 end
 119 
 120 [hReg,xSPM,SPM] = csl_getRes(xSPM);
 121 
 122 % Assign some variables to the workspace - this enables the SPM results GUI buttons 
 123 % (plot, overlays etc) to function properly.
 124 assignin('base','xSPM', xSPM);
 125 assignin('base','hReg', hReg);
 126 assignin('base','SPM', SPM);
 127 
 128 spm_list('List',xSPM,hReg);

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-02-28 16:49:47, 5.8 KB) [[attachment:BatchRenderRFX_0207]]
  • [get | view] (2009-02-25 13:11:19, 4.7 KB) [[attachment:ShowResults.m]]
  • [get | view] (2007-08-10 16:18:52, 10.8 KB) [[attachment:batch_print_results_SPM5.zip]]
  • [get | view] (2006-07-21 12:31:10, 10.6 KB) [[attachment:print_results_SPM5.zip]]
  • [get | view] (2011-09-22 13:43:15, 2.9 KB) [[attachment:showAAResults.m]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.