SpmBatchPrintContrasts - MRC CBU Imaging Wiki
location: SpmBatchPrintContrasts

SPM batch mode for displaying thresholded SPMs

SPM5 version

Batch printing

Batch printing of single subject contrasts is a time saver. This batch goes through all your single subject contrasts and SPM-prints them to a .ps file in your analysis directory. You can then open this .ps file and find your results without going through each contrast by hand and printing it.

This is an updated version of previous instantiations (Ferath's script for SPM2 and the spm_loop Matthew created for spm99 (described below)). These seem to work for SPM5. Should anyone encounter problems, please update this wiki. To download, click here. As a few changes to spm_getSPM and spm_results_ui are required, the zip file contains the adapted versions of these two functions renamed as csl_getSPM and csl_getRes. The third file (print_results.m) is an example on how to use them. Normally you just need to edit this last file, and make the changes corresponding to your analysis (SPM path, contrast numbers to be printed, statistical threshold). Make sure that the updated routines are in the matlab path, so that spm finds them. If you are unsure, you can do this by putting the csl_getSPM and csl_getRes files into a particular folder, then using the addpath command (e.g., addpath /imaging/yourname/yourstudy/batch_print_routines).

And here's a similar script for printing a set of second level SPM5 results. Download it here, or look at the code here: BatchRenderRfx. You will need to change at least the first three lines to specify the location of your data. Other parameters you may well want to change (statistical thresholds etc.) are in the next six lines. For each contrast it will print rendered activations (and deactivations if requested) as well as a table of stats. (DannyMitchell)

Fast results viewing

The scripts above print output to a postscript file. If you instead wish to load up some results in the SPM GUI for closer inspection (e.g., overlaying sections, displaying plots), this function (SPM5) allows you to view results in the SPM interface without clicking through the menus. You will need the csl_getSPM and csl_getRes files from the scripts above. Alternatively, a version for SPM8 that requires the AA toolbox is also available.

After changing some parameters at the top of the script to point it to your SPM results, you can bring up results by entering ShowResults(subjectnumber, contrastnumber, [correction], [treshold]) at the Matlab command line. The final two arguments are optional - the script will instead take your pre-defined defaults. So for instance, ShowResults(1, 3, 'FWE', .05) will bring up the first participant's third contrast, FWE-corrected at p<.05. Alternatively, ShowResults(1, 3) brings up the same results but with the default treshold and correction settings. (JohanCarlin)

SPM99 version

This page describes a beta version of an implemention SPM batch mode for displaying (and printing) thresholded SPM maps. I've found this useful for displaying lots of SPMs across subjects, or for many contrasts, to avoid having to use the GUI for loading the SPM.mat file etc for each one. To install this (it's already installed at the CBU), download the spm_loop.tar.gz archive, and unpack in a directory on your matlab path, that is ahead of the SPM files; check this with 'path' at the matlab prompt. (For those at the CBU, just run 'use_spm_loop' from the matlab prompt).

This can be very useful, but one problem is that, in batch mode, you cannot use the SPM contrast manager. This means that you either have to load the contrast (xCon.mat) file and find the numbers of the contrasts you want, or you have to know the contrast numbers beforehand. There are some tricks to (for example) find all the t or F contrasts in an analysis - see the example in spm_loop.m in the archive. You can find out the numbers of your contrasts by: looking with the SPM contrast manager (the numbers are given down the left hand side of the left window), or by name using the 'conlist' routine (included also).

Once you know the contrast numbers, you can run your analysis, by editing the example spm_loop.m file (mentioned above) to suit your analysis, saving as a different name somewhere, then running this new file from the matlab prompt.

The SPM loop file displays SPMs thresholded at uncorrected p<0.001, but you can get corrected etc levels by changing the values passed; have a look in the spm_loop file for how I have chosen to set the options (in fact via a global variable) and for the names of the other variables you can set - which as usual follow the questions asked in the SPM GUI.

When you run the file, the SPM(s) is(are) displayed, then printed to the SPM .ps file in the working directory.

Warning; if the routine crashes for whatever reason, SPM will still think that it is in batch mode, and the normal SPM results interface will be bypassed by the batch mode version. To reset this, type:

>> clear global BCH

in the matlab window.Let me know how y'all get on.


CbuImaging: SpmBatchPrintContrasts (last edited 2013-03-07 21:24:06 by localhost)