forked from dfsp-spirit/freesurfer_parallel_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmooth_stddata_custom_subject.bash
More file actions
executable file
·95 lines (75 loc) · 3.42 KB
/
smooth_stddata_custom_subject.bash
File metadata and controls
executable file
·95 lines (75 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# smooth_stddata_custom_subject.bash -- smooth standard space data with a custom FWHM setting, i.e.,
# typically something other than the settings 0, 5, 10, 15, 20, 25 which are produced by default.
#
# This script assumes that the measure data has already been mapped to standard space, i.e., the
# files <subject>/surf/?h.<measure>.fsaverage.mgh must already exist for all subjects.
#
# Note that you can run this from smooth_stddata_custom_parallel.bash to apply it to several subjects in parallel.
#
# Written by Tim Schaefer, 2020-06-11
APPTAG="[SMOOTH_CUSTOM]"
if [ -z "$3" ]; then
echo "$APPTAG ERROR: Arguments missing."
echo "$APPTAG Usage: $0 <subject> <measure> <fwhm> [<template_subject>]"
echo "$APPTAG Note that the environment variable SUBJECTS_DIR must also be set correctly."
echo "$APPTAG If you omit <template_subject>, we assume fsaverage."
exit 1
else
SUBJECT="$1"
MEASURE="$2"
FWHM="$3"
fi
TEMPLATE_SUBJECT="fsaverage"
if [ -n "$4" ]; then
TEMPLATE_SUBJECT="$4"
fi
#### settings ####
# Whether to run even if the output files already exist. Set to 'YES' for yes, or anything else for no.
FORCE="NO"
#### check some basic stuff first
if [ -z "${SUBJECTS_DIR}" ]; then
echo "$APPTAG ERROR: Environment variable SUBJECTS_DIR not set. Exiting."
exit 1
fi
if [ ! -d "${SUBJECTS_DIR}" ]; then
echo "$APPTAG ERROR: Environment variable SUBJECTS_DIR points to '${SUBJECTS_DIR}' but that directory does NOT exist. Exiting."
exit 1
fi
if [ ! -d "${SUBJECTS_DIR}/${SUBJECT}" ]; then
echo "$APPTAG ERROR: Directory for subject '${SUBJECT}' not found in SUBJECTS_DIR '${SUBJECTS_DIR}'. Exiting."
exit 1
fi
LH_EXPECTED_INPUT="${SUBJECTS_DIR}/${SUBJECT}/surf/lh.${MEASURE}.${TEMPLATE_SUBJECT}.mgh"
RH_EXPECTED_INPUT="${SUBJECTS_DIR}/${SUBJECT}/surf/rh.${MEASURE}.${TEMPLATE_SUBJECT}.mgh"
if [ -f "${LH_EXPECTED_INPUT}" -a -f "${RH_EXPECTED_INPUT}" ]; then
echo "$APPTAG Measure ${MEASURE} for subject '${SUBJECT}: expected input files found."
else
echo "$APPTAG ERROR: Measure ${MEASURE} for subject '${SUBJECT}': expected input files '${LH_EXPECTED_INPUT}' and/or '${RH_EXPECTED_INPUT}' missing."
exit 1
fi
#### ok, lets go
LH_EXPECTED_OUTPUT="${SUBJECTS_DIR}/${SUBJECT}/surf/lh.${MEASURE}.fwhm${FWHM}.${TEMPLATE_SUBJECT}.mgh"
RH_EXPECTED_OUTPUT="${SUBJECTS_DIR}/${SUBJECT}/surf/rh.${MEASURE}.fwhm${FWHM}.${TEMPLATE_SUBJECT}.mgh"
DO_RUN="YES"
if [ -f "${LH_EXPECTED_OUTPUT}" -a -f "${RH_EXPECTED_OUTPUT}" ]; then
if [ "$FORCE" != "YES" ]; then
DO_RUN="NO"
echo "$APPTAG Measure ${MEASURE} at FWHM ${FWHM} done already for subject '${SUBJECT}', skipping."
else
echo "$APPTAG Measure ${MEASURE} at FWHM ${FWHM} done already for subject '${SUBJECT}', but FORCE is set, re-running."
fi
else
echo "$APPTAG Measure ${MEASURE} at FWHM ${FWHM} not done yet for subject '$SUBJECT.' Running..."
fi
if [ "$DO_RUN" = "YES" ]; then
if [ ! -d "${SUBJECTS_DIR}/${TEMPLATE_SUBJECT}" ]; then
echo "Template subject directory does not exist at '${SUBJECTS_DIR}/${TEMPLATE_SUBJECT}', please fix. Exiting."
exit 1
fi
for HEMI in lh rh; do
##### Smooth data:
MAPPED_DATA_FILE_SMOOTHED="${SUBJECT}/surf/${HEMI}.${MEASURE}.fwhm${FWHM}.${TEMPLATE_SUBJECT}.mgh"
mri_surf2surf --prune --s ${TEMPLATE_SUBJECT} --hemi ${HEMI} --fwhm ${FWHM} --sval ${SUBJECT}/surf/${HEMI}.${MEASURE}.${TEMPLATE_SUBJECT}.mgh --tval ${MAPPED_DATA_FILE_SMOOTHED}
done
fi