-------------------------------------------
 The MGHTools -> Run recon-all menu runs
 MGH recon in the current SUBJECTS_DIR
-------------------------------------------
This minimal, self-explanatory panel is a small
wrapper to conveniently run MGH recon-all in the
current SUBJECTS_DIR.  It uses the MGH freesurfer
distribution pointed to by the current setting of
your environment variable, FSURF_DIR.  The
installation is typically in one of these
locations:

bash:
  export FSURF_DIR=/Applications/freesurfer
  export FSURF_DIR=/usr/local/freesurfer

tcsh:
  setenv FSURF_DIR /Applications/freesurfer
  setenv FSURF_DIR /usr/local/freesurfer

N.B.: recon-all requires tcsh (not just csh).

HOWTO Create New Surface in SUBJECTS_DIR

Collect one or more T1-weighted scans.  For
example, on a Siemens 1.5T machine, one or two
repetitions of a basic 10 minute 1x1x1mm MPRAGE:

  slices per slab (partitions):  160
  FoV read:  256 mm
  FoV phase:  87.5% => phase dir matrix=224
  Slice thickness:  1.00 mm
  TR:  2730 ms (=inversion pulse spacing)
  TE:  3.57 ms
  Filter:  Prescan Normalize => body coil norm
  TI:  1000 ms
  flip angle:  7 deg
  base resolution:  256
  phase resolution:  100%
  slice resolution:  100%
  phase partial Fourier:  Off
  slice partial Fourier:  Off
  orientation:  Sagittal
  bandwidth:  190 Hz/Px
  echo spacing:  8.4 ms (=standard def TR)
  excitation:  Non-sel
  Adjust vol (same as scan):  256x224x160mm

At 3T, you can use one or two repetitions
of an accelerated MPRAGE.  For example:

  slices per slab (partitions):  176
  FoV read:  256 mm
  FoV phase:  100.0% => phase dir matrix=256
  Slice thickness:  1.00 mm
  TR:  2300 ms (=inversion pulse spacing)
  TE:  2.98 ms
  Filter:  Prescan Normalize => body coil norm
  TI:  900 ms
  flip angle:  9 deg
  base resolution:  256
  phase resolution:  100%
  slice resolution:  100%
  phase partial Fourier:  Off
  slice partial Fourier:  Off
  accel: GRAPPA=2
  reference lines PE: 24
  orientation:  Sagittal
  bandwidth:  240 Hz/Px
  echo spacing:  7.1 ms (=standard def TR)
  excitation:  Non-sel
  Adjust vol (same as scan):  256x256x176mm

To create a new subject, first type name of new
subject into "new/redo subject:" followed by
Return.  This checks that a new subject doesn't
overlap an existing one (before doing this, you
can check for which name already exist in the
dropdown).

Next click FIND to select a NIFTI (or an AFNI
BRIK) scan to reconstruct (double-click folders
under "Directories:" in the left column in the
pop-up to see subfolders).  To average multiple
scans for a more accurate reconstruction, use
"ADD SCAN" (or "DEL LAST" if you have added too
many) and FIND again.

The panel will ask to auto-convert a BRIK or
you can convert from BRIK to nifti with:

  3dAFNItoNIFTI scan01+orig.BRIK

and from many other formats to nifti with
MGH mri_convert:

  mri_convert <otherformat> scan01.nii

Finally, click RECON-ALL and wait (~6 hours).  To
monitor progress, use Preferences -> View Logs.
To kill a reconstruction, click the purple
QuitRECON button.

With a single input file and no non-default
flags, this simply runs a command like:

  recon-all -subjid <newsubj> -all -i mprage.nii

HOWTO Redo Reconstruction of a Surface (edit wm.mgz)

First edit the wm data set.  Then select "re-run
starting with edited wm".  Then select an
existing subject in the "new/redo subject:"
dropdown and click RECON-ALL.

HOWTO Redo Reconstruction of a Surface (edit orig.mgz)

If too much of the brain is missing, you may want
to manually normalize the *original* data set
before passing it to recon-all (which performs 3
additional normalizations).  See Help -> Hand
Prenormalize and R-click help for the tkmedit
SMOOTHSTRUCT button for hints.

For example, you may have substantial erosion of
inferotemporal cortex (e.g., misclassified as
cerebellum), which can be fixed by very lightly
smoothing the structural data (e.g., 1 mm FWHM
Gaussian).

Another typical problem is that the anterior
temporal lobes may be very dark, causing parts of
them to be lost, which can be fixed by using
spherical normalization ("sph" tickbox on tkmedit
F3 interface).

To start recon-all from the very beginning, after
editing orig.mgz, convert it back to a nifti with
mri_convert (on the command line), and then use
the nifti to create a brand new subject.

Alternatively, to (more conveniently) continue
with the existing subject, edit orig.mgz, then
open:

  MGHTools -> Run Recon-all

tick "start from edited orig.mgz", select the
edited subject from the "new/redo subject:"
dropdown, hit <Return>, and click RECON-ALL.
This uses the already computed, alignment (if
more than one input scan), and the already
computed Talaiarch transform.  N.B.: currently,
this works if $FSURF_DIR points to an install of
MGH FreeSurfer 5.3, 6.0, or 7.1 (it uses a tiny
hack to the respective recon-all's).

HOWTO Run 'n' Copies of Recon-all in Background

The script "runra" (tcl, csh, and sh versions:
runra.tcl, runra.csh, and runra.sh) runs up to
the requested number of copies of recon-all in
the background to reconstruct the cortical
surfaces of an arbitrarily long list of subjects.
This is in order to take full advantage of a
machine with multiple cores (and enough RAM!).

Make a copy of one of the scripts and then edit
the setting of the variables at the top:

 $sublist	=> space sep list raw/reconned subj names
 $rawdir	=> contains subjname directories w/raw scan
 $rawscan	=> e.g., MPRAGE1.nii (must be all same)
 $maxprocs	=> max num background processes to run

The raw data should be in subject-named
directories, for example:

 /tmp/rawdata/marty/MPRAGE1.nii
 /tmp/rawdata/trevor/MPRAGE1.nii
 /tmp/rawdata/tessa/MPRAGE1.nii

The reconstructed subject directories will be
created in the current SUBJECTS_DIR, for example,
if SUBJECTS_DIR equals /usr0/subjects, then:

 /usr0/subjects/marty
 /usr0/subjects/trevor
 /usr0/subjects/tessa

The runra script starts up the requested number
of copies of recon-all in the background, and
then periodically monitors whether any have
finished.  If one has finished, a new recon-all
is started for the next subject, until the
subject list is finished.  To kill all running
background processes, use Ctrl-C.

After editing a copy of one of the scripts, just
type the name of the script with no arguments to
see the current setting of the lists.

To go, add option "-go"

