diff --git a/DeDriftAndResample/DeDriftAndResamplePipeline.sh b/DeDriftAndResample/DeDriftAndResamplePipeline.sh index c41445877..0abab7531 100755 --- a/DeDriftAndResample/DeDriftAndResamplePipeline.sh +++ b/DeDriftAndResample/DeDriftAndResamplePipeline.sh @@ -508,7 +508,7 @@ for fMRIName in ${fixNames[@]+"${fixNames[@]}"} ${dontFixNames[@]+"${dontFixName ${Caret7_Command} -metric-resample ${ResultsFolder}/${fMRIName}/${fMRIName}.${Hemisphere}.native.func.gii ${NativeFolder}/${Subject}.${Hemisphere}.sphere.${OutputRegName}.native.surf.gii ${DownSampleFolder}/${Subject}.${Hemisphere}.sphere.${LowResMesh}k_fs_LR.surf.gii ADAP_BARY_AREA ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii -area-surfs ${NativeT1wFolder}/${Subject}.${Hemisphere}.midthickness.native.surf.gii ${DownSampleT1wFolder}/${Subject}.${Hemisphere}.midthickness_${OutputRegName}.${LowResMesh}k_fs_LR.surf.gii -current-roi ${NativeFolder}/${Subject}.${Hemisphere}.roi.native.shape.gii ${Caret7_Command} -metric-dilate ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii ${DownSampleT1wFolder}/${Subject}.${Hemisphere}.midthickness_${OutputRegName}.${LowResMesh}k_fs_LR.surf.gii 30 ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii -nearest ${Caret7_Command} -metric-mask ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii ${DownSampleFolder}/${Subject}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.shape.gii ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii - Sigma=`echo "$SmoothingFWHM / ( 2 * ( sqrt ( 2 * l ( 2 ) ) ) )" | bc -l` + Sigma=`echo "$SmoothingFWHM / (2 * sqrt(2 * l(2)))" | bc -l` ${Caret7_Command} -metric-smoothing ${DownSampleT1wFolder}/${Subject}.${Hemisphere}.midthickness_${OutputRegName}.${LowResMesh}k_fs_LR.surf.gii ${ResultsFolder}/${fMRIName}/${fMRIName}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii ${Sigma} ${ResultsFolder}/${fMRIName}/${fMRIName}_s${SmoothingFWHM}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii -roi ${DownSampleFolder}/${Subject}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.shape.gii ${Caret7_Command} -cifti-replace-structure ${ResultsFolder}/${fMRIName}/${fMRIName}_Atlas_${OutputRegName}.dtseries.nii COLUMN -metric ${Structure} ${ResultsFolder}/${fMRIName}/${fMRIName}_s${SmoothingFWHM}_${OutputRegName}.${Hemisphere}.atlasroi.${LowResMesh}k_fs_LR.func.gii done diff --git a/DeDriftAndResample/MSMRemoveGroupDrift.sh b/DeDriftAndResample/MSMRemoveGroupDrift.sh index 1c84ae8cf..1ac86479b 100755 --- a/DeDriftAndResample/MSMRemoveGroupDrift.sh +++ b/DeDriftAndResample/MSMRemoveGroupDrift.sh @@ -4,488 +4,320 @@ # Show usage information for this script # ------------------------------------------------------------------------------ -show_usage() -{ - cat < - - Options: [ ] = optional; < > = user supplied value - - [--help] : show usage information and exit" - - Usage information To Be Written - -EOF -} - -# ------------------------------------------------------------------------------ -# Get the command line options for this script. -# ------------------------------------------------------------------------------ - -get_options() -{ - local arguments=($@) - - # initialize global output variables - unset p_StudyFolder # StudyFolder - unset p_Subjlist # Subjlist - unset p_CommonFolder # CommonFolder - unset p_GroupAverageName # GroupAverageName - unset p_InputRegName # InRegName - unset p_TargetRegName # TargetRegName - unset p_RegName # RegName - unset p_HighResMesh # HighResMesh - unset p_LowResMesh # LowResMesh - - # set default values - - # 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) - show_usage - exit 0 - ;; - --path=*) - p_StudyFolder=${argument#*=} - ;; - --study-folder=*) - p_StudyFolder=${argument#*=} - ;; - --subject-list=*) - p_Subjlist=${argument#*=} - ;; - --common-folder=*) - p_CommonFolder=${argument#*=} - ;; - --group-average-name=*) - p_GroupAverageName=${argument#*=} - ;; - --input-registration-name=*) - p_InputRegName=${argument#*=} - ;; - --target-registration-name=*) - p_TargetRegName=${argument#*=} - ;; - --registration-name=*) - p_RegName=${argument#*=} - ;; - --high-res-mesh=*) - p_HighResMesh=${argument#*=} - ;; - --low-res-mesh=*) - p_LowResMesh=${argument#*=} - ;; - *) - show_usage - log_Err_Abort "unrecognized option: ${argument}" - ;; - esac - done - - local error_count=0 - # check required parameters - if [ -z "${p_StudyFolder}" ]; then - echo "ERROR: path to study folder (--path= or --study-folder=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_StudyFolder: ${p_StudyFolder}" - fi - - if [ -z "${p_Subjlist}" ]; then - echo "ERROR: subject ID list (--subject-list=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_Subjlist: ${p_Subjlist}" - fi - - if [ -z "${p_CommonFolder}" ]; then - echo "ERROR: common folder (--common-folder=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_CommonFolder: ${p_CommonFolder}" - fi - - if [ -z "${p_GroupAverageName}" ]; then - echo "ERROR: group average name (--group-average-name=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_GroupAverageName: ${p_GroupAverageName}" - fi - - if [ -z "${p_InputRegName}" ]; then - echo "ERROR: input registration name (--input-registration-name=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_InputRegName: ${p_InputRegName}" - fi - - if [ -z "${p_TargetRegName}" ]; then - echo "ERROR: target registration name (--target-registration-name=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_TargetRegName: ${p_TargetRegName}" - fi - - if [ -z "${p_RegName}" ]; then - echo "ERROR: registration name (--registration-name=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_RegName: ${p_RegName}" - fi +set -eu + +pipedirguessed=0 +if [[ "${HCPPIPEDIR:-}" == "" ]] +then + pipedirguessed=1 + #fix this if the script is more than one level below HCPPIPEDIR + export HCPPIPEDIR="$(dirname -- "$0")/.." +fi - if [ -z "${p_HighResMesh}" ]; then - echo "ERROR: high resolution mesh (--high-res-mesh=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_HighResMesh: ${p_HighResMesh}" - fi +# Load function libraries +source "${HCPPIPEDIR}/global/scripts/debug.shlib" "$@" # Debugging functions; also sources log.shlib +source "$HCPPIPEDIR/global/scripts/newopts.shlib" "$@" - if [ -z "${p_LowResMesh}" ]; then - echo "ERROR: low resolution mesh (--low-res-mesh=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_LowResMesh: ${p_LowResMesh}" - fi +opts_SetScriptDescription "MSM Remove Group Drift - Compute Group Registration Drift" - if [ ${error_count} -gt 0 ]; then - echo "For usage information, use --help" - exit 1 - fi -} +#ARE THESE DESCRIPTIONS OK????? +opts_AddMandatory '--study-folder' 'StudyFolder' 'path' "path to study folder" -# ------------------------------------------------------------------------------ -# Show Tool Versions -# ------------------------------------------------------------------------------ +opts_AddMandatory '--subject-list' 'Subjlist' 'list' "@ delimited list of subject ids" -show_tool_versions() -{ - # Show HCP pipelines version - log_Msg "Showing HCP Pipelines version" - "${HCPPIPEDIR}"/show_version --short +opts_AddMandatory '--group-folder' 'CommonFolder' 'path' "group-average folder" "--common-folder" - # Show wb_command version - log_Msg "Showing wb_command version" - ${CARET7DIR}/wb_command -version -} +opts_AddMandatory '--group-average-name' 'GroupAverageName' 'name' "output group average name (e.g. S900)" -# ------------------------------------------------------------------------------ -# Main processing of script. -# ------------------------------------------------------------------------------ +opts_AddMandatory '--input-registration-name' 'InRegName' 'string' "Name of the input registration (e.g. MSMSulc)" -main() -{ - # Get command line options - # See documentation for the get_options function for global variables set - get_options "$@" +opts_AddMandatory '--target-registration-name' 'TargetRegName' 'string' "Name of the target registration (e.g. MSMAll)" - StudyFolder="${p_StudyFolder}" - log_Msg "StudyFolder: ${StudyFolder}" +opts_AddMandatory '--registration-name' 'RegName' 'string' "Name of the registration (e.g. MSMAll)" - Subjlist="${p_Subjlist}" - log_Msg "Subjlist: ${Subjlist}" +opts_AddMandatory '--high-res-mesh' 'HighResMesh' 'numstring' "representing the highres mesh (e.g. 164)" - Caret7_Command="${CARET7DIR}/wb_command" - log_Msg "Caret7_Command: ${Caret7_Command}" +opts_AddMandatory '--low-res-meshes' 'LowResMesh' 'numstring' "representing the low res mesh (@ delimited list) (e.g. 32)" - CommonFolder="${p_CommonFolder}" - log_Msg "CommonFolder: ${CommonFolder}" +opts_ParseArguments "$@" - GroupAverageName="${p_GroupAverageName}" - log_Msg "GroupAverageName: ${GroupAverageName}" +if ((pipedirguessed)) +then + log_Err_Abort "HCPPIPEDIR is not set, you must first source your edited copy of Examples/Scripts/SetUpHCPPipeline.sh" +fi - InRegName="${p_InputRegName}" - log_Msg "InRegName: ${InRegName}" +#display the parsed/default values +opts_ShowValues - TargetRegName="${p_TargetRegName}" - log_Msg "TargetRegName: ${TargetRegName}" +log_Check_Env_Var CARET7DIR - RegName="${p_RegName}" - log_Msg "RegName: ${RegName}" +Subjlist=${Subjlist//@/ } +log_Msg "Subjlist: ${Subjlist}" - HighResMesh="${p_HighResMesh}" - log_Msg "HighResMesh: ${HighResMesh}" +CommonAtlasFolder="${CommonFolder}/MNINonLinear" +log_Msg "CommonAtlasFolder: ${CommonAtlasFolder}" - LowResMesh="${p_LowResMesh}" - log_Msg "LowResMes: ${LowResMesh}" +#CommonDownSampleFolder="${CommonAtlasFolder}/fsaverage_LR${LowResMesh}k" +#log_Msg "CommonDownSampleFolder: ${CommonDownSampleFolder}" - Subjlist=${Subjlist//@/ } - log_Msg "Subjlist: ${Subjlist}" +if [ ! -e ${CommonAtlasFolder}/${RegName} ] ; then + mkdir -p ${CommonAtlasFolder}/${RegName} +else + rm -r ${CommonAtlasFolder:?}/${RegName} + mkdir -p ${CommonAtlasFolder}/${RegName} +fi - CommonAtlasFolder="${CommonFolder}/MNINonLinear" - log_Msg "CommonAtlasFolder: ${CommonAtlasFolder}" +for Hemisphere in L R ; do - #CommonDownSampleFolder="${CommonAtlasFolder}/fsaverage_LR${LowResMesh}k" - #log_Msg "CommonDownSampleFolder: ${CommonDownSampleFolder}" + log_Msg "Working on hemisphere: ${Hemisphere}" - if [ ! -e ${CommonAtlasFolder}/${RegName} ] ; then - mkdir -p ${CommonAtlasFolder}/${RegName} - else - rm -r ${CommonAtlasFolder:?}/${RegName} - mkdir -p ${CommonAtlasFolder}/${RegName} + if [ $Hemisphere = "L" ] ; then + Structure="CORTEX_LEFT" + elif [ $Hemisphere = "R" ] ; then + Structure="CORTEX_RIGHT" fi + SurfAverageSTRING="" - for Hemisphere in L R ; do - - log_Msg "Working on hemisphere: ${Hemisphere}" - - if [ $Hemisphere = "L" ] ; then - Structure="CORTEX_LEFT" - elif [ $Hemisphere = "R" ] ; then - Structure="CORTEX_RIGHT" - fi - SurfAverageSTRING="" + for Subject in ${Subjlist} ; do + log_Msg "Working on subject: ${Subject}" - for Subject in ${Subjlist} ; do - log_Msg "Working on subject: ${Subject}" + AtlasFolder="${StudyFolder}/${Subject}/MNINonLinear" + log_Msg "AtlasFolder: ${AtlasFolder}" + NativeFolder="${AtlasFolder}/Native" + log_Msg "NativeFolder: ${NativeFolder}" - AtlasFolder="${StudyFolder}/${Subject}/MNINonLinear" - log_Msg "AtlasFolder: ${AtlasFolder}" - NativeFolder="${AtlasFolder}/Native" - log_Msg "NativeFolder: ${NativeFolder}" + sphere_in="${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii" + log_File_Must_Exist "${sphere_in}" - sphere_in="${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii" - log_File_Must_Exist "${sphere_in}" + sphere_project_to="${NativeFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}.native.surf.gii" + log_File_Must_Exist "${sphere_project_to}" - sphere_project_to="${NativeFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}.native.surf.gii" - log_File_Must_Exist "${sphere_project_to}" + sphere_unproject_from="${NativeFolder}/${Subject}.${Hemisphere}.sphere.${TargetRegName}.native.surf.gii" + log_File_Must_Exist "${sphere_unproject_from}" - sphere_unproject_from="${NativeFolder}/${Subject}.${Hemisphere}.sphere.${TargetRegName}.native.surf.gii" - log_File_Must_Exist "${sphere_unproject_from}" + sphere_out="${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii" + log_Msg "sphere_out: ${sphere_out}" - sphere_out="${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii" - log_Msg "sphere_out: ${sphere_out}" + ${Caret7_Command} -surface-sphere-project-unproject ${sphere_in} ${sphere_project_to} ${sphere_unproject_from} ${sphere_out} - ${Caret7_Command} -surface-sphere-project-unproject ${sphere_in} ${sphere_project_to} ${sphere_unproject_from} ${sphere_out} + log_File_Must_Exist "${sphere_out}" - log_File_Must_Exist "${sphere_out}" + # Note: Surface files are specified in the SurfAverageSTRING using relative paths from the ${StudyFolder}. + # This is to save characters to stave off the point at which we've created a command line for the + # -surface-average operation (done right after we exit this loop) that is longer than a command + # line is allowed to be. (Use the command $ getconf ARG_MAX to find out what the maximum command + # line length is.) - # Note: Surface files are specified in the SurfAverageSTRING using relative paths from the ${StudyFolder}. - # This is to save characters to stave off the point at which we've created a command line for the - # -surface-average operation (done right after we exit this loop) that is longer than a command - # line is allowed to be. (Use the command $ getconf ARG_MAX to find out what the maximum command - # line length is.) + #SurfAverageSTRING=`echo "${SurfAverageSTRING} -surf ${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii"` + SurfAverageSTRING+=" -surf ${Subject}/MNINonLinear/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii" - #SurfAverageSTRING=`echo "${SurfAverageSTRING} -surf ${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii"` - SurfAverageSTRING+=" -surf ${Subject}/MNINonLinear/${Subject}.${Hemisphere}.sphere.${InRegName}_${TargetRegName}.${HighResMesh}k_fs_LR.surf.gii" - - log_Msg "SurfAverageSTRING: ${SurfAverageSTRING}" - #log_Msg "Length of SurfAverageSTRING: ${#SurfAverageSTRING}" - done - - # Put ourselves "in" the ${StudyFolder} so that we can use relative paths to save characters in the following command - pushd ${StudyFolder} - surface_average_cmd="${Caret7_Command} -surface-average " - surface_average_cmd+="${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii " - surface_average_cmd+="${SurfAverageSTRING}" + log_Msg "SurfAverageSTRING: ${SurfAverageSTRING}" + #log_Msg "Length of SurfAverageSTRING: ${#SurfAverageSTRING}" + done - max_cmd_length=$(getconf ARG_MAX) - if [ ${#surface_average_cmd} -gt ${max_cmd_length} ] ; then - log_Err_Abort "Command will be too long to execute. Command: ${surface_average_cmd}." - fi + # Put ourselves "in" the ${StudyFolder} so that we can use relative paths to save characters in the following command + pushd ${StudyFolder} + surface_average_cmd="${Caret7_Command} -surface-average " + surface_average_cmd+="${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii " + surface_average_cmd+="${SurfAverageSTRING}" - ${surface_average_cmd} + max_cmd_length=$(getconf ARG_MAX) + if [ ${#surface_average_cmd} -gt ${max_cmd_length} ] ; then + log_Err_Abort "Command will be too long to execute. Command: ${surface_average_cmd}." + fi - # Don't forget to pop back to whatever directory we were previously in. - popd + ${surface_average_cmd} - ${Caret7_Command} -surface-modify-sphere \ - ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ - 100 \ - ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ - -recenter + # Don't forget to pop back to whatever directory we were previously in. + popd - cp \ - ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii - - if [ ! -e ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii ] ; then - cp \ - ${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii - fi - - ${Caret7_Command} -surface-vertex-areas \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii - - ${Caret7_Command} -surface-vertex-areas \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii - - ${Caret7_Command} -metric-math "ln(spherereg / sphere) / ln(2)" \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii \ - -var sphere ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii \ - -var spherereg ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii - - rm \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii - - ${Caret7_Command} -surface-distortion \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii \ - -edge-method + ${Caret7_Command} -surface-modify-sphere \ + ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ + 100 \ + ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ + -recenter - done + cp \ + ${CommonAtlasFolder}/${RegName}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii - # Copy Atlas ROI files - for Hemisphere in L R ; do + if [ ! -e ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii ] ; then cp \ - ${HCPPIPEDIR}/global/templates/standard_mesh_atlases/${Hemisphere}.atlasroi.${HighResMesh}k_fs_LR.shape.gii \ - ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.atlasroi.${HighResMesh}k_fs_LR.shape.gii - done + ${AtlasFolder}/${Subject}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii + fi - # ------------------------------ - # Create dense timeseries - # ------------------------------ - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - left_metric="${CommonAtlasFolder}/${GroupAverageName}.L.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" - roi_left="${CommonAtlasFolder}/${GroupAverageName}.L.atlasroi.${HighResMesh}k_fs_LR.shape.gii" - right_metric="${CommonAtlasFolder}/${GroupAverageName}.R.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" - roi_right="${CommonAtlasFolder}/${GroupAverageName}.R.atlasroi.${HighResMesh}k_fs_LR.shape.gii" - - log_Msg "About to create ArealDistortion dense timeseries: ${cifti_out}" - - log_File_Must_Exist "${left_metric}" - log_File_Must_Exist "${roi_left}" - log_File_Must_Exist "${right_metric}" - log_File_Must_Exist "${roi_right}" - - ${Caret7_Command} -cifti-create-dense-timeseries ${cifti_out} -left-metric ${left_metric} -roi-left ${roi_left} -right-metric ${right_metric} -roi-right ${roi_right} - - # ------------------------------ - # Create dscalar file from dense timeseries - # ------------------------------ - cifti_in="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - direction="ROW" - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - - log_Msg "About to create ArealDistortion dscalar file: ${cifti_out}" - log_File_Must_Exist "${cifti_in}" - - ${Caret7_Command} -cifti-convert-to-scalar ${cifti_in} ${direction} ${cifti_out} - - # ------------------------------ - # Set map name for dscalar file - # ------------------------------ - data_file="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - index="1" - name="${GroupAverageName}_ArealDistortion_${RegName}" - - log_Msg "About to set map name for ArealDistortion dscalar file: ${data_file}" - log_File_Must_Exist "${data_file}" - - ${Caret7_Command} -set-map-name ${data_file} ${index} ${name} - - # ------------------------------ - # Set palette for dscalar file - # ------------------------------ - cifti_in="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - mode="MODE_USER_SCALE" - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - - log_Msg "About to set palette for ArealDistortion dscalar file: ${cifti_in}" - log_File_Must_Exist "${cifti_in}" - - ${Caret7_Command} -cifti-palette ${cifti_in} ${mode} ${cifti_out} \ - -pos-user 0 1 \ - -neg-user 0 -1 \ - -interpolate true \ - -palette-name ROY-BIG-BL \ - -disp-pos true \ - -disp-neg true \ - -disp-zero false - - # ------------------------------ - # Remove dense timeseries file - # ------------------------------ - file_to_remove="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - - log_Msg "About to remove ArealDistortion dense timeseries file: ${file_to_remove}" - - rm ${file_to_remove} - - # ------------------------------ - # Create dense timeseries - # ------------------------------ - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - left_metric="${CommonAtlasFolder}/${GroupAverageName}.L.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" - roi_left="${CommonAtlasFolder}/${GroupAverageName}.L.atlasroi.${HighResMesh}k_fs_LR.shape.gii" - right_metric="${CommonAtlasFolder}/${GroupAverageName}.R.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" - roi_right="${CommonAtlasFolder}/${GroupAverageName}.R.atlasroi.${HighResMesh}k_fs_LR.shape.gii" - - log_Msg "About to create EdgeDistortion dense timeseries: ${cifti_out}" - - log_File_Must_Exist "${left_metric}" - log_File_Must_Exist "${roi_left}" - log_File_Must_Exist "${right_metric}" - log_File_Must_Exist "${roi_right}" - - ${Caret7_Command} -cifti-create-dense-timeseries ${cifti_out} -left-metric ${left_metric} -roi-left ${roi_left} -right-metric ${right_metric} -roi-right ${roi_right} - - # ------------------------------ - # Create dscalar file from dense timeseries - # ------------------------------ - cifti_in="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - direction="ROW" - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - - log_Msg "About to create EdgeDistortion dscalar file: ${cifti_out}" - log_File_Must_Exist "${cifti_in}" - - ${Caret7_Command} -cifti-convert-to-scalar ${cifti_in} ${direction} ${cifti_out} - - # ------------------------------ - # Set map name for dscalar file - # ------------------------------ - data_file="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - index="1" - name="${GroupAverageName}_EdgeDistortion_${RegName}" + ${Caret7_Command} -surface-vertex-areas \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii + + ${Caret7_Command} -surface-vertex-areas \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii + + ${Caret7_Command} -metric-math "ln(spherereg / sphere) / ln(2)" \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii \ + -var sphere ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii \ + -var spherereg ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii + + rm \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.shape.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.shape.gii + + ${Caret7_Command} -surface-distortion \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii \ + -edge-method + +done + +# Copy Atlas ROI files +for Hemisphere in L R ; do + cp \ + ${HCPPIPEDIR}/global/templates/standard_mesh_atlases/${Hemisphere}.atlasroi.${HighResMesh}k_fs_LR.shape.gii \ + ${CommonAtlasFolder}/${GroupAverageName}.${Hemisphere}.atlasroi.${HighResMesh}k_fs_LR.shape.gii +done + +# ------------------------------ +# Create dense timeseries +# ------------------------------ +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" +left_metric="${CommonAtlasFolder}/${GroupAverageName}.L.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" +roi_left="${CommonAtlasFolder}/${GroupAverageName}.L.atlasroi.${HighResMesh}k_fs_LR.shape.gii" +right_metric="${CommonAtlasFolder}/${GroupAverageName}.R.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" +roi_right="${CommonAtlasFolder}/${GroupAverageName}.R.atlasroi.${HighResMesh}k_fs_LR.shape.gii" + +log_Msg "About to create ArealDistortion dense timeseries: ${cifti_out}" + +log_File_Must_Exist "${left_metric}" +log_File_Must_Exist "${roi_left}" +log_File_Must_Exist "${right_metric}" +log_File_Must_Exist "${roi_right}" + +${Caret7_Command} -cifti-create-dense-timeseries ${cifti_out} -left-metric ${left_metric} -roi-left ${roi_left} -right-metric ${right_metric} -roi-right ${roi_right} + +# ------------------------------ +# Create dscalar file from dense timeseries +# ------------------------------ +cifti_in="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" +direction="ROW" +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" + +log_Msg "About to create ArealDistortion dscalar file: ${cifti_out}" +log_File_Must_Exist "${cifti_in}" + +${Caret7_Command} -cifti-convert-to-scalar ${cifti_in} ${direction} ${cifti_out} + +# ------------------------------ +# Set map name for dscalar file +# ------------------------------ +data_file="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" +index="1" +name="${GroupAverageName}_ArealDistortion_${RegName}" + +log_Msg "About to set map name for ArealDistortion dscalar file: ${data_file}" +log_File_Must_Exist "${data_file}" + +${Caret7_Command} -set-map-name ${data_file} ${index} ${name} + +# ------------------------------ +# Set palette for dscalar file +# ------------------------------ +cifti_in="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" +mode="MODE_USER_SCALE" +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" + +log_Msg "About to set palette for ArealDistortion dscalar file: ${cifti_in}" +log_File_Must_Exist "${cifti_in}" + +${Caret7_Command} -cifti-palette ${cifti_in} ${mode} ${cifti_out} \ + -pos-user 0 1 \ + -neg-user 0 -1 \ + -interpolate true \ + -palette-name ROY-BIG-BL \ + -disp-pos true \ + -disp-neg true \ + -disp-zero false + +# ------------------------------ +# Remove dense timeseries file +# ------------------------------ +file_to_remove="${CommonAtlasFolder}/${GroupAverageName}.ArealDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" + +log_Msg "About to remove ArealDistortion dense timeseries file: ${file_to_remove}" + +rm ${file_to_remove} + +# ------------------------------ +# Create dense timeseries +# ------------------------------ +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" +left_metric="${CommonAtlasFolder}/${GroupAverageName}.L.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" +roi_left="${CommonAtlasFolder}/${GroupAverageName}.L.atlasroi.${HighResMesh}k_fs_LR.shape.gii" +right_metric="${CommonAtlasFolder}/${GroupAverageName}.R.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.shape.gii" +roi_right="${CommonAtlasFolder}/${GroupAverageName}.R.atlasroi.${HighResMesh}k_fs_LR.shape.gii" + +log_Msg "About to create EdgeDistortion dense timeseries: ${cifti_out}" + +log_File_Must_Exist "${left_metric}" +log_File_Must_Exist "${roi_left}" +log_File_Must_Exist "${right_metric}" +log_File_Must_Exist "${roi_right}" + +${Caret7_Command} -cifti-create-dense-timeseries ${cifti_out} -left-metric ${left_metric} -roi-left ${roi_left} -right-metric ${right_metric} -roi-right ${roi_right} + +# ------------------------------ +# Create dscalar file from dense timeseries +# ------------------------------ +cifti_in="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" +direction="ROW" +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" + +log_Msg "About to create EdgeDistortion dscalar file: ${cifti_out}" +log_File_Must_Exist "${cifti_in}" + +${Caret7_Command} -cifti-convert-to-scalar ${cifti_in} ${direction} ${cifti_out} + +# ------------------------------ +# Set map name for dscalar file +# ------------------------------ +data_file="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" +index="1" +name="${GroupAverageName}_EdgeDistortion_${RegName}" - log_Msg "About to set map name for EdgeDistortion dscalar file: ${data_file}" - log_File_Must_Exist "${data_file}" - - ${Caret7_Command} -set-map-name ${data_file} ${index} ${name} - - # ------------------------------ - # Set palette for dscalar file - # ------------------------------ - cifti_in="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - mode="MODE_USER_SCALE" - cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" - - log_Msg "About to set palette for EdgeDistortion dscalar file: ${cifti_in}" - log_File_Must_Exist "${cifti_in}" - - ${Caret7_Command} -cifti-palette ${cifti_in} ${mode} ${cifti_out} \ - -pos-user 0 1 \ - -neg-user 0 -1 \ - -interpolate true \ - -palette-name ROY-BIG-BL \ - -disp-pos true \ - -disp-neg true \ - -disp-zero false - - # ------------------------------ - # Remove dense timeseries file - # ------------------------------ - file_to_remove="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" +log_Msg "About to set map name for EdgeDistortion dscalar file: ${data_file}" +log_File_Must_Exist "${data_file}" + +${Caret7_Command} -set-map-name ${data_file} ${index} ${name} + +# ------------------------------ +# Set palette for dscalar file +# ------------------------------ +cifti_in="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" +mode="MODE_USER_SCALE" +cifti_out="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dscalar.nii" + +log_Msg "About to set palette for EdgeDistortion dscalar file: ${cifti_in}" +log_File_Must_Exist "${cifti_in}" + +${Caret7_Command} -cifti-palette ${cifti_in} ${mode} ${cifti_out} \ + -pos-user 0 1 \ + -neg-user 0 -1 \ + -interpolate true \ + -palette-name ROY-BIG-BL \ + -disp-pos true \ + -disp-neg true \ + -disp-zero false + +# ------------------------------ +# Remove dense timeseries file +# ------------------------------ +file_to_remove="${CommonAtlasFolder}/${GroupAverageName}.EdgeDistortion_${RegName}.${HighResMesh}k_fs_LR.dtseries.nii" - log_Msg "About to remove EdgeDistortion dense timeseries file: ${file_to_remove}" - - rm ${file_to_remove} +log_Msg "About to remove EdgeDistortion dense timeseries file: ${file_to_remove}" + +rm ${file_to_remove} #for Mesh in ${LowResMesh} ; do @@ -499,54 +331,3 @@ main() # ${Caret7_Command} -cifti-resample ${CommonAtlasFolder}/${GroupAverageName}.${NativeMap}.${HighResMesh}k_fs_LR.dscalar.nii COLUMN ${Folder}/${GroupAverageName}.thickness.${Mesh}k_fs_LR.dscalar.nii COLUMN ADAP_BARY_AREA ENCLOSING_VOXEL ${Folder}/${GroupAverageName}.${Map}_${RegName}.${Mesh}k_fs_LR.dscalar.nii -surface-postdilate 30 -left-spheres ${CommonAtlasFolder}/${GroupAverageName}.L.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii ${Folder}/${GroupAverageName}.L.sphere.${Mesh}k_fs_LR.surf.gii -left-area-surfs ${CommonAtlasFolder}/${GroupAverageName}.L.midthickness.${HighResMesh}k_fs_LR.surf.gii ${Folder}/${GroupAverageName}.L.midthickness.${Mesh}k_fs_LR.surf.gii -right-spheres ${CommonAtlasFolder}/${GroupAverageName}.R.sphere.${RegName}.${HighResMesh}k_fs_LR.surf.gii ${Folder}/${GroupAverageName}.R.sphere.${Mesh}k_fs_LR.surf.gii -right-area-surfs ${CommonAtlasFolder}/${GroupAverageName}.R.midthickness.${HighResMesh}k_fs_LR.surf.gii ${Folder}/${GroupAverageName}.R.midthickness.${Mesh}k_fs_LR.surf.gii # done #done - -} - -# ------------------------------------------------------------------------------ -# "Global" processing - everything above here should be in a function -# ------------------------------------------------------------------------------ - -# Establish defaults - -# Set global variables -g_script_name=$(basename "${0}") - -# Allow script to return a Usage statement, before any other output -if [ "$#" = "0" ]; then - show_usage - exit 1 -fi - -# Verify HCPPIPEDIR environment variable is set -if [ -z "${HCPPIPEDIR}" ]; then - echo "${g_script_name}: ABORTING: HCPPIPEDIR environment variable must be set" - exit 1 -fi - -# Load function libraries -source "${HCPPIPEDIR}/global/scripts/debug.shlib" "$@" # Debugging functions; also sources log.shlib -source ${HCPPIPEDIR}/global/scripts/opts.shlib # Command line option functions - -opts_ShowVersionIfRequested $@ - -if opts_CheckForHelpRequest $@; then - show_usage - exit 0 -fi - -${HCPPIPEDIR}/show_version - -log_Debug_On - -# Verify required environment variables are set and log value -log_Check_Env_Var HCPPIPEDIR -log_Check_Env_Var CARET7DIR - -# Show tool versions -show_tool_versions - -# -# -# Invoke the 'main' function to get things started -# -main "$@" diff --git a/DiffusionPreprocessing/DiffPreprocPipeline_PreEddy.sh b/DiffusionPreprocessing/DiffPreprocPipeline_PreEddy.sh index fdf7714eb..6796abc08 100755 --- a/DiffusionPreprocessing/DiffPreprocPipeline_PreEddy.sh +++ b/DiffusionPreprocessing/DiffPreprocPipeline_PreEddy.sh @@ -476,7 +476,7 @@ main() { # if the number of slices are odd, check that the user has a way to deal with that if [ "${EnsureEvenSlices}" == "false" ] && [ "${TopupConfig}" == "${HCPPIPEDIR_Config}/b02b0.cnf" ] ; then - dimz=$(${FSLDIR}/bin/fslval ${outdir}/topup/Pos_b0 dim3) + dimz=$(${FSLDIR}/bin/fslval ${outdir}/topup/Pos_Neg_b0 dim3) if [ $(isodd $dimz) -eq 1 ]; then log_Msg "Input images have an odd number of slices. This is incompatible with the default topup configuration file." log_Msg "Either supply a topup configuration file that doesn't use subsampling (e.g., FSL's 'b02b0_1.cnf') using the --topup-config-file= flag (recommended)" @@ -533,7 +533,7 @@ main() { fi if [ "${EnsureEvenSlices}" == "true" ]; then - dimz=$(${FSLDIR}/bin/fslval ${outdir}/topup/Pos_b0 dim3) + dimz=$(${FSLDIR}/bin/fslval ${outdir}/topup/Pos_Neg_b0 dim3) if [ $(isodd $dimz) -eq 1 ]; then echo "Removing one slice from data to get even number of slices" for filename in Pos_Neg_b0 Pos_b0 Neg_b0 ; do diff --git a/FreeSurfer/FreeSurferPipeline.sh b/FreeSurfer/FreeSurferPipeline.sh index 438abc0d4..f959852cb 100755 --- a/FreeSurfer/FreeSurferPipeline.sh +++ b/FreeSurfer/FreeSurferPipeline.sh @@ -144,9 +144,9 @@ opts_AddOptional '--flair' 'flairString' 'TRUE/FALSE' "Indicates that recon-all opts_AddOptional '--existing-subject' 'existing_subjectString' 'TRUE/FALSE' "Indicates that the script is to be run on top of an already existing analysis/subject. This excludes the '-i' and '-T2/-FLAIR' flags from the invocation of recon-all (i.e., uses previous input volumes). The --t1w-image, --t1w-brain and --t2w-image arguments, if provided, are ignored. It also excludes the -all' flag from the invocation of recon-all. Consequently, user needs to explicitly specify which recon-all stage(s) to run using the --extra-reconall-arg flag. This flag allows for the application of FreeSurfer edits." "FALSE" #TSC: repeatable options aren't currently supported in newopts, do them manually and fake the help info for now -opts_AddOptional '--extra-reconall-arg' 'extra_reconall_args' 'token' "(repeatable) Generic single token argument to pass to recon-all. Provides a mechanism to: (i) customize the recon-all command (ii) specify the recon-all stage(s) to be run (e.g., in the case of FreeSurfer edits) If you want to avoid running all the stages inherent to the '-all' flag in recon-all, you also need to include the --existing-subject flag. The token itself may include dashes and equal signs (although Freesurfer doesn't currently use equal signs in its argument specification). e.g., --extra-reconall-arg=-3T is the correct syntax for adding the stand-alone '-3T' flag to recon-all. But, --extra-reconall-arg='-norm3diters 3' is NOT acceptable. For recon-all flags that themselves require an argument, you can handle that by specifying --extra-reconall-arg multiple times (in the proper sequential fashion). e.g., --extra-reconall-arg=-norm3diters --extra-reconall-arg=3 will be translated to '-norm3diters 3' when passed to recon-all." +opts_AddOptional '--extra-reconall-arg' 'extra_reconall_args' 'token' "(repeatable) Generic single token argument to pass to recon-all. Provides a mechanism to customize the recon-all command and/or specify the recon-all stage(s) to be run (e.g., in the case of FreeSurfer edits). If you want to avoid running all the stages inherent to the '-all' flag in recon-all, you also need to include the --existing-subject flag. The token itself may include dashes and equal signs (although Freesurfer doesn't currently use equal signs in its argument specification). e.g., --extra-reconall-arg=-3T is the correct syntax for adding the stand-alone '-3T' flag to recon-all, but --extra-reconall-arg='-norm3diters 3' is NOT acceptable. For recon-all flags that themselves require an argument, you can handle that by specifying --extra-reconall-arg multiple times (in the proper sequential fashion), e.g. --extra-reconall-arg=-norm3diters --extra-reconall-arg=3 will be translated to '-norm3diters 3' when passed to recon-all." -opts_AddOptional '--conf2hires' 'conf2hiresString' 'TRUE/FALSE' "Indicates that the script should include -conf2hires as an argument to recon-all. By default, -conf2hires is included, so that recon-all will place the surfaces on the hires T1 (and T2). Setting this to false is an advanced option, intended for situations where: (i) the original T1w and T2w images are NOT 'hires' (i.e., they are 1 mm isotropic or worse), or (ii) you want to be able to run some flag in recon-all, without also regenerating the surfaces. e.g., --existing-subject --extra-reconall-arg=-show-edits --conf2hires=FALSE" "TRUE" +opts_AddOptional '--conf2hires' 'conf2hiresString' 'TRUE/FALSE' "Indicates that the script should include -conf2hires as an argument to recon-all. By default, -conf2hires is included, so that recon-all will place the surfaces on the hires T1 (and T2). Setting this to false is an advanced option, intended for situations where: (i) the original T1w and T2w images are NOT 'hires' (i.e., they are 1 mm isotropic or worse), or (ii) you want to be able to run some flag in recon-all, without also regenerating the surfaces, e.g. --existing-subject --extra-reconall-arg=-show-edits --conf2hires=FALSE" "TRUE" opts_AddOptional '--processing-mode' 'ProcessingMode' 'HCPStyleData or LegacyStyleData' "Controls whether the HCP acquisition and processing guidelines should be treated as requirements. 'HCPStyleData' (the default) follows the processing steps described in Glasser et al. (2013) and requires 'HCP-Style' data acquistion. 'LegacyStyleData' allows additional processing functionality and use of some acquisitions that do not conform to 'HCP-Style' expectations. In this script, it allows not having a high-resolution T2w image." "HCPStyleData" diff --git a/ICAFIX/ApplyHandReClassifications.sh b/ICAFIX/ApplyHandReClassifications.sh index 6d21df4df..73e27290e 100755 --- a/ICAFIX/ApplyHandReClassifications.sh +++ b/ICAFIX/ApplyHandReClassifications.sh @@ -4,140 +4,55 @@ # Show usage information for this script # ------------------------------------------------------------------------------ -show_usage() -{ - cat << EOF -${g_script_name}: Apply Hand Reclassifications of Noise and Signal components -from FIX using the ReclassifyAsNoise.txt and ReclassifyAsSignal.txt input files. +set -eu -Generates HandNoise.txt and HandSignal.txt as output. -Script does NOT reapply the FIX cleanup. -For that, use the ReApplyFix scripts. +pipedirguessed=0 +if [[ "${HCPPIPEDIR:-}" == "" ]] +then + pipedirguessed=1 + #fix this if the script is more than one level below HCPPIPEDIR + export HCPPIPEDIR="$(dirname -- "$0")/.." +fi -Usage: ${g_script_name} PARAMETER..." +# Load function libraries +source "${HCPPIPEDIR}/global/scripts/fsl_version.shlib" # Functions for getting FSL version +source "${HCPPIPEDIR}/global/scripts/debug.shlib" "$@" # Debugging functions; also sources log.shlib +source "$HCPPIPEDIR/global/scripts/newopts.shlib" "$@" -PARAMETERs are: [ ] = optional; < > = user supplied value - [--help] : show usage information and exit - --path= OR --study-folder= - --subject= - --fmri-name= - --high-pass= +opts_SetScriptDescription "Apply Hand Reclassifications of Noise and Signal components from FIX using the ReclassifyAsNoise.txt and ReclassifyAsSignal.txt input files. Generates HandNoise.txt and HandSignal.txt as output. Script does NOT reapply the FIX cleanup. For that, use the ReApplyFix scripts." -EOF -} +opts_AddMandatory '--study-folder' 'StudyFolder' 'path' "path to study folder" "--path" -# ------------------------------------------------------------------------------ -# Get the command line options for this script. -# ------------------------------------------------------------------------------ -get_options() -{ - local arguments=($@) - - # initialize global output variables - unset p_StudyFolder - unset p_Subject - unset p_fMRIName - unset p_HighPass - g_matlab_run_mode=0 - - # parse arguments - local num_args=${#arguments[@]} - local argument - local index=0 - - while [ ${index} -lt ${num_args} ]; do - argument=${arguments[index]} - - case ${argument} in - --help) - show_usage - exit 0 - ;; - --path=*) - p_StudyFolder=${argument#*=} - index=$(( index + 1 )) - ;; - --study-folder=*) - p_StudyFolder=${argument#*=} - index=$(( index + 1 )) - ;; - --subject=*) - p_Subject=${argument#*=} - index=$(( index + 1 )) - ;; - --fmri-name=*) - p_fMRIName=${argument#*=} - index=$(( index + 1 )) - ;; - --high-pass=*) - p_HighPass=${argument#*=} - index=$(( index + 1 )) - ;; - --matlab-run-mode=*) - g_matlab_run_mode=${argument#*=} - index=$(( index + 1 )) - ;; - *) - show_usage - log_Err_Abort "unrecognized option: ${argument}" - ;; - esac - done - - local error_count=0 - - # check required parameters - if [ -z "${p_StudyFolder}" ]; then - log_Err "Study Folder (--path= or --study-folder=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_StudyFolder: ${p_StudyFolder}" - fi +opts_AddMandatory '--subject' 'Subject' 'id' "subject ID" - if [ -z "${p_Subject}" ]; then - log_Err "Subject ID (--subject=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_Subject: ${p_Subject}" - fi +opts_AddMandatory '--fmri-name' 'fMRIName' 'string' "fMRI name" - if [ -z "${p_fMRIName}" ]; then - log_Err "fMRI Name (--fmri-name=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_fMRIName: ${p_fMRIName}" - fi +opts_AddMandatory '--high-pass' 'HighPass' 'amount' "high-pass filter used in ICA+FIX" - if [ -z "${p_HighPass}" ]; then - log_Err "High Pass: (--high-pass=) required" - error_count=$(( error_count + 1 )) - else - log_Msg "p_HighPass: ${p_HighPass}" - fi +##Optional Args +## deprecated, matlab code is not used +opts_AddOptional '--matlab-run-mode' 'g_matlab_run_mode' '0, 1, 2' "deprecated, this code does not currently use matlab" - #--matlab-run-mode is now ignored, but still accepted, to make old scripts work without changes +opts_ParseArguments "$@" - if [ ${error_count} -gt 0 ]; then - log_Err_Abort "For usage information, use --help" - fi -} +if ((pipedirguessed)) +then + log_Err_Abort "HCPPIPEDIR is not set, you must first source your edited copy of Examples/Scripts/SetUpHCPPipeline.sh" +fi -# ------------------------------------------------------------------------------ -# Show Tool Versions -# ------------------------------------------------------------------------------ +#display the parsed/default values +opts_ShowValues -show_tool_versions() -{ - # Show HCP Pipelines Version - log_Msg "Showing HCP Pipelines version" - "${HCPPIPEDIR}"/show_version --short - - # Show FSL version - log_Msg "Showing FSL version" - fsl_version_get fsl_ver - log_Msg "FSL version: ${fsl_ver}" -} +log_Check_Env_Var FSLDIR +# Show HCP Pipelines Version +log_Msg "Showing HCP Pipelines version" +"${HCPPIPEDIR}"/show_version --short + +# Show FSL version +log_Msg "Showing FSL version" +fsl_version_get fsl_ver +log_Msg "FSL version: ${fsl_ver}" # ------------------------------------------------------------------------------ # List lookup helper function for this script @@ -169,190 +84,138 @@ list_file_to_lookup() # Main processing of script. # ------------------------------------------------------------------------------ -main() -{ - get_options $@ - show_tool_versions +# NOTE: HighPass flag may be "pd*", if polynomial detrending was requested in +# hcp_fix_multi_run (not supported in hcp_fix currently) - # NOTE: HighPass flag may be "pd*", if polynomial detrending was requested in - # hcp_fix_multi_run (not supported in hcp_fix currently) +if [[ "${HighPass}" == pd* ]]; then + hpNum=${HighPass:2} +else + hpNum=${HighPass} +fi - if [[ "${p_HighPass}" == pd* ]]; then - hpNum=${p_HighPass:2} - else - hpNum=${p_HighPass} - fi +# Confirm that $hpNum is a valid numeric +if ! [[ "${hpNum}" =~ ^[-]?[0-9]+$ ]]; then + log_Err_Abort "Invalid value for --high-pass (${HighPass})" +fi - # Confirm that $hpNum is a valid numeric - if ! [[ "${hpNum}" =~ ^[-]?[0-9]+$ ]]; then - log_Err_Abort "Invalid value for --high-pass (${HighPass})" - fi +# If HighPass < 0, then no high-pass was applied and directories/filenames +# will not include an "_hp" string +if (( hpNum < 0 )); then + hpStr="" +else + hpStr="_hp${HighPass}" +fi - # If HighPass < 0, then no high-pass was applied and directories/filenames - # will not include an "_hp" string - if (( hpNum < 0 )); then - hpStr="" - else - hpStr="_hp${p_HighPass}" - fi +# Naming Conventions +AtlasFolder="${StudyFolder}/${Subject}/MNINonLinear" +log_Msg "AtlasFolder: ${AtlasFolder}" - # Naming Conventions - AtlasFolder="${p_StudyFolder}/${p_Subject}/MNINonLinear" - log_Msg "AtlasFolder: ${AtlasFolder}" +ResultsFolder="${AtlasFolder}/Results/${fMRIName}" +log_Msg "ResultsFolder: ${ResultsFolder}" - ResultsFolder="${AtlasFolder}/Results/${p_fMRIName}" - log_Msg "ResultsFolder: ${ResultsFolder}" +ICAFolder="${ResultsFolder}/${fMRIName}${hpStr}.ica/filtered_func_data.ica" +log_Msg "ICAFolder: ${ICAFolder}" - ICAFolder="${ResultsFolder}/${p_fMRIName}${hpStr}.ica/filtered_func_data.ica" - log_Msg "ICAFolder: ${ICAFolder}" +FIXFolder="${ResultsFolder}/${fMRIName}${hpStr}.ica" +log_Msg "FIXFolder: ${FIXFolder}" - FIXFolder="${ResultsFolder}/${p_fMRIName}${hpStr}.ica" - log_Msg "FIXFolder: ${FIXFolder}" - - OriginalFixSignal="${FIXFolder}/Signal.txt" - log_Msg "OriginalFixSignal: ${OriginalFixSignal}" +OriginalFixSignal="${FIXFolder}/Signal.txt" +log_Msg "OriginalFixSignal: ${OriginalFixSignal}" - OriginalFixNoise="${FIXFolder}/Noise.txt" - log_Msg "OriginalFixNoise: ${OriginalFixNoise}" +OriginalFixNoise="${FIXFolder}/Noise.txt" +log_Msg "OriginalFixNoise: ${OriginalFixNoise}" - ReclassifyAsSignal="${ResultsFolder}/ReclassifyAsSignal.txt" - log_Msg "ReclassifyAsSignal: ${ReclassifyAsSignal}" +ReclassifyAsSignal="${ResultsFolder}/ReclassifyAsSignal.txt" +log_Msg "ReclassifyAsSignal: ${ReclassifyAsSignal}" - ReclassifyAsNoise="${ResultsFolder}/ReclassifyAsNoise.txt" - log_Msg "ReclassifyAsNoise: ${ReclassifyAsNoise}" +ReclassifyAsNoise="${ResultsFolder}/ReclassifyAsNoise.txt" +log_Msg "ReclassifyAsNoise: ${ReclassifyAsNoise}" - HandSignalName="${FIXFolder}/HandSignal.txt" - log_Msg "HandSignalName: ${HandSignalName}" +HandSignalName="${FIXFolder}/HandSignal.txt" +log_Msg "HandSignalName: ${HandSignalName}" - HandNoiseName="${FIXFolder}/HandNoise.txt" - log_Msg "HandNoiseName: ${HandNoiseName}" +HandNoiseName="${FIXFolder}/HandNoise.txt" +log_Msg "HandNoiseName: ${HandNoiseName}" - TrainingLabelsName="${FIXFolder}/hand_labels_noise.txt" - log_Msg "TrainingLabelsName: ${TrainingLabelsName}" +TrainingLabelsName="${FIXFolder}/hand_labels_noise.txt" +log_Msg "TrainingLabelsName: ${TrainingLabelsName}" - # Retrieve number of ICAs - NumICAs=`${FSLDIR}/bin/fslval ${ICAFolder}/melodic_oIC.nii.gz dim4` - log_Msg "NumICAs: ${NumICAs}" +# Retrieve number of ICAs +NumICAs=`${FSLDIR}/bin/fslval ${ICAFolder}/melodic_oIC.nii.gz dim4` +log_Msg "NumICAs: ${NumICAs}" - log_Msg "merging classifications start" +log_Msg "merging classifications start" - list_file_to_lookup "${OriginalFixSignal}" "$NumICAs" - orig_signal=("${lookup_result[@]}") - list_file_to_lookup "${OriginalFixNoise}" "$NumICAs" - orig_noise=("${lookup_result[@]}") +list_file_to_lookup "${OriginalFixSignal}" "$NumICAs" +orig_signal=("${lookup_result[@]}") +list_file_to_lookup "${OriginalFixNoise}" "$NumICAs" +orig_noise=("${lookup_result[@]}") - list_file_to_lookup "${ReclassifyAsSignal}" "$NumICAs" - reclass_signal=("${lookup_result[@]}") - list_file_to_lookup "${ReclassifyAsNoise}" "$NumICAs" - reclass_noise=("${lookup_result[@]}") +list_file_to_lookup "${ReclassifyAsSignal}" "$NumICAs" +reclass_signal=("${lookup_result[@]}") +list_file_to_lookup "${ReclassifyAsNoise}" "$NumICAs" +reclass_noise=("${lookup_result[@]}") - fail="" - hand_signal="" - hand_noise="" - training_labels="" +fail="" +hand_signal="" +hand_noise="" +training_labels="" - # Make sure that there is something to do (i.e., ReclassifyAs*.txt files are not BOTH empty) - if (( ! ${#reclass_signal[@]} && ! ${#reclass_noise[@]} )) - then - log_Warn "${ReclassifyAsNoise} and ${ReclassifyAsSignal} are both empty; nothing to do" - log_Msg "Completed!" - exit - fi +# Make sure that there is something to do (i.e., ReclassifyAs*.txt files are not BOTH empty) +if (( ! ${#reclass_signal[@]} && ! ${#reclass_noise[@]} )) +then + log_Warn "${ReclassifyAsNoise} and ${ReclassifyAsSignal} are both empty; nothing to do" + log_Msg "Completed!" + exit +fi - for ((i = 1; i <= NumICAs; ++i)) - do - if (( reclass_signal[i] || (orig_signal[i] && ! reclass_noise[i]) )) +for ((i = 1; i <= NumICAs; ++i)) +do + if (( reclass_signal[i] || (orig_signal[i] && ! reclass_noise[i]) )) + then + if [[ "$hand_signal" ]] then - if [[ "$hand_signal" ]] - then - hand_signal+=" $i" - else - hand_signal="$i" - fi + hand_signal+=" $i" else - if [[ "$hand_noise" ]] - then - hand_noise+=" $i" - training_labels+=", $i" - else - hand_noise="$i" - training_labels+="$i" - fi - fi - #error checking - if (( reclass_noise[i] && reclass_signal[i] )) - then - log_Msg "Duplicate Component Error with Manual Classification on ICA: $i" - fail=1 - fi - if (( ! (orig_noise[i] || orig_signal[i]) )) - then - log_Msg "Missing Component Error with Automatic Classification on ICA: $i" - fail=1 + hand_signal="$i" fi - if (( orig_noise[i] && orig_signal[i] )) + else + if [[ "$hand_noise" ]] then - log_Msg "Duplicate Component Error with Automatic Classification on ICA: $i" - fail=1 + hand_noise+=" $i" + training_labels+=", $i" + else + hand_noise="$i" + training_labels+="$i" fi - #the hand check from the matlab version can't be tripped here without the above code being wrong - done - - if [[ $fail ]] + fi + #error checking + if (( reclass_noise[i] && reclass_signal[i] )) then - log_Err_Abort "Sanity checks on input files failed" + log_Msg "Duplicate Component Error with Manual Classification on ICA: $i" + fail=1 fi + if (( ! (orig_noise[i] || orig_signal[i]) )) + then + log_Msg "Missing Component Error with Automatic Classification on ICA: $i" + fail=1 + fi + if (( orig_noise[i] && orig_signal[i] )) + then + log_Msg "Duplicate Component Error with Automatic Classification on ICA: $i" + fail=1 + fi + #the hand check from the matlab version can't be tripped here without the above code being wrong +done - echo "$hand_signal" > "${HandSignalName}" - echo "$hand_noise" > "${HandNoiseName}" - echo "[$training_labels]" > "${TrainingLabelsName}" - - log_Msg "merging classifications complete" - log_Msg "Completed!" - -} - -# ------------------------------------------------------------------------------ -# "Global" processing - everything above here should be in a function -# ------------------------------------------------------------------------------ - -# Set global variables -g_script_name=$(basename "${0}") - -# Allow script to return a Usage statement, before any other output -if [ "$#" = "0" ]; then - show_usage - exit 1 -fi - -# Verify that HCPPIPEDIR environment variable is set -if [ -z "${HCPPIPEDIR}" ]; then - echo "${g_script_name}: ABORTING: HCPPIPEDIR environment variable must be set" - exit 1 -fi - -# Load function libraries -source "${HCPPIPEDIR}/global/scripts/debug.shlib" "$@" # Debugging functions; also sources log.shlib -source ${HCPPIPEDIR}/global/scripts/opts.shlib # Command line option functions -source "${HCPPIPEDIR}/global/scripts/fsl_version.shlib" # Functions for getting FSL version - -opts_ShowVersionIfRequested $@ - -if opts_CheckForHelpRequest $@; then - show_usage - exit 0 +if [[ $fail ]] +then + log_Err_Abort "Sanity checks on input files failed" fi -${HCPPIPEDIR}/show_version - -# Verify required environment variables are set and log value -log_Check_Env_Var HCPPIPEDIR -log_Check_Env_Var FSLDIR - -# Invoke the 'main' function to get things started -main $@ - - - - +echo "$hand_signal" > "${HandSignalName}" +echo "$hand_noise" > "${HandNoiseName}" +echo "[$training_labels]" > "${TrainingLabelsName}" +log_Msg "merging classifications complete" +log_Msg "Completed!" diff --git a/ICAFIX/PostFix.sh b/ICAFIX/PostFix.sh index 60070fb45..35aa100c7 100755 --- a/ICAFIX/PostFix.sh +++ b/ICAFIX/PostFix.sh @@ -35,210 +35,89 @@ # Show usage information for this script # ------------------------------------------------------------------------------ -show_usage() -{ - cat < = user supplied value - - [--help] : show usage information and exit - --path= OR --study-folder= - --subject= - --fmri-name= - In the case of applying PostFix to the output of multi-run FIX, - should be the used in multi-run FIX. - --high-pass= - --template-scene-dual-screen=