forked from PennLINC/xcpEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jlf.mod
executable file
·198 lines (156 loc) · 6.76 KB
/
jlf.mod
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bash
###################################################################
# ✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡✡ #
###################################################################
###################################################################
# SPECIFIC MODULE HEADER
# This module uses joint label fusion (JLF) to generate an
# anatomical parcellation based on the openly available set of
# OASIS challenge labels (or a subset thereof).
###################################################################
mod_name_short=jlf
mod_name='JOINT LABEL FUSION MODULE'
mod_head=${XCPEDIR}/core/CONSOLE_MODULE_AFGR
###################################################################
# GENERAL MODULE HEADER
###################################################################
source ${XCPEDIR}/core/constants
source ${XCPEDIR}/core/functions/library.sh
source ${XCPEDIR}/core/parseArgsMod
###################################################################
# MODULE COMPLETION
###################################################################
completion() {
atlas miccai
assign image labelsGMIntersect[cxt] \
or labels[cxt] \
as jlfLabels
atlas_set miccai Map ${jlfLabels}
atlas_set miccai Space ${structural[sub]}
atlas_set miccai Type Map
atlas_set miccai NodeIndex ${BRAINATLAS}/miccai/miccaiNodeIndex.1D
atlas_set miccai NodeNames ${BRAINATLAS}/miccai/miccaiNodeNames.txt
atlas_set miccai Citation ${BRAINATLAS}/miccai/miccaiReference.bib
write_atlas
source ${XCPEDIR}/core/auditComplete
source ${XCPEDIR}/core/updateQuality
source ${XCPEDIR}/core/moduleEnd
}
###################################################################
# OUTPUTS
###################################################################
derivative intensity ${prefix}_Intensity
output labels ${prefix}_Labels.nii.gz
output labelsGMIntersect ${prefix}_LabelsGMIntersect.nii.gz
load_atlas ${atlas[sub]}
<<DICTIONARY
intensity
The weighted, fused intensity map of all images registered to
the target space.
labels
The anatomical parcellation directly produced as the output
of the joint label fusion procedure.
labelsGMIntersect
The JLF-derived parcellation after postprocessing, in the form
of excising non-ventricular CSF fron the brain periphery.
DICTIONARY
###################################################################
# * Run ANTs JLF w/ OASIS label set
###################################################################
if ! is_image ${labels[cxt]} \
|| rerun
then
routine @1 ANTs Joint Label Fusion
################################################################
# Now create and declare the call to run the JLF pipeline
################################################################
subroutine @1.1 Cohort: ${jlf_cohort[cxt]}
mapfile oasis < ${XCPEDIR}/thirdparty/oasis30/Cohorts/${jlf_cohort[cxt]}
labelDir=${XCPEDIR}/thirdparty/oasis30/MICCAI2012ChallengeLabels/
if (( ${jlf_extract[cxt]} == 1 ))
then
subroutine @1.2 Using brains only
brainDir=$XCPEDIR/thirdparty/oasis30/Brains/
else
subroutine @1.3 Using whole heads
brainDir=${XCPEDIR}/thirdparty/oasis30/Heads/
fi
subroutine @1.4 Assembling cohort
unset jlfReg
for o in ${oasis[@]}
do
jlfReg="${jlfReg} -g ${brainDir}${o}.nii.gz"
jlfReg="${jlfReg} -l ${labelDir}${o}.nii.gz"
done
subroutine @1.5 Configuring parallelisation
case ${jlf_parallel[cxt]} in
sge)
define jlf_parallel 1
;;
pbs)
define jlf_parallel 4
;;
*)
define jlf_parallel 0
esac
subroutine @1.6a Executing joint label fusion routine
subroutine @1.6b Delegating control to antsJointLabelFusion
export ANTSPATH=${ANTSPATH}/
exec_ants antsJointLabelFusion.sh \
-d 3 \
-q ${jlf_quick[cxt]} \
-f 0 \
-j 2 \
-k ${jlf_keep_warps[cxt]} \
-t ${img} \
-o ${outdir}/${prefix}_ \
-c ${jlf_parallel[cxt]} \
${jlfReg}
routine_end
fi
###################################################################
# Now apply the intersection between the ANTsCT segmentation
# and the output of JLF if a brain segmentation image exists
###################################################################
if ! is_image ${labelsGMIntersect[cxt]}\
|| rerun
then
if is_image ${segmentation[sub]}
then
routine @2 Preparing grey matter intersection
valsToBin='2:6'
csfValsToBin='4,11,46,51,52'
vdcValsToBin="61,62"
subroutine @2.1 Generating non-CSF mask
exec_xcp val2mask.R \
-i ${segmentation[sub]} \
-v ${valsToBin} \
-o ${intermediate}-thresholdedImage.nii.gz
subroutine @2.2 Generating ventricular CSF mask
exec_xcp val2mask.R \
-i ${labels[cxt]} \
-v ${csfValsToBin} \
-o ${intermediate}-binMaskCSF.nii.gz
subroutine @2.3 Generating ventral diencephalon mask
exec_xcp val2mask.R \
-i ${labels[cxt]} \
-v ${vdcValsToBin} \
-o ${intermediate}-binMaskVD.nii.gz
subroutine @2.4 Dilating ventricular CSF mask
exec_afni 3dmask_tool \
-input ${intermediate}-binMaskCSF.nii.gz \
-prefix ${intermediate}-binMaskCSF_dil.nii.gz \
-dilate_input 2
subroutine @2.5 Union of vCSF, VDC, and non-CSF masks
exec_fsl fslmaths ${intermediate}-thresholdedImage.nii.gz \
-add ${intermediate}-binMaskCSF_dil.nii.gz \
-add ${intermediate}-binMaskVD.nii.gz \
-bin ${intermediate}-thresholdedImage.nii.gz
subroutine @2.6 Excising extraventricular CSF from labels
exec_fsl fslmaths ${intermediate}-thresholdedImage.nii.gz \
-mul ${labels[cxt]} \
${labelsGMIntersect[cxt]}
routine_end
fi
fi
completion