FreeSurfer
==========

Harvard's Freesurfer_ pipeline is one of the most straight forward things to
parallelize.  The time consuming :program:`recon-all` command will take up to
20 hours to complete and often needs to be run for a large number of subjects.
Obviously you can run all those processes independently of each other and in
parallel.

Example
-------

The simple subject loop shown in section :ref:`slurm_job_wrappers` and can be adapted like this:

.. code-block:: bash

    SUBJECTS_IDS=SOME_ID{1..99}    # SOME_ID1, SOME_ID2, ... , SOME_ID99
    SUBJECTS_DIR="./subjects"      # The freesurfer import location

    for subject in $SUBJECTS_IDS ; do
        echo '#!/bin/bash'                                          > tmp.sh
        echo "#SBATCH --output $HOME/logs/slurm-%j.out"            >> tmp.sh
        echo "export FREESURFER_HOME=/opt/freesurfer/6.0.0"        >> tmp.sh
        echo "source \$FREESURFER_HOME/SetUpFreeSurfer.sh"         >> tmp.sh
        echo "export SUBJECTS_DIR=$SUBJECTS_DIR"                   >> tmp.sh
        echo "recon-all -all -i ${subject}.nii -subjid ${subject}" >> tmp.sh

        sbatch tmp.sh
    done


You can currently choose between different versions of FreeSurfer located in
the folder :file:`/opt/freesurfer/` by activating a freesurfer module with
:program:`module load freesurfer[/version]`. See :doc:`../environment/modules`
for details.

.. _Freesurfer: https://surfer.nmr.mgh.harvard.edu/fswiki
