From 90e527b22b05c16634ddd8b4ba3702c084af5456 Mon Sep 17 00:00:00 2001 From: Jure Demsar Date: Thu, 16 Jun 2022 06:36:16 -0400 Subject: [PATCH 01/97] Initial implementation of the Longitudinal FreeSurfer pipeline --- FreeSurfer/LongitudinalFreeSurferPipeline.sh | 489 +++++++++++++++++++ 1 file changed, 489 insertions(+) create mode 100755 FreeSurfer/LongitudinalFreeSurferPipeline.sh diff --git a/FreeSurfer/LongitudinalFreeSurferPipeline.sh b/FreeSurfer/LongitudinalFreeSurferPipeline.sh new file mode 100755 index 000000000..e42b7922e --- /dev/null +++ b/FreeSurfer/LongitudinalFreeSurferPipeline.sh @@ -0,0 +1,489 @@ +#!/bin/bash + +#~ND~FORMAT~MARKDOWN~ +#~ND~START~ +# +# # LongitudinalFreeSurferPipeline.sh +# +# ## Copyright Notice +# +# Copyright (C) 2015-2018 The Human Connectome Project/Connectome Coordination Facility +# +# * Washington University in St. Louis +# * Univeristy of Ljubljana +# +# ## Author(s) +# +# * Jure Demsar, Faculty of Computer and Information Science, University of Ljubljana +# * Matthew F. Glasser, Department of Anatomy and Neurobiology, Washington University in St. Louis +# +# ## Product +# +# [Human Connectome Project](http://www.humanconnectome.org) (HCP) Pipelines +# +# ## License +# +# See the [LICENSE](https://github.com/Washington-University/Pipelines/blob/master/LICENSE.md) file +# +#~ND~END~ + +# Configure custom tools +# - Determine if the PATH is configured so that the custom FreeSurfer v6 tools used by this script +# (the recon-all.v6.hires script and other scripts called by the recon-all.v6.hires script) +# are found on the PATH. If all such custom scripts are found, then we do nothing here. +# If any one of them is not found on the PATH, then we change the PATH so that the +# versions of these scripts found in ${HCPPIPEDIR}/FreeSurfer/custom are used. +configure_custom_tools() +{ + local which_recon_all + local which_conf2hires + local which_longmc + + which_recon_all=$(which recon-all.v6.hires) + which_conf2hires=$(which conf2hires) + which_longmc=$(which longmc) + + if [[ "${which_recon_all}" = "" || "${which_conf2hires}" == "" || "${which_longmc}" = "" ]] ; then + export PATH="${HCPPIPEDIR}/FreeSurfer/custom:${PATH}" + log_Warn "We were not able to locate one of the following required tools:" + log_Warn "recon-all.v6.hires, conf2hires, or longmc" + log_Warn "" + log_Warn "To be able to run this script using the standard versions of these tools," + log_Warn "we added ${HCPPIPEDIR}/FreeSurfer/custom to the beginning of the PATH." + log_Warn "" + log_Warn "If you intended to use some other version of these tools, please configure" + log_Warn "your PATH before invoking this script, such that the tools you intended to" + log_Warn "use can be found on the PATH." + log_Warn "" + log_Warn "PATH set to: ${PATH}" + fi +} + +# Show tool versions +show_tool_versions() +{ + # Show HCP pipelines version + log_Msg "Showing HCP Pipelines version" + ${HCPPIPEDIR}/show_version + + # Show recon-all version + log_Msg "Showing recon-all.v6.hires version" + local which_recon_all=$(which recon-all.v6.hires) + log_Msg ${which_recon_all} + recon-all.v6.hires -version + + # Show tkregister version + log_Msg "Showing tkregister version" + which tkregister + tkregister -version + + # Show mri_concatenate_lta version + log_Msg "Showing mri_concatenate_lta version" + which mri_concatenate_lta + mri_concatenate_lta -version + + # Show mri_surf2surf version + log_Msg "Showing mri_surf2surf version" + which mri_surf2surf + mri_surf2surf -version + + # Show fslmaths location + log_Msg "Showing fslmaths location" + which fslmaths +} + +validate_freesurfer_version() +{ + if [ -z "${FREESURFER_HOME}" ]; then + log_Err_Abort "FREESURFER_HOME must be set" + fi + + freesurfer_version_file="${FREESURFER_HOME}/build-stamp.txt" + + if [ -f "${freesurfer_version_file}" ]; then + freesurfer_version_string=$(cat "${freesurfer_version_file}") + log_Msg "INFO: Determined that FreeSurfer full version string is: ${freesurfer_version_string}" + else + log_Err_Abort "Cannot tell which version of FreeSurfer you are using." + fi + + # strip out extraneous stuff from FreeSurfer version string + freesurfer_version_string_array=(${freesurfer_version_string//-/ }) + freesurfer_version=${freesurfer_version_string_array[5]} + freesurfer_version=${freesurfer_version#v} # strip leading "v" + + log_Msg "INFO: Determined that FreeSurfer version is: ${freesurfer_version}" + + # break FreeSurfer version into components + # primary, secondary, and tertiary + # version X.Y.Z ==> X primary, Y secondary, Z tertiary + freesurfer_version_array=(${freesurfer_version//./ }) + + freesurfer_primary_version="${freesurfer_version_array[0]}" + freesurfer_primary_version=${freesurfer_primary_version//[!0-9]/} + + freesurfer_secondary_version="${freesurfer_version_array[1]}" + freesurfer_secondary_version=${freesurfer_secondary_version//[!0-9]/} + + freesurfer_tertiary_version="${freesurfer_version_array[2]}" + freesurfer_tertiary_version=${freesurfer_tertiary_version//[!0-9]/} + + if [[ $(( ${freesurfer_primary_version} )) -lt 6 ]]; then + # e.g. 4.y.z, 5.y.z + log_Err_Abort "FreeSurfer version 6.0.0 or greater is required. (Use FreeSurferPipeline-v5.3.0-HCP.sh if you want to continue using FreeSurfer 5.3)" + fi +} + +# Show usage information +show_usage() +{ + cat < = user supplied value + + [--help] : show usage information and exit + + one from the following group is required + + --subject-dir= + --subjectDIR= + + --subject= + --sessions=<@ delimited list of session ids> + --template=