Freesurfer on ARC

From RCSWiki
Jump to navigation Jump to search

Freesurfer is a collection of neuroimaging software that can be used to process Magnetic Resonance Imaging files like DICOMs and NIFTIs. Detailed documentation can be found on the Freesurfer website. Most simple workflows that are scalable on ARC use recon-all to perform a reconstruction of the MRI image from the collection of slices. This is done by parallelizing over scans or subjects.

Freesurfer Singularity Containers

The more recent versions of Freesurfer installed on ARC have been built as Singularity containers based off of the official public Freesurfer docker release: [1]

We currently have a Freesurfer 7.1.1 container available for use with an integrated license in the container. This container cannot be used for commercial or clinical purposes. We strongly encourage you to submit a request for your own license so that you have registered with the makers of Freesurfer: [2]

The 7.1.1 container built for use on ARC can be called from the directory /global/software/freesurfer/7.1.1/containers/freesurfer711.simg

Freesurfer Interactive Job

The main command that can be called from an interactive job is singularity shell:

[userrname@arc ~]$ salloc --partition=single --time=2:0:0 --nodes=1 --ntasks=1 --cpus-per-task=8 --mem=0
salloc: Pending job allocation 8430460
salloc: job 8430460 queued and waiting for resources
salloc: job 8430460 has been allocated resources
salloc: Granted job allocation 8430460
salloc: Waiting for resource configuration
salloc: Nodes cn056 are ready for job
[username@cn056 ~]$ CONTAINER=/global/software/freesurfer/7.1.1/containers/freesurfer711.simg
[username@cn056 ~]$ singularity shell $CONTAINER
Singularity> recon-all --version

Once you have a prompt inside the container you can run any non-graphical command that is part of freesurfer. We do not have instructions for running freeview yet.

Freesurfer Sample Script

As MRI reconstruction is memory intensive in general and highly serial for a single scan when using Freesurfer, we encourage users to submit jobs in a non-interactive mode. This wiki page will include a simple example for running one reconstruction and a more complex example for submitting many reconstructions as a job array.

Single Scan Script

For the simple case, we will use a specification of the time, memory, and CPU requirements and leave off a partition specification. Here we are assuming that any partition on the default partition list (mostly cpu2019-like hardware as of October 2021) will suffice. This is a sample recon-all command. You can replace it with any Freesurfer command that is appropriate to your work.

#SBATCH --time=24:0:0 
#SBATCH --nodes=1 
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1  
#SBATCH --mem=16G


#These paths don't need to be in your home dir

singularity exec -B $output_dir -B $subjects_dir $CONTAINER recon-all -cw256 -subject ${subjects_dir}/${subject} -i ${subjects_dir}/${subject}/${dicom_file} -all -sd ${output_dir}/

Multiple Scans Reconstruction in Parallel with a Job Array

This script supposes that you have a fixed output directory, a fixed parent directory where the source data lives, a file consisting of a list of child directory names to be processed, and that the same file name should be passed as input for each child directory. The specifics of your research data management scheme will be particular to your project and the corresponding changes that will be required will depend on how you have organized your work. However, this is primarily a matter

#SBATCH --time=24:0:0 
#SBATCH --nodes=1 
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1  
#SBATCH --mem=16G
#SBATCH --array=0-99



###This section collects the paths relevant to a specific task (i.e. processing a particular image and will change from workflow to workflow.

#check existence of subjects directory list file
if [ ! -e "${subjects_file}" ]; then
  >&2 echo "error: subjects_file does not exist"
  exit 1

# read the subjects from the subjects file
IFS=$'\n'; subjects=( $(cat "${subjects_file}") );

#populate the parent directory for data, the child directory, the file to process, and the output directory

#This is the actual processing command with task specific variables filled in
singularity exec -B $output_dir -B $subjects_dir $CONTAINER recon-all -cw256 -subject ${subjects_dir}/${subject} -i ${subjects_dir}/${subject}/${dicom_file} -all -sd ${output_dir}/