diff --git a/DiffusionPreprocessing/DiffPreprocPipeline.sh b/DiffusionPreprocessing/DiffPreprocPipeline.sh index 1cae0d4c0..fed795a3d 100755 --- a/DiffusionPreprocessing/DiffPreprocPipeline.sh +++ b/DiffusionPreprocessing/DiffPreprocPipeline.sh @@ -544,6 +544,14 @@ main() { log_Msg "eddy_cmd: ${eddy_cmd}" ${eddy_cmd} + echo """ + Observe the following output files in ${StudyFolder}/${Subject}: + dwi: Diffusion/eddy/eddy_unwarped_images.nii.gz + bvals: Diffusion/eddy/Pos_Neg.bvals + bvecs: Diffusion/eddy/eddy_unwarped_images.eddy_rotated_bvecs + mask: Diffusion/eddy/nodif_brain_mask.nii.gz + """ + exit log_Msg "Invoking Post-Eddy Steps" diff --git a/DiffusionPreprocessing/scripts/eddy_pnl_repol.py b/DiffusionPreprocessing/scripts/eddy_pnl_repol.py index da53a5f1b..4e5aebd9d 100755 --- a/DiffusionPreprocessing/scripts/eddy_pnl_repol.py +++ b/DiffusionPreprocessing/scripts/eddy_pnl_repol.py @@ -43,7 +43,7 @@ def main(): if '--repol' in eddy_openmp_params and len(ind): print('\nDoing eddy_openmp/cuda again without --repol option ' - 'to obtain eddy correction w/o outlier replacement for b<=500 shells\n') + f'to obtain eddy correction w/o outlier replacement for b<={REPOL_BSHELL_GREATER} shells\n') eddy_openmp_params.remove('--repol') print(eddy_openmp_params) diff --git a/DiffusionPreprocessing/scripts/run_eddy.sh b/DiffusionPreprocessing/scripts/run_eddy.sh index 98a685fe3..122727c2f 100755 --- a/DiffusionPreprocessing/scripts/run_eddy.sh +++ b/DiffusionPreprocessing/scripts/run_eddy.sh @@ -626,25 +626,24 @@ main() { # remove rawdata and release space rm -r ${workingdir}/../rawdata - # remove intensity normalized data - # rm ${workingdir}/Pos* - # rm ${workingdir}/Neg* - # Redoing eddy without --repol flag to obtain not outlier replaced <=500 bshell if [ ! -z "${extra_eddy_args}" ]; then - for extra_eddy_arg in ${extra_eddy_args}; do + for extra_eddy_arg in ${extra_eddy_args}; do + + if [ $extra_eddy_arg = '--repol' ]; then + log_Msg "Redoing eddy without --repol flag to obtain not outlier replaced b<=550 shells" + eddy_command="${HCPPIPEDIR}/DiffusionPreprocessing/scripts/eddy_pnl_repol.py ${eddy_command}" + log_Msg "${eddy_command}" + ${eddy_command} + eddyReturnValue=$? + log_Msg "Completed with return value: ${eddyReturnValue}" + fi - if [ $extra_eddy_arg = '--repol' ]; then - log_Msg "Redoing eddy without --repol flag to obtain not outlier replaced b<=500 shells" - eddy_command="${HCPPIPEDIR}/DiffusionPreprocessing/scripts/eddy_pnl_repol.py ${eddy_command}" - log_Msg "${eddy_command}" - ${eddy_command} - eddyReturnValue=$? - log_Msg "Completed with return value: ${eddyReturnValue}" - fi + done + fi - done - fi + # remove intensity normalized data + rm ${workingdir}/Pos_Neg.nii.gz exit ${eddyReturnValue} diff --git a/DiffusionPreprocessing/scripts/run_topup.sh b/DiffusionPreprocessing/scripts/run_topup.sh index 27945383d..0ecdfa2a5 100755 --- a/DiffusionPreprocessing/scripts/run_topup.sh +++ b/DiffusionPreprocessing/scripts/run_topup.sh @@ -14,16 +14,16 @@ ${FSLDIR}/bin/topup --imain=${workingdir}/Pos_Neg_b0 --datain=${workingdir}/acqp dimt=$(${FSLDIR}/bin/fslval ${workingdir}/Pos_b0 dim4) dimt=$((${dimt} + 1)) -# echo "Applying topup to get a hifi b0" -# ${FSLDIR}/bin/fslroi ${workingdir}/Pos_b0 ${workingdir}/Pos_b01 0 1 -# ${FSLDIR}/bin/fslroi ${workingdir}/Neg_b0 ${workingdir}/Neg_b01 0 1 -# ${FSLDIR}/bin/applytopup --imain=${workingdir}/Pos_b01,${workingdir}/Neg_b01 --topup=${workingdir}/topup_Pos_Neg_b0 --datain=${workingdir}/acqparams.txt --inindex=1,${dimt} --out=${workingdir}/hifib0 -# -# if [ ! -f ${workingdir}/hifib0.nii.gz ]; then -# echo "run_topup.sh -- ERROR -- ${FSLDIR}/bin/applytopup failed to generate ${workingdir}/hifib0.nii.gz" -# # Need to add mechanism whereby scripts that invoke this script (run_topup.sh) -# # check for a return code to determine success or failure -# fi +echo "Applying topup to get a hifi b0" +${FSLDIR}/bin/fslroi ${workingdir}/Pos_b0 ${workingdir}/Pos_b01 0 1 +${FSLDIR}/bin/fslroi ${workingdir}/Neg_b0 ${workingdir}/Neg_b01 0 1 +${FSLDIR}/bin/applytopup --imain=${workingdir}/Pos_b01,${workingdir}/Neg_b01 --topup=${workingdir}/topup_Pos_Neg_b0 --datain=${workingdir}/acqparams.txt --inindex=1,${dimt} --out=${workingdir}/hifib0 + +if [ ! -f ${workingdir}/hifib0.nii.gz ]; then + echo "run_topup.sh -- ERROR -- ${FSLDIR}/bin/applytopup failed to generate ${workingdir}/hifib0.nii.gz" + # Need to add mechanism whereby scripts that invoke this script (run_topup.sh) + # check for a return code to determine success or failure +fi ${FSLDIR}/bin/imrm ${workingdir}/Pos_b0* @@ -32,49 +32,29 @@ ${FSLDIR}/bin/imrm ${workingdir}/Neg_b0* # echo "Running BET on the hifi b0" # ${FSLDIR}/bin/bet ${workingdir}/hifib0 ${workingdir}/nodif_brain -m -f 0.2 -# echo "Applying PNL invented CNN masking tool to obtain b0 brain mask" -# cnn_mask_exe=`which dwi_masking.py` -# if [ ! -z $cnn_mask_exe ]; then -# echo "CNN-Diffusion-MRIBrain-Segmentation/pipeline/dwi_masking.py is not available in PATH" -# exit 1 -# fi -# -# # TODO -# $cnn_mask_exe -i ${workingdir}/hifib0 -f $(dirname $cnn_mask_exe)/../model_folder -o ${workingdir}/nodif_brain - - -# define the masks in PA,AP order (pos,neg) -# obtain 107 masks -IFS=' ' read -ra masks_107 <<< $MASKS_107 -${FSLDIR}/bin/applytopup --imain=${masks_107[0]},${masks_107[1]} --topup=${workingdir}/topup_Pos_Neg_b0 --datain=${workingdir}/acqparams.txt --inindex=1,${dimt} --out=${workingdir}/mask_107 --verbose --method=jac --interp=trilinear - -# obtain 99 masks -IFS=' ' read -ra masks_99 <<< $MASKS_99 -${FSLDIR}/bin/applytopup --imain=${masks_99[0]},${masks_99[1]} --topup=${workingdir}/topup_Pos_Neg_b0 --datain=${workingdir}/acqparams.txt --inindex=1,${dimt} --out=${workingdir}/mask_99 --verbose --method=jac --interp=trilinear - -# take their union -pushd . -cd ${workingdir} - -fslmaths mask_107 -abs mask_107 -fslmaths mask_99 -abs mask_99 -fslmaths mask_107 -add mask_99 nodif_brain_mask -odt char -fslmaths nodif_brain_mask -bin nodif_brain_mask - -# filter the resultant mask -if [ -z `which maskfilter.py` ]; then - echo "pnlNipype/scripts/maskfilter.py is not available in PATH" +echo "Applying PNL invented CNN masking tool to obtain b0 brain mask" +cnn_mask_exe=`which dwi_masking.py` +if [ -z $cnn_mask_exe ]; then + echo "CNN-Diffusion-MRIBrain-Segmentation/pipeline/dwi_masking.py is not available in PATH" exit 1 fi -# maskfilter.py nodif_brain.nii.gz 2 nodif_brain.nii.gz - -${FSLDIR}/bin/imrm ${workingdir}/mask_107 -${FSLDIR}/bin/imrm ${workingdir}/mask_99 +pushd . +cd ${workingdir} +listpre=b0_list +realpath hifib0.nii.gz > ${listpre}.txt +$cnn_mask_exe -i ${listpre}.txt +# rename +mv hifib0_bse-multi_BrainMask.nii.gz nodif_brain_mask.nii.gz +# cleanup +rm ${listpre}* +rm *_cases_* +rm -r slicesdir_multi/ popd -if [ ! -f ${workingdir}/nodif_brain.nii.gz ]; then - echo "run_topup.sh -- ERROR -- ${FSLDIR}/bin/bet failed to generate ${workingdir}/nodif_brain.nii.gz" + +if [ ! -f ${workingdir}/nodif_brain_mask.nii.gz ]; then + echo "run_topup.sh -- ERROR -- CNN-Diffusion-MRIBrain-Segmentation/pipeline/dwi_masking.py failed to generate ${workingdir}/nodif_brain_mask.nii.gz" # Need to add mechanism whereby scripts that invoke this script (run_topup.sh) # check for a return code to determine success or failure fi