From a50375f9073bbeafcd80e423a2b23eed10c753ff Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Sat, 7 Dec 2024 19:11:30 -0600 Subject: [PATCH 1/9] *Initial Commit of HippUnfoldHCP and PostHippUnfoldHCP, tested but preliminary and is CERTAIN TO CHANGE including file organization given additional Connectome Workbench features needed, HippUnfold bugs discovered and further development and optimization needed. --- Examples/Scripts/RunHippUnfoldHCP.sh | 94 +++++++ Examples/Scripts/RunPostHippUnfoldHCP.sh | 94 +++++++ HippUnfoldHCP/HippUnfoldHCP.sh | 102 +++++++ HippUnfoldHCP/PostHippUnfoldHCP.sh | 271 +++++++++++++++++++ HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m | 7 + global/config/HippUnfoldLut.txt | 33 +++ 6 files changed, 601 insertions(+) create mode 100755 Examples/Scripts/RunHippUnfoldHCP.sh create mode 100755 Examples/Scripts/RunPostHippUnfoldHCP.sh create mode 100755 HippUnfoldHCP/HippUnfoldHCP.sh create mode 100755 HippUnfoldHCP/PostHippUnfoldHCP.sh create mode 100644 HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m create mode 100644 global/config/HippUnfoldLut.txt diff --git a/Examples/Scripts/RunHippUnfoldHCP.sh b/Examples/Scripts/RunHippUnfoldHCP.sh new file mode 100755 index 000000000..cfbd871c1 --- /dev/null +++ b/Examples/Scripts/RunHippUnfoldHCP.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +get_batch_options() { + local arguments=("$@") + + command_line_specified_study_folder="" + command_line_specified_subject="" + command_line_specified_run_local="FALSE" + + local index=0 + local numArgs=${#arguments[@]} + local argument + + while [ ${index} -lt ${numArgs} ]; do + argument=${arguments[index]} + + case ${argument} in + --StudyFolder=*) + command_line_specified_study_folder=${argument#*=} + index=$(( index + 1 )) + ;; + --Subject=*) + command_line_specified_subject=${argument#*=} + index=$(( index + 1 )) + ;; + --runlocal) + command_line_specified_run_local="TRUE" + index=$(( index + 1 )) + ;; + *) + echo "" + echo "ERROR: Unrecognized Option: ${argument}" + echo "" + exit 1 + ;; + esac + done +} + +get_batch_options "$@" + +StudyFolder="${HOME}/projects/Pipelines_ExampleData" #Location of Subject folders (named by SubjectID) +Subjlist="100307 100610" #Space delimited list of subject IDs +EnvironmentScript="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" #Pipeline environment script + +if [ -n "${command_line_specified_study_folder}" ]; then + StudyFolder="${command_line_specified_study_folder}" +fi + +if [ -n "${command_line_specified_subject}" ]; then + Subjlist="${command_line_specified_subject}" +fi + +#Set up pipeline environment variables and software +source "$EnvironmentScript" + +# Log the originating call +echo "$@" + +#NOTE: syntax for QUEUE has changed compared to earlier pipeline releases, +#DO NOT include "-q " at the beginning +#default to no queue, implying run local +QUEUE="" +#QUEUE="hcp_priority.q" + +########################################## INPUTS ########################################## + +#Scripts called by this script do assume they run on the outputs of the PostFreeSurfer Pipeline + +######################################### DO WORK ########################################## + +for Subject in $Subjlist ; do + echo $Subject + + if [[ "${command_line_specified_run_local}" == "TRUE" || "$QUEUE" == "" ]] ; then + echo "About to locally run ${HCPPIPEDIR}/HippUnfoldHCP/HippUnfoldHCP.sh" + queuing_command=("$HCPPIPEDIR"/global/scripts/captureoutput.sh) + else + echo "About to use fsl_sub to queue ${HCPPIPEDIR}/HippUnfoldHCP/HippUnfoldHCP.sh" + queuing_command=("$FSLDIR/bin/fsl_sub" -q "$QUEUE") + fi + + "${queuing_command[@]}" "$HCPPIPEDIR"/HippUnfoldHCP/HippUnfoldHCP.sh \ + --study-folder="$StudyFolder" \ + --subject="$Subject" \ + + # The following lines are used for interactive debugging to set the positional parameters: $1 $2 $3 ... + + echo "set -- --study-folder=$StudyFolder \ + --subject=$Subject" \ + + echo ". ${EnvironmentScript}" + +done diff --git a/Examples/Scripts/RunPostHippUnfoldHCP.sh b/Examples/Scripts/RunPostHippUnfoldHCP.sh new file mode 100755 index 000000000..b7134559a --- /dev/null +++ b/Examples/Scripts/RunPostHippUnfoldHCP.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +get_batch_options() { + local arguments=("$@") + + command_line_specified_study_folder="" + command_line_specified_subject="" + command_line_specified_run_local="FALSE" + + local index=0 + local numArgs=${#arguments[@]} + local argument + + while [ ${index} -lt ${numArgs} ]; do + argument=${arguments[index]} + + case ${argument} in + --StudyFolder=*) + command_line_specified_study_folder=${argument#*=} + index=$(( index + 1 )) + ;; + --Subject=*) + command_line_specified_subject=${argument#*=} + index=$(( index + 1 )) + ;; + --runlocal) + command_line_specified_run_local="TRUE" + index=$(( index + 1 )) + ;; + *) + echo "" + echo "ERROR: Unrecognized Option: ${argument}" + echo "" + exit 1 + ;; + esac + done +} + +get_batch_options "$@" + +StudyFolder="${HOME}/projects/Pipelines_ExampleData" #Location of Subject folders (named by SubjectID) +Subjlist="100307 100610" #Space delimited list of subject IDs +EnvironmentScript="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" #Pipeline environment script + +if [ -n "${command_line_specified_study_folder}" ]; then + StudyFolder="${command_line_specified_study_folder}" +fi + +if [ -n "${command_line_specified_subject}" ]; then + Subjlist="${command_line_specified_subject}" +fi + +#Set up pipeline environment variables and software +source "$EnvironmentScript" + +# Log the originating call +echo "$@" + +#NOTE: syntax for QUEUE has changed compared to earlier pipeline releases, +#DO NOT include "-q " at the beginning +#default to no queue, implying run local +QUEUE="" +#QUEUE="hcp_priority.q" + +########################################## INPUTS ########################################## + +#Scripts called by this script do assume they run on the outputs of the PostFreeSurfer Pipeline + +######################################### DO WORK ########################################## + +for Subject in $Subjlist ; do + echo $Subject + + if [[ "${command_line_specified_run_local}" == "TRUE" || "$QUEUE" == "" ]] ; then + echo "About to locally run ${HCPPIPEDIR}/HippUnfoldHCP/PostHippUnfoldHCP.sh" + queuing_command=("$HCPPIPEDIR"/global/scripts/captureoutput.sh) + else + echo "About to use fsl_sub to queue ${HCPPIPEDIR}/HippUnfoldHCP/PostHippUnfoldHCP.sh" + queuing_command=("$FSLDIR/bin/fsl_sub" -q "$QUEUE") + fi + + "${queuing_command[@]}" "$HCPPIPEDIR"/HippUnfoldHCP/PostHippUnfoldHCP.sh \ + --study-folder="$StudyFolder" \ + --subject="$Subject" \ + + # The following lines are used for interactive debugging to set the positional parameters: $1 $2 $3 ... + + echo "set -- --study-folder=$StudyFolder \ + --subject=$Subject" \ + + echo ". ${EnvironmentScript}" + +done diff --git a/HippUnfoldHCP/HippUnfoldHCP.sh b/HippUnfoldHCP/HippUnfoldHCP.sh new file mode 100755 index 000000000..99b29a76e --- /dev/null +++ b/HippUnfoldHCP/HippUnfoldHCP.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -eu +pipedirguessed=0 +if [[ "${HCPPIPEDIR:-}" == "" ]] +then + # pipedirguessed=1 + #fix this if the script is more than one level below HCPPIPEDIR + export HCPPIPEDIR="$(dirname -- "$0")/.." +fi + +source "$HCPPIPEDIR/global/scripts/newopts.shlib" "$@" +source "$HCPPIPEDIR/global/scripts/debug.shlib" "$@" + + +opts_SetScriptDescription "Make some BIDS structures and run HippUnfold" + +opts_AddMandatory '--study-folder' 'StudyFolder' 'path' "folder containing all subjects" +opts_AddMandatory '--subject' 'Subject' 'subject ID' "" +opts_AddOptional '--hippunfold-dir' 'HippUnfoldDIR' 'path' "location of HippUnfold outputs" + +opts_ParseArguments "$@" + +if ((pipedirguessed)) +then + log_Err_Abort "HCPPIPEDIR is not set, you must first source your edited copy of Examples/Scripts/SetUpHCPPipeline.sh" +fi + +opts_ShowValues + +T1wFolder="$StudyFolder/$Subject/T1w" # input data + +if [ -z ${HippUnfoldDIR} ] ; then + HippUnfoldDIR="${T1wFolder}/HippUnfold" +fi + +#Couldn't get non-BIDS to work (wouldn't do anything) +#HippUnfoldT1wFolder="$HippUnfoldDIR/T1w" +#HippUnfoldT2wFolder="$HippUnfoldDIR/T2w" +#HippUnfoldT2wFolder="$HippUnfoldDIR/T1wT2w" #TODO: T1wT2w not working in HippUnfold + +HippUnfoldT1wFolder="$HippUnfoldDIR/T1w/sub-${Subject}/anat" +HippUnfoldT2wFolder="$HippUnfoldDIR/T2w/sub-${Subject}/anat" +#HippUnfoldT1wT2wFolder="$HippUnfoldDIR/T1wT2w/sub-${Subject}/anat" #TODO: T1wT2w not working in HippUnfold + +HippUnfoldT1wFolderOut="$HippUnfoldDIR/T1w_hippunfold" +HippUnfoldT2wFolderOut="$HippUnfoldDIR/T2w_hippunfold" +#HippUnfoldT1wT2wFolderOut="$HippUnfoldDIR/T1wT2w_hippunfold" #TODO: T1wT2w not working in HippUnfold + + +T1wImage="$T1wFolder/T1w_acpc_dc_restore.nii.gz" +T2wImage="$T1wFolder/T2w_acpc_dc_restore.nii.gz" + + +if [ ! -f "$T1wImage" ]; then + echo "Error: T1w image not found at $T1wImage" >&2 + exit 1 +fi + +if [ ! -f "$T2wImage" ]; then + echo "Error: T2w image not found at $T2wImage" >&2 + exit 1 +fi + + +mkdir -p "$HippUnfoldT1wFolder" "$HippUnfoldT2wFolder" "$HippUnfoldT1wT2wFolder" + +#Couldn't get non-BIDS to work (wouldn't do anything) +#cp "$T1wImage" "$HippUnfoldT1wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" +#cp "$T2wImage" "$HippUnfoldT1wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" +#cp "$T1wImage" "$HippUnfoldT2wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" +#cp "$T2wImage" "$HippUnfoldT2wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" +#cp "$T1wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" #TODO: T1wT2w not working in HippUnfold +#cp "$T2wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" #TODO: T1wT2w not working in HippUnfold + +cp "$T1wImage" "$HippUnfoldT1wFolder/sub-${Subject}_T1w.nii.gz" +cp "$T2wImage" "$HippUnfoldT1wFolder/sub-${Subject}_T2w.nii.gz" +cp "$T1wImage" "$HippUnfoldT2wFolder/sub-${Subject}_T1w.nii.gz" +cp "$T2wImage" "$HippUnfoldT2wFolder/sub-${Subject}_T2w.nii.gz" +#cp "$T1wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T1w.nii.gz" #TODO: T1wT2w not working in HippUnfold +#cp "$T2wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T2w.nii.gz" #TODO: T1wT2w not working in HippUnfold + + +log_Msg "Created folder structure under $HippUnfoldDIR and copied T1w and T2w images" +log_Msg "Starting HippUnfold pipeline for subject: $Subject" + +#Couldn't get non-BIDS to work (wouldn't do anything) #Seriously: don't put a $ here... +#apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wFolder $HippUnfoldT1wFolder participant --modality T1w --path-T1w $HippUnfoldT1wFolder/{Subject}_T1w_acpc_dc_restore.nii.gz --cores all --force-output --generate_myelin_map +#apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolder participant --modality T2w --path-T2w $HippUnfoldT2wFolder/{Subject}_T2w_acpc_dc_restore.nii.gz --cores all --force-output --generate_myelin_map +#apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolder participant --modality T2w --path-T2w $HippUnfoldT2wFolder/{Subject}_T2w_acpc_dc_restore.nii.gz --cores all --force-output --generate_myelin_map --force-nnunet-model T1T2w + +#TODO: Both T1w and T2w? --force-nnunet-model T1T2w? --output-spaces native vs T1w? --nnunet_enable_tta more accurate but 8x slower? +log_Msg "Running T1w HippUnfold for subject: $Subject" +apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wFolder $HippUnfoldT1wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map +log_Msg "T1w HippUnfold completed." +log_Msg "Running T2w HippUnfold for subject: $Subject" +apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolderOut participant --modality T2w --cores all --force-output --generate_myelin_map +log_Msg "T2w HippUnfold completed." +#log_Msg "Running T1wT2w HippUnfold for subject: $Subject" #TODO: T1wT2w not working in HippUnfold +#apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wT2wFolder $HippUnfoldT1wT2wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map --force-nnunet-model T1T2w #TODO: T1wT2w not working in HippUnfold +#log_Msg "T1wT2w HippUnfold completed." #TODO: T1wT2w not working in HippUnfold + +log_Msg "HippUnfold pipeline completed successfully for subject: $Subject" diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh new file mode 100755 index 000000000..e097711c1 --- /dev/null +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -0,0 +1,271 @@ +#!/bin/bash +set -eu +pipedirguessed=0 +if [[ "${HCPPIPEDIR:-}" == "" ]] +then + # pipedirguessed=1 + #fix this if the script is more than one level below HCPPIPEDIR + export HCPPIPEDIR="$(dirname -- "$0")/.." +fi + +source "$HCPPIPEDIR/global/scripts/newopts.shlib" "$@" +source "$HCPPIPEDIR/global/scripts/debug.shlib" "$@" + + +opts_SetScriptDescription "Make some BIDS structures and run HippUnfold" + +opts_AddMandatory '--study-folder' 'StudyFolder' 'path' "folder containing all subjects" +opts_AddMandatory '--subject' 'Subject' 'subject ID' "" +opts_AddOptional '--hippunfold-dir' 'HippUnfoldDIR' 'path' "location of HippUnfold outputs" +opts_AddOptional '--atlas-hippunfold-dir' 'AtlasHippUnfoldDIR' 'path' "location of Atlas HippUnfold outputs" + +opts_ParseArguments "$@" + +if ((pipedirguessed)) +then + log_Err_Abort "HCPPIPEDIR is not set, you must first source your edited copy of Examples/Scripts/SetUpHCPPipeline.sh" +fi + +opts_ShowValues + +log_Msg "Starting PostHippUnfold pipeline for subject: $Subject" + +T1wFolder="$StudyFolder/$Subject/T1w" +AtlasFolder="$StudyFolder/$Subject/MNINonLinear" + +if [ -z ${HippUnfoldDIR} ] ; then + HippUnfoldDIR="${T1wFolder}/HippUnfold" +fi + +if [ -z ${AtlasHippUnfoldDIR} ] ; then + AtlasHippUnfoldDIR="${AtlasFolder}/HippUnfold" +fi + + +HippUnfoldT1wFolderOut="$HippUnfoldDIR/T1w_hippunfold" +HippUnfoldT2wFolderOut="$HippUnfoldDIR/T2w_hippunfold" +HippUnfoldT1wT2wFolderOut="$HippUnfoldDIR/T1wT2w_hippunfold" +AtlasHippUnfoldT1wFolderOut="$AtlasHippUnfoldDIR/T1w_hippunfold" +AtlasHippUnfoldT2wFolderOut="$AtlasHippUnfoldDIR/T2w_hippunfold" +AtlasHippUnfoldT1wT2wFolderOut="$AtlasHippUnfoldDIR/T1wT2w_hippunfold" + + +#TODO: Apparently all HippUnfold surfaces have the same mesh for a given surface and thus these are not "native" meshes? +NativeFolderT1w="$HippUnfoldT1wFolderOut/Native" +NativeFolderT2w="$HippUnfoldT2wFolderOut/Native" +NativeFolderT1wT2w="$HippUnfoldT1wT2wFolderOut/Native" +AtlasNativeFolderT1w="$AtlasHippUnfoldT1wFolderOut/Native" +AtlasNativeFolderT2w="$AtlasHippUnfoldT2wFolderOut/Native" +AtlasNativeFolderT1wT2w="$AtlasHippUnfoldT1wT2wFolderOut/Native" + +mkdir -p ${NativeFolderT1w} ${NativeFolderT2w} ${NativeFolderT1wT2w} ${AtlasNativeFolderT1w} ${AtlasNativeFolderT2w} ${AtlasNativeFolderT1wT2w} + +function PostHippUnfold { +HippUnfoldFolderOut=${1} +NativeFolder=${2} +AtlasNativeFolder=${3} +AtlasFolder=${4} +Subject=${5} +Modality=${6} + +#TODO: Replace hack with just recreating the CIFTIs +function MATLABHACK { +File=${1} +Left=${2} +Right=${3} +matlab -nojvm -nodisplay -nosplash < Date: Sat, 14 Dec 2024 11:41:01 -0600 Subject: [PATCH 2/9] *Add Apptainer/Singularity Cache control *Add Support for multi-resolution meshes *Add Spec Files *Add Support for Dentate in cifti-matlab --- Examples/Scripts/SetUpHCPPipeline.sh | 2 + HippUnfoldHCP/HippUnfoldHCP.sh | 25 +- HippUnfoldHCP/PostHippUnfoldHCP.sh | 269 ++++++++++-------- .../cifti-matlab/private/cifti_write_xml.m | 4 +- 4 files changed, 168 insertions(+), 132 deletions(-) diff --git a/Examples/Scripts/SetUpHCPPipeline.sh b/Examples/Scripts/SetUpHCPPipeline.sh index 048444dbf..c59ab2646 100644 --- a/Examples/Scripts/SetUpHCPPipeline.sh +++ b/Examples/Scripts/SetUpHCPPipeline.sh @@ -26,6 +26,8 @@ export MATLAB_COMPILER_RUNTIME=/export/matlab/MCR/R2017b/v93 # If a suitable version of wb_command is on your $PATH, CARET7DIR can be blank export CARET7DIR= export HCPCIFTIRWDIR="$HCPPIPEDIR"/global/matlab/cifti-matlab +export HIPPUNFOLDPATH="${HOME}/pipeline_tools/HippUnfold/khanlab_hippunfold_latest.sif" +export HIPPUNFOLD_CACHE_DIR="${HOME}/.cache/hippunfold" ## Set up FSL (if not already done so in the running environment) ## Uncomment the following 2 lines (remove the leading #) and correct the FSLDIR setting for your setup diff --git a/HippUnfoldHCP/HippUnfoldHCP.sh b/HippUnfoldHCP/HippUnfoldHCP.sh index 99b29a76e..68f5a5372 100755 --- a/HippUnfoldHCP/HippUnfoldHCP.sh +++ b/HippUnfoldHCP/HippUnfoldHCP.sh @@ -36,15 +36,15 @@ fi #Couldn't get non-BIDS to work (wouldn't do anything) #HippUnfoldT1wFolder="$HippUnfoldDIR/T1w" #HippUnfoldT2wFolder="$HippUnfoldDIR/T2w" -#HippUnfoldT2wFolder="$HippUnfoldDIR/T1wT2w" #TODO: T1wT2w not working in HippUnfold +#HippUnfoldT2wFolder="$HippUnfoldDIR/T1wT2w" HippUnfoldT1wFolder="$HippUnfoldDIR/T1w/sub-${Subject}/anat" HippUnfoldT2wFolder="$HippUnfoldDIR/T2w/sub-${Subject}/anat" -#HippUnfoldT1wT2wFolder="$HippUnfoldDIR/T1wT2w/sub-${Subject}/anat" #TODO: T1wT2w not working in HippUnfold +HippUnfoldT1wT2wFolder="$HippUnfoldDIR/T1wT2w/sub-${Subject}/anat" HippUnfoldT1wFolderOut="$HippUnfoldDIR/T1w_hippunfold" HippUnfoldT2wFolderOut="$HippUnfoldDIR/T2w_hippunfold" -#HippUnfoldT1wT2wFolderOut="$HippUnfoldDIR/T1wT2w_hippunfold" #TODO: T1wT2w not working in HippUnfold +HippUnfoldT1wT2wFolderOut="$HippUnfoldDIR/T1wT2w_hippunfold" T1wImage="$T1wFolder/T1w_acpc_dc_restore.nii.gz" @@ -69,15 +69,15 @@ mkdir -p "$HippUnfoldT1wFolder" "$HippUnfoldT2wFolder" "$HippUnfoldT1wT2wFolder" #cp "$T2wImage" "$HippUnfoldT1wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" #cp "$T1wImage" "$HippUnfoldT2wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" #cp "$T2wImage" "$HippUnfoldT2wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" -#cp "$T1wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" #TODO: T1wT2w not working in HippUnfold -#cp "$T2wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" #TODO: T1wT2w not working in HippUnfold +#cp "$T1wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T1w_acpc_dc_restore.nii.gz" +#cp "$T2wImage" "$HippUnfoldT1wT2wFolder/${Subject}_T2w_acpc_dc_restore.nii.gz" cp "$T1wImage" "$HippUnfoldT1wFolder/sub-${Subject}_T1w.nii.gz" cp "$T2wImage" "$HippUnfoldT1wFolder/sub-${Subject}_T2w.nii.gz" cp "$T1wImage" "$HippUnfoldT2wFolder/sub-${Subject}_T1w.nii.gz" cp "$T2wImage" "$HippUnfoldT2wFolder/sub-${Subject}_T2w.nii.gz" -#cp "$T1wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T1w.nii.gz" #TODO: T1wT2w not working in HippUnfold -#cp "$T2wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T2w.nii.gz" #TODO: T1wT2w not working in HippUnfold +cp "$T1wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T1w.nii.gz" +cp "$T2wImage" "$HippUnfoldT1wT2wFolder/sub-${Subject}_T2w.nii.gz" log_Msg "Created folder structure under $HippUnfoldDIR and copied T1w and T2w images" @@ -88,15 +88,14 @@ log_Msg "Starting HippUnfold pipeline for subject: $Subject" #apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolder participant --modality T2w --path-T2w $HippUnfoldT2wFolder/{Subject}_T2w_acpc_dc_restore.nii.gz --cores all --force-output --generate_myelin_map #apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolder participant --modality T2w --path-T2w $HippUnfoldT2wFolder/{Subject}_T2w_acpc_dc_restore.nii.gz --cores all --force-output --generate_myelin_map --force-nnunet-model T1T2w -#TODO: Both T1w and T2w? --force-nnunet-model T1T2w? --output-spaces native vs T1w? --nnunet_enable_tta more accurate but 8x slower? log_Msg "Running T1w HippUnfold for subject: $Subject" -apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wFolder $HippUnfoldT1wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map +apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wFolder $HippUnfoldT1wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map --output-density 0p5mm 1mm 2mm log_Msg "T1w HippUnfold completed." log_Msg "Running T2w HippUnfold for subject: $Subject" -apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolderOut participant --modality T2w --cores all --force-output --generate_myelin_map +apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT2wFolder $HippUnfoldT2wFolderOut participant --modality T2w --cores all --force-output --generate_myelin_map --output-density 0p5mm 1mm 2mm log_Msg "T2w HippUnfold completed." -#log_Msg "Running T1wT2w HippUnfold for subject: $Subject" #TODO: T1wT2w not working in HippUnfold -#apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wT2wFolder $HippUnfoldT1wT2wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map --force-nnunet-model T1T2w #TODO: T1wT2w not working in HippUnfold -#log_Msg "T1wT2w HippUnfold completed." #TODO: T1wT2w not working in HippUnfold +log_Msg "Running T1wT2w HippUnfold for subject: $Subject" +apptainer run --bind $StudyFolder -e $HIPPUNFOLDPATH $HippUnfoldT1wT2wFolder $HippUnfoldT1wT2wFolderOut participant --modality T1w --cores all --force-output --generate_myelin_map --output-density 0p5mm 1mm 2mm --force-nnunet-model T1T2w +log_Msg "T1wT2w HippUnfold completed." log_Msg "HippUnfold pipeline completed successfully for subject: $Subject" diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index e097711c1..16e8ee511 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -16,7 +16,7 @@ opts_SetScriptDescription "Make some BIDS structures and run HippUnfold" opts_AddMandatory '--study-folder' 'StudyFolder' 'path' "folder containing all subjects" opts_AddMandatory '--subject' 'Subject' 'subject ID' "" -opts_AddOptional '--hippunfold-dir' 'HippUnfoldDIR' 'path' "location of HippUnfold outputs" +opts_AddOptional '--hippunfold-dir' 'PhysicalHippUnfoldDIR' 'path' "location of HippUnfold outputs" opts_AddOptional '--atlas-hippunfold-dir' 'AtlasHippUnfoldDIR' 'path' "location of Atlas HippUnfold outputs" opts_ParseArguments "$@" @@ -33,40 +33,30 @@ log_Msg "Starting PostHippUnfold pipeline for subject: $Subject" T1wFolder="$StudyFolder/$Subject/T1w" AtlasFolder="$StudyFolder/$Subject/MNINonLinear" -if [ -z ${HippUnfoldDIR} ] ; then - HippUnfoldDIR="${T1wFolder}/HippUnfold" +if [ -z ${PhysicalHippUnfoldDIR} ] ; then + PhysicalHippUnfoldDIR="${T1wFolder}/HippUnfold" fi if [ -z ${AtlasHippUnfoldDIR} ] ; then AtlasHippUnfoldDIR="${AtlasFolder}/HippUnfold" fi - -HippUnfoldT1wFolderOut="$HippUnfoldDIR/T1w_hippunfold" -HippUnfoldT2wFolderOut="$HippUnfoldDIR/T2w_hippunfold" -HippUnfoldT1wT2wFolderOut="$HippUnfoldDIR/T1wT2w_hippunfold" -AtlasHippUnfoldT1wFolderOut="$AtlasHippUnfoldDIR/T1w_hippunfold" -AtlasHippUnfoldT2wFolderOut="$AtlasHippUnfoldDIR/T2w_hippunfold" -AtlasHippUnfoldT1wT2wFolderOut="$AtlasHippUnfoldDIR/T1wT2w_hippunfold" - - -#TODO: Apparently all HippUnfold surfaces have the same mesh for a given surface and thus these are not "native" meshes? -NativeFolderT1w="$HippUnfoldT1wFolderOut/Native" -NativeFolderT2w="$HippUnfoldT2wFolderOut/Native" -NativeFolderT1wT2w="$HippUnfoldT1wT2wFolderOut/Native" -AtlasNativeFolderT1w="$AtlasHippUnfoldT1wFolderOut/Native" -AtlasNativeFolderT2w="$AtlasHippUnfoldT2wFolderOut/Native" -AtlasNativeFolderT1wT2w="$AtlasHippUnfoldT1wT2wFolderOut/Native" - -mkdir -p ${NativeFolderT1w} ${NativeFolderT2w} ${NativeFolderT1wT2w} ${AtlasNativeFolderT1w} ${AtlasNativeFolderT2w} ${AtlasNativeFolderT1wT2w} - function PostHippUnfold { HippUnfoldFolderOut=${1} -NativeFolder=${2} -AtlasNativeFolder=${3} -AtlasFolder=${4} -Subject=${5} -Modality=${6} +PhysicalHippUnfoldFolder=${2} +AtlasHippUnfoldFolder=${3} +T1wFolder=${4} +AtlasFolder=${5} +Subject=${6} +Modality=${7} +Mesh=${8} + +if [ ${Modality} = "T1wT2w" ] ; then + Modality="T1w" + Flag="On" +else + Flag="Off" +fi #TODO: Replace hack with just recreating the CIFTIs function MATLABHACK { @@ -103,169 +93,212 @@ Labels="atlas-multihist7_subfields@HippocampalSubfields" for Structure in $Structures ; do if [ ${Structure} = "dentate" ] ; then - #Left="HIPPOCAMPUS_DENTATE_LEFT" - #Right="HIPPCAMPUS_DENTATE_RIGHT" - Left="HIPPOCAMPUS_LEFT" #TODO: Change to Dentate - Right="HIPPOCAMPUS_RIGHT" #TODO: Change to Dentate + Left="HIPPOCAMPUS_DENTATE_LEFT" + Right="HIPPOCAMPUS_DENTATE_RIGHT" for Hemisphere in L R ; do #No dentate thickness if computed by HippUnfold - ${CARET7DIR}/wb_command -surface-to-surface-3d-distance $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_inner.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_outer.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_thickness.shape.gii - #Buggy dentate curvature computed by HippUnfold #TODO: Remove if fixed - ${CARET7DIR}/wb_command -surface-curvature $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_midthickness.surf.gii -mean $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_curvature.shape.gii - #HippUnfold applys a tanh normalization for some reason - ${CARET7DIR}/wb_command -metric-math "tanh(X)" $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_curvature.shape.gii -var X $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_curvature.shape.gii + ${CARET7DIR}/wb_command -surface-to-surface-3d-distance $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_inner.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_outer.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_thickness.shape.gii done #No dentate thickness if computed by HippUnfold - ${CARET7DIR}/wb_command -cifti-create-dense-scalar $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_thickness.dscalar.nii -left-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-L_space-${Modality}_den-0p5mm_label-${Structure}_thickness.shape.gii -right-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-R_space-${Modality}_den-0p5mm_label-${Structure}_thickness.shape.gii - #Buggy dentate curvature computed by HippUnfold #TODO: Remove if fixed - ${CARET7DIR}/wb_command -cifti-create-dense-scalar $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_curvature.dscalar.nii -left-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-L_space-${Modality}_den-0p5mm_label-${Structure}_curvature.shape.gii -right-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-R_space-${Modality}_den-0p5mm_label-${Structure}_curvature.shape.gii + ${CARET7DIR}/wb_command -cifti-create-dense-scalar $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_thickness.dscalar.nii -left-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-L_space-${Modality}_den-${Mesh}_label-${Structure}_thickness.shape.gii -right-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-R_space-${Modality}_den-${Mesh}_label-${Structure}_thickness.shape.gii elif [ ${Structure} = "hipp" ] ; then Left="HIPPOCAMPUS_LEFT" Right="HIPPOCAMPUS_RIGHT" fi #No surface area CIFTI is made by HippUnfold - ${CARET7DIR}/wb_command -cifti-create-dense-scalar $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_surfarea.dscalar.nii -left-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-L_space-${Modality}_den-0p5mm_label-${Structure}_surfarea.shape.gii -right-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-R_space-${Modality}_den-0p5mm_label-${Structure}_surfarea.shape.gii + ${CARET7DIR}/wb_command -cifti-create-dense-scalar $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_surfarea.dscalar.nii -left-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-L_space-${Modality}_den-${Mesh}_label-${Structure}_surfarea.shape.gii -right-metric $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-R_space-${Modality}_den-${Mesh}_label-${Structure}_surfarea.shape.gii for Hemisphere in L R ; do if [ ${Hemisphere} = "L" ] ; then if [ ${Structure} = "dentate" ] ; then - #HemiStructure="HIPPOCAMPUS_DENTATE_LEFT" - HemiStructure="HIPPOCAMPUS_LEFT" #TODO: Change to Dentate + HemiStructure="HIPPOCAMPUS_DENTATE_LEFT" elif [ ${Structure} = "hipp" ] ; then HemiStructure="HIPPOCAMPUS_LEFT" fi elif [ ${Hemisphere} = "R" ] ; then if [ ${Structure} = "dentate" ] ; then - #HemiStructure="HIPPOCAMPUS_DENTATE_RIGHT" - HemiStructure="HIPPOCAMPUS_RIGHT" #TODO: Change to Dentate + HemiStructure="HIPPOCAMPUS_DENTATE_RIGHT" elif [ ${Structure} = "hipp" ] ; then HemiStructure="HIPPOCAMPUS_RIGHT" fi fi + + #Anatomical Surfaces for Surface in $Surfaces ; do SurfaceType=`echo $Surface | cut -d "@" -f 2` Surface=`echo $Surface | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Surface}.surf.gii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Surface}.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.native.surf.gii - ${CARET7DIR}/wb_command -set-structure ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.native.surf.gii ${HemiStructure} -surface-type ANATOMICAL -surface-secondary-type ${SurfaceType} - ${CARET7DIR}/wb_command -surface-apply-warpfield ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.native.surf.gii ${AtlasFolder}/xfms/standard2acpc_dc.nii.gz ${AtlasNativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.native.surf.gii -fnirt ${AtlasFolder}/T1w_restore.nii.gz + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Surface}.surf.gii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Surface}.surf.gii ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii + ${CARET7DIR}/wb_command -set-structure ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii ${HemiStructure} -surface-type ANATOMICAL -surface-secondary-type ${SurfaceType} + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${HemiStructure} ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii + ${CARET7DIR}/wb_command -surface-apply-warpfield ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii ${AtlasFolder}/xfms/standard2acpc_dc.nii.gz ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii -fnirt ${AtlasFolder}/T1w_restore.nii.gz + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${HemiStructure} ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Surface}.${Mesh}.surf.gii fi done - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Surface}.surf.gii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-0p5mm_label-${Structure}_midthickness.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_flat.native.surf.gii - ${CARET7DIR}/wb_command -set-structure ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_flat.native.surf.gii ${HemiStructure} -surface-type FLAT - cp ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_flat.native.surf.gii ${AtlasNativeFolder}/${Subject}.${Hemisphere}.${Structure}_flat.native.surf.gii + + #Flat Surfaces + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Surface}.surf.gii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-${Mesh}_label-${Structure}_midthickness.surf.gii ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii + ${CARET7DIR}/wb_command -set-structure ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii ${HemiStructure} -surface-type FLAT + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${HemiStructure} ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${HemiStructure} ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_flat.${Mesh}.surf.gii fi + + #GIFTI Metrics + #Don't add GIFTI to Specs for Scalar in $Scalars ; do Name=`echo $Scalar | cut -d "@" -f 3` Color=`echo $Scalar | cut -d "@" -f 2` Scalar=`echo $Scalar | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Scalar}.shape.gii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Scalar}.shape.gii ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii - ${CARET7DIR}/wb_command -set-structure ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii ${HemiStructure} - PALETTE ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii ${Color} metric ${CARET7DIR}/wb_command - ${CARET7DIR}/wb_command -set-map-names ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii -map 1 "${Subject}_${Name}" - cp ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii ${AtlasNativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.native.shape.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Scalar}.shape.gii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Scalar}.shape.gii ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii + ${CARET7DIR}/wb_command -set-structure ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${HemiStructure} + PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${Color} metric ${CARET7DIR}/wb_command + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii -map 1 "${Subject}_${Name}" + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? fi done + + #GIFTI Labels + #Don't add GIFTI to Specs for Label in $Labels ; do Name=`echo $Label | cut -d "@" -f 2` Label=`echo $Label | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Label}.label.gii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-${Structure}_${Label}.label.gii ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.native.label.gii - ${CARET7DIR}/wb_command -set-structure ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.native.label.gii ${HemiStructure} - ${CARET7DIR}/wb_command -set-map-names ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.native.label.gii -map 1 "${Subject}_${Name}" - cp ${NativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.native.label.gii ${AtlasNativeFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.native.label.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.label.gii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.label.gii ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii + ${CARET7DIR}/wb_command -set-structure ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii ${HemiStructure} + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii -map 1 "${Subject}_${Name}" + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? fi done + + #NIFTI Hemispheric Labels if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/anat/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_desc-subfields_atlas-multihist7_dseg.nii.gz ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/anat/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_desc-subfields_atlas-multihist7_dseg.nii.gz ${NativeFolder}/${Subject}.${Hemisphere}.HippocampalSubfields.nii.gz + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/anat/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_desc-subfields_atlas-multihist7_dseg.nii.gz ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.HippocampalSubfields.nii.gz fi done + + #CIFTI Scalars for Scalar in $Scalars ; do Name=`echo $Scalar | cut -d "@" -f 3` Color=`echo $Scalar | cut -d "@" -f 2` Scalar=`echo $Scalar | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_${Scalar}.dscalar.nii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_${Scalar}.dscalar.nii ${NativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii - MATLABHACK ${NativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii ${Left} ${Right} - PALETTE ${NativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command - ${CARET7DIR}/wb_command -set-map-names ${NativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii -map 1 "${Subject}_${Name}" - cp ${NativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii ${AtlasNativeFolder}/${Subject}.${Structure}_${Scalar}.native.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Scalar}.dscalar.nii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Scalar}.dscalar.nii ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii + MATLABHACK ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Left} ${Right} > /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs + PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? fi done + + #CIFTI Labels for Label in $Labels ; do Name=`echo $Label | cut -d "@" -f 2` Label=`echo $Label | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_${Label}.dlabel.nii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-${Structure}_${Label}.dlabel.nii ${NativeFolder}/${Subject}.${Structure}_${Label}.native.dlabel.nii - MATLABHACK ${NativeFolder}/${Subject}.${Structure}_${Label}.native.dlabel.nii ${Left} ${Right} - ${CARET7DIR}/wb_command -set-map-names ${NativeFolder}/${Subject}.${Structure}_${Label}.native.dlabel.nii -map 1 "${Subject}_${Name}" - cp ${NativeFolder}/${Subject}.${Structure}_${Label}.native.dlabel.nii ${AtlasNativeFolder}/${Subject}.${Structure}_${Label}.native.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.dlabel.nii ] ; then + cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.dlabel.nii ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii + MATLABHACK ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii ${Left} ${Right} > /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii -map 1 "${Subject}_${Name}" + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? fi done done -fslmaths ${NativeFolder}/${Subject}.R.HippocampalSubfields.nii.gz -add 8 -mas ${NativeFolder}/${Subject}.R.HippocampalSubfields.nii.gz -add ${NativeFolder}/${Subject}.L.HippocampalSubfields.nii.gz ${NativeFolder}/${Subject}.HippocampalSubfields.nii.gz -${CARET7DIR}/wb_command -volume-label-import ${NativeFolder}/${Subject}.HippocampalSubfields.nii.gz $HCPPIPEDIR/global/config/HippUnfoldLut.txt ${NativeFolder}/${Subject}.HippocampalSubfields.nii.gz -rm ${NativeFolder}/${Subject}.L.HippocampalSubfields.nii.gz ${NativeFolder}/${Subject}.R.HippocampalSubfields.nii.gz -${CARET7DIR}/wb_command -volume-resample ${NativeFolder}/${Subject}.HippocampalSubfields.nii.gz ${AtlasFolder}/T1w_restore.nii.gz ENCLOSING_VOXEL ${AtlasNativeFolder}/${Subject}.HippocampalSubfields.nii.gz -warp ${AtlasFolder}/xfms/acpc_dc2standard.nii.gz -fnirt ${AtlasFolder}/T1w_restore.nii.gz -#TODO: Make spec files once hippocampus and dentate can both be loaded together + +#NIFTI Label Volumes +fslmaths ${PhysicalHippUnfoldFolder}/${Subject}.R.HippocampalSubfields.nii.gz -add 8 -mas ${PhysicalHippUnfoldFolder}/${Subject}.R.HippocampalSubfields.nii.gz -add ${PhysicalHippUnfoldFolder}/${Subject}.L.HippocampalSubfields.nii.gz ${PhysicalHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz +${CARET7DIR}/wb_command -volume-label-import ${PhysicalHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz $HCPPIPEDIR/global/config/HippUnfoldLut.txt ${PhysicalHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz +rm ${PhysicalHippUnfoldFolder}/${Subject}.L.HippocampalSubfields.nii.gz ${PhysicalHippUnfoldFolder}/${Subject}.R.HippocampalSubfields.nii.gz +${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz +${CARET7DIR}/wb_command -volume-resample ${PhysicalHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz ${AtlasFolder}/T1w_restore.nii.gz ENCLOSING_VOXEL ${AtlasHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz -warp ${AtlasFolder}/xfms/acpc_dc2standard.nii.gz -fnirt ${AtlasFolder}/T1w_restore.nii.gz +${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.HippocampalSubfields.nii.gz + +#NIFTI Input Volumes +${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${T1wFolder}/T1w_acpc_dc_restore.nii.gz +${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${T1wFolder}/T2w_acpc_dc_restore.nii.gz +${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T1w_restore.nii.gz +${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T2w_restore.nii.gz + +#TODO: How to combine hippocampal and cerebral cortex? Put in same spec files + +if [ ${Flag} = "On" ] ; then + Modality="T1wT2w" +fi } -PostHippUnfold $HippUnfoldT1wFolderOut $NativeFolderT1w $AtlasNativeFolderT1w $AtlasFolder $Subject T1w -PostHippUnfold $HippUnfoldT2wFolderOut $NativeFolderT2w $AtlasNativeFolderT2w $AtlasFolder $Subject T2w -#PostHippUnfold $HippUnfoldT1wT2wFolderOut $NativeFolderT1wT2w $AtlasNativeFolderT1wT2w $Subject T1w #TODO: T1wT2w not working in HippUnfold; #Modality is still T1w + +for Modality in T1w T2w T1wT2w ; do + for Mesh in 0p5mm 1mm 2mm ; do #TODO: Native meshes not yet available from HippUnfold: "Native" Folder Name "native" Mesh Name + + PhysicalHippUnfoldFolderOut="$PhysicalHippUnfoldDIR/${Modality}_hippunfold" + AtlasHippUnfoldolderOut="$AtlasHippUnfoldDIR/${Modality}_hippunfold" + + PhysicalHippUnfoldFolder="$PhysicalHippUnfoldFolderOut/$Mesh" + AtlasHippUnfoldFolder="$AtlasHippUnfoldolderOut/$Mesh" + + mkdir -p ${PhysicalHippUnfoldFolder} ${AtlasHippUnfoldFolder} + + log_Msg "Processing $Modality $Mesh" + PostHippUnfold $PhysicalHippUnfoldFolderOut $PhysicalHippUnfoldFolder $AtlasHippUnfoldFolder $T1wFolder $AtlasFolder $Subject $Modality $Mesh + done +done + log_Msg "PostHippUnfold pipeline completed successfully for subject: $Subject" #HippUnfold Outputs Used By HCP #Scalars -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_curvature.shape.gii #Wrong mesh by default TODO: Remove if fixed -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_gyrification.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_myelin.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_surfarea.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_thickness.shape.gii #Not created by default -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_curvature.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_gyrification.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_myelin.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_surfarea.shape.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_thickness.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_curvature.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_gyrification.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_myelin.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_surfarea.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_thickness.shape.gii #Not created by default +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_curvature.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_gyrification.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_myelin.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_surfarea.shape.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_thickness.shape.gii #Surfaces -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_inner.surf.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_midthickness.surf.gii -#$HippUnfoldTolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_outer.surf.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_inner.surf.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_midthickness.surf.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_outer.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_inner.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_midthickness.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_outer.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_inner.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_midthickness.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_outer.surf.gii #Flat Surfaces -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-0p5mm_label-dentate_midthickness.surf.gii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-0p5mm_label-hipp_midthickness.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-${Mesh}_label-dentate_midthickness.surf.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-unfold_den-${Mesh}_label-hipp_midthickness.surf.gii #Labels -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-hipp_atlas-multihist7_subfields.label.gii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-hipp_atlas-multihist7_subfields.label.gii #Specs -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-0p5mm_label-dentate_surfaces.spec -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}den-0p5mm_label-hipp_surfaces.spec -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}den-0p5mm_label-dentate_surfaces.spec -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_surfaces.spec +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-dentate_surfaces.spec +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}den-${Mesh}_label-hipp_surfaces.spec +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}den-${Mesh}_label-dentate_surfaces.spec +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_surfaces.spec #CIFTIScalars -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-dentate_curvature.dscalar.nii #Wrong mesh by default TODO: Remove if fixed -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-dentate_gyrification.dscalar.nii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-dentate_myelin.dscalar.nii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-dentate_surfarea.dscalar.nii #Not created by default -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-dentate_thickness.dscalar.nii #Not created by default -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_curvature.dscalar.nii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_gyrification.dscalar.nii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_myelin.dscalar.nii -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_surfarea.dscalar.nii #Not created by default -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_thickness.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_curvature.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_gyrification.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_myelin.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_surfarea.dscalar.nii #Not created by default +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_thickness.dscalar.nii #Not created by default +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_curvature.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_gyrification.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_myelin.dscalar.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_surfarea.dscalar.nii #Not created by default +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_thickness.dscalar.nii #CIFTILabels -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-0p5mm_label-hipp_atlas-multihist7_subfields.dlabel.nii +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_atlas-multihist7_subfields.dlabel.nii #VolumeLabels -#$HippUnfoldFolderOut/hippunfold/sub-${Subject}/anat/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_desc-subfields_atlas-multihist7_dseg.nii.gz +#$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/anat/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_desc-subfields_atlas-multihist7_dseg.nii.gz diff --git a/global/matlab/cifti-matlab/private/cifti_write_xml.m b/global/matlab/cifti-matlab/private/cifti_write_xml.m index 87524f2e4..46cb757e5 100644 --- a/global/matlab/cifti-matlab/private/cifti_write_xml.m +++ b/global/matlab/cifti-matlab/private/cifti_write_xml.m @@ -143,6 +143,8 @@ case 'DIENCEPHALON_VENTRAL_RIGHT'; outstr = 'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_RIGHT'; case 'HIPPOCAMPUS_LEFT'; outstr = 'CIFTI_STRUCTURE_HIPPOCAMPUS_LEFT'; case 'HIPPOCAMPUS_RIGHT'; outstr = 'CIFTI_STRUCTURE_HIPPOCAMPUS_RIGHT'; + case 'HIPPOCAMPUS_DENTATE_LEFT'; outstr = 'CIFTI_STRUCTURE_HIPPOCAMPUS_DENTATE_LEFT'; + case 'HIPPOCAMPUS_DENTATE_RIGHT'; outstr = 'CIFTI_STRUCTURE_HIPPOCAMPUS_DENTATE_RIGHT'; case 'OTHER'; outstr = 'CIFTI_STRUCTURE_OTHER'; case 'OTHER_GREY_MATTER'; outstr = 'CIFTI_STRUCTURE_OTHER_GREY_MATTER'; case 'OTHER_WHITE_MATTER'; outstr = 'CIFTI_STRUCTURE_OTHER_WHITE_MATTER'; @@ -153,7 +155,7 @@ case 'THALAMUS_LEFT'; outstr = 'CIFTI_STRUCTURE_THALAMUS_LEFT'; case 'THALAMUS_RIGHT'; outstr = 'CIFTI_STRUCTURE_THALAMUS_RIGHT'; otherwise - error(['invalid structure name "' instr '"in cifti struct']); + error(['invalid structure name "' instr '" in cifti struct']); end end From b279be65593525fb6d39c118ced9b4a6bf5ca0d9 Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Sat, 14 Dec 2024 14:09:54 -0600 Subject: [PATCH 3/9] *Make vertex areas specific to the volume space they are located in --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index 16e8ee511..4c341ca53 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -86,7 +86,7 @@ elif [ ${Type} = 'cifti' ] ; then fi } -Structures="dentate hipp" +Structures="dentate hipp" #TODO: Put both hipp and dentate in the same CIFTI files Surfaces="inner@PIAL midthickness@MIDTHICKNESS outer@GRAY_WHITE" #TODO: Need inner and outer secondary types Scalars="curvature@GRAY@Curvature gyrification@GRAY@Gyrification surfarea@VIDEEN@SurfaceArea thickness@VIDEEN@Thickness myelin@VIDEEN@MyelinMap" Labels="atlas-multihist7_subfields@HippocampalSubfields" @@ -155,7 +155,11 @@ for Structure in $Structures ; do ${CARET7DIR}/wb_command -set-structure ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${HemiStructure} PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${Color} metric ${CARET7DIR}/wb_command ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii -map 1 "${Subject}_${Name}" - cp ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ $Scalar = "surfarea" ] ; then + ${CARET7DIR}/wb_command -surface-vertex-areas ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_midthickness.${Mesh}.surf.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii + else + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii ${AtlasHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Scalar}.${Mesh}.shape.gii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + fi fi done @@ -178,6 +182,7 @@ for Structure in $Structures ; do fi done + #TODO: Put both hipp and dentate in the same CIFTI files, end structure loop above this comment #CIFTI Scalars for Scalar in $Scalars ; do Name=`echo $Scalar | cut -d "@" -f 3` @@ -189,7 +194,14 @@ for Structure in $Structures ; do PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + if [ $Scalar = "surfarea" ] ; then + ${CARET7DIR}/wb_command -cifti-create-dense-scalar ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -left-metric ${AtlasHippUnfoldFolder}/${Subject}.L.${Structure}_${Scalar}.${Mesh}.shape.gii -right-metric ${AtlasHippUnfoldFolder}/${Subject}.R.${Structure}_${Scalar}.${Mesh}.shape.gii + MATLABHACK ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Left} ${Right} > /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs + PALETTE ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command + ${CARET7DIR}/wb_command -set-map-names ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" + else + cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + fi ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? fi done @@ -223,7 +235,7 @@ ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject} ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T1w_restore.nii.gz ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T2w_restore.nii.gz -#TODO: How to combine hippocampal and cerebral cortex? Put in same spec files +#TODO: How to combine hippocampal and cerebral cortex? Merge spec files using merge wb_command if [ ${Flag} = "On" ] ; then Modality="T1wT2w" From 30356e7e3445ab4b2578a498aba80bb4f3017d8e Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Sat, 21 Dec 2024 17:37:03 -0600 Subject: [PATCH 4/9] *Combine hipp and dentate in CIFTI files *Support reading CIFTI files with dentate in cifti-matlab *Use consistent hippocampal labels in CIFTI and volume *Code cleanup *Remove matlab hack and just recreate all CIFTI files --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 149 ++++++++---------- .../cifti-matlab/private/cifti_parse_xml.m | 2 + 2 files changed, 66 insertions(+), 85 deletions(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index 4c341ca53..1955ef2b8 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -58,17 +58,6 @@ else Flag="Off" fi -#TODO: Replace hack with just recreating the CIFTIs -function MATLABHACK { -File=${1} -Left=${2} -Right=${3} -matlab -nojvm -nodisplay -nosplash < /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs - PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command - ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" - ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - if [ $Scalar = "surfarea" ] ; then - ${CARET7DIR}/wb_command -cifti-create-dense-scalar ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -left-metric ${AtlasHippUnfoldFolder}/${Subject}.L.${Structure}_${Scalar}.${Mesh}.shape.gii -right-metric ${AtlasHippUnfoldFolder}/${Subject}.R.${Structure}_${Scalar}.${Mesh}.shape.gii - MATLABHACK ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Left} ${Right} > /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs - PALETTE ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command - ${CARET7DIR}/wb_command -set-map-names ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" - else - cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - fi - ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - fi - done +#CIFTI Scalars +for Scalar in $Scalars ; do + Name=`echo $Scalar | cut -d "@" -f 3` + Color=`echo $Scalar | cut -d "@" -f 2` + Scalar=`echo $Scalar | cut -d "@" -f 1` + ${CARET7DIR}/wb_command -cifti-create-dense-scalar ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii -metric HIPPOCAMPUS_LEFT ${PhysicalHippUnfoldFolder}/${Subject}.L.hipp_${Scalar}.${Mesh}.shape.gii -metric HIPPOCAMPUS_RIGHT ${PhysicalHippUnfoldFolder}/${Subject}.R.hipp_${Scalar}.${Mesh}.shape.gii -metric HIPPOCAMPUS_DENTATE_LEFT ${PhysicalHippUnfoldFolder}/${Subject}.L.dentate_${Scalar}.${Mesh}.shape.gii -metric HIPPOCAMPUS_DENTATE_RIGHT ${PhysicalHippUnfoldFolder}/${Subject}.R.dentate_${Scalar}.${Mesh}.shape.gii + PALETTE ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii ${Color} cifti ${CARET7DIR}/wb_command + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii -map 1 "${Subject}_${Name}" + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + cp ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii ${AtlasHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.hippocampus_${Scalar}.${Mesh}.dscalar.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? +done + - #CIFTI Labels - for Label in $Labels ; do - Name=`echo $Label | cut -d "@" -f 2` - Label=`echo $Label | cut -d "@" -f 1` - if [ -e $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.dlabel.nii ] ; then - cp $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-${Structure}_${Label}.dlabel.nii ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii - MATLABHACK ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii ${Left} ${Right} > /dev/null 2>&1 #TODO: Replace hack with just recreating the CIFTIs - ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii -map 1 "${Subject}_${Name}" - ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - cp ${PhysicalHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.${Structure}_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? - fi - done +#CIFTI Labels +for Label in $Labels ; do + Name=`echo $Label | cut -d "@" -f 2` + Label=`echo $Label | cut -d "@" -f 1` + ${CARET7DIR}/wb_command -cifti-create-label ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii -label HIPPOCAMPUS_LEFT ${PhysicalHippUnfoldFolder}/${Subject}.L.hipp_${Label}.${Mesh}.label.gii -label HIPPOCAMPUS_RIGHT ${PhysicalHippUnfoldFolder}/${Subject}.R.hipp_${Label}.${Mesh}.label.gii -label HIPPOCAMPUS_DENTATE_LEFT ${PhysicalHippUnfoldFolder}/${Subject}.L.dentate_${Label}.${Mesh}.label.gii -label HIPPOCAMPUS_DENTATE_RIGHT ${PhysicalHippUnfoldFolder}/${Subject}.R.dentate_${Label}.${Mesh}.label.gii + ${CARET7DIR}/wb_command -set-map-names ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii -map 1 "${Subject}_${Name}" + ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + cp ${PhysicalHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii ${AtlasHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? + ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasHippUnfoldFolder}/${Subject}.hippocampus_${Label}.${Mesh}.dlabel.nii #TODO: mv to have maps in AtlasFolder like Cerebral Cortex? done #NIFTI Label Volumes @@ -296,7 +275,7 @@ log_Msg "PostHippUnfold pipeline completed successfully for subject: $Subject" #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}den-${Mesh}_label-dentate_surfaces.spec #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_surfaces.spec -#CIFTIScalars +#CIFTIScalars (recreated by the script) #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_curvature.dscalar.nii #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_gyrification.dscalar.nii #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-dentate_myelin.dscalar.nii @@ -308,7 +287,7 @@ log_Msg "PostHippUnfold pipeline completed successfully for subject: $Subject" #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_surfarea.dscalar.nii #Not created by default #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_thickness.dscalar.nii -#CIFTILabels +#CIFTILabels (recreated by the script) #$PhysicalHippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_space-${Modality}_den-${Mesh}_label-hipp_atlas-multihist7_subfields.dlabel.nii #VolumeLabels diff --git a/global/matlab/cifti-matlab/private/cifti_parse_xml.m b/global/matlab/cifti-matlab/private/cifti_parse_xml.m index 325b74b90..27d804e16 100644 --- a/global/matlab/cifti-matlab/private/cifti_parse_xml.m +++ b/global/matlab/cifti-matlab/private/cifti_parse_xml.m @@ -264,6 +264,8 @@ function mywarn(msg, filename) case 'CIFTI_STRUCTURE_DIENCEPHALON_VENTRAL_RIGHT'; outstr = 'DIENCEPHALON_VENTRAL_RIGHT'; case 'CIFTI_STRUCTURE_HIPPOCAMPUS_LEFT'; outstr = 'HIPPOCAMPUS_LEFT'; case 'CIFTI_STRUCTURE_HIPPOCAMPUS_RIGHT'; outstr = 'HIPPOCAMPUS_RIGHT'; + case 'CIFTI_STRUCTURE_HIPPOCAMPUS_DENTATE_LEFT'; outstr = 'HIPPOCAMPUS_DENTATE_LEFT'; + case 'CIFTI_STRUCTURE_HIPPOCAMPUS_DENTATE_RIGHT'; outstr = 'HIPPOCAMPUS_DENTATE_RIGHT'; case 'CIFTI_STRUCTURE_OTHER'; outstr = 'OTHER'; case 'CIFTI_STRUCTURE_OTHER_GREY_MATTER'; outstr = 'OTHER_GREY_MATTER'; case 'CIFTI_STRUCTURE_OTHER_WHITE_MATTER'; outstr = 'OTHER_WHITE_MATTER'; From 6a3f00b82b59072fb404c45a63f61fb580ffe774 Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Sat, 21 Dec 2024 17:44:05 -0600 Subject: [PATCH 5/9] *Remove matlab hack code --- HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m diff --git a/HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m b/HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m deleted file mode 100644 index 6bd368110..000000000 --- a/HippUnfoldHCP/scripts/HippUnfoldMatlabHack.m +++ /dev/null @@ -1,7 +0,0 @@ -function HippUnfoldMatlabHack(File,Left,Right) -cii=ciftiopen(File,'wb_command'); -cii.diminfo{1,1}.models{1,1}.struct=Left; -cii.diminfo{1,1}.models{1,2}.struct=Right; -ciftisave(cii,File,'wb_command'); -end - From 10238bf440f30e9c1d91c908c43f59917aa17952 Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Fri, 3 Jan 2025 17:02:11 -0600 Subject: [PATCH 6/9] *Add inner and outer surfaces *Add some combined hippocampal and cerebral spec files --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index 1955ef2b8..fe19e57c2 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -76,7 +76,7 @@ fi } Structures="dentate hipp" -Surfaces="inner@PIAL midthickness@MIDTHICKNESS outer@GRAY_WHITE" #TODO: Need inner and outer secondary types +Surfaces="inner@INNER midthickness@MIDTHICKNESS outer@OUTER" Scalars="curvature@GRAY@Curvature gyrification@GRAY@Gyrification surfarea@VIDEEN@SurfaceArea thickness@VIDEEN@Thickness myelin@VIDEEN@MyelinMap" Labels="atlas-multihist7_subfields@HippocampalSubfields" @@ -85,10 +85,9 @@ for Structure in $Structures ; do Left="HIPPOCAMPUS_DENTATE_LEFT" Right="HIPPOCAMPUS_DENTATE_RIGHT" for Hemisphere in L R ; do - #No dentate thickness if computed by HippUnfold + #No dentate thickness is computed by HippUnfold ${CARET7DIR}/wb_command -surface-to-surface-3d-distance $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_inner.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_outer.surf.gii $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_thickness.shape.gii done - #No dentate thickness if computed by HippUnfold elif [ ${Structure} = "hipp" ] ; then Left="HIPPOCAMPUS_LEFT" Right="HIPPOCAMPUS_RIGHT" @@ -214,7 +213,13 @@ ${CARET7DIR}/wb_command -add-to-spec-file ${PhysicalHippUnfoldFolder}/${Subject} ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T1w_restore.nii.gz ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec INVALID ${AtlasFolder}/T2w_restore.nii.gz -#TODO: How to combine hippocampal and cerebral cortex? Merge spec files using merge wb_command +#TODO: Merge Native Meshes, anything with 0pt5mm meshes? +if [ $Mesh = "2mm" ] ; then + ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/T1w/fsaverage_LR32k/100307.MSMAll.32k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex + ${CARET7DIR}/wb_command -spec-file-merge ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/MNINonLinear/fsaverage_LR32k/100307.MSMAll.32k_fs_LR.wb.spec ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex +elif [ $Mesh = "1mm" ] ; then + ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/MNINonLinear/100307.MSMAll.164k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.164k.wb_spec #TODO: Don't Hardcode Cortex +fi if [ ${Flag} = "On" ] ; then Modality="T1wT2w" From 3d320b779dfc57e43501c2d5c3071afc58440660 Mon Sep 17 00:00:00 2001 From: Matt Glasser Date: Sun, 5 Jan 2025 17:07:28 -0600 Subject: [PATCH 7/9] *Remove absolute paths --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index fe19e57c2..727294335 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -215,10 +215,10 @@ ${CARET7DIR}/wb_command -add-to-spec-file ${AtlasHippUnfoldFolder}/${Subject}.${ #TODO: Merge Native Meshes, anything with 0pt5mm meshes? if [ $Mesh = "2mm" ] ; then - ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/T1w/fsaverage_LR32k/100307.MSMAll.32k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex - ${CARET7DIR}/wb_command -spec-file-merge ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/MNINonLinear/fsaverage_LR32k/100307.MSMAll.32k_fs_LR.wb.spec ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex + ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${T1wFolder}/fsaverage_LR32k/${Subject}.MSMAll.32k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex + ${CARET7DIR}/wb_command -spec-file-merge ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${AtlasFolder}/fsaverage_LR32k/${Subject}.MSMAll.32k_fs_LR.wb.spec ${AtlasHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.32k.wb_spec #TODO: Don't Hardcode Cortex elif [ $Mesh = "1mm" ] ; then - ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec /media/myelin/brainmappers/Connectome_Project/YA_HCP_Final/100307/MNINonLinear/100307.MSMAll.164k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.164k.wb_spec #TODO: Don't Hardcode Cortex + ${CARET7DIR}/wb_command -spec-file-merge ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.wb_spec ${AtlasFolder}/${Subject}.MSMAll.164k_fs_LR.wb.spec ${PhysicalHippUnfoldFolder}/${Subject}.${Mesh}.MSMAll.164k.wb_spec #TODO: Don't Hardcode Cortex fi if [ ${Flag} = "On" ] ; then From 03a4bc65aa6520f28d7d40dd2a07bdc4cd7be592 Mon Sep 17 00:00:00 2001 From: glasserm Date: Sat, 11 Jan 2025 10:49:07 -0600 Subject: [PATCH 8/9] *math doesn't require the Var to be used Co-authored-by: Tim Coalson --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index 727294335..46271bbae 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -157,9 +157,9 @@ for Structure in $Structures ; do ${CARET7DIR}/wb_command -metric-label-import ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.shape.gii $HCPPIPEDIR/global/config/HippUnfoldLut.txt ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii elif [ ${Structure} = "dentate" ] ; then if [ ${Hemisphere} = "L" ] ; then - Expression="Var*0+1*6" + Expression="6" elif [ ${Hemisphere} = "R" ] ; then - Expression="Var*0+1*6 + 8" + Expression="6 + 8" fi ${CARET7DIR}/wb_command -metric-math "${Expression}" ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.shape.gii -var Var $HippUnfoldFolderOut/hippunfold/sub-${Subject}/surf/sub-${Subject}_hemi-${Hemisphere}_space-${Modality}_den-${Mesh}_label-${Structure}_${Scalar}.shape.gii ${CARET7DIR}/wb_command -metric-label-import ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.shape.gii $HCPPIPEDIR/global/config/HippUnfoldLut.txt ${PhysicalHippUnfoldFolder}/${Subject}.${Hemisphere}.${Structure}_${Label}.${Mesh}.label.gii From 8b1c4655b2a64d7b8420ebb84cf2b71de3891aff Mon Sep 17 00:00:00 2001 From: glasserm Date: Sat, 11 Jan 2025 10:50:26 -0600 Subject: [PATCH 9/9] *math allows Var to be used without modification. Co-authored-by: Tim Coalson --- HippUnfoldHCP/PostHippUnfoldHCP.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HippUnfoldHCP/PostHippUnfoldHCP.sh b/HippUnfoldHCP/PostHippUnfoldHCP.sh index 46271bbae..ff717021f 100755 --- a/HippUnfoldHCP/PostHippUnfoldHCP.sh +++ b/HippUnfoldHCP/PostHippUnfoldHCP.sh @@ -149,7 +149,7 @@ for Structure in $Structures ; do Label=`echo $Label | cut -d "@" -f 1` if [ ${Structure} = "hipp" ] ; then if [ ${Hemisphere} = "L" ] ; then - Expression="Var*1" + Expression="Var" elif [ ${Hemisphere} = "R" ] ; then Expression="Var + 8" fi