-
Notifications
You must be signed in to change notification settings - Fork 3
/
JLF_T1w_classic.sh
executable file
·106 lines (95 loc) · 2.97 KB
/
JLF_T1w_classic.sh
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
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# This script is basically just a wrapper, but created such that it could be modified later without impacting other scripts.
options=`getopt -o t:d:r:g:l:o:n:hx -l target:,working-dir:,refdir:,ncores:,ref:,lab:,pexec:,output:,help,brainmask -n 'run_JLF.sh' -- "$@"`
eval set -- "$options"
function display_help() {
echo "Usage: `basename $0` "
echo " Required:"
echo " -t|--target <target brain> subject brain"
echo " -d|--working-dir <directory> working directory for intermediate outputs"
echo " -g|--ref <template brain> 1 per template brain, in order"
echo " -l|--labels <template seg> 1 per template segmentation, in order"
echo " -o|--output <output name> output aseg"
echo " Optional:"
echo " -r|--refdir optional directory such that templates may be"
echo " relative paths to here. Must come before first -g/-l"
echo " -n|--ncores <cpus> number of cores for parallel execution"
exit $1
}
echo "`basename $0` $options"
debug=0
# extract options and their arguments into variables.
while true ; do
case "$1" in
-t|--target)
target="$2"
shift 2
;;
-d|--working-dir)
WD="$2"
shift 2
;;
-r|--refdir)
if ((${#references[@]})); then
echo "Reference directory must be declared before references"
exit 1
fi
refdir="$2"
shift 2
;;
-g|--ref)
references+=("${refdir}${refdir:+/}$2")
shift 2
;;
-l|--lab)
labels+=("${refdir}${refdir:+/}$2")
shift 2
;;
-n|--ncores)
if (($2 - 1)); then
pexec="-c 2 -j $2"
fi
shift 2
;;
-x|--brainmask)
maskcmd="-x brainmask.nii.gz"
shift
;;
-o|--output)
output="$2"
shift 2
;;
-h|--help)
display_help;;
--) shift ; break ;;
*) echo "Unexpected error parsing args!" ; display_help 1 ;;
esac
done
if [ ! $(command -v ${ANTSPATH}${ANTSPATH:+/}antsJointLabelFusion.sh) ]; then
echo "could not find ants scripts necessary for running joint label fusion in paths..."
echo ${ANTSPATH}${ANTSPATH:+/}antsJointLabelFusion.sh
exit 1
fi
if [ ! -z $ANTSPATH ]; then
export ANTSPATH=${ANTSPATH%/}${ANTSPATH:+/} # ANTs script requires a trailing slash on this variable...
fi
if [ -z "$WD" ]; then
WD="$PWD"
elif [ ! -e "$WD" ]; then
mkdir -p "$WD" &> /dev/null || true
fi
if [ ${#references[@]} -ne ${#labels[@]} ]; then
echo "Reference/Label quantity mismatch in `basename $0`! Cannot run segmentation"
exit 1
fi
cd "$WD"
${FSLDIR}/bin/fslmaths $target -bin brainmask.nii.gz
# construct call to joint label fusion
cmd="${ANTSPATH}antsJointLabelFusion.sh -d 3 -o ants_multiatlas_ -t $target $maskcmd -y b ${pexec:-"-c 0"}"
for (( i=0; i<${#references[@]}; i++ )); do
cmd=${cmd}" -g ${references[$i]} -l ${labels[$i]}"
done
# call process
echo $cmd | tee cmd.txt
$cmd
imcp "$WD"/ants_multiatlas_Labels $output