From 1483c8414fc40908357a9ecc4ea5f2f4d107499a Mon Sep 17 00:00:00 2001 From: Tim Coalson Date: Fri, 17 May 2019 20:04:44 -0500 Subject: [PATCH] modify msmall scripts to support MR FIX data --- Examples/Scripts/MSMAllPipelineBatch.sh | 65 ++++--- MSMAll/MSMAllPipeline.sh | 220 ++++++++++++++++-------- MSMAll/scripts/MSMAll.sh | 164 ++++++------------ MSMAll/scripts/MSMregression.m | 7 +- MSMAll/scripts/SingleSubjectConcat.sh | 21 +-- 5 files changed, 256 insertions(+), 221 deletions(-) diff --git a/Examples/Scripts/MSMAllPipelineBatch.sh b/Examples/Scripts/MSMAllPipelineBatch.sh index 70dd3787b..040f27fc4 100755 --- a/Examples/Scripts/MSMAllPipelineBatch.sh +++ b/Examples/Scripts/MSMAllPipelineBatch.sh @@ -75,8 +75,24 @@ PRINTCOM="" ######################################### DO WORK ########################################## +# fMRINames is for single-run FIX data, set MR FIX settings to empty fMRINames="rfMRI_REST1_LR@rfMRI_REST1_RL@rfMRI_REST2_LR@rfMRI_REST2_RL" +mrfixNames="" +mrfixConcatName="" +mrfixNamesToUse="" OutfMRIName="rfMRI_REST" + +# For MR FIX, set fMRINames to empty +#fMRINames="" +# the original MR FIX parameter for what to concatenate +#mrfixNames="rfMRI_REST1_RL@rfMRI_REST1_LR@tfMRI_WM_RL@tfMRI_WM_LR@tfMRI_GAMBLING_RL@tfMRI_GAMBLING_LR@tfMRI_MOTOR_RL@tfMRI_MOTOR_LR@rfMRI_REST2_LR@rfMRI_REST2_RL@tfMRI_LANGUAGE_RL@tfMRI_LANGUAGE_LR@tfMRI_SOCIAL_RL@tfMRI_SOCIAL_LR@tfMRI_RELATIONAL_RL@tfMRI_RELATIONAL_LR@tfMRI_EMOTION_RL@tfMRI_EMOTION_LR" +# the original MR FIX concatenated name +#mrfixConcatName="fMRI_CONCAT" +# @-separate list of runs to use +#mrfixNamesToUse="rfMRI_REST1_RL@rfMRI_REST1_LR@rfMRI_REST2_LR@rfMRI_REST2_RL" +#OutfMRIName="rfMRI_REST_CONCAT" + + HighPass="2000" fMRIProcSTRING="_Atlas_hp2000_clean" MSMAllTemplates="${HCPPIPEDIR}/global/templates/MSMAll" @@ -89,29 +105,32 @@ MatlabMode="1" #Mode=0 compiled Matlab, Mode=1 interpreted Matlab fMRINames=`echo ${fMRINames} | sed 's/ /@/g'` for Subject in $Subjlist ; do - echo " ${Subject}" - - if [ -n "${command_line_specified_run_local}" ] ; then - echo "About to run ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh" - queuing_command="" - else - echo "About to use fsl_sub to queue or run ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh" - queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" - fi - - ${queuing_command} ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh \ - --path=${StudyFolder} \ - --subject=${Subject} \ - --fmri-names-list=${fMRINames} \ - --output-fmri-name=${OutfMRIName} \ - --high-pass=${HighPass} \ - --fmri-proc-string=${fMRIProcSTRING} \ - --msm-all-templates=${MSMAllTemplates} \ - --output-registration-name=${RegName} \ - --high-res-mesh=${HighResMesh} \ - --low-res-mesh=${LowResMesh} \ - --input-registration-name=${InRegName} \ - --matlab-run-mode=${MatlabMode} + echo " ${Subject}" + + if [ -n "${command_line_specified_run_local}" ] ; then + echo "About to run ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh" + queuing_command="" + else + echo "About to use fsl_sub to queue or run ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh" + queuing_command="${FSLDIR}/bin/fsl_sub ${QUEUE}" + fi + + ${queuing_command} ${HCPPIPEDIR}/MSMAll/MSMAllPipeline.sh \ + --path=${StudyFolder} \ + --subject=${Subject} \ + --fmri-names-list=${fMRINames} \ + --multirun-fix-names="${mrfixNames}" \ + --multirun-fix-concat-name="${mrfixConcatName}" \ + --multirun-fix-names-to-use="${mrfixNamesToUse}" \ + --output-fmri-name=${OutfMRIName} \ + --high-pass=${HighPass} \ + --fmri-proc-string=${fMRIProcSTRING} \ + --msm-all-templates=${MSMAllTemplates} \ + --output-registration-name=${RegName} \ + --high-res-mesh=${HighResMesh} \ + --low-res-mesh=${LowResMesh} \ + --input-registration-name=${InRegName} \ + --matlab-run-mode=${MatlabMode} done diff --git a/MSMAll/MSMAllPipeline.sh b/MSMAll/MSMAllPipeline.sh index 32bf7b668..e5e62422d 100755 --- a/MSMAll/MSMAllPipeline.sh +++ b/MSMAll/MSMAllPipeline.sh @@ -48,7 +48,14 @@ PARAMETERs are [ ] = optional; < > = user supplied value [--help] : show usage information and exit --path= OR --study-folder= --subject= - --fmri-names-list= an @ symbol separated list of fMRI scan names + --fmri-names-list= an @ symbol separated list of fMRI scan + names, cannot be used with --multirun-fix-* options + --multirun-fix-names= an @-separated list of names, identical + to what was used in hcp_fix_multi_run + --multirun-fix-concat-name=, identical to what was used + in hcp_fix_multi_run + --multirun-fix-names-to-use= @-separated list, + choose which runs should be used as resting state data --output-fmri-name= --high-pass= --fmri-proc-string= @@ -81,6 +88,9 @@ get_options() unset p_StudyFolder unset p_Subject unset p_fMRINames + unset p_mrfixNames + unset p_mrfixConcatName + unset p_mrfixNamesToUse unset p_OutputfMRIName unset p_HighPass unset p_fMRIProcSTRING @@ -97,9 +107,11 @@ get_options() # parse arguments local num_args=${#arguments[@]} local argument - local index=0 +# local index=0 - while [ "${index}" -lt "${num_args}" ]; do +# while [ "${index}" -lt "${num_args}" ]; do + for ((index = 0; index < num_args; ++index)) + do argument=${arguments[index]} case ${argument} in @@ -109,61 +121,58 @@ get_options() ;; --path=*) p_StudyFolder=${argument#*=} - index=$(( index + 1 )) ;; --study-folder=*) p_StudyFolder=${argument#*=} - index=$(( index + 1 )) ;; --subject=*) p_Subject=${argument#*=} - index=$(( index + 1 )) ;; --fmri-names-list=*) p_fMRINames=${argument#*=} - index=$(( index + 1 )) ;; + --multirun-fix-names=*) + p_mrfixNames=${argument#*=} + ;; + --multirun-fix-concat-name=*) + p_mrfixConcatName=${argument#*=} + ;; + --multirun-fix-names-to-use=*) + p_mrfixNamesToUse=${argument#*=} + ;; --output-fmri-name=*) p_OutputfMRIName=${argument#*=} - index=$(( index + 1 )) ;; --high-pass=*) p_HighPass=${argument#*=} - index=$(( index + 1 )) ;; --fmri-proc-string=*) p_fMRIProcSTRING=${argument#*=} - index=$(( index + 1 )) ;; --msm-all-templates=*) p_MSMAllTemplates=${argument#*=} - index=$(( index + 1 )) ;; --output-registration-name=*) p_OutputRegName=${argument#*=} - index=$(( index + 1 )) ;; --high-res-mesh=*) p_HighResMesh=${argument#*=} - index=$(( index + 1 )) ;; --low-res-mesh=*) p_LowResMesh=${argument#*=} - index=$(( index + 1 )) ;; --input-registration-name=*) p_InputRegName=${argument#*=} - index=$(( index + 1 )) ;; --matlab-run-mode=*) p_MatlabRunMode=${argument#*=} - index=$(( index + 1 )) ;; *) usage log_Err_Abort "unrecognized option: ${argument}" ;; esac +# index=$(( index + 1 )) done local error_count=0 @@ -184,9 +193,31 @@ get_options() fi if [ -z "${p_fMRINames}" ]; then - log_Err "fMRI name list (--fmri-names-list=) required" - error_count=$(( error_count + 1 )) + if [[ -z "${p_mrfixNames}" ]] + then + log_Err "fMRI name list (--fmri-names-list=) or MR fix name list (--multirun-fix-names) required" + error_count=$(( error_count + 1 )) + else + if [[ -z "$p_mrfixConcatName" ]] + then + log_Err "--multirun-fix-concat-name is required when using --multirun-fix-names" + error_count=$(( error_count + 1 )) + fi + if [[ -z "$p_mrfixNamesToUse" ]] + then + log_Err "--multirun-fix-concat-name is required when using --multirun-fix-names" + error_count=$(( error_count + 1 )) + fi + fi + log_Msg "MR fix fMRI Names: ${p_mrfixNames}" + log_Msg "MR fix fMRI Concat Name: ${p_mrfixConcatName}" + log_Msg "MR fix fMRI Names to use: ${p_mrfixNamesToUse}" else + if [[ ! -z "${p_mrfixNames}" ]] + then + log_Err "fMRI name list (--fmri-names-list=) and MR fix name list (--multirun-fix-names) must not be used together" + error_count=$(( error_count + 1 )) + fi log_Msg "fMRI Names: ${p_fMRINames}" fi @@ -316,6 +347,10 @@ main() MatlabRunMode="${12}" fi + local mrfixNames="${13}" + local mrfixConcatName="${14}" + local mrfixNamesToUse="${15}" + # Log values retrieved from positional parameters log_Msg "StudyFolder: ${StudyFolder}" log_Msg "Subject: ${Subject}" @@ -329,57 +364,108 @@ main() log_Msg "LowResMesh: ${LowResMesh}" log_Msg "InputRegName: ${InputRegName}" log_Msg "MatlabRunMode: ${MatlabRunMode}" + log_Msg "mrfixNames: ${mrfixNames}" + log_Msg "mrfixConcatName: ${mrfixConcatName}" + log_Msg "mrfixNamesToUse: ${mrfixNamesToUse}" # Naming Conventions and other variables local InPCARegName="${InputRegName}" log_Msg "InPCARegName: ${InPCARegName}" - # Values of variables determining MIGP usage - # Form: UseMIGP @ PCAInitDim @ PCAFinalDim @ ReRunIfExists @ VarianceNormalization - # Values: YES or NO @ number or NONE @ number or NONE @ YES or NO @ YES or NO - # - # Note: Spaces should not be used in the variable's value. They are used above to - # help make the form and values easier to understand. - # Note: If UseMIGP value is NO, then we use the full timeseries - log_Msg "Running MSM on full timeseries" -# migp_vars="NO@0@0@YES@YES" -# log_Msg "migp_vars: ${migp_vars}" - - local output_proc_string="_vn" #To VN only to indicate that we did not revert the bias field before computing VN - log_Msg "output_proc_string: ${output_proc_string}" - - local Demean="YES" - log_Msg "Demean: ${Demean}" - - local VarianceNormalization="YES" - log_Msg "VarianceNormalization: ${VarianceNormalization}" - - local ComputeVarianceNormalization="YES" #Don't rely on RestingStateStats to have been run - log_Msg "ComputeVarianceNormalization: ${ComputeVarianceNormalization}" - - local RevertBiasField="NO" # Will recompute VN based on not reverting bias field - log_Msg "RevertBiasField: ${RevertBiasField}" - - "${HCPPIPEDIR}"/MSMAll/scripts/SingleSubjectConcat.sh \ - --path="${StudyFolder}" \ - --subject="${Subject}" \ - --fmri-names-list="${fMRINames}" \ - --high-pass="${HighPass}" \ - --output-fmri-name="${OutputfMRIName}" \ - --fmri-proc-string="${fMRIProcSTRING}" \ - --output-proc-string="${output_proc_string}" \ - --demean="${Demean}" \ - --variance-normalization="${VarianceNormalization}" \ - --compute-variance-normalization="${ComputeVarianceNormalization}" \ - --revert-bias-field="${RevertBiasField}" \ - --matlab-run-mode="${MatlabRunMode}" - - local expected_concatenated_output_file="" - expected_concatenated_output_file+="${StudyFolder}" - expected_concatenated_output_file+="/${Subject}/MNINonLinear/Results" - expected_concatenated_output_file+="/${OutputfMRIName}" - expected_concatenated_output_file+="/${OutputfMRIName}${fMRIProcSTRING}${output_proc_string}" - expected_concatenated_output_file+=".dtseries.nii" + local output_proc_string="_vn" #To VN only to indicate that we did not revert the bias field before computing VN + log_Msg "output_proc_string: ${output_proc_string}" + + local expected_concatenated_output_dir="${StudyFolder}/${Subject}/MNINonLinear/Results/${OutputfMRIName}" + expected_concatenated_output_file="${expected_concatenated_output_dir}/${OutputfMRIName}${fMRIProcSTRING}${output_proc_string}.dtseries.nii" + before_vn_output_file="${expected_concatenated_output_dir}/${OutputfMRIName}${fMRIProcSTRING}_novn.dtseries.nii" + + if [[ -z "$fMRINames" ]] + then + local -a mrNamesArray mrNamesUseArray runSplits runIndices + local curTimepoints=0 + #convention: one before the first index of the run + runSplits[0]="$curTimepoints" + IFS=@ read -a mrNamesArray <<< "${mrfixNames}" + IFS=@ read -a mrNamesUseArray <<< "${mrfixNamesToUse}" + #sanity check for identical names + for ((index = 0; index < ${#mrNamesArray[@]}; ++index)) + do + for ((index2 = 0; index2 < ${#mrNamesArray[@]}; ++index2)) + do + if ((index != index2)) && [[ "${mrNamesArray[$index]}" == "${mrNamesArray[$index2]}" ]] + then + log_Err_Abort "MR fix names list contains '${mrNamesArray[$index]}' more than once" + fi + done + done + #calculate the timepoints where the concatenated switches runs, find which runs are used + for ((index = 0; index < ${#mrNamesArray[@]}; ++index)) + do + fmriName="${mrNamesArray[$index]}" + NumTPS=`${CARET7DIR}/wb_command -file-information "${StudyFolder}/${Subject}/MNINonLinear/Results/${fmriName}/${fmriName}_Atlas.dtseries.nii" -only-number-of-maps` + ((curTimepoints += NumTPS)) + runSplits[$((index + 1))]="$curTimepoints" + for ((index2 = 0; index2 < ${#mrNamesUseArray[@]}; ++index2)) + do + if [[ "${mrNamesUseArray[$index2]}" == "${mrNamesArray[$index]}" ]] + then + runIndices[$index2]="$index" + fi + done + done + #check that we found all requested runs, build the merge command + mergeArgs=() + for ((index2 = 0; index2 < ${#mrNamesUseArray[@]}; ++index2)) + do + runIndex="${runIndices[$index2]}" + if [[ "$runIndex" == "" ]] + then + log_Err_Abort "requested run '${mrNamesUseArray[$index2]}' not found in list of MR fix runs" + fi + mergeArgs+=(-column $((runSplits[runIndex] + 1)) -up-to $((runSplits[runIndex + 1])) ) + done + mkdir -p "${expected_concatenated_output_dir}" + ${CARET7DIR}/wb_command -cifti-merge "${before_vn_output_file}" -cifti "${StudyFolder}/${Subject}/MNINonLinear/Results/${mrfixConcatName}/${mrfixConcatName}_Atlas_hp${HighPass}_clean.dtseries.nii" "${mergeArgs[@]}" + ${CARET7DIR}/wb_command -cifti-math 'data / variance' "${expected_concatenated_output_file}" -var data "${before_vn_output_file}" -var variance "${StudyFolder}/${Subject}/MNINonLinear/Results/${mrfixConcatName}/${mrfixConcatName}_Atlas_hp${HighPass}_clean_vn.dscalar.nii" -select 1 1 -repeat + rm -f -- "${before_vn_output_file}" + else + # Values of variables determining MIGP usage + # Form: UseMIGP @ PCAInitDim @ PCAFinalDim @ ReRunIfExists @ VarianceNormalization + # Values: YES or NO @ number or NONE @ number or NONE @ YES or NO @ YES or NO + # + # Note: Spaces should not be used in the variable's value. They are used above to + # help make the form and values easier to understand. + # Note: If UseMIGP value is NO, then we use the full timeseries + log_Msg "Running MSM on full timeseries" + # migp_vars="NO@0@0@YES@YES" + # log_Msg "migp_vars: ${migp_vars}" + + local Demean="YES" + log_Msg "Demean: ${Demean}" + + local VarianceNormalization="YES" + log_Msg "VarianceNormalization: ${VarianceNormalization}" + + local ComputeVarianceNormalization="NO" #This is computed in FIX now + log_Msg "ComputeVarianceNormalization: ${ComputeVarianceNormalization}" + + local RevertBiasField="NO" # Will recompute VN based on not reverting bias field + log_Msg "RevertBiasField: ${RevertBiasField}" + + "${HCPPIPEDIR}"/MSMAll/scripts/SingleSubjectConcat.sh \ + --path="${StudyFolder}" \ + --subject="${Subject}" \ + --fmri-names-list="${fMRINames}" \ + --high-pass="${HighPass}" \ + --output-fmri-name="${OutputfMRIName}" \ + --fmri-proc-string="${fMRIProcSTRING}" \ + --output-proc-string="${output_proc_string}" \ + --demean="${Demean}" \ + --variance-normalization="${VarianceNormalization}" \ + --compute-variance-normalization="${ComputeVarianceNormalization}" \ + --revert-bias-field="${RevertBiasField}" \ + --matlab-run-mode="${MatlabRunMode}" + fi log_File_Must_Exist "${expected_concatenated_output_file}" @@ -606,13 +692,13 @@ if [[ ${1} == --* ]]; then get_options "$@" # Invoke main functionality using positional parameters - # ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} - main "${p_StudyFolder}" "${p_Subject}" "${p_fMRINames}" "${p_OutputfMRIName}" "${p_HighPass}" "${p_fMRIProcSTRING}" "${p_MSMAllTemplates}" "${p_OutputRegName}" "${p_HighResMesh}" "${p_LowResMesh}" "${p_InputRegName}" "${p_MatlabRunMode}" + # ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} ${15} + main "${p_StudyFolder}" "${p_Subject}" "${p_fMRINames}" "${p_OutputfMRIName}" "${p_HighPass}" "${p_fMRIProcSTRING}" "${p_MSMAllTemplates}" "${p_OutputRegName}" "${p_HighResMesh}" "${p_LowResMesh}" "${p_InputRegName}" "${p_MatlabRunMode}" "${p_mrfixNames}" "${p_mrfixConcatName}" "${p_mrfixNamesToUse}" else # Positional parameters are used log_Msg "Using positional parameters" - main $@ + main "$@" fi diff --git a/MSMAll/scripts/MSMAll.sh b/MSMAll/scripts/MSMAll.sh index 982886be3..f8bc62891 100755 --- a/MSMAll/scripts/MSMAll.sh +++ b/MSMAll/scripts/MSMAll.sh @@ -714,32 +714,13 @@ main() matlab_compiler_runtime="${MATLAB_COMPILER_RUNTIME}" - matlab_function_arguments="'${inputspatialmaps}'" - matlab_function_arguments+=" '${inputdtseries}'" - matlab_function_arguments+=" '${inputweights}'" - matlab_function_arguments+=" '${outputspatialmaps}'" - matlab_function_arguments+=" '${outputweights}'" - matlab_function_arguments+=" '${Caret7_Command}'" - matlab_function_arguments+=" '${Method}'" - matlab_function_arguments+=" '${Params}'" - matlab_function_arguments+=" '${VN}'" - matlab_function_arguments+=" ${nTPsForSpectra}" - matlab_function_arguments+=" '${BC}'" - matlab_function_arguments+=" '${VolParams}'" - - matlab_logging=">> ${StudyFolder}/${Subject}.MSMregression.matlab.C.Iteration${i}.log 2>&1" - - matlab_cmd="${matlab_exe} ${matlab_compiler_runtime} ${matlab_function_arguments} ${matlab_logging}" - - # Note: Simply using ${matlab_cmd} here instead of echo "${matlab_cmd}" | bash - # does NOT work. The output redirects that are part of the ${matlab_logging} - # value, get quoted by the run_*.sh script generated by the MATLAB compiler - # such that they get passed as parameters to the underlying executable. - # So ">>" gets passed as a parameter to the executable as does the - # log file name and the "2>&1" redirection. This causes the executable - # to die with a "too many parameters" error message. - log_Msg "Run MATLAB command: ${matlab_cmd}" - echo "${matlab_cmd}" | bash + matlab_function_arguments=("${inputspatialmaps}" "${inputdtseries}" "${inputweights}" "${outputspatialmaps}" "${outputweights}" "${Caret7_Command}" "${Method}" "${Params}" "${VN}" "${nTPsForSpectra}" "${BC}" "${VolParams}") + + matlab_cmd=("${matlab_exe}" "${matlab_compiler_runtime}" "${matlab_function_arguments[@]}") + + #don't log to a separate file, separate log files have never been desirable + log_Msg "Run MATLAB command: ${matlab_cmd[*]}" + "${matlab_cmd[@]}" log_Msg "MATLAB command return code: $?" ;; @@ -814,37 +795,17 @@ main() case ${MatlabRunMode} in 0) # Use Compiled Matlab - matlab_exe="${HCPPIPEDIR}" - matlab_exe+="/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" + matlab_exe="${HCPPIPEDIR}/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" matlab_compiler_runtime="${MATLAB_COMPILER_RUNTIME}" - matlab_function_arguments="'${inputspatialmaps}'" - matlab_function_arguments+=" '${inputdtseries}'" - matlab_function_arguments+=" '${inputweights}'" - matlab_function_arguments+=" '${outputspatialmaps}'" - matlab_function_arguments+=" '${outputweights}'" - matlab_function_arguments+=" '${Caret7_Command}'" - matlab_function_arguments+=" '${Method}'" - matlab_function_arguments+=" '${Params}'" - matlab_function_arguments+=" '${VN}'" - matlab_function_arguments+=" ${nTPsForSpectra}" - matlab_function_arguments+=" '${BC}'" - matlab_function_arguments+=" '${VolParams}'" - - matlab_logging=">> ${StudyFolder}/${Subject}.MSMregression.matlab.T.Iteration${i}.log 2>&1" - - matlab_cmd="${matlab_exe} ${matlab_compiler_runtime} ${matlab_function_arguments} ${matlab_logging}" + matlab_function_arguments=("${inputspatialmaps}" "${inputdtseries}" "${inputweights}" "${outputspatialmaps}" "${outputweights}" "${Caret7_Command}" "${Method}" "${Params}" "${VN}" "${nTPsForSpectra}" "${BC}" "${VolParams}") + + matlab_cmd=("${matlab_exe}" "${matlab_compiler_runtime}" "${matlab_function_arguments[@]}") - # Note: Simply using ${matlab_cmd} here instead of echo "${matlab_cmd}" | bash - # does NOT work. The output redirects that are part of the ${matlab_logging} - # value, get quoted by the run_*.sh script generated by the MATLAB compiler - # such that they get passed as parameters to the underlying executable. - # So ">>" gets passed as a parameter to the executable as does the - # log file name and the "2>&1" redirection. This causes the executable - # to die with a "too many parameters" error message. - log_Msg "Run Matlab command: ${matlab_cmd}" - echo "${matlab_cmd}" | bash + #don't log to a separate file, separate log files have never been desirable + log_Msg "Run Matlab command: ${matlab_cmd[*]}" + "${matlab_cmd[@]}" log_Msg "Matlab command return code: $?" ;; @@ -859,7 +820,8 @@ main() mPath="${HCPPIPEDIR}/MSMAll/scripts" mGlobalPath="${HCPPIPEDIR}/global/matlab" - matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; MSMregression('${inputspatialmaps}','${inputdtseries}','${inputweights}','${outputspatialmaps}','${outputweights}','${Caret7_Command}','${Method}','${Params}','${VN}',${nTPsForSpectra},'${BC}','${VolParams}');" + matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; + MSMregression('${inputspatialmaps}', '${inputdtseries}', '${inputweights}', '${outputspatialmaps}', '${outputweights}', '${Caret7_Command}', '${Method}', '${Params}', '${VN}', ${nTPsForSpectra}, '${BC}', '${VolParams}');" log_Msg "$matlabCode" "${interpreter[@]}" <<<"$matlabCode" @@ -1156,6 +1118,10 @@ main() rm ${NativeFolder}/${Subject}.${Hemisphere}.sphere.native.shape.gii ${NativeFolder}/${Subject}.${Hemisphere}.sphere.${RegName}.native.shape.gii ${Caret7_Command} -surface-distortion ${NativeFolder}/${Subject}.${Hemisphere}.sphere.native.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.sphere.${RegName}.native.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.EdgeDistortion_${RegName}.native.shape.gii -edge-method + ${Caret7_Command} -surface-distortion ${NativeFolder}/${Subject}.${Hemisphere}.sphere.native.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.sphere.${RegName}.native.surf.gii ${NativeFolder}/${Subject}.${Hemisphere}.Strain_${RegName}_raw.native.shape.gii -local-affine-method + ${Caret7_Command} -metric-math 'ln(x) / ln(2)' ${NativeFolder}/${Subject}.${Hemisphere}.StrainJ_${RegName}.native.shape.gii -var x ${NativeFolder}/${Subject}.${Hemisphere}.Strain_${RegName}_raw.native.shape.gii -column 1 + ${Caret7_Command} -metric-math 'ln(x) / ln(2)' ${NativeFolder}/${Subject}.${Hemisphere}.StrainR_${RegName}.native.shape.gii -var x ${NativeFolder}/${Subject}.${Hemisphere}.Strain_${RegName}_raw.native.shape.gii -column 2 + rm -f ${NativeFolder}/${Subject}.${Hemisphere}.Strain_${RegName}_raw.native.shape.gii # Make MSM Registration Areal Distortion Maps log_Msg "Make MSM Registration Areal Distortion Maps" @@ -1178,6 +1144,14 @@ main() ${Caret7_Command} -set-map-name ${NativeFolder}/${Subject}.EdgeDistortion_${RegName}.native.dscalar.nii 1 ${Subject}_EdgeDistortion_${RegName} ${Caret7_Command} -cifti-palette ${NativeFolder}/${Subject}.EdgeDistortion_${RegName}.native.dscalar.nii MODE_USER_SCALE ${NativeFolder}/${Subject}.EdgeDistortion_${RegName}.native.dscalar.nii -pos-user 0 1 -neg-user 0 -1 -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false rm ${NativeFolder}/${Subject}.EdgeDistortion_${RegName}.native.dtseries.nii + + ${Caret7_Command} -cifti-create-dense-scalar ${NativeFolder}/${Subject}.StrainJ_${RegName}.native.dscalar.nii -left-metric ${NativeFolder}/${Subject}.L.StrainJ_${RegName}.native.shape.gii -roi-left ${NativeFolder}/${Subject}.L.atlasroi.native.shape.gii -right-metric ${NativeFolder}/${Subject}.R.StrainJ_${RegName}.native.shape.gii -roi-right ${NativeFolder}/${Subject}.R.atlasroi.native.shape.gii + ${Caret7_Command} -set-map-name ${NativeFolder}/${Subject}.StrainJ_${RegName}.native.dscalar.nii 1 ${Subject}_StrainJ_${RegName} + ${Caret7_Command} -cifti-palette ${NativeFolder}/${Subject}.StrainJ_${RegName}.native.dscalar.nii MODE_USER_SCALE ${NativeFolder}/${Subject}.StrainJ_${RegName}.native.dscalar.nii -pos-user 0 1 -neg-user 0 -1 -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false + + ${Caret7_Command} -cifti-create-dense-scalar ${NativeFolder}/${Subject}.StrainR_${RegName}.native.dscalar.nii -left-metric ${NativeFolder}/${Subject}.L.StrainR_${RegName}.native.shape.gii -roi-left ${NativeFolder}/${Subject}.L.atlasroi.native.shape.gii -right-metric ${NativeFolder}/${Subject}.R.StrainR_${RegName}.native.shape.gii -roi-right ${NativeFolder}/${Subject}.R.atlasroi.native.shape.gii + ${Caret7_Command} -set-map-name ${NativeFolder}/${Subject}.StrainR_${RegName}.native.dscalar.nii 1 ${Subject}_StrainR_${RegName} + ${Caret7_Command} -cifti-palette ${NativeFolder}/${Subject}.StrainR_${RegName}.native.dscalar.nii MODE_USER_SCALE ${NativeFolder}/${Subject}.StrainR_${RegName}.native.dscalar.nii -pos-user 0 1 -neg-user 0 -1 -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false ${Caret7_Command} -cifti-create-dense-timeseries ${NativeFolder}/${Subject}.SphericalDistortion.native.dtseries.nii -left-metric ${NativeFolder}/${Subject}.L.SphericalDistortion.native.shape.gii -roi-left ${NativeFolder}/${Subject}.L.atlasroi.native.shape.gii -right-metric ${NativeFolder}/${Subject}.R.SphericalDistortion.native.shape.gii -roi-right ${NativeFolder}/${Subject}.R.atlasroi.native.shape.gii ${Caret7_Command} -cifti-convert-to-scalar ${NativeFolder}/${Subject}.SphericalDistortion.native.dtseries.nii ROW ${NativeFolder}/${Subject}.SphericalDistortion.native.dscalar.nii @@ -1197,8 +1171,8 @@ main() elif [ $Mesh = ${LowResMesh} ] ; then Folder=${DownSampleFolder} fi - for Map in ArealDistortion EdgeDistortion sulc SphericalDistortion MyelinMap_BC ; do - if [[ ${Map} = "ArealDistortion" || ${Map} = "EdgeDistortion" || ${Map} = "MyelinMap_BC" ]] ; then + for Map in ArealDistortion EdgeDistortion StrainJ StrainR sulc SphericalDistortion MyelinMap_BC ; do + if [[ ${Map} = "ArealDistortion" || ${Map} = "EdgeDistortion" || ${Map} = "MyelinMap_BC" || ${Map} = "StrainJ" || ${Map} = "StrainR" ]] ; then NativeMap="${Map}_${RegName}" else NativeMap="${Map}" @@ -1239,37 +1213,17 @@ main() case ${MatlabRunMode} in 0) # Use Compiled Matlab - matlab_exe="${HCPPIPEDIR}" - matlab_exe+="/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" + matlab_exe="${HCPPIPEDIR}/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" matlab_compiler_runtime="${MATLAB_COMPILER_RUNTIME}" - matlab_function_arguments="'${inputspatialmaps}'" - matlab_function_arguments+=" '${inputdtseries}'" - matlab_function_arguments+=" '${inputweights}'" - matlab_function_arguments+=" '${outputspatialmaps}'" - matlab_function_arguments+=" '${outputweights}'" - matlab_function_arguments+=" '${Caret7_Command}'" - matlab_function_arguments+=" '${Method}'" - matlab_function_arguments+=" '${Params}'" - matlab_function_arguments+=" '${VN}'" - matlab_function_arguments+=" ${nTPsForSpectra}" - matlab_function_arguments+=" '${BC}'" - matlab_function_arguments+=" '${VolParams}'" - - matlab_logging=">> ${StudyFolder}/${Subject}.MSMregression.matlab.1.log 2>&1" - - matlab_cmd="${matlab_exe} ${matlab_compiler_runtime} ${matlab_function_arguments} ${matlab_logging}" - - # Note: Simply using ${matlab_cmd} here instead of echo "${matlab_cmd}" | bash - # does NOT work. The output redirects that are part of the ${matlab_logging} - # value, get quoted by the run_*.sh script generated by the MATLAB compiler - # such that they get passed as parameters to the underlying executable. - # So ">>" gets passed as a parameter to the executable as does the - # log file name and the "2>&1" redirection. This causes the executable - # to die with a "too many parameters" error message. - log_Msg "Run Matlab command: ${matlab_cmd}" - echo "${matlab_cmd}" | bash + matlab_function_arguments=("${inputspatialmaps}" "${inputdtseries}" "${inputweights}" "${outputspatialmaps}" "${outputweights}" "${Caret7_Command}" "${Method}" "${Params}" "${VN}" "${nTPsForSpectra}" "${BC}" "${VolParams}") + + matlab_cmd=("${matlab_exe}" "${matlab_compiler_runtime}" "${matlab_function_arguments[@]}") + + #don't log to a separate file, separate log files have never been desirable + log_Msg "Run Matlab command: ${matlab_cmd[*]}" + echo "${matlab_cmd[@]}" | bash log_Msg "Matlab command return code: $?" ;; @@ -1284,7 +1238,8 @@ main() mPath="${HCPPIPEDIR}/MSMAll/scripts" mGlobalPath="${HCPPIPEDIR}/global/matlab" - matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; MSMregression('${inputspatialmaps}','${inputdtseries}','${inputweights}','${outputspatialmaps}','${outputweights}','${Caret7_Command}','${Method}','${Params}','${VN}',${nTPsForSpectra},'${BC}','${VolParams}');" + matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; + MSMregression('${inputspatialmaps}', '${inputdtseries}', '${inputweights}', '${outputspatialmaps}', '${outputweights}', '${Caret7_Command}', '${Method}', '${Params}', '${VN}', ${nTPsForSpectra}, '${BC}', '${VolParams}');" log_Msg "$matlabCode" "${interpreter[@]}" <<<"$matlabCode" @@ -1327,37 +1282,17 @@ main() 0) # Use Compiled Matlab - matlab_exe="${HCPPIPEDIR}" - matlab_exe+="/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" + matlab_exe="${HCPPIPEDIR}/MSMAll/scripts/Compiled_MSMregression/run_MSMregression.sh" matlab_compiler_runtime="${MATLAB_COMPILER_RUNTIME}" - matlab_function_arguments="'${inputspatialmaps}'" - matlab_function_arguments+=" '${inputdtseries}'" - matlab_function_arguments+=" '${inputweights}'" - matlab_function_arguments+=" '${outputspatialmaps}'" - matlab_function_arguments+=" '${outputweights}'" - matlab_function_arguments+=" '${Caret7_Command}'" - matlab_function_arguments+=" '${Method}'" - matlab_function_arguments+=" '${Params}'" - matlab_function_arguments+=" '${VN}'" - matlab_function_arguments+=" ${nTPsForSpectra}" - matlab_function_arguments+=" '${BC}'" - matlab_function_arguments+=" '${VolParams}'" - - matlab_logging=">> ${StudyFolder}/${Subject}.MSMregression.matlab.2.log 2>&1" - - matlab_cmd="${matlab_exe} ${matlab_compiler_runtime} ${matlab_function_arguments} ${matlab_logging}" - - # Note: Simply using ${matlab_cmd} here instead of echo "${matlab_cmd}" | bash - # does NOT work. The output redirects that are part of the ${matlab_logging} - # value, get quoted by the run_*.sh script generated by the MATLAB compiler - # such that they get passed as parameters to the underlying executable. - # So ">>" gets passed as a parameter to the executable as does the - # log file name and the "2>&1" redirection. This causes the executable - # to die with a "too many parameters" error message. - log_Msg "Run Matlab command: ${matlab_cmd}" - echo "${matlab_cmd}" | bash + matlab_function_arguments=("${inputspatialmaps}" "${inputdtseries}" "${inputweights}" "${outputspatialmaps}" "${outputweights}" "${Caret7_Command}" "${Method}" "${Params}" "${VN}" "${nTPsForSpectra}" "${BC}" "${VolParams}") + + matlab_cmd=("${matlab_exe}" "${matlab_compiler_runtime}" "${matlab_function_arguments[@]}") + + #don't log to a separate file, separate log files have never been desirable + log_Msg "Run Matlab command: ${matlab_cmd[*]}" + "${matlab_cmd[@]}" log_Msg "Matlab command return code: $?" ;; @@ -1372,7 +1307,8 @@ main() mPath="${HCPPIPEDIR}/MSMAll/scripts" mGlobalPath="${HCPPIPEDIR}/global/matlab" - matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; MSMregression('${inputspatialmaps}','${inputdtseries}','${inputweights}','${outputspatialmaps}','${outputweights}','${Caret7_Command}','${Method}','${Params}','${VN}',${nTPsForSpectra},'${BC}','${VolParams}');" + matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; + MSMregression('${inputspatialmaps}', '${inputdtseries}', '${inputweights}', '${outputspatialmaps}', '${outputweights}', '${Caret7_Command}', '${Method}', '${Params}', '${VN}', ${nTPsForSpectra}, '${BC}', '${VolParams}');" log_Msg "$matlabCode" "${interpreter[@]}" <<<"$matlabCode" diff --git a/MSMAll/scripts/MSMregression.m b/MSMAll/scripts/MSMregression.m index a25501404..57d5d7fa8 100755 --- a/MSMAll/scripts/MSMregression.m +++ b/MSMAll/scripts/MSMregression.m @@ -107,9 +107,10 @@ function MSMregression(inputspatialmaps,inputdtseries,inputweights,outputspatial end SpatialWeightscii=BO; SpatialWeightscii.cdata=mean(corrs,2); - ciftisavereset(SpatialWeightscii,outputspatialmaps,wbcommand); - unix([wbcommand ' -cifti-smoothing ' outputspatialmaps ' ' num2str(WRSmoothingSigma) ' ' num2str(WRSmoothingSigma) ' COLUMN ' outputspatialmaps ' -left-surface ' txtfileArray{2,1} ' -right-surface ' txtfileArray{3,1}]); - SpatialWeightsSmoothcii=ciftiopen(outputspatialmaps,wbcommand); + ciftisavereset(SpatialWeightscii, [outputspatialmaps '_tosmooth.dscalar.nii'], wbcommand); + unix([wbcommand ' -cifti-smoothing ' outputspatialmaps '_tosmooth.dscalar.nii ' num2str(WRSmoothingSigma) ' ' num2str(WRSmoothingSigma) ' COLUMN ' outputspatialmaps '_tosmooth.dscalar.nii -left-surface ' txtfileArray{2,1} ' -right-surface ' txtfileArray{3,1}]); + SpatialWeightsSmoothcii=ciftiopen([outputspatialmaps '_tosmooth.dscalar.nii'], wbcommand); + delete([outputspatialmaps '_tosmooth.dscalar.nii']); MEAN=mean(SpatialWeightscii.cdata); SpatialWeights=repmat(MEAN,length(SpatialWeightscii.cdata),1)+SpatialWeightscii.cdata-SpatialWeightsSmoothcii.cdata; ScaledSpatialWeights=(SpatialWeights.*(SpatialWeights>0)).^3; diff --git a/MSMAll/scripts/SingleSubjectConcat.sh b/MSMAll/scripts/SingleSubjectConcat.sh index d48c6fb1e..31a355e93 100755 --- a/MSMAll/scripts/SingleSubjectConcat.sh +++ b/MSMAll/scripts/SingleSubjectConcat.sh @@ -400,21 +400,13 @@ main() matlab_compiler_runtime="${MATLAB_COMPILER_RUNTIME}" - matlab_function_arguments="'${cleandtseries}' '${bias}' '${ICAtcs}' '${ICANoise}' '${OutputVN}' '${Caret7_Command}'" + matlab_function_arguments=("${cleandtseries}" "${bias}" "${ICAtcs}" "${ICANoise}" "${OutputVN}" "${Caret7_Command}") - matlab_logging=">> ${StudyFolder}/${Subject}.ComputeVN.matlab.log 2>&1" + matlab_cmd=("${matlab_exe}" "${matlab_compiler_runtime}" "${matlab_function_arguments[@]}") - matlab_cmd="${matlab_exe} ${matlab_compiler_runtime} ${matlab_function_arguments} ${matlab_logging}" - - # Note: Simply using ${matlab_cmd} here instead of echo "${matlab_cmd}" | bash - # does NOT work. The output redirects that are part of the ${matlab_logging} - # value, get quoted by the run_*.sh script generated by the MATLAB compiler - # such that they get passed as parameters to the underlying executable. - # So ">>" gets passed as a parameter to the executable as does the - # log file name and the "2>&1" redirection. This causes the executable - # to die with a "too many parameters" error message. - log_Msg "Run MATLAB command: ${matlab_cmd}" - echo "${matlab_cmd}" | bash + #don't log to a separate file, separate log files have never been desirable + log_Msg "Run MATLAB command: ${matlab_cmd[*]}" + "${matlab_cmd[@]}" log_Msg "MATLAB command return code: $?" ;; @@ -429,7 +421,8 @@ main() mPath="${HCPPIPEDIR}/MSMAll/scripts" mGlobalPath="${HCPPIPEDIR}/global/matlab" - matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; ComputeVN('${cleandtseries}', '${bias}', '${ICAtcs}', '${ICANoise}', '${OutputVN}', '${Caret7_Command}');" + matlabCode="addpath '$mPath'; addpath '$mGlobalPath'; + ComputeVN('${cleandtseries}', '${bias}', '${ICAtcs}', '${ICANoise}', '${OutputVN}', '${Caret7_Command}');" log_Msg "$matlabCode" "${interpreter[@]}" <<<"$matlabCode"