#!/usr/local/bin/bash # preprocessing for DTI images acquired at FMRIB Usage() { echo "REMOVE_VOLS - Remove dodgy volumes from DTI data acquired at FMRIB " echo "" echo "USAGE: remove_vols <input_file> <output_file> <dodgyvols> " echo "" echo "example: remove_vols data data_rv 4 19 35" echo "" echo "Note that the first volume is 0 and not 1" echo "" exit } [ "$1" = "" ] && Usage [ "$2" = "" ] && Usage [ "$3" = "" ] && Usage input_file=$1 output_file=$2 current_dir=`pwd` if [ ! -e $input_file.hdr ]; then echo Cant find $input_file exit fi if [ ! -e bvals ]; then echo Cant find bvals exit fi if [ ! -e bvecs ]; then echo Cant find bvecs exit fi avwsplit $input_file.hdr vol=0 num_vols=`expr $# - 2` t="" rm dodgy_vols -f echo -n $t >dodgy_vols while [ $vol -lt $num_vols ]; do echo -n $t>tmp1 echo -n $t>tmp2 v=$3 shift if [ -e vol000${v}.hdr ]; then rm vol000${v}.hdr -f rm vol000${v}.img -f fi if [ -e vol00${v}.hdr ]; then rm vol00${v}.hdr -f rm vol00${v}.img -f fi echo $v > tmp1 cat dodgy_vols tmp1 > tmp2 cat tmp2 > dodgy_vols vol=`expr $vol + 1` done echo "addpath('/usr/people/dtiuser/etc/FMRIB_bvals_bvecs/')">tmp3 echo "remove_vols('$current_dir')">tmp4 cat tmp3 tmp4 >tmp.m cat tmp.m | matlab rm tmp* -f echo "Merging Volumes" avwmerge -t $output_file vol*.hdr rm vol* -f rm dodgy_vols -f