Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Examples/Scripts/RunHippUnfoldHCP.sh
Original file line number Diff line number Diff line change
@@ -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
94 changes: 94 additions & 0 deletions Examples/Scripts/RunPostHippUnfoldHCP.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Examples/Scripts/SetUpHCPPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
coalsont marked this conversation as resolved.
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
Expand Down
122 changes: 122 additions & 0 deletions HippUnfoldHCP/HippUnfoldHCP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/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' ""
Comment thread
glasserm marked this conversation as resolved.
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

HippUnfoldT1wFolder="$HippUnfoldDIR/T1w/hippunfold"
HippUnfoldT2wFolder="$HippUnfoldDIR/T2w/hippunfold"
HippUnfoldT1wT2wFolder="$HippUnfoldDIR/T1wT2w/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"

ln -sf "$T1wImage" "$HippUnfoldT1wFolder/s_${Subject}_T1w_acpc_dc_restore.nii.gz"
ln -sf "$T2wImage" "$HippUnfoldT1wFolder/s_${Subject}_T2w_acpc_dc_restore.nii.gz"
ln -sf "$T1wImage" "$HippUnfoldT2wFolder/s_${Subject}_T1w_acpc_dc_restore.nii.gz"
ln -sf "$T2wImage" "$HippUnfoldT2wFolder/s_${Subject}_T2w_acpc_dc_restore.nii.gz"
ln -sf "$T1wImage" "$HippUnfoldT1wT2wFolder/s_${Subject}_T1w_acpc_dc_restore.nii.gz"
ln -sf "$T2wImage" "$HippUnfoldT1wT2wFolder/s_${Subject}_T2w_acpc_dc_restore.nii.gz"

log_Msg "Created folder structure under $HippUnfoldDIR and copied T1w and T2w images"
log_Msg "Starting HippUnfold pipeline for subject: $Subject"

export APPTAINER_BINDPATH=${HIPPUNFOLD_CACHE_DIR}:${HIPPUNFOLD_CACHE_DIR}
export APPTAINER_CACHEDIR=${HIPPUNFOLD_CACHE_DIR}/apptainer
export APPTAINERENV_HIPPUNFOLD_CACHE_DIR=${HIPPUNFOLD_CACHE_DIR} #This one actually did something

#export HIPPUNFOLD_CACHE_DIR=${HippUnfoldDIR}/cache #Keep for QuNex?
#export APPTAINER_BINDPATH=${StudyFolder}:${StudyFolder}
#export APPTAINER_CACHEDIR=${HippUnfoldDIR}/apptainer
#export APPTAINERENV_HIPPUNFOLD_CACHE_DIR=${HippUnfoldDIR}/cache #This one actually did something
#mkdir -p ${HIPPUNFOLD_CACHE_DIR}
#mkdir -p ${APPTAINER_CACHEDIR}


if [[ "${HIPPUNFOLDPATH:-}" == "" ]]
then
hippcmd=(hippunfold --use-conda)
else
hippcmd=(apptainer run --bind "$StudyFolder" -e "$HIPPUNFOLDPATH")
fi

log_Msg "Running T1w HippUnfold for subject: $Subject"
#Seriously: don't put a $ on {subject} and don't capitalize the S...
"${hippcmd[@]}" "$HippUnfoldT1wFolder" "$HippUnfoldT1wFolder" participant \
--modality T1w \
--path-T1w "$HippUnfoldT1wFolder"/s_{subject}_T1w_acpc_dc_restore.nii.gz \
--path-T2w "$HippUnfoldT1wFolder"/s_{subject}_T2w_acpc_dc_restore.nii.gz \
--cores all \
--force-output \
--generate_myelin_map \
--output-density native 512 2k 8k 18k
log_Msg "T1w HippUnfold completed."

log_Msg "Running T2w HippUnfold for subject: $Subject"
"${hippcmd[@]}" "$HippUnfoldT2wFolder" "$HippUnfoldT2wFolder" participant \
--modality T2w \
--path-T1w "$HippUnfoldT2wFolder"/s_{subject}_T1w_acpc_dc_restore.nii.gz \
--path-T2w "$HippUnfoldT2wFolder"/s_{subject}_T2w_acpc_dc_restore.nii.gz \
--cores all \
--force-output \
--generate_myelin_map \
--output-density native 512 2k 8k 18k
log_Msg "T2w HippUnfold completed."

log_Msg "Running T1wT2w HippUnfold for subject: $Subject"
"${hippcmd[@]}" "$HippUnfoldT1wT2wFolder" "$HippUnfoldT1wT2wFolder" participant \
--modality T2w \
--path-T1w "$HippUnfoldT1wT2wFolder"/s_{subject}_T1w_acpc_dc_restore.nii.gz \
--path-T2w "$HippUnfoldT1wT2wFolder"/s_{subject}_T2w_acpc_dc_restore.nii.gz \
--cores all \
--force-output \
--generate_myelin_map \
--output-density native 512 2k 8k 18k \
--force-nnunet-model T1T2w
log_Msg "T1wT2w HippUnfold completed."
Comment thread
glasserm marked this conversation as resolved.

log_Msg "HippUnfold pipeline completed successfully for subject: $Subject"

Loading