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

Updated cortical thickness and curvature regression #300

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
c19e4ed
New cortical thickness-curvature regression
nagedem Sep 17, 2024
f37027b
Merge branch 'Washington-University:master' into master
nagedem Sep 17, 2024
90f3ca4
Update CreateMyelinMaps.sh
nagedem Sep 17, 2024
93aa8ab
Some updates to recent MRcorrThickness pull request
nagedem Sep 21, 2024
8bde758
Update CorrThick.sh
nagedem Sep 21, 2024
e362b54
Fix palette scale
nagedem Sep 24, 2024
8539259
Update CorrThick.sh
nagedem Sep 26, 2024
4f01827
Updated CorrThick.sh
nagedem Sep 26, 2024
bba0e1b
Fixed Indentation/Tabs
nagedem Sep 26, 2024
8cf9503
Updates
nagedem Sep 27, 2024
13a7175
Updated CorrThick.sh
nagedem Sep 30, 2024
05c55d4
Changed argument name
nagedem Sep 30, 2024
f4d96f0
Update CorrThick.sh
nagedem Oct 1, 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
2 changes: 2 additions & 0 deletions PostFreeSurfer/PostFreeSurferPipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ opts_AddOptional '--inflatescale' 'InflateExtraScale' 'number' "surface inflatio
opts_AddOptional '--processing-mode' 'ProcessingMode' 'HCPStyleData|LegacyStyleData' "disable some HCP preprocessing requirements to allow processing of data that doesn't meet HCP acquisition guidelines - don't use this if you don't need to" 'HCPStyleData'
opts_AddOptional '--structural-qc' 'QCMode' 'yes|no|only' "whether to run structural QC, default 'yes'" 'yes'
opts_AddOptional '--use-ind-mean' 'UseIndMean' 'YES or NO' "whether to use the mean of the subject's myelin map as reference map's myelin map mean, defaults to 'YES'" 'YES'
opts_AddOptional '--metric-regression' 'MetricReg' 'OLD, NEW or BOTH' "whether to use the updated curvature-thickness regression, defaults to 'BOTH'" 'BOTH'

opts_ParseArguments "$@"

Expand Down Expand Up @@ -281,6 +282,7 @@ if ((doProcessing)); then
argList+=("$CorrectionSigma")
argList+=("$RegName") # ${39}
argList+=("$UseIndMean")
argList+=("$MetricReg") # ${41}
"$PipelineScripts"/CreateMyelinMaps.sh "${argList[@]}"
fi

Expand Down
10 changes: 8 additions & 2 deletions PostFreeSurfer/scripts/CreateMyelinMaps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ReferenceMyelinMaps="${37}"
CorrectionSigma="${38}"
RegName="${39}"
UseIndMean="${40}"
MetricReg="${41}"

log_Msg "RegName: ${RegName}"

Expand Down Expand Up @@ -171,7 +172,6 @@ if [ "${T2wPresent}" = "YES" ] ; then
${CARET7DIR}/wb_command -add-to-spec-file "$T1wFolder"/"$NativeFolder"/"$Subject".native.wb.spec INVALID "$T1wFolder"/T1wDividedByT2w_ribbon.nii.gz
fi


MapListFunc="corrThickness@shape"
if [ "${T2wPresent}" = "YES" ] ; then
MapListFunc+=" MyelinMap@func SmoothedMyelinMap@func"
Expand All @@ -191,7 +191,9 @@ for Hemisphere in L R ; do
RegSphere="${AtlasSpaceFolder}/${NativeFolder}/${Subject}.${Hemisphere}.sphere.reg.reg_LR.native.surf.gii"
fi

${CARET7DIR}/wb_command -metric-regression "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".thickness.native.shape.gii "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".corrThickness.native.shape.gii -roi "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".roi.native.shape.gii -remove "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".curvature.native.shape.gii
if [ "${MetricReg}" = "OLD" ] || [ "${MetricReg}" = "BOTH" ]; then
${CARET7DIR}/wb_command -metric-regression "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".thickness.native.shape.gii "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".corrThickness.native.shape.gii -roi "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".roi.native.shape.gii -remove "$AtlasSpaceFolder"/"$NativeFolder"/"$Subject"."$Hemisphere".curvature.native.shape.gii
fi

#Reduce memory usage by smoothing on downsampled mesh
LowResMesh="${LowResMeshesArray[0]}"
Expand All @@ -217,6 +219,10 @@ for Hemisphere in L R ; do
done
done

if [ "${MetricReg}" = "NEW" ] || [ "${MetricReg}" = "BOTH" ]; then
$HCPPIPEDIR/global/scripts/CorrThick.sh --subject-dir="$StudyFolder" --subject="$Subject" --regnames="$RegName"
fi

LowResMeshList=""
for LowResMesh in "${LowResMeshesArray[@]}" ; do
LowResMeshList+="${AtlasSpaceFolder}/fsaverage_LR${LowResMesh}k@${LowResMesh}k_fs_LR@atlasroi "
Expand Down
139 changes: 139 additions & 0 deletions global/scripts/CorrThick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/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 curvature-corrected cortical thickness python script and save curvatures, regression coefficients, and curvature-corrected thickness"

opts_AddMandatory '--subject-dir' 'SubjectDir' 'path' "folder containing all subjects"
opts_AddMandatory '--subject' 'Subject' 'subject ID' "subject-id"
opts_AddOptional '--regnames' 'RegNamesStr' 'my reg str' "set the desired registration name(s) separated by @, 'string' 'RegName@RegName@[email protected].' default MSMSulc" "MSMSulc"
opts_AddOptional '--hemi' 'Hemi' 'hemisphere' "provide hemisphere for regression calculation, L=Left, R=Right, or B=Both, default 'B'" "B"
opts_AddOptional '--surf' 'Surface' 'surface' "provide surface for regression calculation, white or midthickness, default midthickness" "midthickness"
opts_AddOptional '--patch-size' 'PatchSize' 'distance' "provide patch kernel size in millimeters FWHM for regression, default 6" "6"
opts_AddOptional '--surf-smooth' 'SurfSmooth' 'distance' "provide surface smoothing in millimeters FWHM, default 2.14" "2.14"
opts_AddOptional '--metric-smooth' 'MetricSmooth' 'distance' "provide metric smoothing in millimeters FWHM, default 2.52" "2.52"
opts_AddOptional '--skip-computation' 'SkipCompute' 'YES or NO' "whether or not to compute the curvature-corrected cortical thickness, if it is already available, but just to resample it to 164k and 32k, defaults to 'NO'" "NO"

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

#sanity check boolean strings and convert to 1 and 0
SkC=$(opts_StringToBool "$SkipCompute")

#set paths
NonlinearFolder="$SubjectDir"/"$Subject"/MNINonLinear
NativeFolder="$NonlinearFolder"/Native
T1wFolder="$SubjectDir"/"$Subject"/T1w/Native

#Make intermediate directory to save intermediate files
mkdir -p "$NativeFolder"/CorrThick

#Loop through left and right hemispheres
if [[ "$Hemi" == *B* ]]
then
Hemi="L R"
fi

RegNames=`echo "$RegNamesStr" | sed s/"@"/" "/g`

LowResMesh="32"
HighResMesh="164"
MapListFunc="MRcorrThickness MRcorrThickness_intercept MRcorrThickness_normcoeffs MRcorrThickness_curvs MRcorrThickness_coeffs"

#Generate MRcorrThickness in Native Space
if ((! SkC)); then
for Hemisphere in $Hemi ; do
if [[ "$Hemisphere" == "L" ]] ; then
Structure="CORTEX_LEFT"
elif [[ "$Hemisphere" == "R" ]] ; then
Structure="CORTEX_RIGHT"
fi
(
cd "$HCPPIPEDIR"/global/scripts/CorrThick
python CorrThick.py "$SubjectDir" "$Subject" "$Structure" "$Hemisphere" "$Surface" "$PatchSize" "$SurfSmooth" "$MetricSmooth"
)
done
fi

#Set the Color Palette(s) and Resample to HighResMesh and LowResMesh
for Hemisphere in $Hemi ; do

for Map in $MapListFunc ; do
if [[ "$Map" == MRcorrThickness || "$Map" == MRcorrThickness_intercept ]] ; then
wb_command -metric-palette "$NativeFolder"/"$Subject"."$Hemisphere"."$Map".native.shape.gii MODE_AUTO_SCALE_PERCENTAGE -pos-percent 4 96 -interpolate true -palette-name videen_style -disp-pos true -disp-neg false -disp-zero false -normalization NORMALIZATION_SELECTED_MAP_DATA
elif [[ "$Map" == MRcorrThickness_normcoeffs ]] ; then
wb_command -metric-palette "$NativeFolder"/"$Subject"."$Hemisphere"."$Map".native.shape.gii MODE_AUTO_SCALE_ABSOLUTE_PERCENTAGE -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false -normalization NORMALIZATION_ALL_MAP_DATA
else
wb_command -metric-palette "$NativeFolder"/"$Subject"."$Hemisphere"."$Map".native.shape.gii MODE_AUTO_SCALE_ABSOLUTE_PERCENTAGE -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false -normalization NORMALIZATION_SELECTED_MAP_DATA
fi
done

for RegName in $RegNames ; do
RegSphere=""$NativeFolder"/"$Subject"."$Hemisphere".sphere."$RegName".native.surf.gii"

if [[ "$RegName" == "MSMSulc" ]] ; then
RegString=""
else
RegString="_$RegName"
fi
for Map in $MapListFunc ; do
wb_command -metric-resample "$NativeFolder"/"$Subject"."$Hemisphere"."$Map".native.shape.gii "$RegSphere" "$NonlinearFolder"/"$Subject"."$Hemisphere".sphere."$HighResMesh"k_fs_LR.surf.gii ADAP_BARY_AREA "$NonlinearFolder"/"$Subject"."$Hemisphere"."$Map""$RegString"."$HighResMesh"k_fs_LR.shape.gii -area-surfs "$T1wFolder"/"$Subject"."$Hemisphere".midthickness.native.surf.gii "$NonlinearFolder"/"$Subject"."$Hemisphere".midthickness."$HighResMesh"k_fs_LR.surf.gii -current-roi "$NativeFolder"/"$Subject"."$Hemisphere".roi.native.shape.gii
wb_command -metric-mask "$NonlinearFolder"/"$Subject"."$Hemisphere"."$Map""$RegString"."$HighResMesh"k_fs_LR.shape.gii "$NonlinearFolder"/"$Subject"."$Hemisphere".atlasroi."$HighResMesh"k_fs_LR.shape.gii "$NonlinearFolder"/"$Subject"."$Hemisphere"."$Map""$RegString"."$HighResMesh"k_fs_LR.shape.gii
wb_command -metric-resample "$NativeFolder"/"$Subject"."$Hemisphere"."$Map".native.shape.gii "$RegSphere" "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere".sphere."$LowResMesh"k_fs_LR.surf.gii ADAP_BARY_AREA "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere"."$Map""$RegString"."$LowResMesh"k_fs_LR.shape.gii -area-surfs "$T1wFolder"/"$Subject"."$Hemisphere".midthickness.native.surf.gii "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere".midthickness."$LowResMesh"k_fs_LR.surf.gii -current-roi "$NativeFolder"/"$Subject"."$Hemisphere".roi.native.shape.gii
wb_command -metric-mask "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere"."$Map""$RegString"."$LowResMesh"k_fs_LR.shape.gii "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere".atlasroi."$LowResMesh"k_fs_LR.shape.gii "$NonlinearFolder"/fsaverage_LR"$LowResMesh"k/"$Subject"."$Hemisphere"."$Map""$RegString"."$LowResMesh"k_fs_LR.shape.gii
done
done
done

#Create CIFTI Files in Native, HighResMesh, and LowResMesh
if [[ "$Hemi" == *L* && "$Hemi" == *R* ]] ; then
for STRING in "$NativeFolder"@native@roi "$NonlinearFolder"@"$HighResMesh"k_fs_LR@atlasroi "$NonlinearFolder/fsaverage_LR"$LowResMesh"k@"$LowResMesh"k_fs_LR@atlasroi" ; do
Folder=`echo $STRING | cut -d "@" -f 1`
Mesh=`echo $STRING | cut -d "@" -f 2`
ROI=`echo $STRING | cut -d "@" -f 3`

for RegName in $RegNames ; do
if [[ "$RegName" == "MSMSulc" || "$Folder" == "$NativeFolder" ]] ; then
RegString=""
else
RegString="_$RegName"
fi

for Map in $MapListFunc ; do
wb_command -cifti-create-dense-scalar "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii -left-metric "$Folder"/"$Subject".L."$Map""$RegString"."$Mesh".shape.gii -roi-left "$Folder"/"$Subject".L."$ROI"."$Mesh".shape.gii -right-metric "$Folder"/"$Subject".R."$Map""$RegString"."$Mesh".shape.gii -roi-right "$Folder"/"$Subject".R."$ROI"."$Mesh".shape.gii
if [[ "$Map" == MRcorrThickness || "$Map" == MRcorrThickness_intercept ]] ; then
wb_command -cifti-palette "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii MODE_AUTO_SCALE_PERCENTAGE "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii -pos-percent 4 96 -interpolate true -palette-name videen_style -disp-pos true -disp-neg false -disp-zero false -normalization NORMALIZATION_SELECTED_MAP_DATA
elif [[ "$Map" == MRcorrThickness_normcoeffs ]] ; then
wb_command -cifti-palette "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii MODE_AUTO_SCALE_ABSOLUTE_PERCENTAGE "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false -normalization NORMALIZATION_ALL_MAP_DATA
else
wb_command -cifti-palette "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii MODE_AUTO_SCALE_ABSOLUTE_PERCENTAGE "$Folder"/"$Subject"."$Map""$RegString"."$Mesh".dscalar.nii -interpolate true -palette-name ROY-BIG-BL -disp-pos true -disp-neg true -disp-zero false -normalization NORMALIZATION_SELECTED_MAP_DATA
fi
done
if [[ "$Folder" == "$NativeFolder" ]] ; then
break
fi
done
done
fi

#Remove preliminary directory and all its contents
rm -rf "$NativeFolder"/CorrThick

42 changes: 42 additions & 0 deletions global/scripts/CorrThick/CorrThick.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 20 14:44:13 2024

@author: brainmappers
"""
import sys

subjects_dir=str(sys.argv[1])
subject=str(sys.argv[2])
structure=str(sys.argv[3])
hemi=str(sys.argv[4])
surface=str(sys.argv[5])
number=float(sys.argv[6])
iteration=str(sys.argv[7])
smooth=str(sys.argv[8])

import neighbor_info
import curvature
import metric_regression
import roi
import wb

################################################################################
mesh='164k'
wb.wb_metric_resample_to_164k(subjects_dir,subject,hemi,surface,mesh)
wb.wb_surf_resample_to_164k(subjects_dir,subject,hemi,surface,mesh)
x,y,z,a,b,c = wb.wb_taubin(subjects_dir,subject,hemi,surface,mesh,iteration)
neighbor_info.neighbor_info(a,b,c,x,y,z,subjects_dir,subject,hemi,surface,mesh)
curvature.Gaussian_curvature(x,y,z,subjects_dir,subject,hemi,surface)
curvature.mean_curvature(x,y,z,subjects_dir,subject,hemi,surface)
curvature.k1_k2_SI(x,y,z,subjects_dir,subject,hemi,surface)
wb.wb_smooth(subjects_dir,subject,hemi,surface,mesh,smooth)
wb.wb_rois(subjects_dir,subject,hemi,surface,mesh,number)
rois,weights=roi.roi(subjects_dir,subject,hemi,surface,mesh,number)
metric_regression.metric_regression(subjects_dir,subject,hemi,surface,mesh,rois,weights)
wb.wb_metric_resample_to_native(subjects_dir,subject,hemi,surface)
wb.wb_structure(subjects_dir,subject,hemi,surface,structure)
wb.wb_set_map_names(subjects_dir,subject,hemi)


Loading