diff --git a/asl_calib.in b/asl_calib.in index 8e6afd4..2b8f60a 100755 --- a/asl_calib.in +++ b/asl_calib.in @@ -8,6 +8,11 @@ # # SHCOPYRIGHT +# Make script use local copies of helper scripts/programs in the same +# directory, if present. This allows for multiple versions of the scripts +# to be used, possibly with bundled dependencies +PATH=`dirname $0`:${FSLDIR}/bin:${PATH} + #deal with options Usage() { @@ -182,15 +187,7 @@ done echo "ASL_CALIB" # set the version of fabber to use -fabber=fabber -#fabber=$FSLDIR/bin/fabber -if [ ! -z $devel ]; then - fabber=~chappell/cproject/fabber/fabber - if [ $FSLMACHTYPE = linux_64-gcc4.1 ]; then #assumption that the architecuture tell me that we are on a jalapeno node - echo "We are on jalapeno" - fabber=~chappell/cproject/jalapeno/fabber/fabber - fi -fi +fabber=fabber_asl #check for mandatory inputs if [ -z $calib ]; then @@ -227,7 +224,7 @@ if [ ! -d $outdir ]; then fi # make a temporary directory to work in - delete at end -tmpbase=`$FSLDIR/bin/tmpnam` +tmpbase=`tmpnam` temp_calib=${tmpbase}_asl_calib mkdir $temp_calib @@ -311,7 +308,7 @@ echo "Tissue reference : $tissref" >> $log # command line override of default T1 and T2 if [ ! -z $T1rin ]; then - if [ `${FSLDIR}/bin/imtest $T1rin` ]; then + if [ `imtest $T1rin` ]; then # we have been supplied with a T1 image - record that here to process later T1rim=$T1rin echo "Loading T1 image for reference region: T1im" >> $log @@ -321,7 +318,7 @@ if [ ! -z $T1rin ]; then fi fi if [ ! -z $T2rin ]; then - if [ `${FSLDIR}/bin/imtest $T2rin` ]; then + if [ `imtest $T2rin` ]; then # we have been supplied with a T2 image - record that here to process later T2rim=$T2rin echo "Loading T2 image for reference region: T2im" >> $log @@ -395,7 +392,7 @@ fi if [ $tissref = "none" ]; then # whole brain M0 # in this case use the brain mask - ${FSLDIR}/bin/imcp $bmask $temp_calib/refmask + imcp $bmask $temp_calib/refmask maskflag=1 echo "Brain mask is being used as the reference tissue (beware!)" >> $log fi @@ -502,8 +499,8 @@ if [ -z $maskflag ]; then if [ ! -z $fasthasrun ] && [ -z $senson ]; then # also extract the bias field and convert to sensitivity image (as long as we have already been supplied by a sensivity iamge or reference) - ${FSLDIR}/bin/applywarp --ref=$calib --in=$temp_calib/seg_bias --out=$temp_calib/biasfield --premat=$temp_calib/high2low.mat --super --interp=spline --superlevel=4 - ${FSLDIR}/bin/fslmaths $temp_calib/biasfield -recip $temp_calib/sens + applywarp --ref=$calib --in=$temp_calib/seg_bias --out=$temp_calib/biasfield --premat=$temp_calib/high2low.mat --super --interp=spline --superlevel=4 + fslmaths $temp_calib/biasfield -recip $temp_calib/sens senson=1 echo "Using bias field from structural image for sensitivity correction" >> $log fi @@ -521,7 +518,7 @@ if [ -z $maskflag ]; then else #use supplied tissue reference mask - ${FSLDIR}/bin/imcp $mask $temp_calib/refmask + imcp $mask $temp_calib/refmask echo "Using supplied reference tissue mask: $mask" >> $log fi @@ -636,10 +633,10 @@ elif [ $mode = satrecov ]; then if [ ! -z $senson ]; then echo "Apply sensitivity image to data for reference tisse M0 estimation" >> $log # apply sensitivity map to calibration image - ONLY for the reference tissue calculations - ${FSLDIR}/bin/fslmaths $calib -div $temp_calib/sens $temp_calib/calib_senscorr + fslmaths $calib -div $temp_calib/sens $temp_calib/calib_senscorr else # no sensitivity correction required, but copy image over ready for next command - ${FSLDIR}/bin/imcp $calib $temp_calib/calib_senscorr + imcp $calib $temp_calib/calib_senscorr fi echo "FABBER within reference tissue mask" >> $log $fabber --data=$temp_calib/calib_senscorr --mask=$mask --output=$temp_calib/satrecov --data-order=singlefile --model=satrecov --noise=white --method=vb $tislist $llopts $sropts --t1=$T1r diff --git a/asl_preproc.in b/asl_preproc.in index e2bf812..e07553e 100755 --- a/asl_preproc.in +++ b/asl_preproc.in @@ -8,6 +8,11 @@ # # SHCOPYRIGHT +# Make script use local copies of helper scripts/programs in the same +# directory, if present. This allows for multiple versions of the scripts +# to be used, possibly with bundled dependencies +PATH=`dirname $0`:${FSLDIR}/bin:${PATH} + Usage() { echo "ASL_PREPROC" echo "Version: ${GIT_SHA1} ${GIT_DATE}" @@ -47,7 +52,7 @@ if [ -z $1 ]; then exit 1 fi -perfusion_subtract=${FSLDIR}/bin/perfusion_subtract +perfusion_subtract=perfusion_subtract until [ -z $1 ]; do case $1 in @@ -92,7 +97,7 @@ echo "ASL_PREPROC" oldpwd=`pwd` -tmpbase=`$FSLDIR/bin/tmpnam` +tmpbase=`tmpnam` if [ -z $debug ]; then tempdir=${tmpbase}_asl_pre else diff --git a/asl_reg.in b/asl_reg.in index 6cfa84b..46b1964 100755 --- a/asl_reg.in +++ b/asl_reg.in @@ -8,6 +8,11 @@ # # SHCOPYRIGHT +# Make script use local copies of helper scripts/programs in the same +# directory, if present. This allows for multiple versions of the scripts +# to be used, possibly with bundled dependencies +PATH=`dirname $0`:${FSLDIR}/bin:${PATH} + Usage() { echo "ASL_REG" echo "Version: ${GIT_SHA1} ${GIT_DATE}" @@ -182,7 +187,7 @@ if [ ! -d $outdir ]; then fi # make a temporary directory to work in - delete at end -tmpbase=`$FSLDIR/bin/tmpnam` +tmpbase=`tmpnam` if [ -z $debug ]; then tempdir=${tmpbase}_asl_reg else @@ -219,7 +224,7 @@ fi # BET the structural image if required if [ -z $sbet ]; then echo "Running BET on structural image" - $FSLDIR/bin/bet $struc $tempdir/struc_brain + bet $struc $tempdir/struc_brain sbet=$tempdir/struc_brain fi @@ -228,20 +233,20 @@ if [ -z $finalonly ]; then echo "Registration MAIN stage (FLIRT)" if [ -z $lowstrucflag ]; then #Step1: 3DOF translation only transformation - $FSLDIR/bin/flirt -in $cfile -ref $sbet -schedule $FSLDIR/etc/flirtsch/xyztrans.sch -omat $tempdir/low2high1.mat -out $tempdir/low2hig1 $inittext $weigthinstr + flirt -in $cfile -ref $sbet -schedule $FSLDIR/etc/flirtsch/xyztrans.sch -omat $tempdir/low2high1.mat -out $tempdir/low2hig1 $inittext $weigthinstr #step2: 6DOF transformation with small search region - $FSLDIR/bin/flirt -in $cfile -ref $sbet -dof $DOF -omat $tempdir/low2high.mat -init $tempdir/low2high1.mat -schedule $flirtsch -out $tempdir/low2high $weigthinstr + flirt -in $cfile -ref $sbet -dof $DOF -omat $tempdir/low2high.mat -init $tempdir/low2high1.mat -schedule $flirtsch -out $tempdir/low2high $weigthinstr else #as we have a structural image in perfusion space use it to improve registration echo "Using structral image in perfusion space ($lowstruc)" #Step1: 3DOF translation only transformation perfusion->lowstruc - $FSLDIR/bin/flirt -in $cfile -ref $lowstruc -schedule $FSLDIR/etc/flirtsch/xyztrans.sch -omat $tempdir/low2low1.mat $inittext $weigthinstr + flirt -in $cfile -ref $lowstruc -schedule $FSLDIR/etc/flirtsch/xyztrans.sch -omat $tempdir/low2low1.mat $inittext $weigthinstr #Step2: 6DOF limited transformation in perfusion space - $FSLDIR/bin/flirt -in $cfile -ref $lowstruc -dof $DOF -schedule $flirtsch -init $tempdir/low2low1.mat -omat $tempdir/low2low.mat $weigthinstr + flirt -in $cfile -ref $lowstruc -dof $DOF -schedule $flirtsch -init $tempdir/low2low1.mat -omat $tempdir/low2low.mat $weigthinstr #step3: 6DOF transformation of lowstruc to struc - $FSLDIR/bin/flirt -in $lowstruc -ref $sbet -omat $tempdir/str2str.mat + flirt -in $lowstruc -ref $sbet -omat $tempdir/str2str.mat #step4: combine the two transformations - $FSLDIR/bin/convert_xfm -omat $tempdir/low2high.mat -concat $tempdir/str2str.mat $tempdir/low2low.mat + convert_xfm -omat $tempdir/low2high.mat -concat $tempdir/str2str.mat $tempdir/low2low.mat fi # update the init text ready for the 'final' step to start with the result of the MAIN registration epi_inittext="--init=$tempdir/low2high.mat" @@ -255,9 +260,9 @@ if [ -z $mainonly ]; then echo "Registration FINAL stage (BBR)" if [ -z $tissseg ]; then # Running FAST segmentation - $FSLDIR/bin/fast -o $tempdir/struct_fast $sbet + fast -o $tempdir/struct_fast $sbet # WM segmentation - $FSLDIR/bin/fslmaths $tempdir/struct_fast_pve_2 -thr 0.5 -bin ${tempdir}/fast_tissseg + fslmaths $tempdir/struct_fast_pve_2 -thr 0.5 -bin ${tempdir}/fast_tissseg tissseg=${tempdir}/fast_tissseg fi @@ -266,31 +271,31 @@ echo "Registration FINAL stage (BBR)" convert_xfm -omat $tempdir/high2low.mat -inverse $tempdir/low2high.mat fslmaths $sbet -thr 0 -bin $tempdir/struct_brain_mask - ${FSLDIR}/bin/flirt -in $tempdir/struct_brain_mask -ref $infile -applyxfm -init $tempdir/high2low.mat -out $tempdir/mask -interp trilinear - ${FSLDIR}/bin/fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask - ${FSLDIR}/bin/fslcpgeom $infile $tempdir/mask + flirt -in $tempdir/struct_brain_mask -ref $infile -applyxfm -init $tempdir/high2low.mat -out $tempdir/mask -interp trilinear + fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask + fslcpgeom $infile $tempdir/mask mask=$tempdir/mask fi # apply mask to asldata - $FSLDIR/bin/fslmaths $infile -mas $mask $tempdir/asldata_brain + fslmaths $infile -mas $mask $tempdir/asldata_brain # copy mask to output for future reference - ${FSLDIR}/bin/imcp $mask $outdir/mask + imcp $mask $outdir/mask # do a final refinement of the registration using the perfusion and the white matter segmentation - using epi_reg to get BBR (and allow for fielmap correction in future) if [ -z $fmap ]; then # Without fieldmap - $FSLDIR/bin/epi_reg --epi=$tempdir/asldata_brain --t1=$struc --t1brain=$sbet $epi_inittext --out=$tempdir/low2high_final --wmseg=$tissseg $weigthinstr + epi_reg --epi=$tempdir/asldata_brain --t1=$struc --t1brain=$sbet $epi_inittext --out=$tempdir/low2high_final --wmseg=$tissseg $weigthinstr else # With fieldmap fmapregstr="" if [ ! -z $nofmapreg ]; then fmapregstr="--nofmapreg" fi - $FSLDIR/bin/epi_reg --epi=$tempdir/asldata_brain --t1=$struc --t1brain=$sbet $epi_inittext --out=$tempdir/low2high_final --wmseg=$tissseg $weigthinstr --fmap=$fmap --fmapmag=$fmapmag --fmapmagbrain=$fmapmagbrain --pedir=$pedir --echospacing=$echospacing $fmapregstr + epi_reg --epi=$tempdir/asldata_brain --t1=$struc --t1brain=$sbet $epi_inittext --out=$tempdir/low2high_final --wmseg=$tissseg $weigthinstr --fmap=$fmap --fmapmag=$fmapmag --fmapmagbrain=$fmapmagbrain --pedir=$pedir --echospacing=$echospacing $fmapregstr fi - # $FSLDIR/bin/flirt -ref $sbet -in $infile -dof 6 -cost bbr -wmseg $wmseg -init $tempdir/low2high.mat -omat $tempdir/low2high.mat -out $tempdir/low2high_final -schedule ${FSLDIR}/etc/flirtsch/bbr.sch + # flirt -ref $sbet -in $infile -dof 6 -cost bbr -wmseg $wmseg -init $tempdir/low2high.mat -omat $tempdir/low2high.mat -out $tempdir/low2high_final -schedule ${FSLDIR}/etc/flirtsch/bbr.sch echo "BBR end" @@ -298,15 +303,15 @@ echo "Registration FINAL stage (BBR)" echo "Saving FINAL output" cp $outdir/asl2struct.mat $outdir/asl2struct_init.mat # save the initial transformation matrix to allow chekcing if this part failed cp $tempdir/low2high_final.mat $outdir/asl2struct.mat #the transformation matrix from epi_reg - this overwrites the version from MAIN registration - ${FSLDIR}/bin/convert_xfm -omat $outdir/struct2asl.mat -inverse $outdir/asl2struct.mat #often useful to have the inverse transform, so calcuate it + convert_xfm -omat $outdir/struct2asl.mat -inverse $outdir/asl2struct.mat #often useful to have the inverse transform, so calcuate it if [ ! -z $fmap ]; then - ${FSLDIR}/bin/imcp $tempdir/low2high_final_warp $outdir/asl2struct_warp #the warp from epi_reg + imcp $tempdir/low2high_final_warp $outdir/asl2struct_warp #the warp from epi_reg fi - ${FSLDIR}/bin/imcp $tempdir/low2high_final $outdir/asl2struct # save the transformed image to check on the registration + imcp $tempdir/low2high_final $outdir/asl2struct # save the transformed image to check on the registration # copy the edge image from epi_reg output as that is good for visualisation - ${FSLDIR}/bin/imcp $tissseg $outdir/tissseg - ${FSLDIR}/bin/imcp $tempdir/low2high_final_fast_wmedge $outdir/tissedge + imcp $tissseg $outdir/tissseg + imcp $tempdir/low2high_final_fast_wmedge $outdir/tissedge fi ## ASL-->standard transformation (if specified) diff --git a/oxford_asl.in b/oxford_asl.in index 2282f6a..b98a86c 100755 --- a/oxford_asl.in +++ b/oxford_asl.in @@ -8,6 +8,11 @@ # # SHCOPYRIGHT +# Make script use local copies of helper scripts/programs in the same +# directory, if present. This allows for multiple versions of the scripts +# to be used, possibly with bundled dependencies +PATH=`dirname $0`:${FSLDIR}/bin:${PATH} + Usage() { echo "OXFORD_ASL" echo "Calculate perfusion maps from ASL data" @@ -220,7 +225,7 @@ Report() { subdir=$2 masktype=$3 - repval=`${FSLDIR}/bin/fslstats $outdir/native_space/$subdir/$parname -k $tempdir/${masktype}mask_pure -m` + repval=`fslstats $outdir/native_space/$subdir/$parname -k $tempdir/${masktype}mask_pure -m` echo $repval > $outdir/native_space/$subdir/${parname}_${masktype}_mean.txt Log "Mean $parname in $masktype is $repval" @@ -447,7 +452,7 @@ fi if [ ! -z $varout ]; then #get varainces out of finalMVN - ${FSLDIR}/bin/fabber_var -d ${finalstep} -m $tempdir/mask + fabber_var -d ${finalstep} -m $tempdir/mask # do correction of negative values fslmaths ${finalstep}/var_ftiss -bin -add 1 -uthr 1 -mul 1e12 -add ${finalstep}/var_ftiss $2/var_ftiss if [ ! -z $senscorr ]; then @@ -460,7 +465,7 @@ fi fi #copy the final MVN to the temp directory for future use -${FSLDIR}/bin/imcp ${finalstep}/finalMVN $2/finalMVN +imcp ${finalstep}/finalMVN $2/finalMVN cp ${finalstep}/paramnames.txt $2/paramnames.txt @@ -532,7 +537,7 @@ if [ ! -z $calibflag ]; then if [ $cmethod = 'single' ]; then malpha=`echo "$Mo * $alpha" | bc` #include the inversion efficiency when we do the final calibration elif [ $cmethod = 'voxel' ]; then - ${FSLDIR}/bin/fslmaths $outdir/calib/M0 -mul $alpha $tempdir/malpha + fslmaths $outdir/calib/M0 -mul $alpha $tempdir/malpha malpha=$tempdir/malpha fi @@ -552,7 +557,7 @@ if [ ! -z $calibflag ]; then if [ $cmethod = 'single' ]; then Mosq=`echo "$Mo * $Mo * $alpha * $alpha" | bc` #include the inversion efficiency when we do the final calibration elif [ $cmethod = 'voxel' ]; then - ${FSLDIR}/bin/fslmaths $outdir/calib/M0 -mul $outdir/calib/M0 -mul $alpha -mul $alpha $tempdir/mosq + fslmaths $outdir/calib/M0 -mul $outdir/calib/M0 -mul $alpha -mul $alpha $tempdir/mosq Mosq=$tempdir/mosq fi @@ -568,7 +573,7 @@ fi # advanced output if [ ! -z $advout ]; then if [ ! -d $outdir/advanced/$subdir ]; then mkdir $outdir/advanced/$subdir; fi - ${FSLDIR}/bin/imcp $tempdir/$subdir/finalMVN $outdir/advanced/$subdir/finalMVN + imcp $tempdir/$subdir/finalMVN $outdir/advanced/$subdir/finalMVN cp $tempdir/$subdir/paramnames.txt $outdir/advanced/$subdir/paramnames.txt fi @@ -597,9 +602,9 @@ fi #asl_reg=asl_reg #asl_calib=asl_calib -basil=${FSLDIR}/bin/basil -asl_reg=${FSLDIR}/bin/asl_reg -asl_calib=${FSLDIR}/bin/asl_calib +basil=basil +asl_reg=asl_reg +asl_calib=asl_calib # defaults that (boolean) command line options can overide spatial=1; # we always use spatial priors, use --spatial=off to turn off. @@ -837,7 +842,7 @@ if [ -z $verbose ]; then fi # deal with the temporary directory -tmpbase=`$FSLDIR/bin/tmpnam` +tmpbase=`tmpnam` tempdir=${tmpbase}_ox_asl mkdir $tempdir @@ -885,7 +890,7 @@ if [ -z $inflag ]; then echo "ERROR: no input file specified" exit 1 else - if [ `${FSLDIR}/bin/imtest $infile` -eq 0 ]; then + if [ `imtest $infile` -eq 0 ]; then echo "ERROR: $infile is not an image/has not been found" exit 1 fi @@ -894,7 +899,7 @@ Log "Input file: $infile" if [ ! -z $strucflag ]; then if [ ! -z $struc ]; then - if [ `${FSLDIR}/bin/imtest $struc` -eq 0 ]; then + if [ `imtest $struc` -eq 0 ]; then echo "ERROR: $struc is not an image/has not been found" exit 1 fi @@ -912,7 +917,7 @@ if [ ! -z $transflag ]; then Log "Structural to standard transformation matrix: $trans" fi if [ ! -z $lowstruc ]; then - if [ `${FSLDIR}/bin/imtest $lowstruc` -eq 0 ]; then + if [ `imtest $lowstruc` -eq 0 ]; then echo "ERROR: $lowstruc is not an image/has not been found" exit 1 fi @@ -967,24 +972,24 @@ echo "Pre-processing" if [ ! -z $fslanat ]; then # we are being supplied with an fslanat directory # copy over the structural and brain extracted strucutral so that we can use them - ${FSLDIR}/bin/imcp $fslanat/T1_biascorr $tempdir/struc - ${FSLDIR}/bin/imcp $fslanat/T1_biascorr_brain $tempdir/struc_bet + imcp $fslanat/T1_biascorr $tempdir/struc + imcp $fslanat/T1_biascorr_brain $tempdir/struc_bet elif [ ! -z $struc ]; then - ${FSLDIR}/bin/fslmaths $struc $tempdir/struc + fslmaths $struc $tempdir/struc Log "Structural image is: $struc" if [ -z $strucbet ]; then #bet the structural for calibration and registration bet $struc $tempdir/struc_bet Log "BET on structural image" else - ${FSLDIR}/bin/fslmaths $strucbet $tempdir/struc_bet + fslmaths $strucbet $tempdir/struc_bet fi fi if [ ! -z $lowstrucflag ]; then - ${FSLDIR}/bin/fslmaths $lowstruc $tempdir/lowstruc + fslmaths $lowstruc $tempdir/lowstruc ## bet the low res. struc (if present) # bet $lowstruc $tempdir/lowstruc_bet # Log "BET on low res. structural image" @@ -1006,18 +1011,18 @@ if [ ! -z $calib ]; then # take the mean fslmaths $tempdir/calib -Tmean $tempdir/calib else - ${FSLDIR}/bin/fslmaths $calib $tempdir/calib + fslmaths $calib $tempdir/calib fi # bet - ${FSLDIR}/bin/imcp $tempdir/calib $tempdir/calib_wholehead # keep the whole head for motion correction later if reqd - ${FSLDIR}/bin/bet $tempdir/calib $tempdir/calib + imcp $tempdir/calib $tempdir/calib_wholehead # keep the whole head for motion correction later if reqd + bet $tempdir/calib $tempdir/calib fi # read in ASL data -${FSLDIR}/bin/imcp $infile $tempdir/asldata # this is the MAIN data that we will reflect any corrections applied +imcp $infile $tempdir/asldata # this is the MAIN data that we will reflect any corrections applied # take a copy that will not be subject to any subsequent corrections -${FSLDIR}/bin/imcp $tempdir/asldata $tempdir/asldata_orig +imcp $tempdir/asldata $tempdir/asldata_orig ### Motion Correction (main) # note motion correction within calibration data is done above @@ -1027,22 +1032,22 @@ if [ ! -z $moco ]; then # we use the calibration image as our reference for motion correction - since this will be most consistent if the data has a range of different TIs and background suppression etc # this also removes motion effects between asldata and calibration image Log "Motion correction to calibration image" - ${FSLDIR}/bin/mcflirt -in $tempdir/asldata -out $tempdir/asldata -r $tempdir/calib_wholehead -mats + mcflirt -in $tempdir/asldata -out $tempdir/asldata -r $tempdir/calib_wholehead -mats # to reduce interpolation of the ASL data change the transformations so that we end up in the space of the central volume of asldata # Extract the middle transformation middlemat=`ls $tempdir/asldata.mat/MAT_* | awk '{ lines[NR]=$0; } END { print lines[int(NR/2)+1] }'` - ${FSLDIR}/bin/convert_xfm -omat $tempdir/calib2asl.mat -inverse $middlemat + convert_xfm -omat $tempdir/calib2asl.mat -inverse $middlemat # convert all the transofmrations for mat in `ls $tempdir/asldata.mat/MAT_*`; do - ${FSLDIR}/bin/convert_xfm -omat $mat -concat $tempdir/calib2asl.mat $mat + convert_xfm -omat $mat -concat $tempdir/calib2asl.mat $mat done - ${FSLDIR}/bin/applyxfm4D $tempdir/asldata_orig $tempdir/asldata $tempdir/asldata $tempdir/asldata.mat -fourdigit + applyxfm4D $tempdir/asldata_orig $tempdir/asldata $tempdir/asldata $tempdir/asldata.mat -fourdigit # Convert the calibration image to align with asldata - ${FSLDIR}/bin/flirt -in $tempdir/calib -out $tempdir/calib -ref $tempdir/asldata -init $tempdir/calib2asl.mat -applyxfm + flirt -in $tempdir/calib -out $tempdir/calib -ref $tempdir/asldata -init $tempdir/calib2asl.mat -applyxfm else Log "Motion correction to middle volume of ASL data" - ${FSLDIR}/bin/mcflirt -in $tempdir/asldata -out $tempdir/asldata -mats + mcflirt -in $tempdir/asldata -out $tempdir/asldata -mats fi cat $tempdir/asldata.mat/MAT* > $tempdir/asldata.cat # save the motion matrices for distortion correction if reqd fi @@ -1180,7 +1185,7 @@ if [ ! -z $strucflag ]; then # if structural image has not been suppled then ski register=0 Log "Using existing asl to structural transform: $asl2struc" cp $asl2struc $tempdir/asl2struct.mat - ${FSLDIR}/bin/convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat + convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat fi fi @@ -1192,7 +1197,7 @@ if [ -z $regfrom ]; then regfrom=$tempdir/calib else # brain extract the meanasl image - ${FSLDIR}/bin/bet $tempdir/meanasl $tempdir/meanasl_brain -f 0.2 #somewhat conservative fraction to avoid erosion + bet $tempdir/meanasl $tempdir/meanasl_brain -f 0.2 #somewhat conservative fraction to avoid erosion regfrom=$tempdir/meanasl_brain fi fi @@ -1210,7 +1215,7 @@ if [ $register -eq 1 ]; then Registration $regfrom $extraoptions fi - ${FSLDIR}/bin/convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat + convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat fi ### End of: Registration (1/2) @@ -1220,18 +1225,18 @@ if [ ! -z $fslanat ]; then fasthasrun=1 #this means that we have PVE for calibration & PVC purposes # copy over the things we need and place them using the names used elsewhere - ${FSLDIR}/bin/imcp $fslanat/T1_fast_pve_0 $tempdir/pvcsf_struct #indicate that it is in structural space! - ${FSLDIR}/bin/imcp $fslanat/T1_fast_pve_1 $tempdir/pvgm_struct - ${FSLDIR}/bin/imcp $fslanat/T1_fast_pve_2 $tempdir/pvwm_struct + imcp $fslanat/T1_fast_pve_0 $tempdir/pvcsf_struct #indicate that it is in structural space! + imcp $fslanat/T1_fast_pve_1 $tempdir/pvgm_struct + imcp $fslanat/T1_fast_pve_2 $tempdir/pvwm_struct - $FSLDIR/bin/imcp $fslanat/T1_fast_bias $tempdir/biasfield_struct + imcp $fslanat/T1_fast_bias $tempdir/biasfield_struct elif [ ! -z $struc ]; then # do we have the results from FAST already? If not run it if [ -z $fastsrc ]; then echo "Segmenting the structural image" Log "Segmenting the structural image" - ${FSLDIR}/bin/fast -B -b -o $tempdir/seg -p $tempdir/struc_bet + fast -B -b -o $tempdir/seg -p $tempdir/struc_bet fastsrc=$tempdir/seg else # FAST has been run externally @@ -1242,24 +1247,24 @@ elif [ ! -z $struc ]; then fasthasrun=1 # copy over the things we need and place them using the names used elsewhere - ${FSLDIR}/bin/imcp ${fastsrc}_pve_0 $tempdir/pvcsf_struct #indicate that it is in structural space! - ${FSLDIR}/bin/imcp ${fastsrc}_pve_1 $tempdir/pvgm_struct - ${FSLDIR}/bin/imcp ${fastsrc}_pve_2 $tempdir/pvwm_struct + imcp ${fastsrc}_pve_0 $tempdir/pvcsf_struct #indicate that it is in structural space! + imcp ${fastsrc}_pve_1 $tempdir/pvgm_struct + imcp ${fastsrc}_pve_2 $tempdir/pvwm_struct - $FSLDIR/bin/imcp ${fastsrc}_bias $tempdir/biasfield_struct + imcp ${fastsrc}_bias $tempdir/biasfield_struct fi # some useful preproc to do with FAST outputs if [ ! -z $fasthasrun ]; then # create a tissseg (wmseg) image for BBR in asl_reg - $FSLDIR/bin/fslmaths $tempdir/pvwm_struct -thr 0.5 -bin ${tempdir}/tissseg + fslmaths $tempdir/pvwm_struct -thr 0.5 -bin ${tempdir}/tissseg # transform the bias field and invert to use for sensitivity correction in calibration - ${FSLDIR}/bin/applywarp --ref=$tempdir/asldata --in=$tempdir/biasfield_struct --out=$tempdir/biasfield --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 + applywarp --ref=$tempdir/asldata --in=$tempdir/biasfield_struct --out=$tempdir/biasfield --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 if [ ! -z $senscorr ]; then - ${FSLDIR}/bin/fslmaths $tempdir/biasfield -recip $outdir/native_space/sensitivity + fslmaths $tempdir/biasfield -recip $outdir/native_space/sensitivity fi fi @@ -1272,32 +1277,32 @@ echo "Creating mask" Log "Automatic mask generation" # preferred option is to use brain extracted structural if [ ! -z $struc ]; then - ${FSLDIR}/bin/fslmaths $tempdir/struc_bet -bin $tempdir/struc_bet_mask - ${FSLDIR}/bin/flirt -in $tempdir/struc_bet_mask -ref $regfrom -applyxfm -init $tempdir/struct2asl.mat -out $tempdir/mask -interp trilinear - ${FSLDIR}/bin/fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask - ${FSLDIR}/bin/fslcpgeom $regfrom $tempdir/mask + fslmaths $tempdir/struc_bet -bin $tempdir/struc_bet_mask + flirt -in $tempdir/struc_bet_mask -ref $regfrom -applyxfm -init $tempdir/struct2asl.mat -out $tempdir/mask -interp trilinear + fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask + fslcpgeom $regfrom $tempdir/mask # otherwise use the regfrom image (should already be BETed) - note that regfrom may have been set in the Registration (1/2) section. elif [ ! -z $regfrom ]; then - ${FSLDIR}/bin/fslmaths $regfrom -bin $tempdir/mask + fslmaths $regfrom -bin $tempdir/mask Log "Mask generated from regfrom image: $regfrom" # We are unlikey to use these options as regfrom has probably been set above - leave for future reference # next option is to use betted version of mean M0 calib image as mask elif [ ! -z $calib ]; then - ${FSLDIR}/bin/bet $tempdir/calib $tempdir/calib_bet -f 0.2 - ${FSLDIR}/bin/fslmaths $tempdir/calib_bet -bin $tempdir/mask + bet $tempdir/calib $tempdir/calib_bet -f 0.2 + fslmaths $tempdir/calib_bet -bin $tempdir/mask Log "Mask generated from calibration image (post BET)" # use the low resolution strucutral image to create mask (ahould already be BETed) elif [ ! -z $lowstrucflag ]; then # resample - ${FSLDIR}/bin/flirt -in $tempdir/lowstruc -applyxfm -init $FSLDIR/etc/flirtsch/ident.mat -out $tempdir/mask -paddingsize 0.0 -interp trilinear -ref $tempdir/asldata + flirt -in $tempdir/lowstruc -applyxfm -init $FSLDIR/etc/flirtsch/ident.mat -out $tempdir/mask -paddingsize 0.0 -interp trilinear -ref $tempdir/asldata # make binary - ${FSLDIR}/bin/fslmaths $tempdir/mask -bin $tempdir/mask + fslmaths $tempdir/mask -bin $tempdir/mask Log "Mask generated from low res. structural" # otherwise just use mean time series else - ${FSLDIR}/bin/bet $tempdir/meanasl $tempdir/meanasl -f 0.2 # use a fairly low fraction value to avoid erosion - ${FSLDIR}/bin/fslmaths $tempdir/meanasl -bin $tempdir/mask + bet $tempdir/meanasl $tempdir/meanasl -f 0.2 # use a fairly low fraction value to avoid erosion + fslmaths $tempdir/meanasl -bin $tempdir/mask Log "Mask generated from mean time series" fi else @@ -1320,13 +1325,13 @@ if [ ! -z $fmap ]; then Registration $distbase "-m $tempdir/mask --tissseg $tempdir/tissseg --imat $tempdir/asl2struct.mat --finalonly" distcorr # generate the correction warp - ${FSLDIR}/bin/convertwarp -r $tempdir/meanasl -o $tempdir/asldist_warp -w $tempdir/distcorr/asl2struct_warp.nii.gz --postmat=$tempdir/distcorr/struct2asl.mat --rel -j $tempdir/distcorr/jacobian_parts - ${FSLDIR}/bin/fslmaths $tempdir/distcorr/jacobian_parts -Tmean $tempdir/distcorr/jacobian + convertwarp -r $tempdir/meanasl -o $tempdir/asldist_warp -w $tempdir/distcorr/asl2struct_warp.nii.gz --postmat=$tempdir/distcorr/struct2asl.mat --rel -j $tempdir/distcorr/jacobian_parts + fslmaths $tempdir/distcorr/jacobian_parts -Tmean $tempdir/distcorr/jacobian # Now apply the correction to the data. # note that we use the orignal data here and apply the motion correction as part of the process - ${FSLDIR}/bin/applywarp -i $tempdir/asldata_orig -r $tempdir/meanasl -o $tempdir/asldata --premat=$tempdir/asldata.cat -w $tempdir/asldist_warp --rel --interp=spline --paddingsize=1 - ${FSLDIR}/bin/fslmaths $tempdir/asldata -mul $tempdir/distcorr/jacobian $tempdir/asldata + applywarp -i $tempdir/asldata_orig -r $tempdir/meanasl -o $tempdir/asldata --premat=$tempdir/asldata.cat -w $tempdir/asldist_warp --rel --interp=spline --paddingsize=1 + fslmaths $tempdir/asldata -mul $tempdir/distcorr/jacobian $tempdir/asldata # Repeat the label-control subtraction on the corrected data if [ $iaf = 'diff' ]; then # make sure the block format is correct for BASIL @@ -1337,14 +1342,14 @@ if [ ! -z $fmap ]; then fi # Now apply the correction to the calibration image - ${FSLDIR}/bin/applywarp -i $tempdir/calib -r $tempdir/calib -o $tempdir/calib -w $tempdir/asldist_warp --rel --interp=spline --paddingsize=1 - ${FSLDIR}/bin/fslmaths $tempdir/calib -mul $tempdir/distcorr/jacobian $tempdir/calib + applywarp -i $tempdir/calib -r $tempdir/calib -o $tempdir/calib -w $tempdir/asldist_warp --rel --interp=spline --paddingsize=1 + fslmaths $tempdir/calib -mul $tempdir/distcorr/jacobian $tempdir/calib fi ### End of: Distortion Correction if [ ! -z $isen ]; then # place supplied sensitivity image in the right place (over writing the one from FAST if it exists) - ${FSLDIR}/bin/fslmaths $isen $outdir/native_space/sensitivity + fslmaths $isen $outdir/native_space/sensitivity fi # Defaults for (some) parameters @@ -1502,8 +1507,8 @@ if [ ! -z $noiseprior ]; then if [ -z $noisesd ]; then Log "Using SNR of $snr to set noise std dev" # estimate signal magntiude - ${FSLDIR}/bin/fslmaths $datafile -Tmax $tempdir/datamax - brain_mag=`${FSLDIR}/bin/fslstats $tempdir/datamax -k $tempdir/mask -M` + fslmaths $datafile -Tmax $tempdir/datamax + brain_mag=`fslstats $tempdir/datamax -k $tempdir/mask -M` # this will correspond to whole brain CBF (roughly) - about 0.5 of GM noisesd=`echo "scale=2;sqrt( $brain_mag * 2 / $snr )" | bc` fi @@ -1603,15 +1608,15 @@ fi if [ ! -z $fasthasrun ] && [ -z $pvgm ]; then # PVE in ASL space from strcutural segmentation results # invert the transformation matrix - ${FSLDIR}/bin/convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat + convert_xfm -omat $tempdir/struct2asl.mat -inverse $tempdir/asl2struct.mat # Gray matter - assume this will be PVE 1 - ${FSLDIR}/bin/applywarp --ref=$tempdir/asldata --in=$tempdir/pvgm_struct --out=$tempdir/pvgm_inasl --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 + applywarp --ref=$tempdir/asldata --in=$tempdir/pvgm_struct --out=$tempdir/pvgm_inasl --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 # white matter - assume this will be PVE 2 - ${FSLDIR}/bin/applywarp --ref=$tempdir/asldata --in=$tempdir/pvwm_struct --out=$tempdir/pvwm_inasl --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 + applywarp --ref=$tempdir/asldata --in=$tempdir/pvwm_struct --out=$tempdir/pvwm_inasl --premat=$tempdir/struct2asl.mat --super --interp=spline --superlevel=4 # threshold (upper and lower) the PVE to avoid artefacts of spline interpolation and also ignore very low PVE that could cause numerical issues. - ${FSLDIR}/bin/fslmaths $tempdir/pvgm_inasl -thr 0.1 -min 1 $tempdir/pvgm_inasl - ${FSLDIR}/bin/fslmaths $tempdir/pvwm_inasl -thr 0.1 -min 1 $tempdir/pvwm_inasl + fslmaths $tempdir/pvgm_inasl -thr 0.1 -min 1 $tempdir/pvgm_inasl + fslmaths $tempdir/pvwm_inasl -thr 0.1 -min 1 $tempdir/pvwm_inasl pvexist=1 fi @@ -1622,20 +1627,20 @@ if [ ! -z $pvgm ]; then echo "ERROR: no WM PV image has been supplied" fi Log "PV GM is: $pvgm" - ${FSLDIR}/bin/fslmaths $pvgm -thr 0.1 -min 1 $tempdir/pvgm_inasl + fslmaths $pvgm -thr 0.1 -min 1 $tempdir/pvgm_inasl Log "PV WM is: $pvwm" - ${FSLDIR}/bin/fslmaths $pvwm -thr 0.1 -min 1 $tempdir/pvwm_inasl + fslmaths $pvwm -thr 0.1 -min 1 $tempdir/pvwm_inasl pvexist=1 fi if [ ! -z $pvexist ]; then # make some masks # these are currently used for masking after model fitting - ${FSLDIR}/bin/fslmaths $tempdir/pvgm_inasl -thr 0.1 -bin $tempdir/gmmask - ${FSLDIR}/bin/fslmaths $tempdir/pvwm_inasl -thr 0.1 -bin $tempdir/wmmask + fslmaths $tempdir/pvgm_inasl -thr 0.1 -bin $tempdir/gmmask + fslmaths $tempdir/pvwm_inasl -thr 0.1 -bin $tempdir/wmmask # these are for calculating mean perfusion within tissue types - ${FSLDIR}/bin/fslmaths $tempdir/pvgm_inasl -thr 0.8 -bin $tempdir/gmmask_pure - ${FSLDIR}/bin/fslmaths $tempdir/pvwm_inasl -thr 0.9 -bin $tempdir/wmmask_pure + fslmaths $tempdir/pvgm_inasl -thr 0.8 -bin $tempdir/gmmask_pure + fslmaths $tempdir/pvwm_inasl -thr 0.9 -bin $tempdir/wmmask_pure fi ### End of: Partial Volume Estimates @@ -1694,17 +1699,17 @@ if [ ! -z $calib ]; then Log "Calibration is voxelwise" mkdir $outdir/calib # copy over the calibration image and apply the cgain setting - this increases the magntiude of M0 to match that of the ASL data (acquired with a higher gain - cgain>=1 normally) - ${FSLDIR}/bin/fslmaths $calib -mul $cgain $outdir/calib/M0 + fslmaths $calib -mul $cgain $outdir/calib/M0 Mo=$outdir/calib/M0 if [ 1 -eq `echo "$tr < 5" | bc` ]; then # correct the M0 image for short TR using the equation from the white paper Log "Correcting the calibration (M0) image for short TR (using T1 of tissue $t1tset)" ccorr=`echo "1 / (1 - e(- $tr / $t1tset) )" | bc -l` - ${FSLDIR}/bin/fslmaths $Mo -mul $ccorr $Mo + fslmaths $Mo -mul $ccorr $Mo fi #inlcude partiition co-effcient in M0 image to convert from M0 tissue to M0 arterial - ${FSLDIR}/bin/fslmaths $Mo -div 0.9 $Mo + fslmaths $Mo -div 0.9 $Mo # correct for (partial volume) edge effects # median smoothing and erosion @@ -1731,18 +1736,18 @@ fi Dooutput # save the mask used to the (native space) output directory -${FSLDIR}/bin/imcp $tempdir/mask $outdir/native_space/mask +imcp $tempdir/mask $outdir/native_space/mask ### End of: Output main BASIL results ### Partial Volume Correction BASIL if [ ! -z $pvcorr ]; then # redo the mask now that we have a better registration - as this might matter for PV correction # NB we dont use the PVE here since we dont (necessarily) want to exclude the ventricles from the mask as this has implications for the spatial priors - ${FSLDIR}/bin/fslmaths $tempdir/struc_bet -bin $tempdir/struc_bet_mask - ${FSLDIR}/bin/flirt -in $tempdir/struc_bet_mask -ref $regfrom -applyxfm -init $tempdir/struct2asl.mat -out $tempdir/mask -interp trilinear - ${FSLDIR}/bin/fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask - ${FSLDIR}/bin/fslcpgeom $regfrom $tempdir/mask - ${FSLDIR}/bin/imcp $tempdir/mask $outdir/native_space/mask_pvcorr # copy new mask to output directory - indicate that it was used for PV correction analysis + fslmaths $tempdir/struc_bet -bin $tempdir/struc_bet_mask + flirt -in $tempdir/struc_bet_mask -ref $regfrom -applyxfm -init $tempdir/struct2asl.mat -out $tempdir/mask -interp trilinear + fslmaths $tempdir/mask -thr 0.25 -bin -fillh $tempdir/mask + fslcpgeom $regfrom $tempdir/mask + imcp $tempdir/mask $outdir/native_space/mask_pvcorr # copy new mask to output directory - indicate that it was used for PV correction analysis # intructions for BASIL basil_options=$basil_options" --pgm $tempdir/pvgm_inasl --pwm $tempdir/pvwm_inasl " @@ -1751,7 +1756,7 @@ if [ ! -z $pvcorr ]; then # Run BASIL Dobasil $datafile $tempdir/pvcorr - ${FSLDIR}/bin/imcp $tempdir/pvcorr/finalMVN $tempdir/finalMVN #just in case we are about to do a epochwise analysis + imcp $tempdir/pvcorr/finalMVN $tempdir/finalMVN #just in case we are about to do a epochwise analysis #output the results Dooutput pvcorr @@ -1835,16 +1840,16 @@ fi if [ ! -z $pvcorr ]; then # copy PVE in ASL space to output directory -${FSLDIR}/bin/imcp $tempdir/pvgm_inasl $outdir/native_space/pvgm_inasl -${FSLDIR}/bin/imcp $tempdir/pvwm_inasl $outdir/native_space/pvwm_inasl +imcp $tempdir/pvgm_inasl $outdir/native_space/pvgm_inasl +imcp $tempdir/pvwm_inasl $outdir/native_space/pvwm_inasl fi if [ ! -z $pvexist ]; then # copy PV masks to output directory - ${FSLDIR}/bin/imcp $tempdir/gmmask $outdir/native_space/gm_mask - ${FSLDIR}/bin/imcp $tempdir/wmmask $outdir/native_space/wm_mask - ${FSLDIR}/bin/imcp $tempdir/gmmask_pure $outdir/native_space/gm_roi - ${FSLDIR}/bin/imcp $tempdir/wmmask_pure $outdir/native_space/wm_roi + imcp $tempdir/gmmask $outdir/native_space/gm_mask + imcp $tempdir/wmmask $outdir/native_space/wm_mask + imcp $tempdir/gmmask_pure $outdir/native_space/gm_roi + imcp $tempdir/wmmask_pure $outdir/native_space/wm_roi fi # clearup diff --git a/quasil.in b/quasil.in index 25b52cd..1672777 100644 --- a/quasil.in +++ b/quasil.in @@ -8,6 +8,11 @@ # # SHCOPYRIGHT +# Make script use local copies of helper scripts/programs in the same +# directory, if present. This allows for multiple versions of the scripts +# to be used, possibly with bundled dependencies +PATH=`dirname $0`:${FSLDIR}/bin:${PATH} + Usage() { echo "QUASAR Bayesian Inference for Arterial Spin Labelling MRI" echo "" @@ -89,7 +94,7 @@ done #### --- Procedural --- asl_file=asl_file -fabber=fabber +fabber=fabber_asl asl_mfree=asl_mfree ###~/cproject/asl_mfree/asl_mfree #### --- Housekeeping --- @@ -117,7 +122,7 @@ mkdir $outdir; stdir=`pwd` # make a temp directory to work in -tmpbase=`$FSLDIR/bin/tmpnam` +tmpbase=`tmpnam` tempdir=${tmpbase}_quasil mkdir $tempdir