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

Structural longitudinal pipelines #295

Merged
merged 104 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
90e527b
Initial implementation of the Longitudinal FreeSurfer pipeline
demsarjure Jun 16, 2022
1e86a5f
Added extra args for both the Base template preparation and the Long …
demsarjure Jun 17, 2022
ff5fadb
Removed final folder relinking as it is already done by recon all.
demsarjure Jun 17, 2022
1ecdcd7
Creation of additional symlinks.
demsarjure Jun 29, 2022
d59f81c
Removed the link creation.
demsarjure Jul 3, 2022
f1891ba
Fixed template naming.
demsarjure Jul 6, 2022
5670466
Removed a bug in template naming.
demsarjure Jul 6, 2022
b8306e0
Additional cleanup of symlinks
demsarjure Jul 12, 2022
0901fcd
The symlink cleanup was too agressive.
demsarjure Aug 11, 2022
1b0617a
Renamed subject-dir into study-folder and template into template-id.
demsarjure Oct 7, 2022
ae2ddc0
Fixed the folder organization for longitudinal FS so it matches HCP s…
demsarjure Mar 17, 2023
7886eea
Initial implementation of the Longitudinal FreeSurfer pipeline
demsarjure Jun 16, 2022
834deb0
Added extra args for both the Base template preparation and the Long …
demsarjure Jun 17, 2022
327d86a
Removed final folder relinking as it is already done by recon all.
demsarjure Jun 17, 2022
9e14bba
Creation of additional symlinks.
demsarjure Jun 29, 2022
882d15e
Removed the link creation.
demsarjure Jul 3, 2022
a5ac2ac
Fixed template naming.
demsarjure Jul 6, 2022
e3d5c4f
Removed a bug in template naming.
demsarjure Jul 6, 2022
465d2c5
Additional cleanup of symlinks
demsarjure Jul 12, 2022
bf8ddf3
The symlink cleanup was too agressive.
demsarjure Aug 11, 2022
1b3a8b7
Renamed subject-dir into study-folder and template into template-id.
demsarjure Oct 7, 2022
94d31f4
Fixed the folder organization for longitudinal FS so it matches HCP s…
demsarjure Mar 17, 2023
962f917
Merge branch 'feature/longitudinal_fs' of github.com:Washington-Unive…
demsarjure May 11, 2023
7fb7a24
chore: longitudinal FS refactor to new IO
demsarjure May 11, 2023
0396247
Fixed an unbound variable issue.
demsarjure May 12, 2023
b7dfb97
Fixed use of extra recon all args.
demsarjure May 12, 2023
06291ef
FIxed extra recon all args parsing.
demsarjure Aug 23, 2023
31812f7
Merge branch 'feature/longitudinal_fs' of github.com:Washington-Unive…
demsarjure Aug 23, 2023
a88c059
Fixed a bug with extra args parsing.
demsarjure Aug 23, 2023
20eda9d
+post freesurfer timepoint update script
Oct 18, 2023
eddc629
+Changes to correctly apply base template and longitudinal pipelines …
Oct 25, 2023
7b4ecf6
+convert the Affine transform from timepoint to template, from
Nov 30, 2023
7955af4
+permissions
Nov 30, 2023
59d05f4
+experimental script to transform timepoint T1w to template.
Dec 20, 2023
1e06dcd
Merge branch 'master' into feature/longitudinal_fs
coalsont Dec 20, 2023
276bac5
+scripts to create HCP average template based on longitudinal Freesur…
Dec 23, 2023
5d00c31
+ script to resample acpc_dc space to template space (longitudinal)
Feb 5, 2024
15a556a
+PrePostFreesurfer pipeline, initial commit.
Feb 21, 2024
3c0a74b
+diagrams documenting PrePostFreesurferPipeline-long
Feb 22, 2024
17c1c7d
+completed the first pass of the PrePostFreesurferPipeline-long docum…
mmilch01 Feb 23, 2024
1f41415
+alterations per discussion with Matt Glasser 02/27/2024
Feb 27, 2024
138bfd8
+ppFS-long.sh work in progress
coalsont Apr 18, 2024
a0594cc
edits included with "+added .gitignore which was deleted by the previ…
coalsont Apr 18, 2024
3f0744a
Finished ppFS-long rewrite that:
Apr 19, 2024
9131b39
Change separator between input timepoints for consistency
Apr 22, 2024
7a45da6
Fix typos/misspelling; tested to work on TP
Apr 22, 2024
76508fb
+source libraries before calling log_check
Apr 22, 2024
1eed6dd
+change target image from longitudinal (non-existent yet) to cross-se…
Apr 23, 2024
ccc4716
Fix the issue with wrong LTA header at the initial transform conversi…
mmilch01 Apr 23, 2024
0bdc5a2
+Fix the issue with wrong LTA header at the initial transform convers…
mmilch01 Apr 23, 2024
bcea028
Merge branch 'feature/longitudinal_fs' of https://github.com/Washingt…
mmilch01 Apr 23, 2024
717ab38
+Fixed misspellings/typos in template processing code, up to registra…
mmilch01 Apr 24, 2024
0898ae0
+copy warp jacobians from template to timepoints
Apr 25, 2024
6312b72
+copy acpc_dc_restore to acpc_dc
Apr 25, 2024
95208d0
PostFreeSurferPipeline.sh:
Apr 26, 2024
920cd98
+this version is tested in batch mode up to PostFreesurfer
May 1, 2024
d7144fb
+Added clarification to longitudinal arguments in PostFreeSurfer
May 20, 2024
798c3ed
+fix long-l mode conditions
May 21, 2024
bced737
+inflatescale argument fix to remove 'developer error'
May 21, 2024
7c9fd62
+properly set IsLongitudinal flag
May 22, 2024
96541ec
+batch PostFreesurferPipeline batch script for longitudinal mode
May 22, 2024
2d2f890
Merge remote-tracking branch 'origin/master' into feature/longitudina…
mmilch01 May 24, 2024
8b59a56
+Have MSMSulc.sh only run in template mode, precluded by surface aver…
mmilch01 May 26, 2024
38888e6
fix typos
mmilch01 May 27, 2024
e967a9c
+Two-stage mode for longitudinal timepoint processing, to accomodate …
May 28, 2024
097d4c5
+added two timepoint stages to run MSMSulc.
May 31, 2024
85feec4
+typo/syntax fixes for staged longitudinal processing
Jun 4, 2024
a6ba6fb
+syntax fixes. This version of longitudinal pipelines is verified to …
Jun 5, 2024
a84445e
merge PostFreeSurferPipelineLongPrepBatch code into PostFreeSurferPip…
mmilch01 Jun 7, 2024
f717f3b
+Updated documentation diagrams.
Jun 7, 2024
f992acb
+Harmonize example batch scripts
Jun 7, 2024
8fca79c
1. Timepoint naming in batch files changed to more general scheme
Aug 12, 2024
a95002f
1. Updated timepoint naming resolution function to work correctly
Aug 14, 2024
907a572
+added legacy --subject synonym to --session
Aug 14, 2024
a463491
+Fixes needed to correctly run PreFreeSurferPipeline, FreeSurferPipel…
Aug 16, 2024
3db2368
+mostly syntax fixes for calls/parameter names to run the full pipeline.
Aug 26, 2024
9963457
NONE option for parallel mode
demsarjure Sep 1, 2024
802c203
+Added 'NONE' parallel mode
Sep 5, 2024
7e374fc
+update longitudinal Freesurfer and Post-Freesurfer pipelines and bach
Sep 6, 2024
cc355d5
+Renamed 'template', 'template-id' options to 'longitudinal-template'…
Sep 10, 2024
d82592e
+fixes for parallel modes
Sep 11, 2024
9edf66f
+Fixed variable names in PostFreeSurferPipelineLongLauncher directory…
Sep 12, 2024
f4fa563
1. Styling changes suggested by reviewers
Sep 16, 2024
717e912
+address current pull request review comments.
Sep 17, 2024
7b08242
+Addressing more comments from reviewers.
Sep 18, 2024
33371fc
+more reviewer requested changes
mmilch01 Sep 23, 2024
fde843a
Missing ; in one of if sentences.
demsarjure Sep 24, 2024
0b152b1
Update PostFreeSurfer/scripts/FreeSurfer2CaretConvertAndRegisterNonli…
mmilch01 Sep 24, 2024
fca6e56
+Addressing more reviewer comments
mmilch01 Sep 24, 2024
b80fccf
Added a missing ;.
demsarjure Sep 25, 2024
46154cf
Fixed capitalization at several locations: PostFreesurfer -> PostFree…
demsarjure Sep 25, 2024
4b52e2b
Merge branch 'feature/longitudinal_fs' of https://github.com/Washingt…
mmilch01 Sep 26, 2024
06e2004
+Fix TimepointProcessing variable name
mmilch01 Sep 26, 2024
1f5f73d
+Fix timepoints unbound variable issue
mmilch01 Sep 26, 2024
24c9a7b
+An option to specify logfile location in parallel.shlib
Sep 30, 2024
e4fd418
+Append FreeSurfer BBR refinement to T2w-T1w transform in the final T…
Sep 30, 2024
66f61fc
+addressed reviewer comments
Sep 30, 2024
47f474c
+sanity check for mode name in par_addjob_stdin()
Oct 2, 2024
31a6842
Set correct default for the starting stage.
Oct 9, 2024
fa9a7a2
Path fix.
demsarjure Oct 17, 2024
1c70499
+Fix the bug with incorrectly linked longitudinal Freesurfer folders …
Oct 20, 2024
ae32e8c
Merge branch 'feature/longitudinal_fs' of https://github.com/Washingt…
Oct 20, 2024
e374d8d
+reverse the previous 'path fix' commit.
Oct 20, 2024
f675b43
+link atlas transforms to timepoint xfms directory
Oct 21, 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
Empty file modified .gitignore
100755 → 100644
Empty file.
139 changes: 139 additions & 0 deletions Examples/Scripts/FreeSurferPipelineBatch-long.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

command_line_specified_run_local=FALSE
while [ -n "$1" ]; do
case "$1" in
--runlocal) shift; command_line_specified_run_local=TRUE ;;
*) shift ;;
esac
done

#################################################################################################
# General input variables
##################################################################################################
#Location of Subject folders (named by subjectID)
StudyFolder="/my/study/path"
#The list of subject labels, space separated
Subjects=(HCA6002236 HCA6002237 HCA6002238)
#The list of possible visits (aka timepoints, sessions) that each subject may have. Timepoint directories should be named <Subject>_<Visit>.
PossibleVisits=(V1_MR V2_MR V3_MR)
#The list of possible visits that each subject may have. Timepoint (visit) is expected to be named <Subject>_<Visit>.
#Actual visits (timepoints) are determined based on existing directories that match the visit name pattern.
#ExcludeVisits=(HCA6002237_V1_MR HCA6002238_V1_MR)
ExcludeVisits=()
#Longitudinal template labels, one per each subject.
Templates=(HCA6002236_V1_V2 HCA6002237_V1_V2 HCA6002238_V1_V2)

EnvironmentScript="<HCPInstallDir>/scripts/SetUpHCPPipeline.sh" #Pipeline environment script

# Requirements for this script
# installed versions of: FSL, FreeSurfer, Connectome Workbench (wb_command), gradunwarp (HCP version)
# environment: HCPPIPEDIR, FSLDIR, FREESURFER_HOME, CARET7DIR, PATH for gradient_unwarp.py

# If you want to use FreeSurfer 5.3, change the ${queuing_command} line below to use
# ${HCPPIPEDIR}/FreeSurfer/FreeSurferPipeline-v5.3.0-HCP.sh

#Set up pipeline environment variables and software
source "$EnvironmentScript"

# Log the originating call
echo "$@"

#NOTE: syntax for QUEUE has changed compared to earlier pipeline releases,
#DO NOT include "-q " at the beginning
#default to no queue, implying run local
QUEUE="long.q"
#QUEUE="hcp_priority.q"

#parallel options
parallel_mode=BUILTIN

# This setting is for BUILTIN mode. Set to -1 to auto-detect the # of CPU cores on the node where each per-subject job is run.
# Note that in case when multiple subject jobs are run on the same node and are submitted
# in parallel by e.g. fsl_sub, max_jobs should be set manually to not significantly exceed
# (number of available cores)/(number of subjects) in the batch.
max_jobs=-1
#max_jobs=4

#TEMPLATE stage must be run before TIMEPOINTS stage
start_stage=TEMPLATE
end_stage=TIMEPOINTS

#Processing goes here.
function identify_timepoints
{
local subject=$1
local tplist=""
local tp visit n

#build the list of timepoints (sessions)
n=0
for session in ${PossibleVisits[*]}; do
tp="${subject}_${session}"
if [ -d "$StudyFolder/$tp" ] && ! [[ " ${ExcludeVisits[*]+${ExcludeVisits[*]}} " =~ [[:space:]]"$tp"[[:space:]] ]]; then
if (( n==0 )); then
tplist="$tp"
else
tplist="$tplist@$tp"
fi
fi
((n++))
done
echo $tplist
}

########################################## INPUTS ##########################################
#Scripts called by this script do assume they run on the outputs of the PreFreeSurfer Pipeline
######################################### DO WORK ##########################################

for i in ${!Subjects[@]}; do
Subject=${Subjects[i]}
#Subject's time point list, @ separated.
TPlist=(`identify_timepoints $Subject`)
#Array with timepoints
IFS=@ read -ra Timepoints <<< "$TPlist"
#Freesurfer longitudinal average template label
LongitudinalTemplate=${Templates[i]}

#Longitudinal FreeSurfer Input Variables
SubjectID="$Subject" #FreeSurfer Subject ID Name
SubjectDIR="${StudyFolder}/${Subject}/T1w" #Location to Put FreeSurfer Subject's Folder
T1wImage="${StudyFolder}/${Subject}/T1w/T1w_acpc_dc_restore.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T1wImageBrain="${StudyFolder}/${Subject}/T1w/T1w_acpc_dc_restore_brain.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T2wImage="${StudyFolder}/${Subject}/T1w/T2w_acpc_dc_restore.nii.gz" #T2w FreeSurfer Input (Full Resolution)

if [ "$parallel_mode" != FSLSUB ]; then #fsl_sub does not allow nested submissions
if [[ "${command_line_specified_run_local}" == "TRUE" || "$QUEUE" == "" ]] ; then
echo "About to locally run ${HCPPIPEDIR}/FreeSurfer/LongitudinalFreeSurferPipeline.sh"
#NOTE: fsl_sub without -q runs locally and captures output in files
queuing_command=("$FSLDIR/bin/fsl_sub")
else
echo "About to use fsl_sub to queue ${HCPPIPEDIR}/FreeSurfer/LongitudinalFreeSurferPipeline.sh"
queuing_command=("$FSLDIR/bin/fsl_sub" -q "$QUEUE")
fi
else
queuing_command=()
fi

#DO NOT PUT timepoint-specific options here!!!
cmd=(${queuing_command[@]+"${queuing_command[@]}"} "$HCPPIPEDIR"/FreeSurfer/LongitudinalFreeSurferPipeline.sh \
--subject="$Subject" \
--path="$StudyFolder" \
--sessions="$TPlist" \
--fslsub-queue="$QUEUE" \
--longitudinal-template="$LongitudinalTemplate" \
--parallel-mode="$parallel_mode" \
--max-jobs="$max_jobs" \
--start-stage="$start_stage" \
--end-stage="$end_stage" \
)

#--extra-reconall-arg-base=-conf2hires Freesurfer reports this is unneeded.
echo "Running command: ${cmd[*]}"
"${cmd[@]}"

# The following lines are used for interactive debugging to set the positional parameters: $1 $2 $3 ...
# echo set --subject=$Subject --subjectDIR=$SubjectDIR --t1=$T1wImage --t1brain=$T1wImageBrain --t2=$T2wImage --extra-reconall-arg-long="-i \"$SubjectDIR\"/T1w/T1w_acpc_dc_restore.nii.gz -emregmask \"$SubjectDIR\"/T1w/T1w_acpc_dc_restore_brain.nii.gz -T2 $SubjectDIR\"/T1w/T2w_acpc_dc_restore.nii.gz -T2pial"
#echo ". ${EnvironmentScript}"

done
40 changes: 22 additions & 18 deletions Examples/Scripts/FreeSurferPipelineBatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ get_batch_options() {
local arguments=("$@")

command_line_specified_study_folder=""
command_line_specified_subj=""
command_line_specified_session=""
command_line_specified_run_local="FALSE"

local index=0
Expand All @@ -19,8 +19,12 @@ get_batch_options() {
command_line_specified_study_folder=${argument#*=}
index=$(( index + 1 ))
;;
--Subject=*)
command_line_specified_subj=${argument#*=}
--Subject=*) #legacy option, please use '--Session' instead
command_line_specified_session=${argument#*=}
index=$(( index + 1 ))
;;
--Session=*)
command_line_specified_session=${argument#*=}
index=$(( index + 1 ))
;;
--runlocal)
Expand All @@ -39,16 +43,16 @@ get_batch_options() {

get_batch_options "$@"

StudyFolder="${HOME}/projects/Pipelines_ExampleData" #Location of Subject folders (named by subjectID)
Subjlist="100307 100610" #Space delimited list of subject IDs
StudyFolder="${HOME}/projects/Pipelines_ExampleData" #Location of Session folders (named by sessionID)
Sessionlist="100307 100610" #Space delimited list of session IDs
EnvironmentScript="${HOME}/projects/Pipelines/Examples/Scripts/SetUpHCPPipeline.sh" #Pipeline environment script

if [ -n "${command_line_specified_study_folder}" ]; then
StudyFolder="${command_line_specified_study_folder}"
fi

if [ -n "${command_line_specified_subj}" ]; then
Subjlist="${command_line_specified_subj}"
if [ -n "${command_line_specified_session}" ]; then
Sessionlist="${command_line_specified_session}"
fi

# Requirements for this script
Expand Down Expand Up @@ -76,15 +80,15 @@ QUEUE=""

######################################### DO WORK ##########################################

for Subject in $Subjlist ; do
echo $Subject
for Session in $Sessionlist ; do
echo $Session

#Input Variables
SubjectID="$Subject" #FreeSurfer Subject ID Name
SubjectDIR="${StudyFolder}/${Subject}/T1w" #Location to Put FreeSurfer Subject's Folder
T1wImage="${StudyFolder}/${Subject}/T1w/T1w_acpc_dc_restore.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T1wImageBrain="${StudyFolder}/${Subject}/T1w/T1w_acpc_dc_restore_brain.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T2wImage="${StudyFolder}/${Subject}/T1w/T2w_acpc_dc_restore.nii.gz" #T2w FreeSurfer Input (Full Resolution)
SessionID="$Session" #FreeSurfer Subject ID Name
SessionDIR="${StudyFolder}/${Session}/T1w" #Location to Put FreeSurfer Subject's Folder
T1wImage="${StudyFolder}/${Session}/T1w/T1w_acpc_dc_restore.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T1wImageBrain="${StudyFolder}/${Session}/T1w/T1w_acpc_dc_restore_brain.nii.gz" #T1w FreeSurfer Input (Full Resolution)
T2wImage="${StudyFolder}/${Session}/T1w/T2w_acpc_dc_restore.nii.gz" #T2w FreeSurfer Input (Full Resolution)

if [[ "${command_line_specified_run_local}" == "TRUE" || "$QUEUE" == "" ]] ; then
echo "About to locally run ${HCPPIPEDIR}/FreeSurfer/FreeSurferPipeline.sh"
Expand All @@ -95,16 +99,16 @@ for Subject in $Subjlist ; do
fi

"${queuing_command[@]}" "$HCPPIPEDIR"/FreeSurfer/FreeSurferPipeline.sh \
--subject="$Subject" \
--subject-dir="$SubjectDIR" \
--session="$Session" \
--session-dir="$SessionDIR" \
--t1w-image="$T1wImage" \
--t1w-brain="$T1wImageBrain" \
--t2w-image="$T2wImage"

# The following lines are used for interactive debugging to set the positional parameters: $1 $2 $3 ...

echo "set -- --subject=$Subject \
--subject-dir=$SubjectDIR \
echo "set -- --session=$Session \
--session-dir=$SessionDIR \
--t1w-image=$T1wImage \
--t1w-brain=$T1wImageBrain \
--t2w-image=$T2wImage"
Expand Down
169 changes: 169 additions & 0 deletions Examples/Scripts/PostFreeSurferPipelineBatch-long.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/bin/bash

command_line_specified_run_local=FALSE
while [ -n "$1" ]; do
case "$1" in
--runlocal) shift; command_line_specified_run_local=TRUE ;;
*) shift ;;
esac
done

#################################################################################################
# General input variables
##################################################################################################
#Location of Subject folders (named by subjectID)
StudyFolder="<MyStudyPath>"
#The list of subject labels, space separated
Subjects=(HCA6002236 HCA6002237 HCA6002238)
#The list of possible visits that each subject may have. Timepoint (visit) is expected to be named <Subject>_<Visit>.
PossibleVisits=(V1_MR V2_MR V3_MR)
#Actual visits (timepoints) are determined based on existing directories that match the visit name pattern <Subject>_<visit>.
#Excluded timepoint directories
#ExcludeVisits=(HCA6002237_V1_MR HCA6002238_V1_MR)
ExcludeVisits=()
#Longitudinal template labels, one per each subject.
Templates=(HCA6002236_V1_V2 HCA6002237_V1_V2 HCA6002238_V1_V2)
#EnvironmentScript="${HOME}/projects/HCPPipelines/Examples/Scripts/SetUpHCPPipeline.sh" #Pipeline environment script
EnvironmentScript="${HOME}/projects/HCPPipelines/Examples/Scripts/SetUpHCPPipeline.sh"
source "$EnvironmentScript"

##################################################################################################
# Input variables used by PostFreeSurferPipelineLongPrep
##################################################################################################
# Hires T1w MNI template
T1wTemplate="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm.nii.gz"
# Hires brain extracted MNI template1
mmilch01 marked this conversation as resolved.
Show resolved Hide resolved
T1wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain.nii.gz"
# Lowres T1w MNI template
mmilch01 marked this conversation as resolved.
Show resolved Hide resolved
T1wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T1_2mm.nii.gz"
# Hires T2w MNI Template
T2wTemplate="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm.nii.gz"
# Hires T2w brain extracted MNI Template
mmilch01 marked this conversation as resolved.
Show resolved Hide resolved
T2wTemplateBrain="${HCPPIPEDIR_Templates}/MNI152_T2_0.8mm_brain.nii.gz"
# Lowres T2w MNI Template
mmilch01 marked this conversation as resolved.
Show resolved Hide resolved
T2wTemplate2mm="${HCPPIPEDIR_Templates}/MNI152_T2_2mm.nii.gz"
# Hires MNI brain mask template
TemplateMask="${HCPPIPEDIR_Templates}/MNI152_T1_0.8mm_brain_mask.nii.gz"
# Lowres MNI brain mask template
mmilch01 marked this conversation as resolved.
Show resolved Hide resolved
Template2mmMask="${HCPPIPEDIR_Templates}/MNI152_T1_2mm_brain_mask_dil.nii.gz"
# FNIRT 2mm T1w Config
FNIRTConfig="${HCPPIPEDIR_Config}/T1_2_MNI152_2mm.cnf"

##################################################################################################
# Input variables used by PostFreesurferPipeline (longitudinal mode)
##################################################################################################
SurfaceAtlasDIR="${HCPPIPEDIR_Templates}/standard_mesh_atlases"
GrayordinatesSpaceDIR="${HCPPIPEDIR_Templates}/91282_Greyordinates"
GrayordinatesResolutions="2" #Usually 2mm, if multiple delimit with @, must already exist in templates dir
HighResMesh="164" #Usually 164k vertices
LowResMeshes="32" #Usually 32k vertices, if multiple delimit with @, must already exist in templates dir
SubcorticalGrayLabels="${HCPPIPEDIR_Config}/FreeSurferSubcorticalLabelTableLut.txt"
FreeSurferLabels="${HCPPIPEDIR_Config}/FreeSurferAllLut.txt"
ReferenceMyelinMaps="${HCPPIPEDIR_Templates}/standard_mesh_atlases/Conte69.MyelinMap_BC.164k_fs_LR.dscalar.nii"
RegName="MSMSulc" #MSMSulc is recommended, if binary is not available use FS (FreeSurfer)

# Requirements for this script
# installed versions of: FSL, Connectome Workbench (wb_command)
# environment: HCPPIPEDIR, FSLDIR, CARET7DIR

#fslsub queue
#QUEUE=short.q
#top level parallelization

QUEUE="long.q"

#pipeline level parallelization
#parallel mode: FSLSUB, BUILTIN, NONE
parallel_mode=BUILTIN

if [ "$parallel_mode" != FSLSUB ]; then #fsl_sub does not allow nested submissions
if [[ "${command_line_specified_run_local}" == "TRUE" || "$QUEUE" == "" ]] ; then
echo "About to locally run ${HCPPIPEDIR}/PostFreeSurfer/PostFreeSurferPipelineLongLauncher.sh"
# #NOTE: fsl_sub without -q runs locally and captures output in files
queuing_command=("$FSLDIR/bin/fsl_sub")
QUEUE=long.q
else
echo "About to use fsl_sub to queue ${HCPPIPEDIR}/FreeSurfer/PostFreeSurferPipelineLongLauncher.sh"
queuing_command=("$FSLDIR/bin/fsl_sub" -q "$QUEUE")
QUEUE=""
fi
else
queuing_command=""
fi
# This setting is for BUILTIN mode. Set to -1 to auto-detect the # of CPU cores on the node where each per-subject job is run.
# Note that in case when multiple subject jobs are run on the same node and are submitted
# in parallel by e.g. fsl_sub, it may be inefficient to have the
# (number of fsl_sub jobs running per node) * (BUILTIN parallelism) substantially exceed
# the number of cores per node
max_jobs=-1
#max_jobs=4

# Stages to run. Must be run in the following order:
# 1. PREP-TP, 2.PREP-T, 3. POSTFS-TP1, 4. POSTFS-T, 5. POSTFS-TP2
start_stage=PREP-TP
end_stage=POSTFS-TP2


function identify_timepoints
{
local subject=$1
local tplist=""
local tp visit n

#build the list of timepoints
n=0
for visit in ${PossibleVisits[*]}; do
tp="${subject}_${visit}"
if [ -d "$StudyFolder/$tp" ] && ! [[ " ${ExcludeVisits[*]+${ExcludeVisits[*]}} " =~ [[:space:]]"$tp"[[:space:]] ]]; then
if (( n==0 )); then
tplist="$tp"
else
tplist="$tplist@$tp"
fi
fi
((n++))
done
echo $tplist
}

#iterate over all subjects.
for i in ${!Subjects[@]}; do
Subject=${Subjects[i]}
LongitudinalTemplate=${Templates[i]}
Timepoint_list=(`identify_timepoints $Subject`)

echo Subject: $Subject
echo Template: $LongitudinalTemplate
echo Timepoints: $Timepoint_list

cmd=(${queuing_command[@]+"${queuing_command[@]}"} ${HCPPIPEDIR}/PostFreeSurfer/PostFreeSurferPipelineLongLauncher.sh \
--study-folder="$StudyFolder" \
--subject="$Subject" \
--longitudinal-template="$LongitudinalTemplate" \
--sessions="$Timepoint_list" \
--parallel-mode=$parallel_mode \
--fslsub-queue=$QUEUE \
--start-stage=$start_stage \
--end-stage=$end_stage \
--t1template="$T1wTemplate" \
--t1templatebrain="$T1wTemplateBrain" \
--t1template2mm="$T1wTemplate2mm" \
--t2template="$T2wTemplate" \
--t2templatebrain="$T2wTemplateBrain" \
--t2template2mm="$T2wTemplate2mm" \
--templatemask="$TemplateMask" \
--template2mmmask="$Template2mmMask" \
--fnirtconfig="$FNIRTConfig" \
--freesurferlabels="$FreeSurferLabels" \
--surfatlasdir="$SurfaceAtlasDIR" \
--grayordinatesres="$GrayordinatesResolutions" \
--grayordinatesdir="$GrayordinatesSpaceDIR" \
--hiresmesh="$HighResMesh" \
--lowresmesh="$LowResMeshes" \
--subcortgraylabels="$SubcorticalGrayLabels" \
--refmyelinmaps="$ReferenceMyelinMaps" \
--regname="$RegName" \
)
echo "Running $cmd"
"${cmd[@]}"
done
Loading