FreeSurfer
Freesurfer is a surface-based fMRI processing and analysis package written for the Unix environment (including Mac OS X, which is based on Unix). The neuroanatomical organization of the brain has the grey matter on the outside surface of the cortex. Aside from the ventral/medial subcortical structures, the interior volume of the brain is predominately white matter axonal tracts. Because neurons metabolize in the cell body, rather than along the axons, we can focus on the grey matter found in the cortical surface because any fMRI signal changes detected in the white matter should theoretically be noise. This is the motivation for surface-based analyses of fMRI.
Freesurfer has a rigid set of assumptions concerning how the input data is organized and labeled. The following instructions will help avoid any violations of these assumptions that might derail your Freesurfer fMRI processing pipeline.
These instructions assume that Freesurfer has already been installed and configured on your workstation.
Organization
Freesurfer data for a collection of subjects is organized into a single project directory, called $SUBJECTS_DIR. Try this in the Linux terminal:
echo $SUBJECTS_DIR
It is likely that you will see something like the following, which is the sample 'bert' dataset that comes with a Freesurfer installation:
/usr/local/freesurfer/subjects
Let us assume that you have been collecting data for some lexical decision task experiment. All the data for all subjects should be stored in a single directory, which you will set as your $SUBJECTS_DIR variable. For example, if we keep all our data in ~/ubfs/cpmcnorg/openfmri/LDT, then we would type the following:
SUBJECTS_DIR=~/~/ubfs/cpmcnorg/openfmri/LDT
Subject directory organization
Data for each subject should be kept in their own directory. Moreover, different types of data (i.e., anatomical/structural or bold/functional) are kept in separate subdirectories. Assuming your raw data are in the .nii format, the basic directory structure for each participant ('session' in Freesurfer terminology) looks like this:
- SUBJECTS_DIR
- Subject_001
- mri
- orig.nii
- bold
- 001/f.nii
- 002/f.nii
- 003/f.nii
- etc.
- mri
- Subject_002
- mri
- orig.nii
- bold
- 001/f.nii
- 002/f.nii
- 003/f.nii
- etc.
- mri
- Subject_001
Note that all the functional data (in the 'bold' subdirectory) are stored in sequentially numbered folders (3-digits), and all are called 'f.nii'. This seems to be a requirement. It may be possible to circumvent this requirement, but this is a relatively minor concern at this time.
Structural Preprocessing
The structural mri file (orig.nii) is transformed over a series of computationally-intensive steps invoked by the recon-all Freesurfer program. Recon-all is designed to execute all the steps in series without intervention, however in practice it seems preferable to execute the process in a series of smaller groups of steps and check the output in between. This is because the process is automated using computational algorithms, but if one step doesn't execute correctly, everything that follows will be compromised. The steps take many hours to complete, so by inspecting the progress along the way can save many hours of processing time redoing steps that had been done incorrectly.
Image Format: Slicer
The first thing that you will need to do is convert the orig.nii file to .mgz format using Slicer. Though Freesurfer is capable of reading .nii files, it natively uses .mgz files, and so this conversion step will ensure that the structural data file has all the information that Freesurfer expects.
Recon-All
The computationally-intensive surface mapping is carried out by a Freesurfer program called recon-all. This program is extensively spaghetti-documented on the Freesurfer wiki here. Though the Freesurfer documentation goes into much detail, it is also a little hard to follow at times and sometimes does some odd things. Notably, it assumes you're going to just try to jam your data into the program and hope for the best. This might work well for data that you already know is going to be problem-free, but we seldom have that guarantee. Instead, this guide will split the recon-all processing into sub-stages where you can do quality-control inspection at each step.
Stage 1: Skull Stripping
Calling recon-all
with the -autorecon1 flag performs a number of steps related to segmenting the anatomical MRI image into brain/non-brain voxels. A shell script called autorecon1.sh
can be found on the ubfs Scripts/Shell folder. This script simply acts as a wrapper (i.e., a convenient shortcut for executing computer code that might have a bunch of parameters that are error-prone or annoying to have to specify). You can copy this script to your ~/bin directory to be able to run it yourself:
cp ~/ubfs/cpmcnorg/Scripts/Shell/autorecon1.sh ~/bin/
Before you run the script, be sure to first open it up in a text editor so that you can: 1) see what it's actually doing, and 2) modify it so that it matches your particular requirements:
nano ~/autorecon1.sh
If you do so, you will find that it sets some environment variables that you will want to change, such as your $PROJECTROOT
After you have modified your copy of the script, you can run it thus:
autorecon1.sh 501
Where you would replace 501
with the appropriate subject number in your project directory. For example, if I want to execute autorecon1 on subject 501 found in ~/ubfs/cpmcnorg/openfmri/booth/ then my script would have the following line:
PROJECTROOT=/home/chris/ubfs/cpmcnorg/openfmri/booth/
When operating on data stored locally on either wernickesarea or brocasarea, this step takes between 20 and 30 minutes to complete. At the other extreme, operating on data stored on the ubfs network drive using the accumbens micro-computer takes much longer to complete.
Trouble Shooting
Is Freesurfer in your path?
This is an unlikely issue, but it is possible that your ~/.bashrc file doesn't add Freesurfer to your path. To check, launch a new terminal window. You should see something like the following:
-------- freesurfer-Linux-centos6_x86_64-stable-pub-v5.3.0 -------- Setting up environment for FreeSurfer/FS-FAST (and FSL) FREESURFER_HOME /usr/local/freesurfer FSFAST_HOME /usr/local/freesurfer/fsfast FSF_OUTPUT_FORMAT nii.gz SUBJECTS_DIR /usr/local/freesurfer/subjects MNI_DIR /usr/local/freesurfer/mni
If you don't, then open up your .bashrc file with a text editor:
gedit ~/.bashrc
Then add the following lines to the bottom of the file:
#FREESURFER export FREESURFER_HOME=/usr/local/freesurfer source ${FREESURFER_HOME}/SetUpFreeSurfer.sh #FSL export FSLDIR=/usr/share/fsl/5.0 source ${FSLDIR}/etc/fslconf/fsl.sh
Log out of Linux and log back in.