From 3cbf6413bb1a05681193ffb642edb0b7327755c1 Mon Sep 17 00:00:00 2001
From: Taylor Hanayik <hanayik@gmail.com>
Date: Fri, 6 Oct 2023 15:50:42 +0100
Subject: [PATCH] convert indentations to spaces

---
 fsl_anat | 412 +++++++++++++++++++++++++++----------------------------
 1 file changed, 206 insertions(+), 206 deletions(-)

diff --git a/fsl_anat b/fsl_anat
index 2e3a21f..b8dc4c0 100755
--- a/fsl_anat
+++ b/fsl_anat
@@ -55,15 +55,15 @@ get_opt1() {
 # get arg for -- options
 get_arg1() {
     if [ X`echo $1 | grep '='` = X ] ; then 
-	echo "Option $1 requires an argument" 1>&2
-	exit 1
+    echo "Option $1 requires an argument" 1>&2
+    exit 1
     else 
-	arg=`echo $1 | sed 's/.*=//'`
-	if [ X$arg = X ] ; then
-	    echo "Option $1 requires an argument" 1>&2
-	    exit 1
-	fi
-	echo $arg
+    arg=`echo $1 | sed 's/.*=//'`
+    if [ X$arg = X ] ; then
+        echo "Option $1 requires an argument" 1>&2
+        exit 1
+    fi
+    echo $arg
     fi
 }
 
@@ -77,8 +77,8 @@ get_imarg1() {
 # get arg for - options (need to pass both $1 and $2 to this)
 get_arg2() {
     if [ X$2 = X ] ; then
-	echo "Option $1 requires an argument" 1>&2
-	exit 1
+    echo "Option $1 requires an argument" 1>&2
+    exit 1
     fi
     echo $2
 }
@@ -143,91 +143,91 @@ if [ $# -lt 2 ] ; then Usage; exit 1; fi
 while [ $# -ge 1 ] ; do
     iarg=`get_opt1 $1`;
     case "$iarg"
-	in
-	-i)
-	    inputimage=`get_imarg2 $1 $2`;
-	    shift 2;;
-	-o)
-	    outputname=`get_arg2 $1 $2`;
-	    shift 2;;
-	-d)
-	    anatdir=`get_arg2 $1 $2`;
-	    shift 2;;
-	-s)
-	    smooth=`get_arg2 $1 $2`;
-	    shift 2;;
-	-m)
-	    use_lesionmask=yes;
-	    lesionmask=`get_arg2 $1 $2`;
-	    shift 2;;
-	-t)
-	    typestr=`get_arg2 $1 $2`;
-	    if [ $typestr = T1 ] ; then type=1; fi
-	    if [ $typestr = T2 ] ; then type=2; fi
-	    if [ $typestr = PD ] ; then type=3; fi
-	    shift 2;;
-	--list)
-	    imagelist=`get_arg1 $1`;
-	    multipleimages=yes;
-	    shift;;
-	--clobber)
-	    clobber=yes; 
-	    shift;;
-	--noreorient)
-	    do_reorient=no; 
-	    shift;;
-	--nocrop)
-	    do_crop=no; 
-	    shift;;
-	--nobet)
-	    do_bet=no; 
-	    shift;;
-	--noreg)
-	    do_reg=no; 
-	    shift;;
-	--nononlinreg)
-	    do_nonlinreg=no; 
-	    shift;;
-	--noseg)
-	    do_seg=no; 
-	    shift;;
-	--nosubcortseg)
-	    do_subcortseg=no; 
-	    shift;;
-	--nobias)
-	    do_biasrestore=no; 
-	    shift;;
-	--nosearch)
-	    nosearch=-nosearch; 
-	    shift;;
-	--strongbias)
-	    strongbias=yes; 
-	    niter=5;
-	    smooth=10;
-	    shift;;
-	--weakbias)
-	    strongbias=no; 
-	    niter=10;
-	    smooth=20;
-	    shift;;
-	--betfparam)
-	    betfparam=`get_arg1 $1`; 
-	    shift;;
-	--nocleanup)
-	    do_cleanup=no; 
-	    shift;;
-	-v)
-	    verbose=yes; 
-	    shift;;
-	-h)
-	    Usage;
-	    exit 0;;
-	*)
-	    #if [ `echo $1 | sed 's/^\(.\).*/\1/'` = "-" ] ; then 
-	    echo "Unrecognised option $1" 1>&2
-	    exit 1
-	    #fi
-	    #shift;;
+    in
+    -i)
+        inputimage=`get_imarg2 $1 $2`;
+        shift 2;;
+    -o)
+        outputname=`get_arg2 $1 $2`;
+        shift 2;;
+    -d)
+        anatdir=`get_arg2 $1 $2`;
+        shift 2;;
+    -s)
+        smooth=`get_arg2 $1 $2`;
+        shift 2;;
+    -m)
+        use_lesionmask=yes;
+        lesionmask=`get_arg2 $1 $2`;
+        shift 2;;
+    -t)
+        typestr=`get_arg2 $1 $2`;
+        if [ $typestr = T1 ] ; then type=1; fi
+        if [ $typestr = T2 ] ; then type=2; fi
+        if [ $typestr = PD ] ; then type=3; fi
+        shift 2;;
+    --list)
+        imagelist=`get_arg1 $1`;
+        multipleimages=yes;
+        shift;;
+    --clobber)
+        clobber=yes; 
+        shift;;
+    --noreorient)
+        do_reorient=no; 
+        shift;;
+    --nocrop)
+        do_crop=no; 
+        shift;;
+    --nobet)
+        do_bet=no; 
+        shift;;
+    --noreg)
+        do_reg=no; 
+        shift;;
+    --nononlinreg)
+        do_nonlinreg=no; 
+        shift;;
+    --noseg)
+        do_seg=no; 
+        shift;;
+    --nosubcortseg)
+        do_subcortseg=no; 
+        shift;;
+    --nobias)
+        do_biasrestore=no; 
+        shift;;
+    --nosearch)
+        nosearch=-nosearch; 
+        shift;;
+    --strongbias)
+        strongbias=yes; 
+        niter=5;
+        smooth=10;
+        shift;;
+    --weakbias)
+        strongbias=no; 
+        niter=10;
+        smooth=20;
+        shift;;
+    --betfparam)
+        betfparam=`get_arg1 $1`; 
+        shift;;
+    --nocleanup)
+        do_cleanup=no; 
+        shift;;
+    -v)
+        verbose=yes; 
+        shift;;
+    -h)
+        Usage;
+        exit 0;;
+    *)
+        #if [ `echo $1 | sed 's/^\(.\).*/\1/'` = "-" ] ; then 
+        echo "Unrecognised option $1" 1>&2
+        exit 1
+        #fi
+        #shift;;
     esac
 done
 
@@ -241,12 +241,12 @@ fi
 
 if [ $type != 1 ] ; then 
     if [ $do_nonlinreg = yes ] ; then 
-	echo "ERROR: Cannot do non-linear registration with non-T1 images, please re-run with --nononlinreg" ; 
-	exit 1;
+    echo "ERROR: Cannot do non-linear registration with non-T1 images, please re-run with --nononlinreg" ; 
+    exit 1;
     fi ; 
     if [ $do_subcortseg = yes ] ; then 
-	echo "ERROR: Cannot perform subcortical segmentation (with FIRST) on a non-T1 image, please re-run with --nosubcortseg"
-	exit 1;
+    echo "ERROR: Cannot perform subcortical segmentation (with FIRST) on a non-T1 image, please re-run with --nosubcortseg"
+    exit 1;
     fi ;
 fi
 
@@ -262,32 +262,32 @@ betopts="-f ${betfparam}"
 
 if [ X$anatdir = X ] ; then
     if [ X${outputname} = X ] ; then
-	outputname=$inputimage;
+    outputname=$inputimage;
     fi
     
     if [ -d ${outputname}.anat ] ; then
-	if [ $clobber = no ] ; then
-	    echo "ERROR: Directory ${outputname}.anat already exists!"
-	    exit 1;
-	else
-	    rm -rf ${outputname}.anat
-	fi
+    if [ $clobber = no ] ; then
+        echo "ERROR: Directory ${outputname}.anat already exists!"
+        exit 1;
+    else
+        rm -rf ${outputname}.anat
+    fi
     fi
     mkdir ${outputname}.anat
 else
     if [ X${inputimage} != X ] ; then
-	echo "ERROR: Cannot specify both -d and -i";
-	exit 1;
+    echo "ERROR: Cannot specify both -d and -i";
+    exit 1;
     fi
     if [ $multipleimages = yes ] ; then
-	echo "ERROR: Cannot specify both -d and --list";
-	exit 1;
+    echo "ERROR: Cannot specify both -d and --list";
+    exit 1;
     fi
     outputname=`$FSLDIR/bin/fsl_abspath $anatdir`;
     outputname=`echo $outputname | sed 's/\.anat$//'`;
     if [ ! -d ${outputname}.anat ] ; then
-	echo "ERROR: Directory ${outputname}.anat not found"
-	exit 1;
+    echo "ERROR: Directory ${outputname}.anat not found"
+    exit 1;
     fi
     inputimage=$anatdir/T1
 fi
@@ -298,23 +298,23 @@ echo "Output directory = ${outputname}.anat" >> ${outputname}.anat/$LOGFILE
 
 if [ $multipleimages = yes ] ; then
     if [ X${inputimage} != X ] ; then
-	echo "ERROR: Cannot specify both -i and --list";
-	exit 1;
+    echo "ERROR: Cannot specify both -i and --list";
+    exit 1;
     fi
     im1=`echo $imagelist | sed 's/,/ /g' | awk '{ print $1 }'`;
     if [ $FSLDIR/bin/imtest $im1 = 1 ] ; then
-	# this is a comma separated list of image names
-	namelist="`echo ${imagelist} | sed 's/,/ /g'`";
+    # this is a comma separated list of image names
+    namelist="`echo ${imagelist} | sed 's/,/ /g'`";
     else
-	# this is a file containing the image names
-	namelist="`cat ${imagelist}`";
+    # this is a file containing the image names
+    namelist="`cat ${imagelist}`";
     fi
     for name in $namelist ; do
-	if [ $FSLDIR/bin/imtest $name = 0 ] ; then
-	    echo "ERROR: Cannot find image $name"
-	    exit 1;
-	fi
-	$FSLDIR/bin/fslmaths $name ${outputname}.anat/${T1}_${num}
+    if [ $FSLDIR/bin/imtest $name = 0 ] ; then
+        echo "ERROR: Cannot find image $name"
+        exit 1;
+    fi
+    $FSLDIR/bin/fslmaths $name ${outputname}.anat/${T1}_${num}
     done
     echo "Input images are ${namelist}" >> ${outputname}.anat/$LOGFILE
 else
@@ -351,12 +351,12 @@ minval=`$FSLDIR/bin/fslstats ${T1} -p 0`;
 maxval=`$FSLDIR/bin/fslstats ${T1} -p 100`;
 if [ X`echo "if ( $minval < 0 ) { 1 }" | bc -l` = X1 ] ; then
     if [ X`echo "if ( $maxval > 0 ) { 1 }" | bc -l` = X1 ] ; then
-	# if there are just some negative values among the positive ones then reset zero to the min value
-	run ${FSLDIR}/bin/fslmaths ${T1} -sub $minval ${T1} -odt float
+    # if there are just some negative values among the positive ones then reset zero to the min value
+    run ${FSLDIR}/bin/fslmaths ${T1} -sub $minval ${T1} -odt float
     else
-	# if all values are negative then make them positive, but retain any zeros as zeros
-	run ${FSLDIR}/bin/fslmaths ${T1} -bin -binv zeromask
-	run ${FSLDIR}/bin/fslmaths ${T1} -sub $minval -mas zeromask ${T1} -odt float
+    # if all values are negative then make them positive, but retain any zeros as zeros
+    run ${FSLDIR}/bin/fslmaths ${T1} -bin -binv zeromask
+    run ${FSLDIR}/bin/fslmaths ${T1} -sub $minval -mas zeromask ${T1} -odt float
     fi
 fi
 
@@ -382,9 +382,9 @@ if [ $do_crop = yes ] ; then
     run $FSLDIR/bin/robustfov -i ${T1}_fullfov -r ${T1} -m ${T1}_roi2nonroi.mat | grep [0-9] | tail -1 > ${T1}_roi.log
     # combine this mat file and the one above (if generated)
     if [ $do_reorient = yes ] ; then
-	run $FSLDIR/bin/convert_xfm -omat ${T1}_nonroi2roi.mat -inverse ${T1}_roi2nonroi.mat
-	run $FSLDIR/bin/convert_xfm -omat ${T1}_orig2roi.mat -concat ${T1}_nonroi2roi.mat ${T1}_orig2std.mat 
-	run $FSLDIR/bin/convert_xfm -omat ${T1}_roi2orig.mat -inverse ${T1}_orig2roi.mat
+    run $FSLDIR/bin/convert_xfm -omat ${T1}_nonroi2roi.mat -inverse ${T1}_roi2nonroi.mat
+    run $FSLDIR/bin/convert_xfm -omat ${T1}_orig2roi.mat -concat ${T1}_nonroi2roi.mat ${T1}_orig2std.mat 
+    run $FSLDIR/bin/convert_xfm -omat ${T1}_roi2orig.mat -inverse ${T1}_orig2roi.mat
     fi
 fi
 
@@ -395,8 +395,8 @@ if [ $use_lesionmask = yes ] ; then
     if [ -f ${T1}_orig2std.mat ] ; then transform=${T1}_orig2std.mat ; fi
     if [ -f ${T1}_orig2roi.mat ] ; then transform=${T1}_orig2roi.mat ; fi   # this takes precedence if both exist
     if [ X$transform != X ] ; then
-	$FSLDIR/bin/fslmaths lesionmask lesionmask_orig
-	$FSLDIR/bin/flirt -in lesionmask_orig -ref ${T1} -applyxfm -interp nearestneighbour -init ${transform} -out lesionmask
+    $FSLDIR/bin/fslmaths lesionmask lesionmask_orig
+    $FSLDIR/bin/flirt -in lesionmask_orig -ref ${T1} -applyxfm -interp nearestneighbour -init ${transform} -out lesionmask
     fi
 else
     $FSLDIR/bin/fslmaths ${T1} -mul 0 lesionmask
@@ -410,44 +410,44 @@ $FSLDIR/bin/fslmaths lesionmask -binv lesionmaskinv
 # output: ${T1}_biascorr  [ other intermediates to be cleaned up ]
 if [ $do_biasrestore = yes ] ; then
     if [ $strongbias = yes ] ; then
-	date; echo "Estimating and removing field (stage 1 - large-scale fields)"
-	# for the first step (very gross bias field) don't worry about the lesionmask
-	# the following is a replacement for : run $FSLDIR/bin/fslmaths ${T1} -s 20 ${T1}_s20
-	quick_smooth ${T1} ${T1}_s20
-	run $FSLDIR/bin/fslmaths ${T1} -div ${T1}_s20 ${T1}_hpf
-	if [ $do_bet = yes ] ; then
+    date; echo "Estimating and removing field (stage 1 - large-scale fields)"
+    # for the first step (very gross bias field) don't worry about the lesionmask
+    # the following is a replacement for : run $FSLDIR/bin/fslmaths ${T1} -s 20 ${T1}_s20
+    quick_smooth ${T1} ${T1}_s20
+    run $FSLDIR/bin/fslmaths ${T1} -div ${T1}_s20 ${T1}_hpf
+    if [ $do_bet = yes ] ; then
         # get a rough brain mask - it can be *VERY* rough (i.e. missing huge portions of the brain or including non-brain, but non-background) - use -f 0.1 to err on being over inclusive
-	    run $FSLDIR/bin/bet ${T1}_hpf ${T1}_hpf_brain -m -f 0.1
-	else
-	    run $FSLDIR/bin/fslmaths ${T1}_hpf ${T1}_hpf_brain
-	    run $FSLDIR/bin/fslmaths ${T1}_hpf_brain -bin ${T1}_hpf_brain_mask
-	fi
-	run $FSLDIR/bin/fslmaths ${T1}_hpf_brain_mask -mas lesionmaskinv ${T1}_hpf_brain_mask
+        run $FSLDIR/bin/bet ${T1}_hpf ${T1}_hpf_brain -m -f 0.1
+    else
+        run $FSLDIR/bin/fslmaths ${T1}_hpf ${T1}_hpf_brain
+        run $FSLDIR/bin/fslmaths ${T1}_hpf_brain -bin ${T1}_hpf_brain_mask
+    fi
+    run $FSLDIR/bin/fslmaths ${T1}_hpf_brain_mask -mas lesionmaskinv ${T1}_hpf_brain_mask
         # get a smoothed version without the edge effects
-	run $FSLDIR/bin/fslmaths ${T1} -mas ${T1}_hpf_brain_mask ${T1}_hpf_s20
-	quick_smooth ${T1}_hpf_s20 ${T1}_hpf_s20
-	quick_smooth ${T1}_hpf_brain_mask ${T1}_initmask_s20
-	run $FSLDIR/bin/fslmaths ${T1}_hpf_s20 -div ${T1}_initmask_s20 -mas ${T1}_hpf_brain_mask ${T1}_hpf2_s20
-	run $FSLDIR/bin/fslmaths ${T1} -mas ${T1}_hpf_brain_mask -div ${T1}_hpf2_s20 ${T1}_hpf2_brain
-	# make sure the overall scaling doesn't change (equate medians)
-	med0=`$FSLDIR/bin/fslstats ${T1} -k ${T1}_hpf_brain_mask -P 50`;
-	med1=`$FSLDIR/bin/fslstats ${T1}_hpf2_brain -k ${T1}_hpf_brain_mask -P 50`;
-	run $FSLDIR/bin/fslmaths ${T1}_hpf2_brain -div $med1 -mul $med0 ${T1}_hpf2_brain
-	date; echo "Estimating and removing bias field (stage 2 - detailed fields)"
-	run $FSLDIR/bin/fslmaths ${T1}_hpf2_brain -mas lesionmaskinv ${T1}_hpf2_maskedbrain
-	run $FSLDIR/bin/fast -o ${T1}_initfast -l ${smooth} -b -B -t $type --iter=${niter} --nopve --fixed=0 -v ${T1}_hpf2_maskedbrain
-	run $FSLDIR/bin/fslmaths ${T1}_initfast_restore -mas lesionmaskinv ${T1}_initfast_maskedrestore
-	run $FSLDIR/bin/fast -o ${T1}_initfast2 -l ${smooth} -b -B -t $type --iter=${niter} --nopve --fixed=0 -v ${T1}_initfast_maskedrestore
-	run $FSLDIR/bin/fslmaths ${T1}_hpf_brain_mask ${T1}_initfast2_brain_mask
+    run $FSLDIR/bin/fslmaths ${T1} -mas ${T1}_hpf_brain_mask ${T1}_hpf_s20
+    quick_smooth ${T1}_hpf_s20 ${T1}_hpf_s20
+    quick_smooth ${T1}_hpf_brain_mask ${T1}_initmask_s20
+    run $FSLDIR/bin/fslmaths ${T1}_hpf_s20 -div ${T1}_initmask_s20 -mas ${T1}_hpf_brain_mask ${T1}_hpf2_s20
+    run $FSLDIR/bin/fslmaths ${T1} -mas ${T1}_hpf_brain_mask -div ${T1}_hpf2_s20 ${T1}_hpf2_brain
+    # make sure the overall scaling doesn't change (equate medians)
+    med0=`$FSLDIR/bin/fslstats ${T1} -k ${T1}_hpf_brain_mask -P 50`;
+    med1=`$FSLDIR/bin/fslstats ${T1}_hpf2_brain -k ${T1}_hpf_brain_mask -P 50`;
+    run $FSLDIR/bin/fslmaths ${T1}_hpf2_brain -div $med1 -mul $med0 ${T1}_hpf2_brain
+    date; echo "Estimating and removing bias field (stage 2 - detailed fields)"
+    run $FSLDIR/bin/fslmaths ${T1}_hpf2_brain -mas lesionmaskinv ${T1}_hpf2_maskedbrain
+    run $FSLDIR/bin/fast -o ${T1}_initfast -l ${smooth} -b -B -t $type --iter=${niter} --nopve --fixed=0 -v ${T1}_hpf2_maskedbrain
+    run $FSLDIR/bin/fslmaths ${T1}_initfast_restore -mas lesionmaskinv ${T1}_initfast_maskedrestore
+    run $FSLDIR/bin/fast -o ${T1}_initfast2 -l ${smooth} -b -B -t $type --iter=${niter} --nopve --fixed=0 -v ${T1}_initfast_maskedrestore
+    run $FSLDIR/bin/fslmaths ${T1}_hpf_brain_mask ${T1}_initfast2_brain_mask
     else
-	if [ $do_bet = yes ] ; then
+    if [ $do_bet = yes ] ; then
         # get a rough brain mask - it can be *VERY* rough (i.e. missing huge portions of the brain or including non-brain, but non-background) - use -f 0.1 to err on being over inclusive
-	    run $FSLDIR/bin/bet ${T1} ${T1}_initfast2_brain -m -f 0.1
-	else
-	    run $FSLDIR/bin/fslmaths ${T1} ${T1}_initfast2_brain
-	    run $FSLDIR/bin/fslmaths ${T1}_initfast2_brain -bin ${T1}_initfast2_brain_mask
-	fi
-	run $FSLDIR/bin/fslmaths ${T1}_initfast2_brain ${T1}_initfast2_restore
+        run $FSLDIR/bin/bet ${T1} ${T1}_initfast2_brain -m -f 0.1
+    else
+        run $FSLDIR/bin/fslmaths ${T1} ${T1}_initfast2_brain
+        run $FSLDIR/bin/fslmaths ${T1}_initfast2_brain -bin ${T1}_initfast2_brain_mask
+    fi
+    run $FSLDIR/bin/fslmaths ${T1}_initfast2_brain ${T1}_initfast2_restore
     fi
     # redo fast again to try and improve bias field
     run $FSLDIR/bin/fslmaths ${T1}_initfast2_restore -mas lesionmaskinv ${T1}_initfast2_maskedrestore
@@ -472,43 +472,43 @@ fi
 # required input: ${T1}_biascorr
 # output: ${T1}_biascorr_brain ${T1}_biascorr_brain_mask ${T1}_to_MNI_lin ${T1}_to_MNI [plus transforms, inverse transforms, jacobians, etc.]
 if [ $do_reg = yes ]; then
-	if [ $do_bet != yes ]; then
-		echo "Skipping registration, as it requires a non-brain-extracted input image"
-	else
-		date
-		echo "Registering to standard space (linear)"
-		flirtargs="$flirtargs $nosearch"
-		if [ $use_lesionmask = yes ]; then flirtargs="$flirtargs -inweight lesionmaskinv"; fi
-		run $FSLDIR/bin/flirt -interp spline -dof 12 -in ${T1}_biascorr -ref $FSLDIR/data/standard/MNI152_${T1}_2mm -dof 12 -omat ${T1}_to_MNI_lin.mat -out ${T1}_to_MNI_lin $flirtargs
-
-		if [ $do_nonlinreg = yes ]; then
-			date
-			echo "Registering to standard space (non-linear)"
-			#refmask=$FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask_dil1
-			refmask=MNI152_${T1}_2mm_brain_mask_dil1
-			fnirtargs=""
-			if [ $use_lesionmask = yes ]; then fnirtargs="$fnirtargs --inmask=lesionmaskinv"; fi
-			run $FSLDIR/bin/fslmaths $FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask -fillh -dilF $refmask
-			run $FSLDIR/bin/fnirt --in=${T1}_biascorr --ref=$FSLDIR/data/standard/MNI152_${T1}_2mm --fout=${T1}_to_MNI_nonlin_field --jout=${T1}_to_MNI_nonlin_jac --iout=${T1}_to_MNI_nonlin --logout=${T1}_to_MNI_nonlin.txt --cout=${T1}_to_MNI_nonlin_coeff --config=$FSLDIR/etc/flirtsch/${T1}_2_MNI152_2mm.cnf --aff=${T1}_to_MNI_lin.mat --refmask=$refmask $fnirtargs
-
-			date
-			echo "Performing brain extraction (using FNIRT)"
-			run $FSLDIR/bin/invwarp --ref=${T1}_biascorr -w ${T1}_to_MNI_nonlin_coeff -o MNI_to_${T1}_nonlin_field
-			run $FSLDIR/bin/applywarp --interp=nn --in=$FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask --ref=${T1}_biascorr -w MNI_to_${T1}_nonlin_field -o ${T1}_biascorr_brain_mask
-			run $FSLDIR/bin/fslmaths ${T1}_biascorr_brain_mask -fillh ${T1}_biascorr_brain_mask
-			run $FSLDIR/bin/fslmaths ${T1}_biascorr -mas ${T1}_biascorr_brain_mask ${T1}_biascorr_brain
-		else
-			if [ $do_bet = yes ]; then
-				date
-				echo "Performing brain extraction (using BET)"
-				run $FSLDIR/bin/bet ${T1}_biascorr ${T1}_biascorr_brain -m $betopts ## results sensitive to the f parameter
-			else
-				run $FSLDIR/bin/fslmaths ${T1}_biascorr ${T1}_biascorr_brain
-				run $FSLDIR/bin/fslmaths ${T1}_biascorr_brain -bin ${T1}_biascorr_brain_mask
-			fi
-		fi
-		## In the future, could check the initial ROI extraction here
-	fi
+    if [ $do_bet != yes ]; then
+        echo "Skipping registration, as it requires a non-brain-extracted input image"
+    else
+        date
+        echo "Registering to standard space (linear)"
+        flirtargs="$flirtargs $nosearch"
+        if [ $use_lesionmask = yes ]; then flirtargs="$flirtargs -inweight lesionmaskinv"; fi
+        run $FSLDIR/bin/flirt -interp spline -dof 12 -in ${T1}_biascorr -ref $FSLDIR/data/standard/MNI152_${T1}_2mm -dof 12 -omat ${T1}_to_MNI_lin.mat -out ${T1}_to_MNI_lin $flirtargs
+
+        if [ $do_nonlinreg = yes ]; then
+            date
+            echo "Registering to standard space (non-linear)"
+            #refmask=$FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask_dil1
+            refmask=MNI152_${T1}_2mm_brain_mask_dil1
+            fnirtargs=""
+            if [ $use_lesionmask = yes ]; then fnirtargs="$fnirtargs --inmask=lesionmaskinv"; fi
+            run $FSLDIR/bin/fslmaths $FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask -fillh -dilF $refmask
+            run $FSLDIR/bin/fnirt --in=${T1}_biascorr --ref=$FSLDIR/data/standard/MNI152_${T1}_2mm --fout=${T1}_to_MNI_nonlin_field --jout=${T1}_to_MNI_nonlin_jac --iout=${T1}_to_MNI_nonlin --logout=${T1}_to_MNI_nonlin.txt --cout=${T1}_to_MNI_nonlin_coeff --config=$FSLDIR/etc/flirtsch/${T1}_2_MNI152_2mm.cnf --aff=${T1}_to_MNI_lin.mat --refmask=$refmask $fnirtargs
+
+            date
+            echo "Performing brain extraction (using FNIRT)"
+            run $FSLDIR/bin/invwarp --ref=${T1}_biascorr -w ${T1}_to_MNI_nonlin_coeff -o MNI_to_${T1}_nonlin_field
+            run $FSLDIR/bin/applywarp --interp=nn --in=$FSLDIR/data/standard/MNI152_${T1}_2mm_brain_mask --ref=${T1}_biascorr -w MNI_to_${T1}_nonlin_field -o ${T1}_biascorr_brain_mask
+            run $FSLDIR/bin/fslmaths ${T1}_biascorr_brain_mask -fillh ${T1}_biascorr_brain_mask
+            run $FSLDIR/bin/fslmaths ${T1}_biascorr -mas ${T1}_biascorr_brain_mask ${T1}_biascorr_brain
+        else
+            if [ $do_bet = yes ]; then
+                date
+                echo "Performing brain extraction (using BET)"
+                run $FSLDIR/bin/bet ${T1}_biascorr ${T1}_biascorr_brain -m $betopts ## results sensitive to the f parameter
+            else
+                run $FSLDIR/bin/fslmaths ${T1}_biascorr ${T1}_biascorr_brain
+                run $FSLDIR/bin/fslmaths ${T1}_biascorr_brain -bin ${T1}_biascorr_brain_mask
+            fi
+        fi
+        ## In the future, could check the initial ROI extraction here
+    fi
 fi
 
 
@@ -532,7 +532,7 @@ if [ $do_seg = yes ] ; then
     run $FSLDIR/bin/fslmaths ${T1}_biascorr_init -div ${T1}_fast_bias ${T1}_biascorr
     if [ $do_nonlinreg = yes ] ; then
         # regenerate the standard space version with the new bias field correction applied
-	run $FSLDIR/bin/applywarp -i ${T1}_biascorr -w ${T1}_to_MNI_nonlin_field -r $FSLDIR/data/standard/MNI152_${T1}_2mm -o ${T1}_to_MNI_nonlin --interp=spline
+    run $FSLDIR/bin/applywarp -i ${T1}_biascorr -w ${T1}_to_MNI_nonlin_field -r $FSLDIR/data/standard/MNI152_${T1}_2mm -o ${T1}_to_MNI_nonlin --interp=spline
     fi
 fi
 
@@ -545,7 +545,7 @@ if [ $do_reg = yes ] && [ $do_seg = yes ] && [ $T1 = T1 ] ; then
     run ${FSLDIR}/bin/bet ${T1}_biascorr ${T1}_biascorr_bet -s -m $betopts
     run ${FSLDIR}/bin/pairreg ${FSLDIR}/data/standard/MNI152_T1_2mm_brain ${T1}_biascorr_bet ${FSLDIR}/data/standard/MNI152_T1_2mm_skull ${T1}_biascorr_bet_skull ${T1}2std_skullcon.mat
     if [ $use_lesionmask = yes ] ; then
-    	run ${FSLDIR}/bin/fslmaths lesionmask -max ${T1}_fast_pve_2 ${T1}_fast_pve_2_plusmask -odt float
+        run ${FSLDIR}/bin/fslmaths lesionmask -max ${T1}_fast_pve_2 ${T1}_fast_pve_2_plusmask -odt float
         # ${FSLDIR}/bin/fslmaths lesionmask -bin -mul 3 -max ${T1}_fast_seg ${T1}_fast_seg_plusmask -odt int
     fi
     vscale=`${FSLDIR}/bin/avscale ${T1}2std_skullcon.mat | grep Determinant | awk '{ print $3 }'`;
-- 
GitLab