From ad23744b979febdb0ea3fc3385b29b25444459e8 Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Tue, 18 Jun 2019 13:45:27 -0500 Subject: [PATCH 1/7] PreFreeSurferPipelineBatch.sh being adapted for LifeSpan/Course use --- .../Scripts/PreFreeSurferPipelineBatch.sh | 1159 +++++++++++------ 1 file changed, 737 insertions(+), 422 deletions(-) diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index f6d984d95..7c45660b3 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -7,7 +7,7 @@ # # ## Copyright Notice # -# Copyright (C) 2013-2018 The Human Connectome Project +# Copyright (C) 2013-2019 The Human Connectome Project/The Connectome Coordination Facility # # * Washington University in St. Louis # * University of Minnesota @@ -37,22 +37,28 @@ # # ## Prerequisites # -# ### Installed software +# ### Installed software for processing HCP-YA data # # * FSL (version 5.0.6) # * FreeSurfer (version 5.3.0-HCP) # * gradunwarp (HCP version 1.0.2) - if doing gradient distortion correction # +# ### Installed software for processing LifeSpan data +# +# * FSL (version v6.0.1) +# * FreeSurfer (version v6.0.0) +# * gradunwarp (HCP version 1.0.2) - if doing gradient distortion correction +# # ### Environment variables # # Should be set in script file pointed to by EnvironmentScript variable. # See setting of the EnvironmentScript variable in the main() function # below. # -# * FSLDIR - main FSL installation directory -# * FREESURFER_HOME - main FreeSurfer installation directory -# * HCPPIPEDIR - main HCP Pipelines installation directory -# * CARET7DIR - main Connectome Workbench installation directory +# * FSLDIR - FSL installation directory +# * FREESURFER_HOME - FreeSurfer installation directory +# * HCPPIPEDIR - HCP Pipelines installation directory +# * CARET7DIR - Connectome Workbench installation directory # * PATH - must point to where gradient_unwarp.py is if doing gradient unwarping # # @@ -61,431 +67,740 @@ # #~ND~END~ -# Function: get_batch_options -# Description -# -# Retrieve the following command line parameter values if specified -# -# --StudyFolder= - primary study folder containing subject ID subdirectories -# --Subjlist= - quoted, space separated list of subject IDs on which -# to run the pipeline -# --runlocal - if specified (without an argument), processing is run -# on "this" machine as opposed to being submitted to a -# computing grid -# -# Set the values of the following global variables to reflect command -# line specified parameters -# -# command_line_specified_study_folder -# command_line_specified_subj_list -# command_line_specified_run_local -# -# These values are intended to be used to override any values set -# directly within this script file -get_batch_options() { - local arguments=("$@") - - unset command_line_specified_study_folder - unset command_line_specified_subj - unset command_line_specified_run_local - - 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_subj=${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 -} +# Default location of study folder +DEFAULT_STUDY_FOLDER="${HOME}/projects/Pipelines_ExampleData" -# Function: main -# Description: main processing work of this script -main() +# Default space delimited list of subject IDs +DEFAULT_SESSION_LIST="100307" + +# Default pipeline environment script +DEFAULT_ENVIRONMENT_SCRIPT="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" + +usage() { - get_batch_options "$@" + cat < = user supplied value - # Use any command line specified options to override any of the variable settings above - if [ -n "${command_line_specified_study_folder}" ]; then - StudyFolder="${command_line_specified_study_folder}" - fi + [--help] : show this usage information and exit - if [ -n "${command_line_specified_subj}" ]; then - Subjlist="${command_line_specified_subj}" - fi + [--StudyFolder=] + [--study=] + [--working-dir=] + + These are equivalent alternative ways for specifying the study folder in which + to find the session or subject directories. + + If none of these options are specified, the study folder used defaults to: + + ${DEFAULT_STUDY_FOLDER} + + [--Subject=] + [--subject=] + [--Session=] + [--session=] + + These are equivalent alternative ways for specifying a session (or subject) + within the study folder for which to run this processing. + + This parameter can be specified multiple times to create a list of + sessions to process. E.g. --session=100307 --subject=100287 --Session=190876 + would result in the following list of sessions to process: 100307 100287 190876 + + If none of these options are specified, the list of sessions to process + defaults to: - # Report major script control variables to user - echo "StudyFolder: ${StudyFolder}" - echo "Subjlist: ${Subjlist}" - echo "EnvironmentScript: ${EnvironmentScript}" - echo "Run locally: ${command_line_specified_run_local}" - - # Set up pipeline environment variables and software - source ${EnvironmentScript} - - # Define processing queue to be used if submitted to job scheduler - # if [ X$SGE_ROOT != X ] ; then - # QUEUE="-q long.q" - # QUEUE="-q veryshort.q" - QUEUE="-q hcp_priority.q" - # fi - - # If PRINTCOM is not a null or empty string variable, then - # this script and other scripts that it calls will simply - # print out the primary commands it otherwise would run. - # This printing will be done using the command specified - # in the PRINTCOM variable - PRINTCOM="" - # PRINTCOM="echo" - - # - # Inputs: - # - # Scripts called by this script do NOT assume anything about the form of the - # input names or paths. This batch script assumes the HCP raw data naming - # convention, e.g. - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR2/${Subject}_3T_T1w_MPR2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz - - # Scan settings: - # - # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your - # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. - # (i.e., the study collected on the customized Connectom scanner). - - # Readout Distortion Correction: - # - # You have the option of using either gradient echo field maps or spin echo - # field maps to perform readout distortion correction on your structural - # images, or not to do readout distortion correction at all. - # - # The HCP Pipeline Scripts currently support the use of gradient echo field - # maps or spin echo field maps as they are produced by the Siemens Connectom - # Scanner. They also support the use of gradient echo field maps as generated - # by General Electric scanners. - # - # Change either the gradient echo field map or spin echo field map scan - # settings to match your data. This script is setup to use gradient echo - # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. - - # Gradient Distortion Correction: - # - # If using gradient distortion correction, use the coefficents from your - # scanner. The HCP gradient distortion coefficents are only available through - # Siemens. Gradient distortion in standard scanners like the Trio is much - # less than for the HCP Connectom scanner. - - # DO WORK - - # Cycle through specified subjects - for Subject in $Subjlist ; do - echo $Subject - - # Input Images - - # Detect Number of T1w Images and build list of full paths to - # T1w images - numT1ws=`ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l` - echo "Found ${numT1ws} T1w Images for subject ${Subject}" - T1wInputImages="" - i=1 - while [ $i -le $numT1ws ] ; do - T1wInputImages=`echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MPR${i}.nii.gz@"` - i=$(($i+1)) - done - - # Detect Number of T2w Images and build list of full paths to - # T2w images - numT2ws=`ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l` - echo "Found ${numT2ws} T2w Images for subject ${Subject}" - T2wInputImages="" - i=1 - while [ $i -le $numT2ws ] ; do - T2wInputImages=`echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@"` - i=$(($i+1)) - done - - # Readout Distortion Correction: - # - # Currently supported Averaging and readout distortion correction - # methods: (i.e. supported values for the AvgrdcSTRING variable in this - # script and the --avgrdcmethod= command line option for the - # PreFreeSurferPipeline.sh script.) - # - # "NONE" - # Average any repeats but do no readout distortion correction - # - # "FIELDMAP" - # This value is equivalent to the "SiemensFieldMap" value described - # below. Use of the "SiemensFieldMap" value is prefered, but - # "FIELDMAP" is included for backward compatibility with earlier versions - # of these scripts that only supported use of Siemens-specific - # Gradient Echo Field Maps and did not support Gradient Echo Field - # Maps from any other scanner vendor. - # - # "TOPUP" - # Average any repeats and use Spin Echo Field Maps for readout - # distortion correction - # - # "GeneralElectricFieldMap" - # Average any repeats and use General Electric specific Gradient - # Echo Field Map for readout distortion correction - # - # "SiemensFieldMap" - # Average any repeats and use Siemens specific Gradient Echo - # Field Maps for readout distortion correction - # - # Current Setup is for Siemens specific Gradient Echo Field Maps - # - # The following settings for AvgrdcSTRING, MagnitudeInputName, - # PhaseInputName, and TE are for using the Siemens specific - # Gradient Echo Field Maps that are collected and used in the - # standard HCP-YA protocol. - # - # Note: The AvgrdcSTRING variable could also be set to the value - # "FIELDMAP" which is equivalent to "SiemensFieldMap". - AvgrdcSTRING="SiemensFieldMap" - - # ---------------------------------------------------------------------- - # Variables related to using Siemens specific Gradient Echo Field Maps - # ---------------------------------------------------------------------- - - # The MagnitudeInputName variable should be set to a 4D magitude volume - # with two 3D timepoints or "NONE" if not used - MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" - - # The PhaseInputName variable should be set to a 3D phase difference - # volume or "NONE" if not used - PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" - - # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T - # scanner or "NONE" if not using - TE="2.46" - - # ---------------------------------------------------------------------- - # Variables related to using Spin Echo Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") - - # The SpinEchoPhaseEncodeNegative variable should be set to the - # spin echo field map volume with a negative phase encoding direction - # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); - # AP if using a pair of AP/PA Siemens SEFMS) - # and set to "NONE" if not using SEFMs - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz - SpinEchoPhaseEncodeNegative="NONE" - - # The SpinEchoPhaseEncodePositive variable should be set to the - # spin echo field map volume with positive phase encoding direction - # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), - # and set to "NONE" if not using Spin Echo Field Maps - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz - SpinEchoPhaseEncodePositive="NONE" - - # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. - # Set to "NONE" if not used. - # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) - # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and - # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension - # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation - # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) - # - # Example value for when using Spin Echo Field Maps from the HCP-YA - # 0.000580002668012 - SEEchoSpacing="NONE" - - # Spin Echo Unwarping Direction (according to the *voxel* axes) - # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) - # Set to "NONE" if not used. - # - # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} - # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign - # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] - SEUnwarpDir="NONE" - - # Topup Configuration file - # Set to "NONE" if not using SEFMs - # - # Default file to use when using SEFMs - # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" - TopupConfig="NONE" - - # ---------------------------------------------------------------------- - # Variables related to using General Electric specific Gradient Echo - # Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using General Electric specific Gradient Echo Field Maps (i.e. when - # AvgrdcSTRING="GeneralElectricFieldMap") - - # Example value for when using General Electric Gradient Echo Field Map - # - # GEB0InputName should be a General Electric style B0 fieldmap with two - # volumes - # 1) fieldmap in deg and - # 2) magnitude, - # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap - # - # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" - GEB0InputName="NONE" - - # Templates - - # Hires T1w MNI template - T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" - - # Hires brain extracted MNI template - T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" - - # Lowres T1w MNI template - T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" - - # Hires T2w MNI Template - T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" - - # Hires T2w brain extracted MNI Template - T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" - - # Lowres T2w MNI Template - T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" - - # Hires MNI brain mask template - TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" - - # Lowres MNI brain mask template - Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" - - # Structural Scan Settings - # - # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, - # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) - # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction - # of the Spin Echo Field Maps (if using them). - # Note that polarity of UnwarpDir DOES matter. - # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) - # - # set all these values to NONE if not doing readout distortion correction - # - # Sample values for when using General Electric structurals - # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? - - # The values set below are for the HCP-YA Protocol using the Siemens - # Connectom Scanner - - # DICOM field (0019,1018) in s or "NONE" if not used - T1wSampleSpacing="0.0000074" - - # DICOM field (0019,1018) in s or "NONE" if not used - T2wSampleSpacing="0.0000021" - - # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners - UnwarpDir="z" - - # Other Config Settings - - # BrainSize in mm, 150 for humans - BrainSize="150" - - # FNIRT 2mm T1w Config - FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" - - # Location of Coeffs file or "NONE" to skip - # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" - - # Set to NONE to skip gradient distortion correction - GradientDistortionCoeffs="NONE" - - # Establish queuing command based on command line option - if [ -n "${command_line_specified_run_local}" ] ; then - echo "About to run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" - queuing_command="" - else - echo "About to use fsl_sub to queue or run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" - queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" + ${DEFAULT_SESSION_LIST} + + [--runlocal] + [--run-local] + + These are equivalent alternative ways for specifying that processing should + occur "locally" (i.e. on this machine) as opposed to trying to submit the + processing to a queueing system. + + [--lifespan] + + Using this option indicates that the processing should be run on data in a + directory structure that takes the standard HCP/LifeSpan project form as + opposed to the default directory structure which is the HCP Young Adult + (HCP-YA) form. + + [--env=] + [--env-script=] + + These are equivalent alternative ways for specifying the path to the + environment script which sets the environment variables necessary + to run this processing. + + If none of these options are specified, the environment script path + defaults to: + + ${DEFAULT_ENVIRONMENT_SCRIPT} + +EOF +} + +get_options() +{ + # Note that the ($@) construction parses the arguments into an + # array of values using spaces as the delimiter + local arguments=($@) + + unset p_study_folder + unset p_session_list + unset p_run_local + unset p_lifespan_style + unset p_environment_script + + # parse arguments + local num_args=${#arguments[@]} + local argument + local index + + for (( index = 0; index < num_args; ++index )); do + argument=${arguments[index]} + + case ${argument} in + --help) + usage + exit 1 + ;; + --StudyFolder=*) + p_study_folder=${argument#*=} + ;; + --study=*) + p_study_folder=${argument#*=} + ;; + --working-dir=*) + p_study_folder=${argument#*=} + ;; + --Subject=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --subject=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --Session=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --session=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " fi + p_session_list+=${argument#*=} + ;; + --runlocal) + p_run_local="TRUE" + ;; + --run-local) + p_run_local="TRUE" + ;; + --lifespan) + p_lifespan_style="TRUE" + ;; + --env=*) + p_environment_script=${argument#*=} + ;; + --env-script=*) + p_environment_script=${argument#*=} + ;; + *) + usage + exit 1 + ;; + esac + + done + + if [ -z "${p_study_folder}" ]; then + p_study_folder=${DEFAULT_STUDY_FOLDER} + fi + + if [ -z "${p_session_list}" ]; then + p_session_list=${DEFAULT_SESSION_LIST} + fi + + if [ -z "${p_environment_script}" ]; then + p_environment_script=${DEFAULT_ENVIRONMENT_SCRIPT} + fi +} + +main() +{ + get_options "$@" + + # Gather options specified + local StudyFolder="${p_study_folder}" + local SessionList="${p_session_list}" + local RunLocal="${p_run_local}" + local LifeSpanStyle="${p_lifespan_style}" + local EnvironmentScript="${p_environment_script}" + + # Report major script control variables to user + echo "" + echo "StudyFolder: ${StudyFolder}" + echo "SessionList: ${SessionList}" + echo "RunLocal: ${RunLocal}" + echo "LifeSpanStyle: ${LifeSpanStyle}" + echo "EnvironmentScript: ${EnvironmentScript}" + echo "" + + # Set up pipeline environment variables and software + source ${EnvironmentScript} + + # Report environment variables pointing to tools + echo "FSLDIR: ${FSLDIR}" + echo "FREESURFER_HOME: ${FREESURFER_HOME}" + echo "HCPPIPEDIR: ${HCPPIPEDIR}" + echo "CARET7DIR: ${CARET7DIR}" + echo "PATH: ${PATH}" + + # Define processing queue to be used if submitted to job scheduler + # if [ X$SGE_ROOT != X ] ; then + # QUEUE="-q long.q" + # QUEUE="-q veryshort.q" + QUEUE="-q hcp_priority.q" + # fi + + # If PRINTCOM is not a null or empty string variable, then + # this script and other scripts that it calls will simply + # print out the primary commands it otherwise would run. + # This printing will be done using the command specified + # in the PRINTCOM variable + PRINTCOM="" + # PRINTCOM="echo" + + for Session in ${SessionList} ; do + echo "" + echo "Processing: ${Session}" + echo "" + + # Scripts called by this script do NOT assume anything about the form of the + # input names or paths. This batch script assumes either the HCP unprocessed + # data naming convention or the LifeSpan unprocessed data naming convention + # depending upon whether LifeSpanStyle is "TRUE". + + if [ "${LifeSpanStyle}" = "TRUE" ]; then + + # Input Images + # + # If LifeSpanStyle is "TRUE", then the LifeSpan unprocessed data naming convention + # is used. + + T1wInputImages="${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_T1w_MPR_vNav_4e_RMS.nii.gz" + T2wInputImages="${StudyFolder}/${Session}/unprocessed/T2w_SPC_vNav/${Session}_T2w_SPC_vNav.nii.gz" + + if [ ! -e ${T1wInputImages} ]; then + echo "Expected input T1w image: ${T1wInputImages} " + echo "Does not exist" + exit 1 + fi + + if [ ! -e ${T2wInputImages} ]; then + echo "Expected input T2w image: ${T2wInputImages} " + echo "Does not exist" + exit 1 + fi + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/Prisma_3T_coeff_AS82.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # NOT USED IN THIS CASE + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="NONE" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="NONE" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="NONE" + + # The values set below are for the LifeSpan Aging Protocol using + # a Prisma 3T scanner + + # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file + # "DwellTime": 2.1e-06 + T1wSampleSpacing="0.000002100" + + # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file + # "DwellTime": 2.1e-06 + T2wSampleSpacing="0.000002100" + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is to use TOPUP and Spin Echo Field Maps + # + AvgrdcSTRING="TOPUP" + + # Spin Echo Field Maps + + PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) + NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) + + echo "PositiveFieldMaps: " ${PositiveFieldMaps} + echo "PositiveFieldMaps: " ${NegativeFieldMaps} + + exit 1 + + + + # # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # # with all the specified parameter values + + # ${queuing_command} ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh \ + # --path="${StudyFolder}" \ + # --subject="${Session}" \ + # --t1="${T1wInputImages}" \ + # --t2="${T2wInputImages}" \ + # --t1template="${T1wTemplate}" \ + # --t1templatebrain="${T1wTemplateBrain}" \ + # --t1template2mm="${T1wTemplate2mm}" \ + # --t2template="${T2wTemplate}" \ + # --t2templatebrain="${T2wTemplateBrain}" \ + # --t2template2mm="${T2wTemplate2mm}" \ + # --templatemask="${TemplateMask}" \ + # --template2mmmask="${Template2mmMask}" \ + # --fnirtconfig="$FNIRTConfig" \ + # --gdcoeffs="$GradientDistortionCoeffs" \ + # --brainsize="$BrainSize" \ + # --echodiff="${TE}" \ + # --t1samplespacing="$T1wSampleSpacing" \ + # --t2samplespacing="$T2wSampleSpacing" \ + # --avgrdcmethod="$AvgrdcSTRING" \ + + + + + # --SEPhaseNeg="$SpinEchoPhaseEncodeNegative" \ + # --SEPhasePos="$SpinEchoPhaseEncodePositive" \ + # --seechospacing="$SEEchoSpacing" \ + # --seunwarpdir="$SEUnwarpDir" \ + + + + # --unwarpdir="$UnwarpDir" \ + + + # --topupconfig="$TopupConfig" \ + # --printcom=${PRINTCOM} + + + + + + + + + + + + + + else # Default to HCP style + + # Note that for the HCP naming convention, the "Session" and the "Subject" are + # essentially equivalent. Sessions would be subject IDs like 100307, 110226, 997865, etc. + Subject="${Session}" + + # If LifeSpanStyle is NOT "TRUE", then the HCP unprocessed data naming convention + # is used, e.g. + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz + + # Detect Number of T1w Images and build list of full paths to T1w images + numT1ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l) + echo "Found ${numT1ws} T1w Images for subject: ${Subject}" + T1wInputImages="" + i=1 + while [ ${i} -le ${numT1ws} ] ; do + echo "T1w ${i}" + T1wInputImages=$(echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MRP${i}.nii.gz@") + i=$(($i+1)) + done + + # Detect Number of T2w Images and build list of full paths to T2w images + numT2ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l) + echo "Found ${numT2ws} T2w Images for subject: ${Subject}" + T2wInputImages="" + i=1 + while [ ${i} -le ${numT2ws} ] ; do + echo "T2w ${i}" + T2wInputImages=$(echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@") + i=$(($i+1)) + done + + # Scan settings: + # + # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your + # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. + # (i.e., the study collected on the customized Connectom scanner). + + # Readout Distortion Correction: + # + # You have the option of using either gradient echo field maps or spin echo + # field maps to perform readout distortion correction on your structural + # images, or not to do readout distortion correction at all. + # + # The HCP Pipeline Scripts currently support the use of gradient echo field + # maps or spin echo field maps as they are produced by the Siemens Connectom + # Scanner. They also support the use of gradient echo field maps as generated + # by General Electric scanners. + # + # Change either the gradient echo field map or spin echo field map scan + # settings to match your data. This script is setup to use gradient echo + # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. + + # Gradient Distortion Correction: + # + # If using gradient distortion correction, use the coefficents from your + # scanner. The HCP gradient distortion coefficents are only available through + # Siemens. Gradient distortion in standard scanners like the Trio is much + # less than for the HCP Connectom scanner. + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is for Siemens specific Gradient Echo Field Maps + # + # The following settings for AvgrdcSTRING, MagnitudeInputName, + # PhaseInputName, and TE are for using the Siemens specific + # Gradient Echo Field Maps that are collected and used in the + # standard HCP-YA protocol. + # + # Note: The AvgrdcSTRING variable could also be set to the value + # "FIELDMAP" which is equivalent to "SiemensFieldMap". + AvgrdcSTRING="SiemensFieldMap" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="2.46" + + # ---------------------------------------------------------------------- + # Variables related to using Spin Echo Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") + + # The SpinEchoPhaseEncodeNegative variable should be set to the + # spin echo field map volume with a negative phase encoding direction + # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); + # AP if using a pair of AP/PA Siemens SEFMS) + # and set to "NONE" if not using SEFMs + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz + SpinEchoPhaseEncodeNegative="NONE" + + # The SpinEchoPhaseEncodePositive variable should be set to the + # spin echo field map volume with positive phase encoding direction + # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), + # and set to "NONE" if not using Spin Echo Field Maps + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz + SpinEchoPhaseEncodePositive="NONE" + + # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. + # Set to "NONE" if not used. + # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) + # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and + # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension + # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation + # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) + # + # Example value for when using Spin Echo Field Maps from the HCP-YA + # 0.000580002668012 + SEEchoSpacing="NONE" + + # Spin Echo Unwarping Direction (according to the *voxel* axes) + # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) + # Set to "NONE" if not used. + # + # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} + # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign + # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] + SEUnwarpDir="NONE" + + # Topup Configuration file + # Set to "NONE" if not using SEFMs + # + # Default file to use when using SEFMs + # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" + TopupConfig="NONE" + + # ---------------------------------------------------------------------- + # Variables related to using General Electric specific Gradient Echo + # Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using General Electric specific Gradient Echo Field Maps (i.e. when + # AvgrdcSTRING="GeneralElectricFieldMap") + + # Example value for when using General Electric Gradient Echo Field Map + # + # GEB0InputName should be a General Electric style B0 fieldmap with two + # volumes + # 1) fieldmap in deg and + # 2) magnitude, + # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap + # + # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" + GEB0InputName="NONE" + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # Structural Scan Settings + # + # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, + # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) + # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction + # of the Spin Echo Field Maps (if using them). + # Note that polarity of UnwarpDir DOES matter. + # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) + # + # set all these values to NONE if not doing readout distortion correction + # + # Sample values for when using General Electric structurals + # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? + + # The values set below are for the HCP-YA Protocol using the Siemens + # Connectom Scanner + + # DICOM field (0019,1018) in s or "NONE" if not used + T1wSampleSpacing="0.0000074" + + # DICOM field (0019,1018) in s or "NONE" if not used + T2wSampleSpacing="0.0000021" + + # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners + UnwarpDir="z" + + # Other Config Settings + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # Establish queuing command based on command line option + if [ -n "${RunLocal}" ] ; then + echo "About to run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" + queuing_command="" + else + echo "About to use fsl_sub to queue ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" + queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" + fi + + # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # with all the specified parameter values + + PreFreeSurferCmd="${queuing_command} " + PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " + PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " + PreFreeSurferCmd+=" --subject=\"${Subject}\" " + PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " + PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " + PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " + PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " + PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " + PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " + PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " + PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " + PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " + PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " + PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " + PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " + PreFreeSurferCmd+=" --fmapmag=\"${MagnitudeInputName}\" " + PreFreeSurferCmd+=" --fmapphase=\"${PhaseInputName}\" " + PreFreeSurferCmd+=" --fmapgeneralelectric=\"${GEB0InputName}\" " + PreFreeSurferCmd+=" --echodiff=\"${TE}\" " + PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " + PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " + PreFreeSurferCmd+=" --seechospacing=\"${SEEchoSpacing}\" " + PreFreeSurferCmd+=" --seunwarpdir=\"${SEUnwarpDir}\" " + PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " + PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " + PreFreeSurferCmd+=" --unwarpdir=\"${UnwarpDir}\" " + PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " + PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " + PreFreeSurferCmd+=" --topupconfig=\"${TopupConfig}\" " + PreFreeSurferCmd+=" --printcom=\"${PRINTCOM}\" " + + echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" + + # ${PreFreeSurferCmd} + + fi - # Run (or submit to be run) the PreFreeSurferPipeline.sh script - # with all the specified parameter values - - ${queuing_command} ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh \ - --path="$StudyFolder" \ - --subject="$Subject" \ - --t1="$T1wInputImages" \ - --t2="$T2wInputImages" \ - --t1template="$T1wTemplate" \ - --t1templatebrain="$T1wTemplateBrain" \ - --t1template2mm="$T1wTemplate2mm" \ - --t2template="$T2wTemplate" \ - --t2templatebrain="$T2wTemplateBrain" \ - --t2template2mm="$T2wTemplate2mm" \ - --templatemask="$TemplateMask" \ - --template2mmmask="$Template2mmMask" \ - --brainsize="$BrainSize" \ - --fnirtconfig="$FNIRTConfig" \ - --fmapmag="$MagnitudeInputName" \ - --fmapphase="$PhaseInputName" \ - --fmapgeneralelectric="$GEB0InputName" \ - --echodiff="$TE" \ - --SEPhaseNeg="$SpinEchoPhaseEncodeNegative" \ - --SEPhasePos="$SpinEchoPhaseEncodePositive" \ - --seechospacing="$SEEchoSpacing" \ - --seunwarpdir="$SEUnwarpDir" \ - --t1samplespacing="$T1wSampleSpacing" \ - --t2samplespacing="$T2wSampleSpacing" \ - --unwarpdir="$UnwarpDir" \ - --gdcoeffs="$GradientDistortionCoeffs" \ - --avgrdcmethod="$AvgrdcSTRING" \ - --topupconfig="$TopupConfig" \ - --printcom=$PRINTCOM - - done + done } # Invoke the main function to get things started From 948576a3d0553bb9bc47a736b162bd0962761ae3 Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Tue, 18 Jun 2019 13:50:40 -0500 Subject: [PATCH 2/7] PreFreeSurferPipelineBatch.sh in work --- .../Scripts/PreFreeSurferPipelineBatch.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index 7c45660b3..433488b95 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -425,6 +425,25 @@ main() exit 1 + + + + + + --SEPhaseNeg=/HCP/hcpdb/build_ssd/chpc/BUILD/tbbrown/LifeSpanAging/HCA6002236_V1_MR/unprocessed/T1w_MPR_vNav_4e_RMS/HCA6002236_V1\ + _MR_SpinEchoFieldMap2_AP.nii.gz + --SEPhasePos=/HCP/hcpdb/build_ssd/chpc/BUILD/tbbrown/LifeSpanAging/HCA6002236_V1_MR/unprocessed/T1w_MPR_vNav_4e_RMS/HCA6002236_V1\ + _MR_SpinEchoFieldMap2_PA.nii.gz + --seechospacing=0.000580009 + --topupconfig=/home/tbbrown/pipeline_tools/HCPpipelines/global/config/b02b0.cnf + --seunwarpdir=j + --unwarpdir=z + + + + + + # # Run (or submit to be run) the PreFreeSurferPipeline.sh script From ffa69ce7301538d1a9d6febea051c526416cef9f Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Wed, 19 Jun 2019 08:22:28 -0500 Subject: [PATCH 3/7] PreFreeSurferPipelineBatch.sh in work --- .../Scripts/PreFreeSurferPipelineBatch.sh | 1362 ++++++++--------- 1 file changed, 667 insertions(+), 695 deletions(-) diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index 433488b95..18dc965b2 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -16,9 +16,9 @@ # ## Author(s) # # * Matthew F. Glasser, Department of Anatomy and Neurobiology, -# Washington University in St. Louis +# Washington University in St. Louis # * Timothy B. Brown, Neuroinformatics Research Group, -# Washington University in St. Louis +# Washington University in St. Louis # # ## Product # @@ -78,10 +78,10 @@ DEFAULT_ENVIRONMENT_SCRIPT="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCP usage() { - cat < = user supplied value @@ -91,735 +91,707 @@ PARAMETERs are: [ ] = optional; < > = user supplied value [--study=] [--working-dir=] - These are equivalent alternative ways for specifying the study folder in which - to find the session or subject directories. + These are equivalent alternative ways for specifying the study folder in which + to find the session or subject directories. - If none of these options are specified, the study folder used defaults to: + If none of these options are specified, the study folder used defaults to: - ${DEFAULT_STUDY_FOLDER} + ${DEFAULT_STUDY_FOLDER} [--Subject=] [--subject=] [--Session=] [--session=] - These are equivalent alternative ways for specifying a session (or subject) - within the study folder for which to run this processing. + These are equivalent alternative ways for specifying a session (or subject) + within the study folder for which to run this processing. - This parameter can be specified multiple times to create a list of - sessions to process. E.g. --session=100307 --subject=100287 --Session=190876 - would result in the following list of sessions to process: 100307 100287 190876 + This parameter can be specified multiple times to create a list of + sessions to process. E.g. --session=100307 --subject=100287 --Session=190876 + would result in the following list of sessions to process: 100307 100287 190876 - If none of these options are specified, the list of sessions to process - defaults to: + If none of these options are specified, the list of sessions to process + defaults to: - ${DEFAULT_SESSION_LIST} + ${DEFAULT_SESSION_LIST} [--runlocal] [--run-local] - These are equivalent alternative ways for specifying that processing should - occur "locally" (i.e. on this machine) as opposed to trying to submit the - processing to a queueing system. + These are equivalent alternative ways for specifying that processing should + occur "locally" (i.e. on this machine) as opposed to trying to submit the + processing to a queuing system. [--lifespan] - Using this option indicates that the processing should be run on data in a - directory structure that takes the standard HCP/LifeSpan project form as - opposed to the default directory structure which is the HCP Young Adult - (HCP-YA) form. + Using this option indicates that the processing should be run on data in a + directory structure that takes the standard HCP/LifeSpan project form as + opposed to the default directory structure which is the HCP Young Adult + (HCP-YA) form. [--env=] [--env-script=] - These are equivalent alternative ways for specifying the path to the - environment script which sets the environment variables necessary - to run this processing. + These are equivalent alternative ways for specifying the path to the + environment script which sets the environment variables necessary + to run this processing. - If none of these options are specified, the environment script path - defaults to: + If none of these options are specified, the environment script path + defaults to: - ${DEFAULT_ENVIRONMENT_SCRIPT} + ${DEFAULT_ENVIRONMENT_SCRIPT} EOF } get_options() { - # Note that the ($@) construction parses the arguments into an - # array of values using spaces as the delimiter - local arguments=($@) - - unset p_study_folder - unset p_session_list - unset p_run_local - unset p_lifespan_style - unset p_environment_script - - # parse arguments - local num_args=${#arguments[@]} - local argument - local index - - for (( index = 0; index < num_args; ++index )); do - argument=${arguments[index]} - - case ${argument} in - --help) - usage - exit 1 - ;; - --StudyFolder=*) - p_study_folder=${argument#*=} - ;; - --study=*) - p_study_folder=${argument#*=} - ;; - --working-dir=*) - p_study_folder=${argument#*=} - ;; - --Subject=*) - if [ -n "${p_session_list}" ]; then - p_session_list+=" " - fi - p_session_list+=${argument#*=} - ;; - --subject=*) - if [ -n "${p_session_list}" ]; then - p_session_list+=" " - fi - p_session_list+=${argument#*=} - ;; - --Session=*) - if [ -n "${p_session_list}" ]; then - p_session_list+=" " - fi - p_session_list+=${argument#*=} - ;; - --session=*) - if [ -n "${p_session_list}" ]; then - p_session_list+=" " - fi - p_session_list+=${argument#*=} - ;; - --runlocal) - p_run_local="TRUE" - ;; - --run-local) - p_run_local="TRUE" - ;; - --lifespan) - p_lifespan_style="TRUE" - ;; - --env=*) - p_environment_script=${argument#*=} - ;; - --env-script=*) - p_environment_script=${argument#*=} - ;; - *) - usage - exit 1 - ;; - esac - - done - - if [ -z "${p_study_folder}" ]; then - p_study_folder=${DEFAULT_STUDY_FOLDER} - fi - - if [ -z "${p_session_list}" ]; then - p_session_list=${DEFAULT_SESSION_LIST} - fi - - if [ -z "${p_environment_script}" ]; then - p_environment_script=${DEFAULT_ENVIRONMENT_SCRIPT} - fi + # Note that the ($@) construction parses the arguments into an + # array of values using spaces as the delimiter + local arguments=($@) + + unset p_study_folder + unset p_session_list + unset p_run_local + unset p_lifespan_style + unset p_environment_script + + # parse arguments + local num_args=${#arguments[@]} + local argument + local index + + for (( index = 0; index < num_args; ++index )); do + argument=${arguments[index]} + + case ${argument} in + --help) + usage + exit 1 + ;; + --StudyFolder=*) + p_study_folder=${argument#*=} + ;; + --study=*) + p_study_folder=${argument#*=} + ;; + --working-dir=*) + p_study_folder=${argument#*=} + ;; + --Subject=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --subject=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --Session=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --session=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --runlocal) + p_run_local="TRUE" + ;; + --run-local) + p_run_local="TRUE" + ;; + --lifespan) + p_lifespan_style="TRUE" + ;; + --env=*) + p_environment_script=${argument#*=} + ;; + --env-script=*) + p_environment_script=${argument#*=} + ;; + *) + usage + exit 1 + ;; + esac + + done + + if [ -z "${p_study_folder}" ]; then + p_study_folder=${DEFAULT_STUDY_FOLDER} + fi + + if [ -z "${p_session_list}" ]; then + p_session_list=${DEFAULT_SESSION_LIST} + fi + + if [ -z "${p_environment_script}" ]; then + p_environment_script=${DEFAULT_ENVIRONMENT_SCRIPT} + fi } main() { - get_options "$@" - - # Gather options specified - local StudyFolder="${p_study_folder}" - local SessionList="${p_session_list}" - local RunLocal="${p_run_local}" - local LifeSpanStyle="${p_lifespan_style}" - local EnvironmentScript="${p_environment_script}" - - # Report major script control variables to user - echo "" - echo "StudyFolder: ${StudyFolder}" - echo "SessionList: ${SessionList}" - echo "RunLocal: ${RunLocal}" - echo "LifeSpanStyle: ${LifeSpanStyle}" - echo "EnvironmentScript: ${EnvironmentScript}" - echo "" - - # Set up pipeline environment variables and software - source ${EnvironmentScript} - - # Report environment variables pointing to tools - echo "FSLDIR: ${FSLDIR}" - echo "FREESURFER_HOME: ${FREESURFER_HOME}" - echo "HCPPIPEDIR: ${HCPPIPEDIR}" - echo "CARET7DIR: ${CARET7DIR}" - echo "PATH: ${PATH}" - - # Define processing queue to be used if submitted to job scheduler - # if [ X$SGE_ROOT != X ] ; then - # QUEUE="-q long.q" - # QUEUE="-q veryshort.q" - QUEUE="-q hcp_priority.q" - # fi - - # If PRINTCOM is not a null or empty string variable, then - # this script and other scripts that it calls will simply - # print out the primary commands it otherwise would run. - # This printing will be done using the command specified - # in the PRINTCOM variable - PRINTCOM="" - # PRINTCOM="echo" - - for Session in ${SessionList} ; do + get_options "$@" + + # Gather options specified + local StudyFolder="${p_study_folder}" + local SessionList="${p_session_list}" + local RunLocal="${p_run_local}" + local LifeSpanStyle="${p_lifespan_style}" + local EnvironmentScript="${p_environment_script}" + + # Report major script control variables to user echo "" - echo "Processing: ${Session}" + echo "StudyFolder: ${StudyFolder}" + echo "SessionList: ${SessionList}" + echo "RunLocal: ${RunLocal}" + echo "LifeSpanStyle: ${LifeSpanStyle}" + echo "EnvironmentScript: ${EnvironmentScript}" echo "" - - # Scripts called by this script do NOT assume anything about the form of the - # input names or paths. This batch script assumes either the HCP unprocessed - # data naming convention or the LifeSpan unprocessed data naming convention - # depending upon whether LifeSpanStyle is "TRUE". - if [ "${LifeSpanStyle}" = "TRUE" ]; then - - # Input Images - # - # If LifeSpanStyle is "TRUE", then the LifeSpan unprocessed data naming convention - # is used. - - T1wInputImages="${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_T1w_MPR_vNav_4e_RMS.nii.gz" - T2wInputImages="${StudyFolder}/${Session}/unprocessed/T2w_SPC_vNav/${Session}_T2w_SPC_vNav.nii.gz" - - if [ ! -e ${T1wInputImages} ]; then - echo "Expected input T1w image: ${T1wInputImages} " - echo "Does not exist" - exit 1 - fi - - if [ ! -e ${T2wInputImages} ]; then - echo "Expected input T2w image: ${T2wInputImages} " - echo "Does not exist" - exit 1 - fi - - # Templates - - # Hires T1w MNI template - T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz" - - # Hires brain extracted MNI template - T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz" - - # Lowres T1w MNI template - T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" - - # Hires T2w MNI Template - T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz" - - # Hires T2w brain extracted MNI Template - T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz" - - # Lowres T2w MNI Template - T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" - - # Hires MNI brain mask template - TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz" - - # Lowres MNI brain mask template - Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" - - # FNIRT 2mm T1w Config - FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" - - # Location of Coeffs file or "NONE" to skip - # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/Prisma_3T_coeff_AS82.grad" - - # Set to NONE to skip gradient distortion correction - GradientDistortionCoeffs="NONE" - - # BrainSize in mm, 150 for humans - BrainSize="150" - - # ---------------------------------------------------------------------- - # Variables related to using Siemens specific Gradient Echo Field Maps - # NOT USED IN THIS CASE - # ---------------------------------------------------------------------- - - # The MagnitudeInputName variable should be set to a 4D magitude volume - # with two 3D timepoints or "NONE" if not used - MagnitudeInputName="NONE" - - # The PhaseInputName variable should be set to a 3D phase difference - # volume or "NONE" if not used - PhaseInputName="NONE" - - # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T - # scanner or "NONE" if not using - TE="NONE" - - # The values set below are for the LifeSpan Aging Protocol using - # a Prisma 3T scanner - - # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file - # "DwellTime": 2.1e-06 - T1wSampleSpacing="0.000002100" - - # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file - # "DwellTime": 2.1e-06 - T2wSampleSpacing="0.000002100" - - # Readout Distortion Correction: - # - # Currently supported Averaging and readout distortion correction - # methods: (i.e. supported values for the AvgrdcSTRING variable in this - # script and the --avgrdcmethod= command line option for the - # PreFreeSurferPipeline.sh script.) - # - # "NONE" - # Average any repeats but do no readout distortion correction - # - # "FIELDMAP" - # This value is equivalent to the "SiemensFieldMap" value described - # below. Use of the "SiemensFieldMap" value is prefered, but - # "FIELDMAP" is included for backward compatibility with earlier versions - # of these scripts that only supported use of Siemens-specific - # Gradient Echo Field Maps and did not support Gradient Echo Field - # Maps from any other scanner vendor. - # - # "TOPUP" - # Average any repeats and use Spin Echo Field Maps for readout - # distortion correction - # - # "GeneralElectricFieldMap" - # Average any repeats and use General Electric specific Gradient - # Echo Field Map for readout distortion correction - # - # "SiemensFieldMap" - # Average any repeats and use Siemens specific Gradient Echo - # Field Maps for readout distortion correction - # - # Current Setup is to use TOPUP and Spin Echo Field Maps - # - AvgrdcSTRING="TOPUP" - - # Spin Echo Field Maps - - PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) - NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) - - echo "PositiveFieldMaps: " ${PositiveFieldMaps} - echo "PositiveFieldMaps: " ${NegativeFieldMaps} - - exit 1 - - - - - - - --SEPhaseNeg=/HCP/hcpdb/build_ssd/chpc/BUILD/tbbrown/LifeSpanAging/HCA6002236_V1_MR/unprocessed/T1w_MPR_vNav_4e_RMS/HCA6002236_V1\ - _MR_SpinEchoFieldMap2_AP.nii.gz - --SEPhasePos=/HCP/hcpdb/build_ssd/chpc/BUILD/tbbrown/LifeSpanAging/HCA6002236_V1_MR/unprocessed/T1w_MPR_vNav_4e_RMS/HCA6002236_V1\ - _MR_SpinEchoFieldMap2_PA.nii.gz - --seechospacing=0.000580009 - --topupconfig=/home/tbbrown/pipeline_tools/HCPpipelines/global/config/b02b0.cnf - --seunwarpdir=j - --unwarpdir=z - - - - - - - - - # # Run (or submit to be run) the PreFreeSurferPipeline.sh script - # # with all the specified parameter values - - # ${queuing_command} ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh \ - # --path="${StudyFolder}" \ - # --subject="${Session}" \ - # --t1="${T1wInputImages}" \ - # --t2="${T2wInputImages}" \ - # --t1template="${T1wTemplate}" \ - # --t1templatebrain="${T1wTemplateBrain}" \ - # --t1template2mm="${T1wTemplate2mm}" \ - # --t2template="${T2wTemplate}" \ - # --t2templatebrain="${T2wTemplateBrain}" \ - # --t2template2mm="${T2wTemplate2mm}" \ - # --templatemask="${TemplateMask}" \ - # --template2mmmask="${Template2mmMask}" \ - # --fnirtconfig="$FNIRTConfig" \ - # --gdcoeffs="$GradientDistortionCoeffs" \ - # --brainsize="$BrainSize" \ - # --echodiff="${TE}" \ - # --t1samplespacing="$T1wSampleSpacing" \ - # --t2samplespacing="$T2wSampleSpacing" \ - # --avgrdcmethod="$AvgrdcSTRING" \ - - - - - # --SEPhaseNeg="$SpinEchoPhaseEncodeNegative" \ - # --SEPhasePos="$SpinEchoPhaseEncodePositive" \ - # --seechospacing="$SEEchoSpacing" \ - # --seunwarpdir="$SEUnwarpDir" \ - - - - # --unwarpdir="$UnwarpDir" \ - - - # --topupconfig="$TopupConfig" \ - # --printcom=${PRINTCOM} - - - - - - - - - - - - - - else # Default to HCP style - - # Note that for the HCP naming convention, the "Session" and the "Subject" are - # essentially equivalent. Sessions would be subject IDs like 100307, 110226, 997865, etc. - Subject="${Session}" - - # If LifeSpanStyle is NOT "TRUE", then the HCP unprocessed data naming convention - # is used, e.g. - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz - - # Detect Number of T1w Images and build list of full paths to T1w images - numT1ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l) - echo "Found ${numT1ws} T1w Images for subject: ${Subject}" - T1wInputImages="" - i=1 - while [ ${i} -le ${numT1ws} ] ; do - echo "T1w ${i}" - T1wInputImages=$(echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MRP${i}.nii.gz@") - i=$(($i+1)) - done - - # Detect Number of T2w Images and build list of full paths to T2w images - numT2ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l) - echo "Found ${numT2ws} T2w Images for subject: ${Subject}" - T2wInputImages="" - i=1 - while [ ${i} -le ${numT2ws} ] ; do - echo "T2w ${i}" - T2wInputImages=$(echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@") - i=$(($i+1)) - done - - # Scan settings: - # - # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your - # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. - # (i.e., the study collected on the customized Connectom scanner). - - # Readout Distortion Correction: - # - # You have the option of using either gradient echo field maps or spin echo - # field maps to perform readout distortion correction on your structural - # images, or not to do readout distortion correction at all. - # - # The HCP Pipeline Scripts currently support the use of gradient echo field - # maps or spin echo field maps as they are produced by the Siemens Connectom - # Scanner. They also support the use of gradient echo field maps as generated - # by General Electric scanners. - # - # Change either the gradient echo field map or spin echo field map scan - # settings to match your data. This script is setup to use gradient echo - # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. - - # Gradient Distortion Correction: - # - # If using gradient distortion correction, use the coefficents from your - # scanner. The HCP gradient distortion coefficents are only available through - # Siemens. Gradient distortion in standard scanners like the Trio is much - # less than for the HCP Connectom scanner. - - # Readout Distortion Correction: - # - # Currently supported Averaging and readout distortion correction - # methods: (i.e. supported values for the AvgrdcSTRING variable in this - # script and the --avgrdcmethod= command line option for the - # PreFreeSurferPipeline.sh script.) - # - # "NONE" - # Average any repeats but do no readout distortion correction - # - # "FIELDMAP" - # This value is equivalent to the "SiemensFieldMap" value described - # below. Use of the "SiemensFieldMap" value is prefered, but - # "FIELDMAP" is included for backward compatibility with earlier versions - # of these scripts that only supported use of Siemens-specific - # Gradient Echo Field Maps and did not support Gradient Echo Field - # Maps from any other scanner vendor. - # - # "TOPUP" - # Average any repeats and use Spin Echo Field Maps for readout - # distortion correction - # - # "GeneralElectricFieldMap" - # Average any repeats and use General Electric specific Gradient - # Echo Field Map for readout distortion correction - # - # "SiemensFieldMap" - # Average any repeats and use Siemens specific Gradient Echo - # Field Maps for readout distortion correction - # - # Current Setup is for Siemens specific Gradient Echo Field Maps - # - # The following settings for AvgrdcSTRING, MagnitudeInputName, - # PhaseInputName, and TE are for using the Siemens specific - # Gradient Echo Field Maps that are collected and used in the - # standard HCP-YA protocol. - # - # Note: The AvgrdcSTRING variable could also be set to the value - # "FIELDMAP" which is equivalent to "SiemensFieldMap". - AvgrdcSTRING="SiemensFieldMap" - - # ---------------------------------------------------------------------- - # Variables related to using Siemens specific Gradient Echo Field Maps - # ---------------------------------------------------------------------- - - # The MagnitudeInputName variable should be set to a 4D magitude volume - # with two 3D timepoints or "NONE" if not used - MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" - - # The PhaseInputName variable should be set to a 3D phase difference - # volume or "NONE" if not used - PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" - - # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T - # scanner or "NONE" if not using - TE="2.46" - - # ---------------------------------------------------------------------- - # Variables related to using Spin Echo Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") - - # The SpinEchoPhaseEncodeNegative variable should be set to the - # spin echo field map volume with a negative phase encoding direction - # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); - # AP if using a pair of AP/PA Siemens SEFMS) - # and set to "NONE" if not using SEFMs - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz - SpinEchoPhaseEncodeNegative="NONE" - - # The SpinEchoPhaseEncodePositive variable should be set to the - # spin echo field map volume with positive phase encoding direction - # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), - # and set to "NONE" if not using Spin Echo Field Maps - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz - SpinEchoPhaseEncodePositive="NONE" - - # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. - # Set to "NONE" if not used. - # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) - # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and - # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension - # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation - # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) - # - # Example value for when using Spin Echo Field Maps from the HCP-YA - # 0.000580002668012 - SEEchoSpacing="NONE" - - # Spin Echo Unwarping Direction (according to the *voxel* axes) - # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) - # Set to "NONE" if not used. - # - # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} - # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign - # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] - SEUnwarpDir="NONE" - - # Topup Configuration file - # Set to "NONE" if not using SEFMs - # - # Default file to use when using SEFMs - # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" - TopupConfig="NONE" - - # ---------------------------------------------------------------------- - # Variables related to using General Electric specific Gradient Echo - # Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using General Electric specific Gradient Echo Field Maps (i.e. when - # AvgrdcSTRING="GeneralElectricFieldMap") - - # Example value for when using General Electric Gradient Echo Field Map - # - # GEB0InputName should be a General Electric style B0 fieldmap with two - # volumes - # 1) fieldmap in deg and - # 2) magnitude, - # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap - # - # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" - GEB0InputName="NONE" - - # Templates - - # Hires T1w MNI template - T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" - - # Hires brain extracted MNI template - T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" - - # Lowres T1w MNI template - T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" - - # Hires T2w MNI Template - T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" - - # Hires T2w brain extracted MNI Template - T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" - - # Lowres T2w MNI Template - T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" - - # Hires MNI brain mask template - TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" - - # Lowres MNI brain mask template - Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" - - # Structural Scan Settings - # - # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, - # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) - # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction - # of the Spin Echo Field Maps (if using them). - # Note that polarity of UnwarpDir DOES matter. - # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) - # - # set all these values to NONE if not doing readout distortion correction - # - # Sample values for when using General Electric structurals - # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? - - # The values set below are for the HCP-YA Protocol using the Siemens - # Connectom Scanner - - # DICOM field (0019,1018) in s or "NONE" if not used - T1wSampleSpacing="0.0000074" - - # DICOM field (0019,1018) in s or "NONE" if not used - T2wSampleSpacing="0.0000021" - - # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners - UnwarpDir="z" - - # Other Config Settings - - # BrainSize in mm, 150 for humans - BrainSize="150" - - # FNIRT 2mm T1w Config - FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" - - # Location of Coeffs file or "NONE" to skip - # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" - - # Set to NONE to skip gradient distortion correction - GradientDistortionCoeffs="NONE" - - # Establish queuing command based on command line option - if [ -n "${RunLocal}" ] ; then - echo "About to run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" - queuing_command="" - else - echo "About to use fsl_sub to queue ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" - queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" - fi - - # Run (or submit to be run) the PreFreeSurferPipeline.sh script - # with all the specified parameter values - - PreFreeSurferCmd="${queuing_command} " - PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " - PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " - PreFreeSurferCmd+=" --subject=\"${Subject}\" " - PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " - PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " - PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " - PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " - PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " - PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " - PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " - PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " - PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " - PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " - PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " - PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " - PreFreeSurferCmd+=" --fmapmag=\"${MagnitudeInputName}\" " - PreFreeSurferCmd+=" --fmapphase=\"${PhaseInputName}\" " - PreFreeSurferCmd+=" --fmapgeneralelectric=\"${GEB0InputName}\" " - PreFreeSurferCmd+=" --echodiff=\"${TE}\" " - PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " - PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " - PreFreeSurferCmd+=" --seechospacing=\"${SEEchoSpacing}\" " - PreFreeSurferCmd+=" --seunwarpdir=\"${SEUnwarpDir}\" " - PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " - PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " - PreFreeSurferCmd+=" --unwarpdir=\"${UnwarpDir}\" " - PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " - PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " - PreFreeSurferCmd+=" --topupconfig=\"${TopupConfig}\" " - PreFreeSurferCmd+=" --printcom=\"${PRINTCOM}\" " - - echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" - - # ${PreFreeSurferCmd} - + # Set up pipeline environment variables and software + source ${EnvironmentScript} + + # Report environment variables pointing to tools + echo "FSLDIR: ${FSLDIR}" + echo "FREESURFER_HOME: ${FREESURFER_HOME}" + echo "HCPPIPEDIR: ${HCPPIPEDIR}" + echo "CARET7DIR: ${CARET7DIR}" + echo "PATH: ${PATH}" + + # Define processing queue to be used if submitted to job scheduler + # if [ X$SGE_ROOT != X ] ; then + # QUEUE="-q long.q" + # QUEUE="-q veryshort.q" + QUEUE="-q hcp_priority.q" + # fi + + # If PRINTCOM is not a null or empty string variable, then + # this script and other scripts that it calls will simply + # print out the primary commands it otherwise would run. + # This printing will be done using the command specified + # in the PRINTCOM variable + PRINTCOM="" + # PRINTCOM="echo" + + # Establish queuing command based on command line option + if [ -n "${RunLocal}" ] ; then + queuing_command="" + else + queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" fi - - done + + for Session in ${SessionList} ; do + echo "" + echo "Processing: ${Session}" + echo "" + + # Scripts called by this script do NOT assume anything about the form of the + # input names or paths. This batch script assumes either the HCP unprocessed + # data naming convention or the LifeSpan unprocessed data naming convention + # depending upon whether LifeSpanStyle is "TRUE". + + if [ "${LifeSpanStyle}" = "TRUE" ]; then + + # Input Images + # + # If LifeSpanStyle is "TRUE", then the LifeSpan unprocessed data naming convention + # is used. + + T1wInputImages="${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_T1w_MPR_vNav_4e_RMS.nii.gz" + T2wInputImages="${StudyFolder}/${Session}/unprocessed/T2w_SPC_vNav/${Session}_T2w_SPC_vNav.nii.gz" + + if [ ! -e ${T1wInputImages} ]; then + echo "Expected input T1w image: ${T1wInputImages} " + echo "Does not exist" + exit 1 + fi + + if [ ! -e ${T2wInputImages} ]; then + echo "Expected input T2w image: ${T2wInputImages} " + echo "Does not exist" + exit 1 + fi + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/Prisma_3T_coeff_AS82.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # NOT USED IN THIS CASE + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="NONE" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="NONE" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="NONE" + + # The values set below are for the LifeSpan Aging Protocol using + # a Prisma 3T scanner + + # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file + # "DwellTime": 2.1e-06 + T1wSampleSpacing="0.000002100" + + # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file + # "DwellTime": 2.1e-06 + T2wSampleSpacing="0.000002100" + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is to use TOPUP and Spin Echo Field Maps + # + AvgrdcSTRING="TOPUP" + + # Spin Echo Field Maps + + PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) + NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) + + # Take the first found of each field map + SpinEchoPhaseEncodePositive=${PositiveFieldMaps##* } + SpinEchoPhaseEncodeNegative=${NegativeFieldMaps##* } + + echo ${SpinEchoPhaseEncodePositive} + echo ${SpinEchoPhaseEncodeNegative} + + # --seechospacing=0.000580009 + # --topupconfig=/home/tbbrown/pipeline_tools/HCPpipelines/global/config/b02b0.cnf + # --seunwarpdir=j + # --unwarpdir=z + + + + # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # with all the specified parameter values + + PreFreeSurferCmd="${queuing_command} " + PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " + PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " + PreFreeSurferCmd+=" --subject=\"${Session}\" " + PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " + PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " + PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " + PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " + PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " + PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " + PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " + PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " + PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " + PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " + PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " + PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " + PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " + PreFreeSurferCmd+=" --echodiff=\"${TE}\" " + PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " + PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " + PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " + PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " + PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " + + + # --seechospacing="$SEEchoSpacing" \ + # --seunwarpdir="$SEUnwarpDir" \ + # --unwarpdir="$UnwarpDir" \ + # --topupconfig="$TopupConfig" \ + # --printcom=${PRINTCOM} + + + echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" + # ${PreFreeSurferCmd} + + + else # Default to HCP style + + # Note that for the HCP naming convention, the "Session" and the "Subject" are + # essentially equivalent. Sessions would be subject IDs like 100307, 110226, 997865, etc. + Subject="${Session}" + + # If LifeSpanStyle is NOT "TRUE", then the HCP unprocessed data naming convention + # is used, e.g. + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz + + # Detect Number of T1w Images and build list of full paths to T1w images + numT1ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l) + echo "Found ${numT1ws} T1w Images for subject: ${Subject}" + T1wInputImages="" + i=1 + while [ ${i} -le ${numT1ws} ] ; do + echo "T1w ${i}" + T1wInputImages=$(echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MRP${i}.nii.gz@") + i=$(($i+1)) + done + + # Detect Number of T2w Images and build list of full paths to T2w images + numT2ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l) + echo "Found ${numT2ws} T2w Images for subject: ${Subject}" + T2wInputImages="" + i=1 + while [ ${i} -le ${numT2ws} ] ; do + echo "T2w ${i}" + T2wInputImages=$(echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@") + i=$(($i+1)) + done + + # Scan settings: + # + # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your + # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. + # (i.e., the study collected on the customized Connectom scanner). + + # Readout Distortion Correction: + # + # You have the option of using either gradient echo field maps or spin echo + # field maps to perform readout distortion correction on your structural + # images, or not to do readout distortion correction at all. + # + # The HCP Pipeline Scripts currently support the use of gradient echo field + # maps or spin echo field maps as they are produced by the Siemens Connectom + # Scanner. They also support the use of gradient echo field maps as generated + # by General Electric scanners. + # + # Change either the gradient echo field map or spin echo field map scan + # settings to match your data. This script is setup to use gradient echo + # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. + + # Gradient Distortion Correction: + # + # If using gradient distortion correction, use the coefficents from your + # scanner. The HCP gradient distortion coefficents are only available through + # Siemens. Gradient distortion in standard scanners like the Trio is much + # less than for the HCP Connectom scanner. + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is for Siemens specific Gradient Echo Field Maps + # + # The following settings for AvgrdcSTRING, MagnitudeInputName, + # PhaseInputName, and TE are for using the Siemens specific + # Gradient Echo Field Maps that are collected and used in the + # standard HCP-YA protocol. + # + # Note: The AvgrdcSTRING variable could also be set to the value + # "FIELDMAP" which is equivalent to "SiemensFieldMap". + AvgrdcSTRING="SiemensFieldMap" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="2.46" + + # ---------------------------------------------------------------------- + # Variables related to using Spin Echo Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") + + # The SpinEchoPhaseEncodeNegative variable should be set to the + # spin echo field map volume with a negative phase encoding direction + # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); + # AP if using a pair of AP/PA Siemens SEFMS) + # and set to "NONE" if not using SEFMs + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz + SpinEchoPhaseEncodeNegative="NONE" + + # The SpinEchoPhaseEncodePositive variable should be set to the + # spin echo field map volume with positive phase encoding direction + # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), + # and set to "NONE" if not using Spin Echo Field Maps + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz + SpinEchoPhaseEncodePositive="NONE" + + # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. + # Set to "NONE" if not used. + # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) + # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and + # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension + # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation + # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) + # + # Example value for when using Spin Echo Field Maps from the HCP-YA + # 0.000580002668012 + SEEchoSpacing="NONE" + + # Spin Echo Unwarping Direction (according to the *voxel* axes) + # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) + # Set to "NONE" if not used. + # + # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} + # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign + # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] + SEUnwarpDir="NONE" + + # Topup Configuration file + # Set to "NONE" if not using SEFMs + # + # Default file to use when using SEFMs + # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" + TopupConfig="NONE" + + # ---------------------------------------------------------------------- + # Variables related to using General Electric specific Gradient Echo + # Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using General Electric specific Gradient Echo Field Maps (i.e. when + # AvgrdcSTRING="GeneralElectricFieldMap") + + # Example value for when using General Electric Gradient Echo Field Map + # + # GEB0InputName should be a General Electric style B0 fieldmap with two + # volumes + # 1) fieldmap in deg and + # 2) magnitude, + # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap + # + # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" + GEB0InputName="NONE" + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # Structural Scan Settings + # + # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, + # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) + # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction + # of the Spin Echo Field Maps (if using them). + # Note that polarity of UnwarpDir DOES matter. + # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) + # + # set all these values to NONE if not doing readout distortion correction + # + # Sample values for when using General Electric structurals + # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? + + # The values set below are for the HCP-YA Protocol using the Siemens + # Connectom Scanner + + # DICOM field (0019,1018) in s or "NONE" if not used + T1wSampleSpacing="0.0000074" + + # DICOM field (0019,1018) in s or "NONE" if not used + T2wSampleSpacing="0.0000021" + + # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners + UnwarpDir="z" + + # Other Config Settings + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # with all the specified parameter values + + PreFreeSurferCmd="${queuing_command} " + PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " + PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " + PreFreeSurferCmd+=" --subject=\"${Subject}\" " + PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " + PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " + PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " + PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " + PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " + PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " + PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " + PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " + PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " + PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " + PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " + PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " + PreFreeSurferCmd+=" --fmapmag=\"${MagnitudeInputName}\" " + PreFreeSurferCmd+=" --fmapphase=\"${PhaseInputName}\" " + PreFreeSurferCmd+=" --fmapgeneralelectric=\"${GEB0InputName}\" " + PreFreeSurferCmd+=" --echodiff=\"${TE}\" " + PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " + PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " + PreFreeSurferCmd+=" --seechospacing=\"${SEEchoSpacing}\" " + PreFreeSurferCmd+=" --seunwarpdir=\"${SEUnwarpDir}\" " + PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " + PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " + PreFreeSurferCmd+=" --unwarpdir=\"${UnwarpDir}\" " + PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " + PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " + PreFreeSurferCmd+=" --topupconfig=\"${TopupConfig}\" " + PreFreeSurferCmd+=" --printcom=\"${PRINTCOM}\" " + + echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" + # ${PreFreeSurferCmd} + + fi + + done } # Invoke the main function to get things started From 494cad633695d1c045813cb261587785558434a8 Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Wed, 19 Jun 2019 17:29:08 -0500 Subject: [PATCH 4/7] Changes for demonstrating LifeSpan run of PreFreeSurfer in HCP course --- .../Scripts/PreFreeSurferPipelineBatch.sh | 184 ++++++++++-------- 1 file changed, 105 insertions(+), 79 deletions(-) diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index 18dc965b2..703ef4e59 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -431,55 +431,70 @@ main() SpinEchoPhaseEncodePositive=${PositiveFieldMaps##* } SpinEchoPhaseEncodeNegative=${NegativeFieldMaps##* } - echo ${SpinEchoPhaseEncodePositive} - echo ${SpinEchoPhaseEncodeNegative} + # Spin Echo Echo Spacing + # See the EffectiveEchoSpacing value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # "EffectiveEchoSpacing": 0.000580009 + SEEchoSpacing="0.000580009" - # --seechospacing=0.000580009 - # --topupconfig=/home/tbbrown/pipeline_tools/HCPpipelines/global/config/b02b0.cnf - # --seunwarpdir=j - # --unwarpdir=z - - + # Default file to use when using SEFMs + TopupConfig="${HCPPIPEDIR_Config}/b02b0.cnf" + + # Spin Echo Unwarp Direction + # See the PhaseEncodingDirection value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # "PhaseEncodingDirection": "j" + SEUnwarpDir="j" + + # See the ReadoutDirection value in the JSON sidecare file corresponding to the T1w file + # "ReadoutDirection": "k" + # x,y,z corresponds to i,j,k + UnwarpDir="z" - # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # Build the PreFreeSurferPipeline.sh script invocation command to run # with all the specified parameter values - PreFreeSurferCmd="${queuing_command} " - PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " - PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " - PreFreeSurferCmd+=" --subject=\"${Session}\" " - PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " - PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " - PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " - PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " - PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " - PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " - PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " - PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " - PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " - PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " - PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " - PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " - PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " - PreFreeSurferCmd+=" --echodiff=\"${TE}\" " - PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " - PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " - PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " - PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " - PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " - - - # --seechospacing="$SEEchoSpacing" \ - # --seunwarpdir="$SEUnwarpDir" \ - # --unwarpdir="$UnwarpDir" \ - # --topupconfig="$TopupConfig" \ - # --printcom=${PRINTCOM} - - - echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" - # ${PreFreeSurferCmd} - + PreFreeSurferCmd=() + if [ -n "${queuing_command}" ]; then + PreFreeSurferCmd+=("${queuing_command}") + fi + PreFreeSurferCmd+=("${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh") + PreFreeSurferCmd+=("--path=${StudyFolder}") + PreFreeSurferCmd+=("--subject=${Session}") + PreFreeSurferCmd+=("--t1=${T1wInputImages}") + PreFreeSurferCmd+=("--t2=${T2wInputImages}") + PreFreeSurferCmd+=("--t1template=${T1wTemplate}") + PreFreeSurferCmd+=("--t1templatebrain=${T1wTemplateBrain}") + PreFreeSurferCmd+=("--t1template2mm=${T1wTemplate2mm}") + PreFreeSurferCmd+=("--t2template=${T2wTemplate}") + PreFreeSurferCmd+=("--t2templatebrain=${T2wTemplateBrain}") + PreFreeSurferCmd+=("--t2template2mm=${T2wTemplate2mm}") + PreFreeSurferCmd+=("--templatemask=${TemplateMask}") + PreFreeSurferCmd+=("--template2mmmask=${Template2mmMask}") + PreFreeSurferCmd+=("--fnirtconfig=${FNIRTConfig}") + PreFreeSurferCmd+=("--gdcoeffs=${GradientDistortionCoeffs}") + PreFreeSurferCmd+=("--brainsize=${BrainSize}") + PreFreeSurferCmd+=("--echodiff=${TE}") + PreFreeSurferCmd+=("--t1samplespacing=${T1wSampleSpacing}") + PreFreeSurferCmd+=("--t2samplespacing=${T2wSampleSpacing}") + PreFreeSurferCmd+=("--avgrdcmethod=${AvgrdcSTRING}") + PreFreeSurferCmd+=("--SEPhasePos=${SpinEchoPhaseEncodePositive}") + PreFreeSurferCmd+=("--SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") + PreFreeSurferCmd+=("--seechospacing=${SEEchoSpacing}") + PreFreeSurferCmd+=("--topupconfig=${TopupConfig}") + PreFreeSurferCmd+=("--seunwarpdir=${SEUnwarpDir}") + PreFreeSurferCmd+=("--unwarpdir=${UnwarpDir}") + PreFreeSurferCmd+=("--printcom=${PRINTCOM}") + + # Show the command + num_cmd_args=${#PreFreeSurferCmd[@]} + echo "PreFreeSurfer command to execute:" + for (( cmdindex = 0; cmdindex < num_cmd_args; ++cmdindex )); do + echo "${PreFreeSurferCmd[cmdindex]}" + done + echo "" + # Execute the command + "${PreFreeSurferCmd[@]}" + else # Default to HCP style # Note that for the HCP naming convention, the "Session" and the "Subject" are @@ -751,43 +766,54 @@ main() # Set to NONE to skip gradient distortion correction GradientDistortionCoeffs="NONE" - # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # Build the PreFreeSurferPipeline.sh script command to run # with all the specified parameter values + + PreFreeSurferCmd=() + if [ -n "${queuing_command}" ]; then + PreFreeSurferCmd+=("${queuing_command}") + fi + PreFreeSurferCmd+=("${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh") + PreFreeSurferCmd+=(" --path=${StudyFolder}") + PreFreeSurferCmd+=(" --subject=${Subject}") + PreFreeSurferCmd+=(" --t1=${T1wInputImages}") + PreFreeSurferCmd+=(" --t2=${T2wInputImages}") + PreFreeSurferCmd+=(" --t1template=${T1wTemplate}") + PreFreeSurferCmd+=(" --t1templatebrain=${T1wTemplateBrain}") + PreFreeSurferCmd+=(" --t1template2mm=${T1wTemplate2mm}") + PreFreeSurferCmd+=(" --t2template=${T2wTemplate}") + PreFreeSurferCmd+=(" --t2templatebrain=${T2wTemplateBrain}") + PreFreeSurferCmd+=(" --t2template2mm=${T2wTemplate2mm}") + PreFreeSurferCmd+=(" --templatemask=${TemplateMask}") + PreFreeSurferCmd+=(" --template2mmmask=${Template2mmMask}") + PreFreeSurferCmd+=(" --brainsize=${BrainSize}") + PreFreeSurferCmd+=(" --fnirtconfig=${FNIRTConfig}") + PreFreeSurferCmd+=(" --fmapmag=${MagnitudeInputName}") + PreFreeSurferCmd+=(" --fmapphase=${PhaseInputName}") + PreFreeSurferCmd+=(" --fmapgeneralelectric=${GEB0InputName}") + PreFreeSurferCmd+=(" --echodiff=${TE}") + PreFreeSurferCmd+=(" --SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") + PreFreeSurferCmd+=(" --SEPhasePos=${SpinEchoPhaseEncodePositive}") + PreFreeSurferCmd+=(" --seechospacing=${SEEchoSpacing}") + PreFreeSurferCmd+=(" --seunwarpdir=${SEUnwarpDir}") + PreFreeSurferCmd+=(" --t1samplespacing=${T1wSampleSpacing}") + PreFreeSurferCmd+=(" --t2samplespacing=${T2wSampleSpacing}") + PreFreeSurferCmd+=(" --unwarpdir=${UnwarpDir}") + PreFreeSurferCmd+=(" --gdcoeffs=${GradientDistortionCoeffs}") + PreFreeSurferCmd+=(" --avgrdcmethod=${AvgrdcSTRING}") + PreFreeSurferCmd+=(" --topupconfig=${TopupConfig}") + PreFreeSurferCmd+=(" --printcom=${PRINTCOM}") + + # Show the command + num_cmd_args=${#PreFreeSurferCmd[@]} + echo "PreFreeSurfer command to execute:" + for (( cmdindex = 0; cmdindex < num_cmd_args; ++cmdindex )); do + echo "${PreFreeSurferCmd[cmdindex]}" + done + echo "" - PreFreeSurferCmd="${queuing_command} " - PreFreeSurferCmd+="${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh " - PreFreeSurferCmd+=" --path=\"${StudyFolder}\" " - PreFreeSurferCmd+=" --subject=\"${Subject}\" " - PreFreeSurferCmd+=" --t1=\"${T1wInputImages}\" " - PreFreeSurferCmd+=" --t2=\"${T2wInputImages}\" " - PreFreeSurferCmd+=" --t1template=\"${T1wTemplate}\" " - PreFreeSurferCmd+=" --t1templatebrain=\"${T1wTemplateBrain}\" " - PreFreeSurferCmd+=" --t1template2mm=\"${T1wTemplate2mm}\" " - PreFreeSurferCmd+=" --t2template=\"${T2wTemplate}\" " - PreFreeSurferCmd+=" --t2templatebrain=\"${T2wTemplateBrain}\" " - PreFreeSurferCmd+=" --t2template2mm=\"${T2wTemplate2mm}\" " - PreFreeSurferCmd+=" --templatemask=\"${TemplateMask}\" " - PreFreeSurferCmd+=" --template2mmmask=\"${Template2mmMask}\" " - PreFreeSurferCmd+=" --brainsize=\"${BrainSize}\" " - PreFreeSurferCmd+=" --fnirtconfig=\"${FNIRTConfig}\" " - PreFreeSurferCmd+=" --fmapmag=\"${MagnitudeInputName}\" " - PreFreeSurferCmd+=" --fmapphase=\"${PhaseInputName}\" " - PreFreeSurferCmd+=" --fmapgeneralelectric=\"${GEB0InputName}\" " - PreFreeSurferCmd+=" --echodiff=\"${TE}\" " - PreFreeSurferCmd+=" --SEPhaseNeg=\"${SpinEchoPhaseEncodeNegative}\" " - PreFreeSurferCmd+=" --SEPhasePos=\"${SpinEchoPhaseEncodePositive}\" " - PreFreeSurferCmd+=" --seechospacing=\"${SEEchoSpacing}\" " - PreFreeSurferCmd+=" --seunwarpdir=\"${SEUnwarpDir}\" " - PreFreeSurferCmd+=" --t1samplespacing=\"${T1wSampleSpacing}\" " - PreFreeSurferCmd+=" --t2samplespacing=\"${T2wSampleSpacing}\" " - PreFreeSurferCmd+=" --unwarpdir=\"${UnwarpDir}\" " - PreFreeSurferCmd+=" --gdcoeffs=\"${GradientDistortionCoeffs}\" " - PreFreeSurferCmd+=" --avgrdcmethod=\"${AvgrdcSTRING}\" " - PreFreeSurferCmd+=" --topupconfig=\"${TopupConfig}\" " - PreFreeSurferCmd+=" --printcom=\"${PRINTCOM}\" " - - echo "PreFreeSurferCmd: ${PreFreeSurferCmd}" - # ${PreFreeSurferCmd} + # Execute the command + "${PreFreeSurferCmd[@]}" fi From 367cb5b1512bbc45234bda93a37f72f889152541 Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Thu, 20 Jun 2019 10:22:27 -0500 Subject: [PATCH 5/7] Combined several cases in command line option processing. Added default global variables for run_local and lifespan style options. Added some comments. --- .../Scripts/PreFreeSurferPipelineBatch.sh | 130 +++++++++++------- 1 file changed, 78 insertions(+), 52 deletions(-) diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index 703ef4e59..49f609abf 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -67,6 +67,12 @@ # #~ND~END~ +# ---------------------------------------------------------------- +# HERE IS WHERE YOU WOULD CHANGE DEFAULT VALUES TO BE USED +# IF YOU WOULD LIKE TO RUN THIS SCRIPT WITHOUT SPECIFYING +# ANY COMMAND LINE PARAMETERS. +# ---------------------------------------------------------------- + # Default location of study folder DEFAULT_STUDY_FOLDER="${HOME}/projects/Pipelines_ExampleData" @@ -76,6 +82,39 @@ DEFAULT_SESSION_LIST="100307" # Default pipeline environment script DEFAULT_ENVIRONMENT_SCRIPT="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" +# Default indicator of whether to run the processing "locally" (i.e. on the +# machine on which this script is invoked) or try to submit the a job +# to a processing queue using fsl_sub. If this value is anything other +# than empty, then the processing is done "locally". +# +# Example usage: +# +# Set to empty string to submit a job for each session/subject. +# +# DEFAULT_RUN_LOCAL="" +# +# Set to "TRUE" to do processing "locally". +# +# DEFAULT_RUN_LOCAL="TRUE" +# +DEFAULT_RUN_LOCAL="" + +# Default indicator of whether to process data in "LifeSpan" style. +# If this value is anything other than empty, then it is assume that +# the data to be processed follows LifeSpan style naming conventions. +# +# Example usage: +# +# Set to empty string to run processing on HCP-YA style data +# +# DEFAULT_LIFESPAN_STYLE="" +# +# Set to "TRUE" to run processing on LifeSpan style data +# +# DEFAULT_LIFESPAN_STYLE="TRUE" +# +DEFAULT_LIFESPAN_STYLE="" + usage() { cat < Date: Thu, 20 Jun 2019 18:28:32 -0500 Subject: [PATCH 6/7] Reverted PreFreeSurferPipelineBatch.sh to state from master. Created LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh --- .../PreFreeSurferPipelineBatch.LifeSpan.sh | 466 +++++++ .../Scripts/PreFreeSurferPipelineBatch.sh | 1146 ++++++----------- 2 files changed, 860 insertions(+), 752 deletions(-) create mode 100755 Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh diff --git a/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh b/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh new file mode 100755 index 000000000..9e2dbb1db --- /dev/null +++ b/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh @@ -0,0 +1,466 @@ +#!/bin/bash + +#~ND~FORMAT~MARKDOWN~ +#~ND~START~ +# +# # PreFreeSurferPipelineBatch.LifeSpan.sh +# +# ## Copyright Notice +# +# Copyright (C) 2019 The Human Connectome Project/The Connectome Coordination Facility +# +# * Washington University in St. Louis +# * University of Minnesota +# * Oxford University +# +# ## Author(s) +# +# * Timothy B. Brown, Neuroinformatics Research Group, +# Washington University in St. Louis +# +# ## Product +# +# [Human Connectome Project][HCP] (HCP) Pipelines +# +# ## License +# +# See the [LICENSE](https://github.com/Washington-University/Pipelines/blob/master/LICENSE.md) file +# +# ## Description: +# +# Example script for running the Pre-FreeSurfer phase of the HCP Structural +# Preprocessing pipeline on LifeSpan style data. +# +# See [Glasser et al. 2013][GlasserEtAl]. +# +# ## Prerequisites +# +# ### Installed software +# +# * FSL (version v6.0.1) +# * FreeSurfer (version v6.0.0) +# * gradunwarp (HCP version 1.0.2) - if doing gradient distortion correction +# +# ### Environment variables +# +# Should be set in script file pointed to by EnvironmentScript variable. +# See setting of the EnvironmentScript variable in the main() function +# below. +# +# * FSLDIR - FSL installation directory +# * FREESURFER_HOME - FreeSurfer installation directory +# * HCPPIPEDIR - HCP Pipelines installation directory +# * CARET7DIR - Connectome Workbench installation directory +# * PATH - must point to where gradient_unwarp.py is if doing gradient unwarping +# +# +# [HCP]: http://www.humanconnectome.org +# [GlasserEtAl]: http://www.ncbi.nlm.nih.gov/pubmed/23668970 +# +#~ND~END~ + +# ---------------------------------------------------------------- +# HERE IS WHERE YOU WOULD CHANGE DEFAULT VALUES TO BE USED +# IF YOU WOULD LIKE TO RUN THIS SCRIPT WITHOUT SPECIFYING +# ANY COMMAND LINE PARAMETERS. +# ---------------------------------------------------------------- + +# Default location of study folder +DEFAULT_STUDY_FOLDER="${HOME}/projects/Pipelines_ExampleData" + +# Default space delimited list of subject IDs +DEFAULT_SESSION_LIST="100307_MR_3T" + +# Default pipeline environment script +DEFAULT_ENVIRONMENT_SCRIPT="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" + +# Default indicator of whether to run the processing "locally" (i.e. on the +# machine on which this script is invoked) or try to submit the a job +# to a processing queue using fsl_sub. If this value is anything other +# than empty, then the processing is done "locally". +# +# Example usage: +# +# Set to empty string to submit a job for each session/subject. +# +# DEFAULT_RUN_LOCAL="" +# +# Set to "TRUE" to do processing "locally". +# +# DEFAULT_RUN_LOCAL="TRUE" +# +DEFAULT_RUN_LOCAL="" + +usage() +{ + cat < = user supplied value + + [--help] : show this usage information and exit + + [--study=] + + The study folder in which to find the session sub-directories. + + If this option isn't specified, the study folder used defaults to: + + ${DEFAULT_STUDY_FOLDER} + + [--session=] + + A session within the study folder for which to run this processing. + + This parameter can be specified multiple times to create a list of + sessions to process. E.g. --session=100307_MR_3T --session=100287_MR_3T + would result in the following list of sessions to process: 100307_MR_3T 100287_MR_3T + + If none of these options are specified, the list of sessions to process + defaults to: + + ${DEFAULT_SESSION_LIST} + + [--runlocal] + + Specifies that processing should occur "locally" (i.e. on this machine) as + opposed to trying to submit the processing to a queuing system. If this + option is not specified, this script default to trying to submit the + processing job to a queuing system using the fsl_sub command. + + [--env=] + + This parameter specifies the path to the environment script which sets + the environment variables necessary to run this processing. + + If none of these options are specified, the environment script path + defaults to: + + ${DEFAULT_ENVIRONMENT_SCRIPT} + +EOF +} + +get_options() +{ + # Note that the ($@) construction parses the arguments into an + # array of values using spaces as the delimiter + local arguments=($@) + + unset p_study_folder + unset p_session_list + unset p_run_local + unset p_environment_script + + # parse arguments + local num_args=${#arguments[@]} + local argument + local index + + for (( index = 0; index < num_args; ++index )); do + argument=${arguments[index]} + + case ${argument} in + --help) + usage + exit 1 + ;; + --study=*) + p_study_folder=${argument#*=} + ;; + --session=*) + if [ -n "${p_session_list}" ]; then + p_session_list+=" " + fi + p_session_list+=${argument#*=} + ;; + --runlocal) + p_run_local="TRUE" + ;; + --env=*) + p_environment_script=${argument#*=} + ;; + *) + usage + exit 1 + ;; + esac + + done + + if [ -z "${p_study_folder}" ]; then + p_study_folder=${DEFAULT_STUDY_FOLDER} + fi + + if [ -z "${p_session_list}" ]; then + p_session_list=${DEFAULT_SESSION_LIST} + fi + + if [ -z "${p_environment_script}" ]; then + p_environment_script=${DEFAULT_ENVIRONMENT_SCRIPT} + fi + + if [ -z "${p_run_local}" ]; then + p_run_local=${DEFAULT_RUN_LOCAL} + fi +} + +main() +{ + get_options "$@" + + # Gather options specified on the command line or given default values + local StudyFolder="${p_study_folder}" + local SessionList="${p_session_list}" + local EnvironmentScript="${p_environment_script}" + local RunLocal="${p_run_local}" + + # Report major script control variables to user + echo "" + echo "StudyFolder: ${StudyFolder}" + echo "SessionList: ${SessionList}" + echo "EnvironmentScript: ${EnvironmentScript}" + echo "RunLocal: ${RunLocal}" + echo "" + + # Set up pipeline environment variables and software paths + source ${EnvironmentScript} + + # Report environment variables pointing to tools + echo "FSLDIR: ${FSLDIR}" + echo "FREESURFER_HOME: ${FREESURFER_HOME}" + echo "HCPPIPEDIR: ${HCPPIPEDIR}" + echo "CARET7DIR: ${CARET7DIR}" + echo "PATH: ${PATH}" + + # If PRINTCOM is not a null or empty string variable, then + # this script and other scripts that it calls will simply + # print out the primary commands it otherwise would run. + # This printing will be done using the command specified + # in the PRINTCOM variable + PRINTCOM="" + # PRINTCOM="echo" + + # Define processing queue to be used if submitted to job scheduler + # if [ X$SGE_ROOT != X ] ; then + # QUEUE="-q long.q" + # QUEUE="-q veryshort.q" + QUEUE="-q hcp_priority.q" + # fi + + # Establish queuing command based on whether running locally or submitting jobs + if [ -n "${RunLocal}" ] ; then + queuing_command="" + else + queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" + fi + + # Cycle through specified subjects/sessions and run/submit processing + for Session in ${SessionList} ; do + echo "" + echo "Processing: ${Session}" + echo "" + + # Scripts called by this script do NOT assume anything about the form of the + # input names or paths. This batch script assumes either the HCP unprocessed + # data naming convention or the LifeSpan unprocessed data naming convention + # depending upon whether LifeSpanStyle is "TRUE". + + # Input Images + T1wInputImages="${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_T1w_MPR_vNav_4e_RMS.nii.gz" + T2wInputImages="${StudyFolder}/${Session}/unprocessed/T2w_SPC_vNav/${Session}_T2w_SPC_vNav.nii.gz" + + if [ ! -e ${T1wInputImages} ]; then + echo "Expected input T1w image: ${T1wInputImages} " + echo "Does not exist" + exit 1 + fi + + if [ ! -e ${T2wInputImages} ]; then + echo "Expected input T2w image: ${T2wInputImages} " + echo "Does not exist" + exit 1 + fi + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/Prisma_3T_coeff_AS82.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # NOT USED IN THIS CASE + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="NONE" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="NONE" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="NONE" + + # The values set below are for the LifeSpan Aging Protocol using + # a Prisma 3T scanner + + # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file + # "DwellTime": 2.1e-06 + T1wSampleSpacing="0.000002100" + + # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file + # "DwellTime": 2.1e-06 + T2wSampleSpacing="0.000002100" + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is to use TOPUP and Spin Echo Field Maps + # + AvgrdcSTRING="TOPUP" + + # Spin Echo Field Maps + + PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) + NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) + + # Take the first found of each field map + SpinEchoPhaseEncodePositive=${PositiveFieldMaps##* } + SpinEchoPhaseEncodeNegative=${NegativeFieldMaps##* } + + # Spin Echo Echo Spacing + # See the EffectiveEchoSpacing value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # "EffectiveEchoSpacing": 0.000580009 + SEEchoSpacing="0.000580009" + + # Default file to use when using SEFMs + TopupConfig="${HCPPIPEDIR_Config}/b02b0.cnf" + + # Spin Echo Unwarp Direction + # See the PhaseEncodingDirection value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # "PhaseEncodingDirection": "j" + SEUnwarpDir="j" + + # See the ReadoutDirection value in the JSON sidecare file corresponding to the T1w file + # "ReadoutDirection": "k" + # x,y,z corresponds to i,j,k + UnwarpDir="z" + + # Build the PreFreeSurferPipeline.sh script invocation command to run + # with all the specified parameter values + + PreFreeSurferCmd=() + if [ -n "${queuing_command}" ]; then + PreFreeSurferCmd+=("${queuing_command}") + fi + PreFreeSurferCmd+=("${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh") + PreFreeSurferCmd+=("--path=${StudyFolder}") + PreFreeSurferCmd+=("--subject=${Session}") + PreFreeSurferCmd+=("--t1=${T1wInputImages}") + PreFreeSurferCmd+=("--t2=${T2wInputImages}") + PreFreeSurferCmd+=("--t1template=${T1wTemplate}") + PreFreeSurferCmd+=("--t1templatebrain=${T1wTemplateBrain}") + PreFreeSurferCmd+=("--t1template2mm=${T1wTemplate2mm}") + PreFreeSurferCmd+=("--t2template=${T2wTemplate}") + PreFreeSurferCmd+=("--t2templatebrain=${T2wTemplateBrain}") + PreFreeSurferCmd+=("--t2template2mm=${T2wTemplate2mm}") + PreFreeSurferCmd+=("--templatemask=${TemplateMask}") + PreFreeSurferCmd+=("--template2mmmask=${Template2mmMask}") + PreFreeSurferCmd+=("--fnirtconfig=${FNIRTConfig}") + PreFreeSurferCmd+=("--gdcoeffs=${GradientDistortionCoeffs}") + PreFreeSurferCmd+=("--brainsize=${BrainSize}") + PreFreeSurferCmd+=("--echodiff=${TE}") + PreFreeSurferCmd+=("--t1samplespacing=${T1wSampleSpacing}") + PreFreeSurferCmd+=("--t2samplespacing=${T2wSampleSpacing}") + PreFreeSurferCmd+=("--avgrdcmethod=${AvgrdcSTRING}") + PreFreeSurferCmd+=("--SEPhasePos=${SpinEchoPhaseEncodePositive}") + PreFreeSurferCmd+=("--SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") + PreFreeSurferCmd+=("--seechospacing=${SEEchoSpacing}") + PreFreeSurferCmd+=("--topupconfig=${TopupConfig}") + PreFreeSurferCmd+=("--seunwarpdir=${SEUnwarpDir}") + PreFreeSurferCmd+=("--unwarpdir=${UnwarpDir}") + PreFreeSurferCmd+=("--printcom=${PRINTCOM}") + + # Show the command + num_cmd_args=${#PreFreeSurferCmd[@]} + echo "PreFreeSurfer command to execute:" + for (( cmdindex = 0; cmdindex < num_cmd_args; ++cmdindex )); do + echo "${PreFreeSurferCmd[cmdindex]}" + done + echo "" + + # Execute the command + "${PreFreeSurferCmd[@]}" + + done +} + +# Invoke the main function to get things started +main "$@" diff --git a/Examples/Scripts/PreFreeSurferPipelineBatch.sh b/Examples/Scripts/PreFreeSurferPipelineBatch.sh index 49f609abf..f6d984d95 100755 --- a/Examples/Scripts/PreFreeSurferPipelineBatch.sh +++ b/Examples/Scripts/PreFreeSurferPipelineBatch.sh @@ -7,7 +7,7 @@ # # ## Copyright Notice # -# Copyright (C) 2013-2019 The Human Connectome Project/The Connectome Coordination Facility +# Copyright (C) 2013-2018 The Human Connectome Project # # * Washington University in St. Louis # * University of Minnesota @@ -16,9 +16,9 @@ # ## Author(s) # # * Matthew F. Glasser, Department of Anatomy and Neurobiology, -# Washington University in St. Louis +# Washington University in St. Louis # * Timothy B. Brown, Neuroinformatics Research Group, -# Washington University in St. Louis +# Washington University in St. Louis # # ## Product # @@ -37,28 +37,22 @@ # # ## Prerequisites # -# ### Installed software for processing HCP-YA data +# ### Installed software # # * FSL (version 5.0.6) # * FreeSurfer (version 5.3.0-HCP) # * gradunwarp (HCP version 1.0.2) - if doing gradient distortion correction # -# ### Installed software for processing LifeSpan data -# -# * FSL (version v6.0.1) -# * FreeSurfer (version v6.0.0) -# * gradunwarp (HCP version 1.0.2) - if doing gradient distortion correction -# # ### Environment variables # # Should be set in script file pointed to by EnvironmentScript variable. # See setting of the EnvironmentScript variable in the main() function # below. # -# * FSLDIR - FSL installation directory -# * FREESURFER_HOME - FreeSurfer installation directory -# * HCPPIPEDIR - HCP Pipelines installation directory -# * CARET7DIR - Connectome Workbench installation directory +# * FSLDIR - main FSL installation directory +# * FREESURFER_HOME - main FreeSurfer installation directory +# * HCPPIPEDIR - main HCP Pipelines installation directory +# * CARET7DIR - main Connectome Workbench installation directory # * PATH - must point to where gradient_unwarp.py is if doing gradient unwarping # # @@ -67,223 +61,101 @@ # #~ND~END~ -# ---------------------------------------------------------------- -# HERE IS WHERE YOU WOULD CHANGE DEFAULT VALUES TO BE USED -# IF YOU WOULD LIKE TO RUN THIS SCRIPT WITHOUT SPECIFYING -# ANY COMMAND LINE PARAMETERS. -# ---------------------------------------------------------------- - -# Default location of study folder -DEFAULT_STUDY_FOLDER="${HOME}/projects/Pipelines_ExampleData" - -# Default space delimited list of subject IDs -DEFAULT_SESSION_LIST="100307" - -# Default pipeline environment script -DEFAULT_ENVIRONMENT_SCRIPT="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" - -# Default indicator of whether to run the processing "locally" (i.e. on the -# machine on which this script is invoked) or try to submit the a job -# to a processing queue using fsl_sub. If this value is anything other -# than empty, then the processing is done "locally". -# -# Example usage: -# -# Set to empty string to submit a job for each session/subject. -# -# DEFAULT_RUN_LOCAL="" -# -# Set to "TRUE" to do processing "locally". -# -# DEFAULT_RUN_LOCAL="TRUE" -# -DEFAULT_RUN_LOCAL="" - -# Default indicator of whether to process data in "LifeSpan" style. -# If this value is anything other than empty, then it is assume that -# the data to be processed follows LifeSpan style naming conventions. +# Function: get_batch_options +# Description # -# Example usage: +# Retrieve the following command line parameter values if specified # -# Set to empty string to run processing on HCP-YA style data +# --StudyFolder= - primary study folder containing subject ID subdirectories +# --Subjlist= - quoted, space separated list of subject IDs on which +# to run the pipeline +# --runlocal - if specified (without an argument), processing is run +# on "this" machine as opposed to being submitted to a +# computing grid # -# DEFAULT_LIFESPAN_STYLE="" +# Set the values of the following global variables to reflect command +# line specified parameters # -# Set to "TRUE" to run processing on LifeSpan style data +# command_line_specified_study_folder +# command_line_specified_subj_list +# command_line_specified_run_local # -# DEFAULT_LIFESPAN_STYLE="TRUE" -# -DEFAULT_LIFESPAN_STYLE="" - -usage() -{ - cat < = user supplied value - - [--help] : show this usage information and exit - - [--StudyFolder=] - [--study=] - [--working-dir=] - - These are equivalent alternative ways for specifying the study folder in which - to find the session or subject directories. - - If none of these options are specified, the study folder used defaults to: - - ${DEFAULT_STUDY_FOLDER} - - [--Subject=] - [--subject=] - [--Session=] - [--session=] - - These are equivalent alternative ways for specifying a session (or subject) - within the study folder for which to run this processing. - - This parameter can be specified multiple times to create a list of - sessions to process. E.g. --session=100307 --subject=100287 --Session=190876 - would result in the following list of sessions to process: 100307 100287 190876 - - If none of these options are specified, the list of sessions to process - defaults to: - - ${DEFAULT_SESSION_LIST} - - [--runlocal] - [--run-local] - - These are equivalent alternative ways for specifying that processing should - occur "locally" (i.e. on this machine) as opposed to trying to submit the - processing to a queuing system. - - [--lifespan] - - Using this option indicates that the processing should be run on data in a - directory structure that takes the standard HCP/LifeSpan project form as - opposed to the default directory structure which is the HCP Young Adult - (HCP-YA) form. - - [--env=] - [--env-script=] - - These are equivalent alternative ways for specifying the path to the - environment script which sets the environment variables necessary - to run this processing. - - If none of these options are specified, the environment script path - defaults to: +# These values are intended to be used to override any values set +# directly within this script file +get_batch_options() { + local arguments=("$@") - ${DEFAULT_ENVIRONMENT_SCRIPT} + unset command_line_specified_study_folder + unset command_line_specified_subj + unset command_line_specified_run_local -EOF -} - -get_options() -{ - # Note that the ($@) construction parses the arguments into an - # array of values using spaces as the delimiter - local arguments=($@) - - unset p_study_folder - unset p_session_list - unset p_run_local - unset p_lifespan_style - unset p_environment_script - - # parse arguments - local num_args=${#arguments[@]} + local index=0 + local numArgs=${#arguments[@]} local argument - local index - for (( index = 0; index < num_args; ++index )); do + while [ ${index} -lt ${numArgs} ]; do argument=${arguments[index]} - + case ${argument} in - --help) - usage - exit 1 + --StudyFolder=*) + command_line_specified_study_folder=${argument#*=} + index=$(( index + 1 )) ;; - --StudyFolder=* | --study=* | --working-dir=*) - p_study_folder=${argument#*=} + --Subject=*) + command_line_specified_subj=${argument#*=} + index=$(( index + 1 )) ;; - --Subject=* | --subject=* | --Session=* | --session=*) - if [ -n "${p_session_list}" ]; then - p_session_list+=" " - fi - p_session_list+=${argument#*=} - ;; - --runlocal | --run-local) - p_run_local="TRUE" - ;; - --lifespan) - p_lifespan_style="TRUE" - ;; - --env=* | --env-script=*) - p_environment_script=${argument#*=} + --runlocal) + command_line_specified_run_local="TRUE" + index=$(( index + 1 )) ;; *) - usage + echo "" + echo "ERROR: Unrecognized Option: ${argument}" + echo "" exit 1 ;; esac - done - - if [ -z "${p_study_folder}" ]; then - p_study_folder=${DEFAULT_STUDY_FOLDER} - fi - - if [ -z "${p_session_list}" ]; then - p_session_list=${DEFAULT_SESSION_LIST} - fi - - if [ -z "${p_environment_script}" ]; then - p_environment_script=${DEFAULT_ENVIRONMENT_SCRIPT} - fi +} - if [ -z "${p_run_local}" ]; then - p_run_local=${DEFAULT_RUN_LOCAL} +# Function: main +# Description: main processing work of this script +main() +{ + get_batch_options "$@" + + # Set variable values that locate and specify data to process + StudyFolder="${HOME}/projects/Pipelines_ExampleData" # Location of Subject folders (named by subjectID) + Subjlist="100307" # Space delimited list of subject IDs + + # Set variable value that sets up environment + EnvironmentScript="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" # Pipeline environment script + + # Use any command line specified options to override any of the variable settings above + if [ -n "${command_line_specified_study_folder}" ]; then + StudyFolder="${command_line_specified_study_folder}" fi - if [ -z "${p_lifespan_style}" ]; then - p_lifespan_style=${DEFAULT_LIFESPAN_STYLE} + if [ -n "${command_line_specified_subj}" ]; then + Subjlist="${command_line_specified_subj}" fi -} -main() -{ - get_options "$@" - - # Gather options specified on the command line or given default values - local StudyFolder="${p_study_folder}" - local SessionList="${p_session_list}" - local EnvironmentScript="${p_environment_script}" - local RunLocal="${p_run_local}" - local LifeSpanStyle="${p_lifespan_style}" - # Report major script control variables to user - echo "" echo "StudyFolder: ${StudyFolder}" - echo "SessionList: ${SessionList}" + echo "Subjlist: ${Subjlist}" echo "EnvironmentScript: ${EnvironmentScript}" - echo "RunLocal: ${RunLocal}" - echo "LifeSpanStyle: ${LifeSpanStyle}" - echo "" - - # Set up pipeline environment variables and software paths + echo "Run locally: ${command_line_specified_run_local}" + + # Set up pipeline environment variables and software source ${EnvironmentScript} - - # Report environment variables pointing to tools - echo "FSLDIR: ${FSLDIR}" - echo "FREESURFER_HOME: ${FREESURFER_HOME}" - echo "HCPPIPEDIR: ${HCPPIPEDIR}" - echo "CARET7DIR: ${CARET7DIR}" - echo "PATH: ${PATH}" + + # Define processing queue to be used if submitted to job scheduler + # if [ X$SGE_ROOT != X ] ; then + # QUEUE="-q long.q" + # QUEUE="-q veryshort.q" + QUEUE="-q hcp_priority.q" + # fi # If PRINTCOM is not a null or empty string variable, then # this script and other scripts that it calls will simply @@ -293,556 +165,326 @@ main() PRINTCOM="" # PRINTCOM="echo" - # Define processing queue to be used if submitted to job scheduler - # if [ X$SGE_ROOT != X ] ; then - # QUEUE="-q long.q" - # QUEUE="-q veryshort.q" - QUEUE="-q hcp_priority.q" - # fi - - # Establish queuing command based on whether running locally or submitting jobs - if [ -n "${RunLocal}" ] ; then - queuing_command="" - else - queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" - fi - - # Cycle through specified subjects/sessions and run/submit processing - for Session in ${SessionList} ; do - echo "" - echo "Processing: ${Session}" - echo "" - - # Scripts called by this script do NOT assume anything about the form of the - # input names or paths. This batch script assumes either the HCP unprocessed - # data naming convention or the LifeSpan unprocessed data naming convention - # depending upon whether LifeSpanStyle is "TRUE". - - if [ -n "${LifeSpanStyle}" ]; then - - # ---------------------------------------------------------------- - # Set processing parameters for running data in LifeSpan style - # ---------------------------------------------------------------- - - # Input Images - # - # If LifeSpanStyle is non-empty, then the LifeSpan unprocessed data naming convention - # is used. - - T1wInputImages="${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_T1w_MPR_vNav_4e_RMS.nii.gz" - T2wInputImages="${StudyFolder}/${Session}/unprocessed/T2w_SPC_vNav/${Session}_T2w_SPC_vNav.nii.gz" - - if [ ! -e ${T1wInputImages} ]; then - echo "Expected input T1w image: ${T1wInputImages} " - echo "Does not exist" - exit 1 - fi - - if [ ! -e ${T2wInputImages} ]; then - echo "Expected input T2w image: ${T2wInputImages} " - echo "Does not exist" - exit 1 - fi - - # Templates - - # Hires T1w MNI template - T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz" - - # Hires brain extracted MNI template - T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz" - - # Lowres T1w MNI template - T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" - - # Hires T2w MNI Template - T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz" - - # Hires T2w brain extracted MNI Template - T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz" - - # Lowres T2w MNI Template - T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" - - # Hires MNI brain mask template - TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz" - - # Lowres MNI brain mask template - Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" - - # FNIRT 2mm T1w Config - FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" - - # Location of Coeffs file or "NONE" to skip - # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/Prisma_3T_coeff_AS82.grad" - - # Set to NONE to skip gradient distortion correction - GradientDistortionCoeffs="NONE" - - # BrainSize in mm, 150 for humans - BrainSize="150" - - # ---------------------------------------------------------------------- - # Variables related to using Siemens specific Gradient Echo Field Maps - # NOT USED IN THIS CASE - # ---------------------------------------------------------------------- - - # The MagnitudeInputName variable should be set to a 4D magitude volume - # with two 3D timepoints or "NONE" if not used - MagnitudeInputName="NONE" - - # The PhaseInputName variable should be set to a 3D phase difference - # volume or "NONE" if not used - PhaseInputName="NONE" - - # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T - # scanner or "NONE" if not using - TE="NONE" - - # The values set below are for the LifeSpan Aging Protocol using - # a Prisma 3T scanner - - # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file - # "DwellTime": 2.1e-06 - T1wSampleSpacing="0.000002100" - - # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file - # "DwellTime": 2.1e-06 - T2wSampleSpacing="0.000002100" - - # Readout Distortion Correction: - # - # Currently supported Averaging and readout distortion correction - # methods: (i.e. supported values for the AvgrdcSTRING variable in this - # script and the --avgrdcmethod= command line option for the - # PreFreeSurferPipeline.sh script.) - # - # "NONE" - # Average any repeats but do no readout distortion correction - # - # "FIELDMAP" - # This value is equivalent to the "SiemensFieldMap" value described - # below. Use of the "SiemensFieldMap" value is prefered, but - # "FIELDMAP" is included for backward compatibility with earlier versions - # of these scripts that only supported use of Siemens-specific - # Gradient Echo Field Maps and did not support Gradient Echo Field - # Maps from any other scanner vendor. - # - # "TOPUP" - # Average any repeats and use Spin Echo Field Maps for readout - # distortion correction - # - # "GeneralElectricFieldMap" - # Average any repeats and use General Electric specific Gradient - # Echo Field Map for readout distortion correction - # - # "SiemensFieldMap" - # Average any repeats and use Siemens specific Gradient Echo - # Field Maps for readout distortion correction - # - # Current Setup is to use TOPUP and Spin Echo Field Maps - # - AvgrdcSTRING="TOPUP" - - # Spin Echo Field Maps - - PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) - NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) - - # Take the first found of each field map - SpinEchoPhaseEncodePositive=${PositiveFieldMaps##* } - SpinEchoPhaseEncodeNegative=${NegativeFieldMaps##* } - - # Spin Echo Echo Spacing - # See the EffectiveEchoSpacing value in the JSON sidecar file corresponding to the SpinEchoFieldMap file - # "EffectiveEchoSpacing": 0.000580009 - SEEchoSpacing="0.000580009" - - # Default file to use when using SEFMs - TopupConfig="${HCPPIPEDIR_Config}/b02b0.cnf" - - # Spin Echo Unwarp Direction - # See the PhaseEncodingDirection value in the JSON sidecar file corresponding to the SpinEchoFieldMap file - # "PhaseEncodingDirection": "j" - SEUnwarpDir="j" - - # See the ReadoutDirection value in the JSON sidecare file corresponding to the T1w file - # "ReadoutDirection": "k" - # x,y,z corresponds to i,j,k - UnwarpDir="z" - - # Build the PreFreeSurferPipeline.sh script invocation command to run - # with all the specified parameter values - - PreFreeSurferCmd=() - if [ -n "${queuing_command}" ]; then - PreFreeSurferCmd+=("${queuing_command}") - fi - PreFreeSurferCmd+=("${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh") - PreFreeSurferCmd+=("--path=${StudyFolder}") - PreFreeSurferCmd+=("--subject=${Session}") - PreFreeSurferCmd+=("--t1=${T1wInputImages}") - PreFreeSurferCmd+=("--t2=${T2wInputImages}") - PreFreeSurferCmd+=("--t1template=${T1wTemplate}") - PreFreeSurferCmd+=("--t1templatebrain=${T1wTemplateBrain}") - PreFreeSurferCmd+=("--t1template2mm=${T1wTemplate2mm}") - PreFreeSurferCmd+=("--t2template=${T2wTemplate}") - PreFreeSurferCmd+=("--t2templatebrain=${T2wTemplateBrain}") - PreFreeSurferCmd+=("--t2template2mm=${T2wTemplate2mm}") - PreFreeSurferCmd+=("--templatemask=${TemplateMask}") - PreFreeSurferCmd+=("--template2mmmask=${Template2mmMask}") - PreFreeSurferCmd+=("--fnirtconfig=${FNIRTConfig}") - PreFreeSurferCmd+=("--gdcoeffs=${GradientDistortionCoeffs}") - PreFreeSurferCmd+=("--brainsize=${BrainSize}") - PreFreeSurferCmd+=("--echodiff=${TE}") - PreFreeSurferCmd+=("--t1samplespacing=${T1wSampleSpacing}") - PreFreeSurferCmd+=("--t2samplespacing=${T2wSampleSpacing}") - PreFreeSurferCmd+=("--avgrdcmethod=${AvgrdcSTRING}") - PreFreeSurferCmd+=("--SEPhasePos=${SpinEchoPhaseEncodePositive}") - PreFreeSurferCmd+=("--SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") - PreFreeSurferCmd+=("--seechospacing=${SEEchoSpacing}") - PreFreeSurferCmd+=("--topupconfig=${TopupConfig}") - PreFreeSurferCmd+=("--seunwarpdir=${SEUnwarpDir}") - PreFreeSurferCmd+=("--unwarpdir=${UnwarpDir}") - PreFreeSurferCmd+=("--printcom=${PRINTCOM}") - - # Show the command - num_cmd_args=${#PreFreeSurferCmd[@]} - echo "PreFreeSurfer command to execute:" - for (( cmdindex = 0; cmdindex < num_cmd_args; ++cmdindex )); do - echo "${PreFreeSurferCmd[cmdindex]}" - done - echo "" - - # Execute the command - "${PreFreeSurferCmd[@]}" - - else # Default to HCP-YA style - - # ---------------------------------------------------------------- - # Set processing parameters for running data in HCP-YA style - # ---------------------------------------------------------------- - - # Note that for the HCP naming convention, the "Session" and the "Subject" are - # essentially equivalent. Sessions would be subject IDs like 100307, 110226, 997865, etc. - Subject="${Session}" - - # If LifeSpanStyle is empty, then the HCP unprocessed data naming convention - # is used, e.g. - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz - # - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz - - # Detect Number of T1w Images and build list of full paths to T1w images - numT1ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l) - echo "Found ${numT1ws} T1w Images for subject: ${Subject}" - T1wInputImages="" - i=1 - while [ ${i} -le ${numT1ws} ] ; do - echo "T1w ${i}" - T1wInputImages=$(echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MRP${i}.nii.gz@") - i=$(($i+1)) - done - - # Detect Number of T2w Images and build list of full paths to T2w images - numT2ws=$(ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l) - echo "Found ${numT2ws} T2w Images for subject: ${Subject}" - T2wInputImages="" - i=1 - while [ ${i} -le ${numT2ws} ] ; do - echo "T2w ${i}" - T2wInputImages=$(echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@") - i=$(($i+1)) - done - - # Scan settings: - # - # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your - # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. - # (i.e., the study collected on the customized Connectom scanner). - - # Readout Distortion Correction: - # - # You have the option of using either gradient echo field maps or spin echo - # field maps to perform readout distortion correction on your structural - # images, or not to do readout distortion correction at all. - # - # The HCP Pipeline Scripts currently support the use of gradient echo field - # maps or spin echo field maps as they are produced by the Siemens Connectom - # Scanner. They also support the use of gradient echo field maps as generated - # by General Electric scanners. - # - # Change either the gradient echo field map or spin echo field map scan - # settings to match your data. This script is setup to use gradient echo - # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. - - # Gradient Distortion Correction: - # - # If using gradient distortion correction, use the coefficents from your - # scanner. The HCP gradient distortion coefficents are only available through - # Siemens. Gradient distortion in standard scanners like the Trio is much - # less than for the HCP Connectom scanner. - - # Readout Distortion Correction: - # - # Currently supported Averaging and readout distortion correction - # methods: (i.e. supported values for the AvgrdcSTRING variable in this - # script and the --avgrdcmethod= command line option for the - # PreFreeSurferPipeline.sh script.) - # - # "NONE" - # Average any repeats but do no readout distortion correction - # - # "FIELDMAP" - # This value is equivalent to the "SiemensFieldMap" value described - # below. Use of the "SiemensFieldMap" value is prefered, but - # "FIELDMAP" is included for backward compatibility with earlier versions - # of these scripts that only supported use of Siemens-specific - # Gradient Echo Field Maps and did not support Gradient Echo Field - # Maps from any other scanner vendor. - # - # "TOPUP" - # Average any repeats and use Spin Echo Field Maps for readout - # distortion correction - # - # "GeneralElectricFieldMap" - # Average any repeats and use General Electric specific Gradient - # Echo Field Map for readout distortion correction - # - # "SiemensFieldMap" - # Average any repeats and use Siemens specific Gradient Echo - # Field Maps for readout distortion correction - # - # Current Setup is for Siemens specific Gradient Echo Field Maps - # - # The following settings for AvgrdcSTRING, MagnitudeInputName, - # PhaseInputName, and TE are for using the Siemens specific - # Gradient Echo Field Maps that are collected and used in the - # standard HCP-YA protocol. - # - # Note: The AvgrdcSTRING variable could also be set to the value - # "FIELDMAP" which is equivalent to "SiemensFieldMap". - AvgrdcSTRING="SiemensFieldMap" - - # ---------------------------------------------------------------------- - # Variables related to using Siemens specific Gradient Echo Field Maps - # ---------------------------------------------------------------------- - - # The MagnitudeInputName variable should be set to a 4D magitude volume - # with two 3D timepoints or "NONE" if not used - MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" - - # The PhaseInputName variable should be set to a 3D phase difference - # volume or "NONE" if not used - PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" - - # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T - # scanner or "NONE" if not using - TE="2.46" - - # ---------------------------------------------------------------------- - # Variables related to using Spin Echo Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") - - # The SpinEchoPhaseEncodeNegative variable should be set to the - # spin echo field map volume with a negative phase encoding direction - # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); - # AP if using a pair of AP/PA Siemens SEFMS) - # and set to "NONE" if not using SEFMs - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz - SpinEchoPhaseEncodeNegative="NONE" - - # The SpinEchoPhaseEncodePositive variable should be set to the - # spin echo field map volume with positive phase encoding direction - # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), - # and set to "NONE" if not using Spin Echo Field Maps - # (i.e. if AvgrdcSTRING is not equal to "TOPUP") - # - # Example values for when using Spin Echo Field Maps from a Siemens machine: - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz - # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz - SpinEchoPhaseEncodePositive="NONE" - - # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. - # Set to "NONE" if not used. - # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) - # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and - # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension - # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation - # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) - # - # Example value for when using Spin Echo Field Maps from the HCP-YA - # 0.000580002668012 - SEEchoSpacing="NONE" - - # Spin Echo Unwarping Direction (according to the *voxel* axes) - # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) - # Set to "NONE" if not used. - # - # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} - # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign - # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] - SEUnwarpDir="NONE" - - # Topup Configuration file - # Set to "NONE" if not using SEFMs - # - # Default file to use when using SEFMs - # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" - TopupConfig="NONE" - - # ---------------------------------------------------------------------- - # Variables related to using General Electric specific Gradient Echo - # Field Maps - # ---------------------------------------------------------------------- - - # The following variables would be set to values other than "NONE" for - # using General Electric specific Gradient Echo Field Maps (i.e. when - # AvgrdcSTRING="GeneralElectricFieldMap") - - # Example value for when using General Electric Gradient Echo Field Map - # - # GEB0InputName should be a General Electric style B0 fieldmap with two - # volumes - # 1) fieldmap in deg and - # 2) magnitude, - # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap - # - # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" - GEB0InputName="NONE" - - # Templates - - # Hires T1w MNI template - T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" - - # Hires brain extracted MNI template - T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" - - # Lowres T1w MNI template - T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" - - # Hires T2w MNI Template - T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" - - # Hires T2w brain extracted MNI Template - T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" - - # Lowres T2w MNI Template - T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" - - # Hires MNI brain mask template - TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" - - # Lowres MNI brain mask template - Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" - - # Structural Scan Settings - # - # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, - # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) - # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction - # of the Spin Echo Field Maps (if using them). - # Note that polarity of UnwarpDir DOES matter. - # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) - # - # set all these values to NONE if not doing readout distortion correction - # - # Sample values for when using General Electric structurals - # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) - # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? - - # The values set below are for the HCP-YA Protocol using the Siemens - # Connectom Scanner - - # DICOM field (0019,1018) in s or "NONE" if not used - T1wSampleSpacing="0.0000074" - - # DICOM field (0019,1018) in s or "NONE" if not used - T2wSampleSpacing="0.0000021" - - # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners - UnwarpDir="z" - - # Other Config Settings - - # BrainSize in mm, 150 for humans - BrainSize="150" - - # FNIRT 2mm T1w Config - FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" - - # Location of Coeffs file or "NONE" to skip - # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" - - # Set to NONE to skip gradient distortion correction - GradientDistortionCoeffs="NONE" - - # Build the PreFreeSurferPipeline.sh script command to run - # with all the specified parameter values - - PreFreeSurferCmd=() - if [ -n "${queuing_command}" ]; then - PreFreeSurferCmd+=("${queuing_command}") - fi - PreFreeSurferCmd+=("${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh") - PreFreeSurferCmd+=(" --path=${StudyFolder}") - PreFreeSurferCmd+=(" --subject=${Subject}") - PreFreeSurferCmd+=(" --t1=${T1wInputImages}") - PreFreeSurferCmd+=(" --t2=${T2wInputImages}") - PreFreeSurferCmd+=(" --t1template=${T1wTemplate}") - PreFreeSurferCmd+=(" --t1templatebrain=${T1wTemplateBrain}") - PreFreeSurferCmd+=(" --t1template2mm=${T1wTemplate2mm}") - PreFreeSurferCmd+=(" --t2template=${T2wTemplate}") - PreFreeSurferCmd+=(" --t2templatebrain=${T2wTemplateBrain}") - PreFreeSurferCmd+=(" --t2template2mm=${T2wTemplate2mm}") - PreFreeSurferCmd+=(" --templatemask=${TemplateMask}") - PreFreeSurferCmd+=(" --template2mmmask=${Template2mmMask}") - PreFreeSurferCmd+=(" --brainsize=${BrainSize}") - PreFreeSurferCmd+=(" --fnirtconfig=${FNIRTConfig}") - PreFreeSurferCmd+=(" --fmapmag=${MagnitudeInputName}") - PreFreeSurferCmd+=(" --fmapphase=${PhaseInputName}") - PreFreeSurferCmd+=(" --fmapgeneralelectric=${GEB0InputName}") - PreFreeSurferCmd+=(" --echodiff=${TE}") - PreFreeSurferCmd+=(" --SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") - PreFreeSurferCmd+=(" --SEPhasePos=${SpinEchoPhaseEncodePositive}") - PreFreeSurferCmd+=(" --seechospacing=${SEEchoSpacing}") - PreFreeSurferCmd+=(" --seunwarpdir=${SEUnwarpDir}") - PreFreeSurferCmd+=(" --t1samplespacing=${T1wSampleSpacing}") - PreFreeSurferCmd+=(" --t2samplespacing=${T2wSampleSpacing}") - PreFreeSurferCmd+=(" --unwarpdir=${UnwarpDir}") - PreFreeSurferCmd+=(" --gdcoeffs=${GradientDistortionCoeffs}") - PreFreeSurferCmd+=(" --avgrdcmethod=${AvgrdcSTRING}") - PreFreeSurferCmd+=(" --topupconfig=${TopupConfig}") - PreFreeSurferCmd+=(" --printcom=${PRINTCOM}") - - # Show the command - num_cmd_args=${#PreFreeSurferCmd[@]} - echo "PreFreeSurfer command to execute:" - for (( cmdindex = 0; cmdindex < num_cmd_args; ++cmdindex )); do - echo "${PreFreeSurferCmd[cmdindex]}" - done - echo "" - - # Execute the command - "${PreFreeSurferCmd[@]}" - + # + # Inputs: + # + # Scripts called by this script do NOT assume anything about the form of the + # input names or paths. This batch script assumes the HCP raw data naming + # convention, e.g. + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_T1w_MPR1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR2/${Subject}_3T_T1w_MPR2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC1/${Subject}_3T_T2w_SPC1.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC2/${Subject}_3T_T2w_SPC2.nii.gz + # + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz + + # Scan settings: + # + # Change the Scan Settings (e.g. Sample Spacings and $UnwarpDir) to match your + # structural images. These are set to match the HCP-YA ("Young Adult") Protocol by default. + # (i.e., the study collected on the customized Connectom scanner). + + # Readout Distortion Correction: + # + # You have the option of using either gradient echo field maps or spin echo + # field maps to perform readout distortion correction on your structural + # images, or not to do readout distortion correction at all. + # + # The HCP Pipeline Scripts currently support the use of gradient echo field + # maps or spin echo field maps as they are produced by the Siemens Connectom + # Scanner. They also support the use of gradient echo field maps as generated + # by General Electric scanners. + # + # Change either the gradient echo field map or spin echo field map scan + # settings to match your data. This script is setup to use gradient echo + # field maps from the Siemens Connectom Scanner collected using the HCP-YA Protocol. + + # Gradient Distortion Correction: + # + # If using gradient distortion correction, use the coefficents from your + # scanner. The HCP gradient distortion coefficents are only available through + # Siemens. Gradient distortion in standard scanners like the Trio is much + # less than for the HCP Connectom scanner. + + # DO WORK + + # Cycle through specified subjects + for Subject in $Subjlist ; do + echo $Subject + + # Input Images + + # Detect Number of T1w Images and build list of full paths to + # T1w images + numT1ws=`ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T1w_MPR.$' | wc -l` + echo "Found ${numT1ws} T1w Images for subject ${Subject}" + T1wInputImages="" + i=1 + while [ $i -le $numT1ws ] ; do + T1wInputImages=`echo "${T1wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR${i}/${Subject}_3T_T1w_MPR${i}.nii.gz@"` + i=$(($i+1)) + done + + # Detect Number of T2w Images and build list of full paths to + # T2w images + numT2ws=`ls ${StudyFolder}/${Subject}/unprocessed/3T | grep 'T2w_SPC.$' | wc -l` + echo "Found ${numT2ws} T2w Images for subject ${Subject}" + T2wInputImages="" + i=1 + while [ $i -le $numT2ws ] ; do + T2wInputImages=`echo "${T2wInputImages}${StudyFolder}/${Subject}/unprocessed/3T/T2w_SPC${i}/${Subject}_3T_T2w_SPC${i}.nii.gz@"` + i=$(($i+1)) + done + + # Readout Distortion Correction: + # + # Currently supported Averaging and readout distortion correction + # methods: (i.e. supported values for the AvgrdcSTRING variable in this + # script and the --avgrdcmethod= command line option for the + # PreFreeSurferPipeline.sh script.) + # + # "NONE" + # Average any repeats but do no readout distortion correction + # + # "FIELDMAP" + # This value is equivalent to the "SiemensFieldMap" value described + # below. Use of the "SiemensFieldMap" value is prefered, but + # "FIELDMAP" is included for backward compatibility with earlier versions + # of these scripts that only supported use of Siemens-specific + # Gradient Echo Field Maps and did not support Gradient Echo Field + # Maps from any other scanner vendor. + # + # "TOPUP" + # Average any repeats and use Spin Echo Field Maps for readout + # distortion correction + # + # "GeneralElectricFieldMap" + # Average any repeats and use General Electric specific Gradient + # Echo Field Map for readout distortion correction + # + # "SiemensFieldMap" + # Average any repeats and use Siemens specific Gradient Echo + # Field Maps for readout distortion correction + # + # Current Setup is for Siemens specific Gradient Echo Field Maps + # + # The following settings for AvgrdcSTRING, MagnitudeInputName, + # PhaseInputName, and TE are for using the Siemens specific + # Gradient Echo Field Maps that are collected and used in the + # standard HCP-YA protocol. + # + # Note: The AvgrdcSTRING variable could also be set to the value + # "FIELDMAP" which is equivalent to "SiemensFieldMap". + AvgrdcSTRING="SiemensFieldMap" + + # ---------------------------------------------------------------------- + # Variables related to using Siemens specific Gradient Echo Field Maps + # ---------------------------------------------------------------------- + + # The MagnitudeInputName variable should be set to a 4D magitude volume + # with two 3D timepoints or "NONE" if not used + MagnitudeInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Magnitude.nii.gz" + + # The PhaseInputName variable should be set to a 3D phase difference + # volume or "NONE" if not used + PhaseInputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_FieldMap_Phase.nii.gz" + + # The TE variable should be set to 2.46ms for 3T scanner, 1.02ms for 7T + # scanner or "NONE" if not using + TE="2.46" + + # ---------------------------------------------------------------------- + # Variables related to using Spin Echo Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") + + # The SpinEchoPhaseEncodeNegative variable should be set to the + # spin echo field map volume with a negative phase encoding direction + # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); + # AP if using a pair of AP/PA Siemens SEFMS) + # and set to "NONE" if not using SEFMs + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_LR.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_AP.nii.gz + SpinEchoPhaseEncodeNegative="NONE" + + # The SpinEchoPhaseEncodePositive variable should be set to the + # spin echo field map volume with positive phase encoding direction + # (RL if using a pair of LR/RL SEFMs; PA if using a AP/PA pair), + # and set to "NONE" if not using Spin Echo Field Maps + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") + # + # Example values for when using Spin Echo Field Maps from a Siemens machine: + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_RL.nii.gz + # ${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_SpinEchoFieldMap_PA.nii.gz + SpinEchoPhaseEncodePositive="NONE" + + # "Effective" Echo Spacing of *Spin Echo Field Maps*. Specified in seconds. + # Set to "NONE" if not used. + # SEEchoSpacing = 1/(BWPPPE * ReconMatrixPE) + # where BWPPPE is the "BandwidthPerPixelPhaseEncode" = DICOM field (0019,1028) for Siemens, and + # ReconMatrixPE = size of the reconstructed SEFM images in the PE dimension + # In-plane acceleration, phase oversampling, phase resolution, phase field-of-view, and interpolation + # all potentially need to be accounted for (which they are in Siemen's reported BWPPPE) + # + # Example value for when using Spin Echo Field Maps from the HCP-YA + # 0.000580002668012 + SEEchoSpacing="NONE" + + # Spin Echo Unwarping Direction (according to the *voxel* axes) + # {x,y} (FSL nomenclature), or alternatively, {i,j} (BIDS nomenclature for the voxel axes) + # Set to "NONE" if not used. + # + # Example values for when using Spin Echo Field Maps: {x,y} or {i,j} + # Note: '+x' or '+y' are not supported. i.e., for positive values, DO NOT include the '+' sign + # Note: Polarity not important here [i.e., don't use {x-,y-} or {i-,j-}] + SEUnwarpDir="NONE" + + # Topup Configuration file + # Set to "NONE" if not using SEFMs + # + # Default file to use when using SEFMs + # TopUpConfig="${HCPPIPEDIR_Config}/b02b0.cnf" + TopupConfig="NONE" + + # ---------------------------------------------------------------------- + # Variables related to using General Electric specific Gradient Echo + # Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using General Electric specific Gradient Echo Field Maps (i.e. when + # AvgrdcSTRING="GeneralElectricFieldMap") + + # Example value for when using General Electric Gradient Echo Field Map + # + # GEB0InputName should be a General Electric style B0 fieldmap with two + # volumes + # 1) fieldmap in deg and + # 2) magnitude, + # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap + # + # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" + GEB0InputName="NONE" + + # Templates + + # Hires T1w MNI template + T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm.nii.gz" + + # Hires brain extracted MNI template + T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain.nii.gz" + + # Lowres T1w MNI template + T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz" + + # Hires T2w MNI Template + T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm.nii.gz" + + # Hires T2w brain extracted MNI Template + T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.7mm_brain.nii.gz" + + # Lowres T2w MNI Template + T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz" + + # Hires MNI brain mask template + TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.7mm_brain_mask.nii.gz" + + # Lowres MNI brain mask template + Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz" + + # Structural Scan Settings + # + # "UnwarpDir" is the *readout* direction of the *structural* (T1w,T2w) images, + # *after* the application of 'fslreorient2std' (which is built into PreFreeSurferPipeline.sh) + # Do NOT confuse with "SEUnwarpDir" which is the *phase* encoding direction + # of the Spin Echo Field Maps (if using them). + # Note that polarity of UnwarpDir DOES matter. + # Allowed values: {x,y,z,x-,y-,z-} (FSL nomenclature) or {i,j,k,i-,j-,k-} (BIDS nomenclature) + # + # set all these values to NONE if not doing readout distortion correction + # + # Sample values for when using General Electric structurals + # T1wSampleSpacing="0.000011999" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # T2wSampleSpacing="0.000008000" # For General Electric scanners, 1/((0018,0095)*(0028,0010)) + # UnwarpDir="y" ## MPH: This doesn't seem right. Is this accurate?? + + # The values set below are for the HCP-YA Protocol using the Siemens + # Connectom Scanner + + # DICOM field (0019,1018) in s or "NONE" if not used + T1wSampleSpacing="0.0000074" + + # DICOM field (0019,1018) in s or "NONE" if not used + T2wSampleSpacing="0.0000021" + + # z appears to be the appropriate polarity for the 3D structurals collected on Siemens scanners + UnwarpDir="z" + + # Other Config Settings + + # BrainSize in mm, 150 for humans + BrainSize="150" + + # FNIRT 2mm T1w Config + FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf" + + # Location of Coeffs file or "NONE" to skip + # GradientDistortionCoeffs="${HCPPIPEDIR_Config}/coeff_SC72C_Skyra.grad" + + # Set to NONE to skip gradient distortion correction + GradientDistortionCoeffs="NONE" + + # Establish queuing command based on command line option + if [ -n "${command_line_specified_run_local}" ] ; then + echo "About to run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" + queuing_command="" + else + echo "About to use fsl_sub to queue or run ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh" + queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" fi - + + # Run (or submit to be run) the PreFreeSurferPipeline.sh script + # with all the specified parameter values + + ${queuing_command} ${HCPPIPEDIR}/PreFreeSurfer/PreFreeSurferPipeline.sh \ + --path="$StudyFolder" \ + --subject="$Subject" \ + --t1="$T1wInputImages" \ + --t2="$T2wInputImages" \ + --t1template="$T1wTemplate" \ + --t1templatebrain="$T1wTemplateBrain" \ + --t1template2mm="$T1wTemplate2mm" \ + --t2template="$T2wTemplate" \ + --t2templatebrain="$T2wTemplateBrain" \ + --t2template2mm="$T2wTemplate2mm" \ + --templatemask="$TemplateMask" \ + --template2mmmask="$Template2mmMask" \ + --brainsize="$BrainSize" \ + --fnirtconfig="$FNIRTConfig" \ + --fmapmag="$MagnitudeInputName" \ + --fmapphase="$PhaseInputName" \ + --fmapgeneralelectric="$GEB0InputName" \ + --echodiff="$TE" \ + --SEPhaseNeg="$SpinEchoPhaseEncodeNegative" \ + --SEPhasePos="$SpinEchoPhaseEncodePositive" \ + --seechospacing="$SEEchoSpacing" \ + --seunwarpdir="$SEUnwarpDir" \ + --t1samplespacing="$T1wSampleSpacing" \ + --t2samplespacing="$T2wSampleSpacing" \ + --unwarpdir="$UnwarpDir" \ + --gdcoeffs="$GradientDistortionCoeffs" \ + --avgrdcmethod="$AvgrdcSTRING" \ + --topupconfig="$TopupConfig" \ + --printcom=$PRINTCOM + done } From a44b134732a9510a6b0ff668732476dd8c6b3f25 Mon Sep 17 00:00:00 2001 From: "Timothy B. Brown" Date: Sat, 22 Jun 2019 07:08:25 -0500 Subject: [PATCH 7/7] Added some parameters to building of PreFreeSurfer command in PreFreeSurferPipelineBatch.LifeSpan.sh --- .../PreFreeSurferPipelineBatch.LifeSpan.sh | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh b/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh index 9e2dbb1db..f04ff7d72 100755 --- a/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh +++ b/Examples/Scripts/LifeSpan/PreFreeSurferPipelineBatch.LifeSpan.sh @@ -344,11 +344,15 @@ main() # The values set below are for the LifeSpan Aging Protocol using # a Prisma 3T scanner - # See the DwellTime value in the JSON Sidecar file corresponding to the T1w scan file + # If JSON sidecar files are available (e.g. produced by recent versions of dcm2niix), + # The value to be used for T1wSampleSpacing should be found in the DwellTime value + # in the JSON sidecar file corresponding to the T1w scan file. # "DwellTime": 2.1e-06 T1wSampleSpacing="0.000002100" - # See the DwellTime value in the JSON Sidecar file corresponding to the T2w scan file + # If JSON sidecar files are available (e.g. produced by recent versions of dcm2niix), + # The value to be used for T2wSampleSpacing should be found in the DwellTime value + # in the JSON sidecar file corresponding to the T2w scan file. # "DwellTime": 2.1e-06 T2wSampleSpacing="0.000002100" @@ -387,6 +391,16 @@ main() AvgrdcSTRING="TOPUP" # Spin Echo Field Maps + + # The SpinEchoPhaseEncodePositive and SpinEchoPhaseEncodeNegative variables should + # be set to values other than "NONE" for using Spin Echo Field Maps (i.e. when AvgrdcSTRING="TOPUP") + + # The SpinEchoPhaseEncodeNegative variable should be set to the + # spin echo field map volume with a negative phase encoding direction + # (LR if using a pair of LR/RL Siemens Spin Echo Field Maps (SEFMs); + # AP if using a pair of AP/PA Siemens SEFMS) + # and set to "NONE" if not using SEFMs + # (i.e. if AvgrdcSTRING is not equal to "TOPUP") PositiveFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*PA.nii.gz) NegativeFieldMaps=$(ls ${StudyFolder}/${Session}/unprocessed/T1w_MPR_vNav_4e_RMS/${Session}_SpinEchoFieldMap*AP.nii.gz) @@ -396,7 +410,9 @@ main() SpinEchoPhaseEncodeNegative=${NegativeFieldMaps##* } # Spin Echo Echo Spacing - # See the EffectiveEchoSpacing value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # If JSON sidecar files are available (e.g. produced by recent versions of dcm2niix), + # the value to be used for SEEchoSpacing should be found in the EffectiveEchoSpacing value + # in the JSON sidecar file corresponding to the SpinEchoFieldMap file. # "EffectiveEchoSpacing": 0.000580009 SEEchoSpacing="0.000580009" @@ -404,14 +420,38 @@ main() TopupConfig="${HCPPIPEDIR_Config}/b02b0.cnf" # Spin Echo Unwarp Direction - # See the PhaseEncodingDirection value in the JSON sidecar file corresponding to the SpinEchoFieldMap file + # If JSON sidecar files are available (e.g. produced by recent versions of dcm2niix), + # the value to be used for SEUnwarpDir should be found in the PhaseEncodingDirection value + # in the JSON sidecar file corresponding to the SpinEchoFieldMap file. # "PhaseEncodingDirection": "j" SEUnwarpDir="j" - # See the ReadoutDirection value in the JSON sidecare file corresponding to the T1w file + # If JSON sidecar files are available (e.g. produced by recent versions of dcm2niix), + # the value to be used for UnwarpDir should be found in the ReadoutDirection value + # in the JSON sidecare file corresponding to the T1w file. # "ReadoutDirection": "k" - # x,y,z corresponds to i,j,k + # Note: x is equivalent to i, y is equivalent to j, and z is equivalent to k UnwarpDir="z" + + # ---------------------------------------------------------------------- + # Variables related to using General Electric specific Gradient Echo + # Field Maps + # ---------------------------------------------------------------------- + + # The following variables would be set to values other than "NONE" for + # using General Electric specific Gradient Echo Field Maps (i.e. when + # AvgrdcSTRING="GeneralElectricFieldMap") + + # Example value for when using General Electric Gradient Echo Field Map + # + # GEB0InputName should be a General Electric style B0 fieldmap with two + # volumes + # 1) fieldmap in deg and + # 2) magnitude, + # set to NONE if using TOPUP or FIELDMAP/SiemensFieldMap + # + # GEB0InputName="${StudyFolder}/${Subject}/unprocessed/3T/T1w_MPR1/${Subject}_3T_GradientEchoFieldMap.nii.gz" + GEB0InputName="NONE" # Build the PreFreeSurferPipeline.sh script invocation command to run # with all the specified parameter values @@ -443,6 +483,19 @@ main() PreFreeSurferCmd+=("--SEPhasePos=${SpinEchoPhaseEncodePositive}") PreFreeSurferCmd+=("--SEPhaseNeg=${SpinEchoPhaseEncodeNegative}") PreFreeSurferCmd+=("--seechospacing=${SEEchoSpacing}") + + if [ "${MagnitudeInputName}" != "NONE" ]; then + PreFreeSurferCmd+=("--fmapmag=${MagnitudeInputName}") + fi + + if [ "${PhaseInputName}" != "NONE" ]; then + PreFreeSurferCmd+=("--fmapphase=${PhaseInputName}") + fi + + if [ "${GEB0InputName}" != "NONE" ]; then + PreFreeSurferCmd+=("--fmapgeneralelectric=${GEB0InputName}") + fi + PreFreeSurferCmd+=("--topupconfig=${TopupConfig}") PreFreeSurferCmd+=("--seunwarpdir=${SEUnwarpDir}") PreFreeSurferCmd+=("--unwarpdir=${UnwarpDir}")