Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For realizing how to utilize already quality checked masks #9

Open
wants to merge 16 commits into
base: utilize-masks
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DiffusionPreprocessing/DiffPreprocPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion DiffusionPreprocessing/scripts/eddy_pnl_repol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 14 additions & 15 deletions DiffusionPreprocessing/scripts/run_eddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
76 changes: 28 additions & 48 deletions DiffusionPreprocessing/scripts/run_topup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand All @@ -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
Expand Down