Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stand Alone MSMSulc.sh script #290

Merged
merged 23 commits into from
May 6, 2024
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ef0b056
Create MSMSulc.sh
nagedem Apr 9, 2024
2d61793
removed if conditional, adjusted indentations, removed redundant rota…
nagedem Apr 10, 2024
b82f64c
Update global/scripts/MSMSulc.sh
nagedem Apr 11, 2024
c3a1bc6
removed rotated sphere generation from MSMSulc.sh, run MSMSulc.sh in …
nagedem Apr 22, 2024
bba2029
updated MSMSulc.sh
nagedem Apr 23, 2024
2b89908
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem Apr 23, 2024
06928b9
Update MSMSulc.sh
nagedem Apr 26, 2024
5ea18ff
Update MSMSulc.sh
nagedem Apr 26, 2024
90f15fc
Update global/scripts/MSMSulc.sh
nagedem Apr 26, 2024
ce31759
Update global/scripts/MSMSulc.sh
nagedem Apr 26, 2024
ade44da
Update global/scripts/MSMSulc.sh
nagedem Apr 26, 2024
77af7bb
Update global/scripts/MSMSulc.sh
nagedem Apr 26, 2024
0d42906
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem Apr 26, 2024
ee781b8
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem Apr 26, 2024
240e677
Update MSMSulc.sh
nagedem Apr 26, 2024
4fe260a
Merge branch 'master' of https://github.com/nagedem/HCPpipelines
nagedem Apr 26, 2024
9dbc84d
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem Apr 26, 2024
0093d35
set B for both hemispheres
nagedem Apr 29, 2024
9b1bad6
Update MSMSulc.sh
nagedem Apr 29, 2024
d570be3
Update MSMSulc.sh
nagedem Apr 29, 2024
70c3cce
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem Apr 29, 2024
170e44b
Update MSMSulc.sh
nagedem Apr 30, 2024
afbff24
Update FreeSurfer2CaretConvertAndRegisterNonlinear.sh
nagedem May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions global/scripts/MSMSulc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
set -eu

pipedirguessed=0
if [[ ""$HCPPIPEDIR:-"" == "" ]]
then
pipedirguessed=1
#fix this if the script is more than one level below HCPPIPEDIR
export HCPPIPEDIR="$(dirname -- "$0")/.."
fi

source "$HCPPIPEDIR/global/scripts/newopts.shlib" "$@"
source "$HCPPIPEDIR/global/scripts/debug.shlib" "$@"

#description of script/command
opts_SetScriptDescription "Run MSMSulc registration and save distortion outputs"

opts_AddMandatory '--subject-dir' 'SubjectDir' 'path' "folder containing all subjects"
opts_AddMandatory '--subject' 'Subject' 'subject ID' "subject-id"
opts_AddOptional '--regname' 'RegName' 'my reg' "set a new registration name, default MSMSulc" 'MSMSulc'
opts_AddOptional '--msm-conf' 'ConfFile' 'conf file' "provide the name of the configuration file, default MSMSulcStrainFinalconf" "$MSMCONFIGDIR"/MSMSulcStrainFinalconf
opts_AddOptional '--refmesh' 'RefMesh' 'ref mesh' "provide alternate standard sphere, default 164k_fs_LR, use .HEMISPHERE. instead of .L. or .R."
opts_AddOptional '--refdata' 'RefData' 'ref data' "provide alternate reference data, use .HEMISPHERE. instead of .L. or .R."

opts_ParseArguments "$@"

if ((pipedirguessed))
then
log_Err_Abort "HCPPIPEDIR is not set, you must first source your edited copy of Examples/Scripts/SetUpHCPPipeline.sh"
fi

#display the parsed/default values
opts_ShowValues

#set paths
SurfaceTemplateFolder="$HCPPIPEDIR"/global/templates/standard_mesh_atlases
NonlinearFolder="$SubjectDir"/"$Subject"/MNINonLinear
NativeFolder="$NonlinearFolder"/Native

#if user provided --refmesh but not --refdata, scream
if [[ "$RefMesh" != "" && "$RefData" == "" ]]
then
log_Err_Abort "Non-default standard sphere provided, but no non-default reference data"
fi

if [[ "$RefMesh" == "" ]]
then
RefMesh="$SurfaceTemplateFolder"/fsaverage.HEMISPHERE_LR.spherical_std.164k_fs_LR.surf.gii
fi

if [[ "$RefData" == "" ]]
then
RefData="$SurfaceTemplateFolder"/HEMISPHERE.refsulc.164k_fs_LR.shape.gii
fi

#do the same with the conf file
coalsont marked this conversation as resolved.
Show resolved Hide resolved

#Make MSMSulc Directory
mkdir -p "$NativeFolder"/"$RegName"

#Loop through left and right hemispheres
for Hemisphere in L R ; do

if [[ "$Hemisphere" == "L" ]] ; then
Structure="CORTEX_LEFT"
elif [[ "$Hemisphere" == "R" ]] ; then
Structure="CORTEX_RIGHT"
fi
nagedem marked this conversation as resolved.
Show resolved Hide resolved

#Calculate Affine Transform and Apply
wb_command -surface-affine-regression "$NativeFolder"/"$Subject"."$Hemisphere".sphere.native.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".sphere.reg.reg_LR.native.surf.gii "$NativeFolder"/"$RegName"/"$Hemisphere".mat
wb_command -surface-apply-affine "$NativeFolder"/"$Subject"."$Hemisphere".sphere.native.surf.gii "$NativeFolder"/"$RegName"/"$Hemisphere".mat "$NativeFolder"/"$RegName"/"$Hemisphere".sphere_rot.surf.gii
wb_command -surface-modify-sphere "$NativeFolder"/"$RegName"/"$Hemisphere".sphere_rot.surf.gii 100 "$NativeFolder"/"$RegName"/"$Hemisphere".sphere_rot.surf.gii
cp "$NativeFolder"/"$RegName"/"$Hemisphere".sphere_rot.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".sphere.rot.native.surf.gii
rm "$NativeFolder"/"$RegName"/"$Hemisphere".sphere_rot.surf.gii

(
cd "$NativeFolder"/"$RegName"

RefMeshFile=$(basename -- "$RefMesh")
ReferenceMesh="$(dirname -- "$RefMesh")/${RefMeshFile/HEMISPHERE/$Hemisphere}"
RefDataFile=$(basename -- "$RefData")
ReferenceData="$(dirname -- "$RefData")/${RefDataFile/HEMISPHERE/$Hemisphere}"
nagedem marked this conversation as resolved.
Show resolved Hide resolved

#Register using FreeSurfer Sulc Folding Map Using MSM Algorithm Configured for Reduced Distortion
"$MSMBINDIR"/msm --conf="$ConfFile" --inmesh="$NativeFolder"/"$Subject"."$Hemisphere".sphere.rot.native.surf.gii --refmesh="$ReferenceMesh" --indata="$NativeFolder"/"$Subject"."$Hemisphere".sulc.native.shape.gii --refdata="$ReferenceData" --out="$NativeFolder"/"$RegName"/"$Hemisphere". --verbose
)

cp "$ConfFile" "$NativeFolder"/"$RegName"/"$Hemisphere".logdir/conf
cp "$NativeFolder"/"$RegName"/"$Hemisphere".sphere.reg.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".sphere."$RegName".native.surf.gii

wb_command -set-structure "$NativeFolder"/"$Subject"."$Hemisphere".sphere."$RegName".native.surf.gii "$Structure"

wb_command -surface-distortion "$NativeFolder"/"$Subject"."$Hemisphere".sphere.native.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".sphere."$RegName".native.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".ArealDistortion_"$RegName".native.shape.gii
wb_command -set-map-names "$NativeFolder"/"$Subject"."$Hemisphere".ArealDistortion_"$RegName".native.shape.gii -map 1 "$Subject"_"$Hemisphere"_Areal_Distortion_"$RegName"
wb_command -metric-palette "$NativeFolder"/"$Subject"."$Hemisphere".ArealDistortion_"$RegName".native.shape.gii MODE_AUTO_SCALE -palette-name ROY-BIG-BL -thresholding THRESHOLD_TYPE_NORMAL THRESHOLD_TEST_SHOW_OUTSIDE -1 1

wb_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
wb_command -surface-distortion "$NativeFolder"/"$Subject"."$Hemisphere".sphere.native.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".sphere."$RegName".native.surf.gii "$NativeFolder"/"$Subject"."$Hemisphere".Strain_"$RegName".native.shape.gii -local-affine-method -log2

wb_command -metric-merge "$NativeFolder"/"$Subject"."$Hemisphere".StrainJ_"$RegName".native.shape.gii -metric "$NativeFolder"/"$Subject"."$Hemisphere".Strain_"$RegName".native.shape.gii -column 1
wb_command -metric-merge "$NativeFolder"/"$Subject"."$Hemisphere".StrainR_"$RegName".native.shape.gii -metric "$NativeFolder"/"$Subject"."$Hemisphere".Strain_"$RegName".native.shape.gii -column 2

rm "$NativeFolder"/"$Subject"."$Hemisphere".Strain_"$RegName".native.shape.gii
done

#Create CIFTI Files
wb_command -cifti-create-dense-scalar "$NativeFolder"/"$Subject".ArealDistortion_"$RegName".native.dscalar.nii -left-metric "$NativeFolder"/"$Subject".L.ArealDistortion_"$RegName".native.shape.gii -right-metric "$NativeFolder"/"$Subject".R.ArealDistortion_"$RegName".native.shape.gii
wb_command -set-map-names "$NativeFolder"/"$Subject".ArealDistortion_"$RegName".native.dscalar.nii -map 1 "$Subject"_ArealDistortion_"$RegName"
wb_command -cifti-palette "$NativeFolder"/"$Subject".ArealDistortion_"$RegName".native.dscalar.nii MODE_USER_SCALE "$NativeFolder"/"$Subject".ArealDistortion_"$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

wb_command -cifti-create-dense-scalar "$NativeFolder"/"$Subject".EdgeDistortion_"$RegName".native.dscalar.nii -left-metric "$NativeFolder"/"$Subject".L.EdgeDistortion_"$RegName".native.shape.gii -right-metric "$NativeFolder"/"$Subject".R.EdgeDistortion_"$RegName".native.shape.gii
wb_command -set-map-names "$NativeFolder"/"$Subject".EdgeDistortion_"$RegName".native.dscalar.nii -map 1 "$Subject"_EdgeDistortion_"$RegName"
wb_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

wb_command -cifti-create-dense-scalar "$NativeFolder"/"$Subject".StrainJ_"$RegName".native.dscalar.nii -left-metric "$NativeFolder"/"$Subject".L.StrainJ_"$RegName".native.shape.gii -right-metric "$NativeFolder"/"$Subject".R.StrainJ_"$RegName".native.shape.gii
wb_command -set-map-names "$NativeFolder"/"$Subject".StrainJ_"$RegName".native.dscalar.nii -map 1 "$Subject"_StrainJ_"$RegName"
wb_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

wb_command -cifti-create-dense-scalar "$NativeFolder"/"$Subject".StrainR_"$RegName".native.dscalar.nii -left-metric "$NativeFolder"/"$Subject".L.StrainR_"$RegName".native.shape.gii -right-metric "$NativeFolder"/"$Subject".R.StrainR_"$RegName".native.shape.gii
wb_command -set-map-names "$NativeFolder"/"$Subject".StrainR_"$RegName".native.dscalar.nii -map 1 "$Subject"_StrainR_"$RegName"
wb_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

nagedem marked this conversation as resolved.
Show resolved Hide resolved