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

PostFreeSurfer related pull request #135

Merged
merged 23 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cc5ab4a
FreeSurfer2CaretConvertAndRegisterNonlinear.sh related changes
sivcek Sep 27, 2019
4119999
`FreeSurfer2CaretConvertAndRegisterNonlinear_1res.sh related changes
sivcek Sep 27, 2019
598cbc2
PostFreeSurferPipeline_1res.sh
sivcek Sep 27, 2019
4fc5c23
PostFreeSurferPipeline.sh related changes
sivcek Sep 27, 2019
5a56f68
Adjusted MPP compliance checking.
sivcek Oct 2, 2019
92716a2
Added verbose_echo.
sivcek Oct 2, 2019
f85aac0
Avoided skipping CreateMyelinMaps.sh and added checks for what can no…
sivcek Oct 3, 2019
503868d
Corrected variable reporting.
sivcek Oct 7, 2019
077793d
Simplified T2w conditional execution and added it to adding CIFTI Map…
sivcek Oct 7, 2019
53a9b87
Moved -mpp-mode parameter reading and reporting.
sivcek Oct 8, 2019
40fb987
Simplified T2w related checks code placement.
sivcek Oct 8, 2019
14d154b
Changed parameter reading and defaults setting position.
sivcek Oct 8, 2019
274b2a4
Split conceptually # Create T1w/T2w maps using if/fi statements.
sivcek Oct 8, 2019
39498c8
Simplified code.
sivcek Oct 8, 2019
58e0d72
Implemented new naming convention and added warring when using FS for…
sivcek Oct 9, 2019
ee14852
Changed environment var reporting and fixed log_Warn.
sivcek Oct 10, 2019
adb0706
Simplified lists in CreateMyelin maps further.
sivcek Oct 10, 2019
33165d4
Fixed STRINGList and reporting with spaces.
sivcek Oct 11, 2019
b8e66cd
Changed the warning.
sivcek Oct 11, 2019
634ecbd
Changed default from FS to MSMSulc
sivcek Oct 12, 2019
845fd46
In both scripts.
sivcek Oct 12, 2019
9785189
Using variable to report script started / finished in verbose_echo.
sivcek Oct 12, 2019
d2e9c8a
In both scripts.
sivcek Oct 12, 2019
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
68 changes: 59 additions & 9 deletions PostFreeSurfer/PostFreeSurferPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ set -e
script_name=$(basename "${0}")

if [ -z "${HCPPIPEDIR}" ]; then
echo "${script_name}: ABORTING: HCPPIPEDIR environment variable must be set"
exit 1
echo "${script_name}: ABORTING: HCPPIPEDIR environment variable must be set"
exit 1
else
echo "${script_name}: HCPPIPEDIR: ${HCPPIPEDIR}"
echo "${script_name}: HCPPIPEDIR: ${HCPPIPEDIR}"
fi

if [ -z "${HCPPIPEDIR_PostFS}" ]; then
echo "${script_name}: ABORTING: HCPPIPEDIR_PostFS environment variable must be set"
exit 1
echo "${script_name}: ABORTING: HCPPIPEDIR_PostFS environment variable must be set"
exit 1
else
echo "${script_name}: HCPPIPEDIR_PostFS: ${HCPPIPEDIR_PostFS}"
echo "${script_name}: HCPPIPEDIR_PostFS: ${HCPPIPEDIR_PostFS}"
fi

########################################## PIPELINE OVERVIEW ##########################################
Expand All @@ -37,8 +37,9 @@ fi
# Load Function Libraries
# --------------------------------------------------------------------------------

source $HCPPIPEDIR/global/scripts/log.shlib # Logging related functions
source $HCPPIPEDIR/global/scripts/opts.shlib # Command line option functions
source ${HCPPIPEDIR}/global/scripts/log.shlib # Logging related functions
source ${HCPPIPEDIR}/global/scripts/opts.shlib # Command line option functions
source ${HCPPIPEDIR}/global/scripts/processingmodecheck.shlib # Checking processing mode compliance

########################################## SUPPORT FUNCTIONS ##########################################

Expand Down Expand Up @@ -80,16 +81,39 @@ ReferenceMyelinMaps=`opts_GetOpt1 "--refmyelinmaps" $@`
CorrectionSigma=`opts_GetOpt1 "--mcsigma" $@`
RegName=`opts_GetOpt1 "--regname" $@`
InflateExtraScale=`opts_GetOpt1 "--inflatescale" $@`
ProcessingMode=`opts_GetOpt1 "--processing-mode" $@`

log_Msg "RegName: ${RegName}"

# default parameters
CorrectionSigma=`opts_DefaultOpt $CorrectionSigma $(echo "sqrt ( 200 )" | bc -l)`
RegName=`opts_DefaultOpt $RegName FS`
InflateExtraScale=`opts_DefaultOpt $InflateExtraScale 1`
ProcessingMode=`opts_DefaultOpt $ProcessingMode "HCPStyleData"`

PipelineScripts=${HCPPIPEDIR_PostFS}

verbose_red_echo "---> Starting Post FreeSurfer Pipeline"
verbose_echo " "
verbose_echo " Using parameters ..."
verbose_echo " --path: ${StudyFolder}"
verbose_echo " --subject: ${Subject}"
verbose_echo " --surfatlasdir: ${SurfaceAtlasDIR}"
verbose_echo " --grayordinatesdir: ${GrayordinatesSpaceDIR}"
verbose_echo " --grayordinatesres: ${GrayordinatesResolutions}"
verbose_echo " --hiresmesh: ${HighResMesh}"
verbose_echo " --lowresmesh: ${LowResMeshes}"
verbose_echo " --subcortgraylabels: ${SubcorticalGrayLabels}"
verbose_echo " --freesurferlabels: ${FreeSurferLabels}"
verbose_echo " --refmyelinmaps: ${ReferenceMyelinMaps}"
verbose_echo " --mcsigma: ${CorrectionSigma}"
verbose_echo " --regname: ${RegName}"
verbose_echo " --processing-mode: ${ProcessingMode}"
verbose_echo ""
verbose_echo " Using environment setting ..."
verbose_echo " HCPPIPEDIR_PostFS: ${PipelineScripts}"
verbose_echo " "

#Naming Conventions
# Do NOT include spaces in any of these names
T1wImage="T1w_acpc_dc"
Expand Down Expand Up @@ -141,6 +165,29 @@ FreeSurferFolder="$T1wFolder"/"$FreeSurferFolder"
AtlasTransform="$AtlasSpaceFolder"/xfms/"$AtlasTransform"
InverseAtlasTransform="$AtlasSpaceFolder"/xfms/"$InverseAtlasTransform"


# ------------------------------------------------------------------------------
# Compliance check
# ------------------------------------------------------------------------------

Compliance="HCPStyleData"
ComplianceMsg=""

# -- T2w image

if [ `${FSLDIR}/bin/imtest ${T2wFolder}/T2w` -eq 0 ]; then
ComplianceMsg+=" T2w image not present"
Compliance="LegacyStyleData"
T2wRestoreImage="NONE"
fi

if [ "${RegName}" = "FS" ] ; then
logWarn "WARNING: FreeSurfer registration is deprecated in the HCP Pipelines as it results in poorer cross-subject functional and cortical areal alignment relative to MSMSulc. Additionally, FreeSurfer registration results in dramatically higher surface distortion (both isotropic and anisotropic). These things occur because FreeSurfer's registration has too little regularizattion of folding patterns that are imperfectly correlated with function and cortical areas, resulting in overfitting of folding patterns. See Robinson et al 2014, 2018 Neuroimage, and Coalson et al 2018 PNAS for more details."
sivcek marked this conversation as resolved.
Show resolved Hide resolved
fi

check_mode_compliance "${ProcessingMode}" "${Compliance}" "${ComplianceMsg}"


#Conversion of FreeSurfer Volumes and Surfaces to NIFTI and GIFTI and Create Caret Files and Registration
log_Msg "Conversion of FreeSurfer Volumes and Surfaces to NIFTI and GIFTI and Create Caret Files and Registration"
log_Msg "RegName: ${RegName}"
Expand Down Expand Up @@ -184,7 +231,6 @@ argList+="$T1wRestoreImage " # ${7} Called T1wImage in CreateRibbon.s
argList+="$FreeSurferLabels " # ${8}
"$PipelineScripts"/CreateRibbon.sh ${argList}


#Myelin Mapping
log_Msg "Myelin Mapping"
log_Msg "RegName: ${RegName}"
Expand Down Expand Up @@ -230,4 +276,8 @@ argList+="$CorrectionSigma "
argList+="$RegName " # ${39}
"$PipelineScripts"/CreateMyelinMaps.sh ${argList}

verbose_green_echo "---> Finished Post FreeSurfer Pipeline"
sivcek marked this conversation as resolved.
Show resolved Hide resolved
verbose_echo " "

log_Msg "Completed"

66 changes: 58 additions & 8 deletions PostFreeSurfer/PostFreeSurferPipeline_1res.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ set -e
script_name=$(basename "${0}")

if [ -z "${HCPPIPEDIR}" ]; then
echo "${script_name}: ABORTING: HCPPIPEDIR environment variable must be set"
exit 1
echo "${script_name}: ABORTING: HCPPIPEDIR environment variable must be set"
exit 1
else
echo "${script_name}: HCPPIPEDIR: ${HCPPIPEDIR}"
echo "${script_name}: HCPPIPEDIR: ${HCPPIPEDIR}"
fi

if [ -z "${HCPPIPEDIR_PostFS}" ]; then
echo "${script_name}: ABORTING: HCPPIPEDIR_PostFS environment variable must be set"
exit 1
echo "${script_name}: ABORTING: HCPPIPEDIR_PostFS environment variable must be set"
exit 1
else
echo "${script_name}: HCPPIPEDIR_PostFS: ${HCPPIPEDIR_PostFS}"
echo "${script_name}: HCPPIPEDIR_PostFS: ${HCPPIPEDIR_PostFS}"
fi

########################################## PIPELINE OVERVIEW ##########################################
Expand All @@ -37,8 +37,9 @@ fi
# Load Function Libraries
# --------------------------------------------------------------------------------

source $HCPPIPEDIR/global/scripts/log.shlib # Logging related functions
source $HCPPIPEDIR/global/scripts/opts.shlib # Command line option functions
source ${HCPPIPEDIR}/global/scripts/log.shlib # Logging related functions
source ${HCPPIPEDIR}/global/scripts/opts.shlib # Command line option functions
source ${HCPPIPEDIR}/global/scripts/processingmodecheck.shlib # Checking processing mode compliance

########################################## SUPPORT FUNCTIONS ##########################################

Expand Down Expand Up @@ -80,15 +81,37 @@ ReferenceMyelinMaps=`opts_GetOpt1 "--refmyelinmaps" $@`
CorrectionSigma=`opts_GetOpt1 "--mcsigma" $@`
RegName=`opts_GetOpt1 "--regname" $@`
InflateExtraScale=`opts_GetOpt1 "--inflatescale" $@`
ProcessingMode=`opts_GetOpt1 "--processing-mode" $@`

log_Msg "RegName: ${RegName}"
# default parameters
CorrectionSigma=`opts_DefaultOpt $CorrectionSigma $(echo "sqrt ( 200 )" | bc -l)`
RegName=`opts_DefaultOpt $RegName FS`
InflateExtraScale=`opts_DefaultOpt $InflateExtraScale 1`
ProcessingMode=`opts_DefaultOpt $ProcessingMode "HCPStyleData"`

PipelineScripts=${HCPPIPEDIR_PostFS}

verbose_red_echo "---> Starting Post FreeSurfer Pipeline 1res"
verbose_echo " "
verbose_echo " Using parameters ..."
verbose_echo " --path: ${StudyFolder}"
verbose_echo " --subject: ${Subject}"
verbose_echo " --surfatlasdir: ${SurfaceAtlasDIR}"
verbose_echo " --grayordinatesdir: ${GrayordinatesSpaceDIR}"
verbose_echo " --grayordinatesres: ${GrayordinatesResolutions}"
verbose_echo " --hiresmesh: ${HighResMesh}"
verbose_echo " --lowresmesh: ${LowResMeshes}"
verbose_echo " --subcortgraylabels: ${SubcorticalGrayLabels}"
verbose_echo " --freesurferlabels: ${FreeSurferLabels}"
verbose_echo " --refmyelinmaps: ${ReferenceMyelinMaps}"
verbose_echo " --mcsigma: ${CorrectionSigma}"
verbose_echo " --regname: ${RegName}"
verbose_echo " --processing-mode: ${ProcessingMode}"
verbose_echo " "
verbose_echo " Using environment setting ..."
verbose_echo " HCPPIPEDIR_PostFS: ${PipelineScripts}"

#Naming Conventions
# Do NOT include spaces in any of these names
T1wImage="T1w_acpc_dc"
Expand Down Expand Up @@ -140,6 +163,30 @@ FreeSurferFolder="$T1wFolder"/"$FreeSurferFolder"
AtlasTransform="$AtlasSpaceFolder"/xfms/"$AtlasTransform"
InverseAtlasTransform="$AtlasSpaceFolder"/xfms/"$InverseAtlasTransform"


# ------------------------------------------------------------------------------
# Compliance check
# ------------------------------------------------------------------------------

Compliance="HCPStyleData"
ComplianceMsg=""

# -- T2w image

if [ `${FSLDIR}/bin/imtest ${T2wFolder}/T2w` -eq 0 ]; then
ComplianceMsg+=" T2w image not present"
Compliance="LegacyStyleData"
T2wRestoreImage="NONE"
fi

if [ "${RegName}" = "FS" ] ; then
logWarn "WARNING: FreeSurfer registration is deprecated in the HCP Pipelines as it results in poorer cross-subject functional and cortical areal alignment relative to MSMSulc. Additionally, FreeSurfer registration results in dramatically higher surface distortion (both isotropic and anisotropic). These things occur because FreeSurfer's registration has too little regularizattion of folding patterns that are imperfectly correlated with function and cortical areas, resulting in overfitting of folding patterns. See Robinson et al 2014, 2018 Neuroimage, and Coalson et al 2018 PNAS for more details."
sivcek marked this conversation as resolved.
Show resolved Hide resolved
fi

check_mode_compliance "${ProcessingMode}" "${Compliance}" "${ComplianceMsg}"



#Conversion of FreeSurfer Volumes and Surfaces to NIFTI and GIFTI and Create Caret Files and Registration
log_Msg "Conversion of FreeSurfer Volumes and Surfaces to NIFTI and GIFTI and Create Caret Files and Registration"
log_Msg "RegName: ${RegName}"
Expand Down Expand Up @@ -215,4 +262,7 @@ argList+="$CorrectionSigma "
argList+="$RegName " # ${39}
"$PipelineScripts"/CreateMyelinMaps_1res.sh ${argList}

verbose_green_echo "---> Finished Post FreeSurfer Pipeline 1res"
verbose_echo " "

log_Msg "Completed"
Loading