Hi Simon,
On 20 Apr 2007, at 20:12, Simon Davis wrote:
> Has anyone developed a usable batch script for running multiple
> subjects
> through bet, eddy correction, dtifit, and (optionally) tbss? I
> might also
> want to resample my images from 256 to 128; can anyone point my in the
> correct direction?
Something like this may be a useful starting point.
--------------------------->8-----------------------
#!/bin/bash
#set -x
# if * matches nothing in a directory make it expand to the empty
# string instead of itself so we don't iterate over crap
shopt -s nullglob
# if ctrl-c is pressed exit immediatly
trap exit SIGHUP SIGINT SIGTERM
programName=`basename $0`
dirname=$( dirname $0 )
dirname=$( readlink -f "$dirname" )
function execute
{
echo "*** $programName: Executing command: $*"
eval "$*"
}
bvecs=$( readlink -f "../config/bvecs" )
bvals=$( readlink -f "../config/bvals" )
cd ../data/ts
tsDataRoot=`pwd`
# The program can handle multiple command line arguments in the form
# of group/subjectNumber if there are no arguments provided it will
# operate on all subjects in all groups in the data/ts directory.
subjects=""
if (( $# > 0 )) ; then
subjects="$*"
else
subjects=*
fi
for sub in $subjects
do
echo
"#######################################################################
#########"
# the next two lines of code extract the first and second parts,
# respectively, of a path like short/66131
group="${sub%/*}"
subjectNumber="${sub##*/}"
toBePreprocessed=$sub/${subjectNumber}.dti.nii
volumeCorrectedNii=${toBePreprocessed%%dti*}vc.nii.gz
referenceVolume="0"
echo "*** Performing volume correction for subject $subjectNumber"
execute "avwroi ${toBePreprocessed} $volumeCorrectedNii 0 16"
echo "*** Performing eddy currect correction for subject
$subjectNumber"
ecCorrectFile="$sub/data"
execute "(cd $sub; eddy_correct ${volumeCorrectedNii##*/} $
{ecCorrectFile##*/} $referenceVolume)"
echo "*** Creating binary mask from No Diffusion volume"
V0Nii=${toBePreprocessed%%dti*}V0.nii.gz
execute "avwroi ${toBePreprocessed} ${V0Nii} 0 1"
nodifNii=$sub/nodif
execute "bet ${volumeCorrectedNii} ${nodifNii} -m"
execute "mv -f $sub/nodif_mask.nii.gz $sub/nodif_brain_mask.nii.gz"
echo "*** Performing DTIFit for subject $subjectNumber"
dtiFitNii=$sub/dtifit
execute "cp -a $bvecs $bvals $sub"
execute "dtifit --data=${ecCorrectFile}.nii.gz --out=$dtiFitNii
--mask=${nodifNii}_brain_mask.nii.gz \
--bvecs=$sub/bvecs --bvals=$sub/bvals"
execute "bedpost_datacheck $sub"
done # end of for sub in $subjects
--------------------------->8-----------------------
This script was written assuming the following:
1. You have a directory to store all the data and scripts for your
analyses, for example dti;
2. under dti you have directories for scripts, config, and data;
3a. in data there is a ts directory within which there is a directory
for each subject.
3b. if you wish you may instead have directories for different groups
within data and within the group directories a directory for each
subject, in this case you should change "subjects=*" above to
"subjects=*/*"
Regards,
--
Dr Colm G. Connolly
School of Psychology and Institute of Neuroscience
The Lloyd Building
University of Dublin
Trinity College, Dublin 2, Éire
Tel: +353-1-896-8475
Fax: +353-1-671-3183
|