dHCP_neo_dMRI_runPostProc.sh 3.06 KB
Newer Older
Matteo Bastiani's avatar
Matteo Bastiani committed
1 2 3 4 5
#!/bin/bash
set -e
echo -e "\n START: runPostProc"


6 7
subFolder=$1
srFlag=$2
Matteo Bastiani's avatar
Matteo Bastiani committed
8 9
qcFlag=$3

10 11
rawFolder=${subFolder}/raw
prepFolder=${subFolder}/PreProcessed
Matteo Bastiani's avatar
Matteo Bastiani committed
12
eddyFolder=${prepFolder}/eddy
13
diffFolder=${subFolder}/Diffusion
Matteo Bastiani's avatar
Matteo Bastiani committed
14

15
if [ "${qcFlag}" -eq "1" ]; then
Matteo Bastiani's avatar
Matteo Bastiani committed
16 17 18 19
    mkdir -p ${prepFolder}/QC
fi
mkdir -p ${diffFolder}

20

Matteo Bastiani's avatar
Matteo Bastiani committed
21 22 23 24
#============================================================================
# Remove negative intensity values (caused by spline interpolation) from 
# pre-processed data. Copy bvals and (rotated) bvecs to the Diffusion folder.
#============================================================================
25 26 27 28 29 30 31
if [ "${srFlag}" -eq "1" ]; then
    ${FSLDIR}/bin/fslmaths ${eddyFolder}/data_sr -thr 0 ${diffFolder}/data
    rm ${eddyFolder}/data_sr.*
else
    ${FSLDIR}/bin/fslmaths ${eddyFolder}/eddy_corrected -thr 0 ${diffFolder}/data
fi
cp ${rawFolder}/bvals ${diffFolder}/bvals
Matteo Bastiani's avatar
Matteo Bastiani committed
32 33
cp ${eddyFolder}/eddy_corrected.eddy_rotated_bvecs ${diffFolder}/bvecs

34

Matteo Bastiani's avatar
Matteo Bastiani committed
35 36 37 38 39
#============================================================================
# Get the brain mask using BET, average shell data and attenuation profiles.
# Fit diffusion tensor to each shell separately. If interested in qc, store
# volumes and variances.
#============================================================================
40
uniqueBvals=(`cat ${rawFolder}/shells`)
Matteo Bastiani's avatar
Matteo Bastiani committed
41 42 43
for b in "${uniqueBvals[@]}"; do
    ${FSLDIR}/bin/select_dwi_vols ${diffFolder}/data ${diffFolder}/bvals ${diffFolder}/mean_b${b} ${b} -m
    if [ ${qcFlag} -eq 1 ]; then
44 45
	    ${FSLDIR}/bin/select_dwi_vols ${diffFolder}/data ${diffFolder}/bvals ${prepFolder}/QC/vols_b${b} ${b}
	    ${FSLDIR}/bin/select_dwi_vols ${diffFolder}/data ${diffFolder}/bvals ${prepFolder}/QC/var_b${b} ${b} -v
Matteo Bastiani's avatar
Matteo Bastiani committed
46 47
    fi
    if [ ${b} -eq 0 ]; then
48
	    ${FSLDIR}/bin/bet ${diffFolder}/mean_b${b} ${diffFolder}/nodif_brain -m -f 0.25 -R
Matteo Bastiani's avatar
Matteo Bastiani committed
49
    else
50 51 52 53 54
        echo "Fitting DT to b=${b} shell..."
        mkdir -p ${diffFolder}/dtifit_b${b}
        ${FSLDIR}/bin/select_dwi_vols ${diffFolder}/data ${diffFolder}/bvals ${diffFolder}/dtifit_b${b}/b${b} 0 -b ${b} -obv ${diffFolder}/bvecs 
        ${FSLDIR}/bin/dtifit -k ${diffFolder}/dtifit_b${b}/b${b} -o ${diffFolder}/dtifit_b${b}/dti -m ${diffFolder}/nodif_brain_mask -r ${diffFolder}/dtifit_b${b}/b${b}.bvec -b ${diffFolder}/dtifit_b${b}/b${b}.bval --sse --save_tensor
        ${FSLDIR}/bin/fslmaths ${diffFolder}/mean_b${b} -div ${diffFolder}/mean_b0 -mul ${diffFolder}/nodif_brain_mask ${diffFolder}/att_b${b}
Matteo Bastiani's avatar
Matteo Bastiani committed
55 56 57 58
    fi
    ${FSLDIR}/bin/fslmaths ${diffFolder}/mean_b${b} -mul ${diffFolder}/nodif_brain_mask ${diffFolder}/mean_b${b}
done

59

Matteo Bastiani's avatar
Matteo Bastiani committed
60 61 62
#============================================================================
# Fit Kurtosis model.
#============================================================================
63 64 65 66 67
if [ `echo ${#uniqueBvals[@]}` -gt 2 ]; then
    echo "Multi-shell data: fitting DK to all shells..."
    mkdir -p ${diffFolder}/dkifit
    ${FSLDIR}/bin/dtifit -k ${diffFolder}/data -o ${diffFolder}/dkifit/dki -m ${diffFolder}/nodif_brain_mask -r ${diffFolder}/bvecs -b ${diffFolder}/bvals --sse --save_tensor --kurt --kurtdir
fi
Matteo Bastiani's avatar
Matteo Bastiani committed
68 69 70 71


echo -e "\n END: runPostProc"