|
6 | 6 | from nipype.pipeline import engine as pe
|
7 | 7 | from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
|
8 | 8 | from niworkflows.interfaces.fixes import FixHeaderRegistration as Registration
|
| 9 | +from niworkflows.interfaces.nibabel import MapLabels |
9 | 10 | from pkg_resources import resource_filename as pkgr_fn
|
10 | 11 | from smriprep.utils.misc import apply_lut as _apply_bids_lut
|
11 | 12 | from smriprep.workflows.anatomical import (
|
@@ -51,7 +52,7 @@ def init_anat_segmentations_wf(
|
51 | 52 | name="inputnode",
|
52 | 53 | )
|
53 | 54 | outputnode = pe.Node(
|
54 |
| - niu.IdentityInterface(fields=["anat_aseg", "anat_dseg", "anat_tpms"]), |
| 55 | + niu.IdentityInterface(fields=["anat_aseg", "anat_mcrib_aseg", "anat_dseg", "anat_tpms"]), |
55 | 56 | name="outputnode",
|
56 | 57 | )
|
57 | 58 |
|
@@ -175,15 +176,61 @@ def init_anat_segmentations_wf(
|
175 | 176 | lut_anat_dseg.inputs.lut = _aseg_to_three()
|
176 | 177 | split_seg = pe.Node(niu.Function(function=_split_segments), name="split_seg")
|
177 | 178 | out_aseg = validate_aseg if precomp_aseg else jf_label
|
| 179 | + |
| 180 | + wf.__desc__ += """Segmentation volume label indices were remapped |
| 181 | + from FreeSurfer to M-CRIB-compatible format. """ |
| 182 | + |
| 183 | + # dictionary to map labels from aseg to mcrib |
| 184 | + aseg2mcrib = { |
| 185 | + 2: 51, |
| 186 | + 3: 21, |
| 187 | + 4: 49, |
| 188 | + 5: 0, |
| 189 | + 7: 17, |
| 190 | + 8: 17, |
| 191 | + 10: 43, |
| 192 | + 11: 41, |
| 193 | + 12: 47, |
| 194 | + 13: 47, |
| 195 | + 14: 0, |
| 196 | + 15: 0, |
| 197 | + 16: 19, |
| 198 | + 17: 1, |
| 199 | + 18: 3, |
| 200 | + 26: 41, |
| 201 | + 28: 45, |
| 202 | + 31: 49, |
| 203 | + 41: 52, |
| 204 | + 42: 20, |
| 205 | + 43: 50, |
| 206 | + 44: 0, |
| 207 | + 46: 18, |
| 208 | + 47: 18, |
| 209 | + 49: 42, |
| 210 | + 50: 40, |
| 211 | + 51: 46, |
| 212 | + 52: 46, |
| 213 | + 53: 2, |
| 214 | + 54: 4, |
| 215 | + 58: 40, |
| 216 | + 60: 44, |
| 217 | + 63: 50, |
| 218 | + 253: 48, |
| 219 | + } |
| 220 | + map_labels = pe.Node(MapLabels(mappings=aseg2mcrib), name="map_labels") |
| 221 | + |
178 | 222 | # fmt: off
|
179 | 223 | wf.connect([
|
180 | 224 | (out_aseg, outputnode, [('out_file', 'anat_aseg')]),
|
181 | 225 | (out_aseg, lut_anat_dseg, [('out_file', 'in_dseg')]),
|
182 | 226 | (lut_anat_dseg, outputnode, [('out', 'anat_dseg')]),
|
183 | 227 | (lut_anat_dseg, split_seg, [('out', 'in_file')]),
|
184 | 228 | (split_seg, outputnode, [('out', 'anat_tpms')]),
|
| 229 | + (out_aseg, map_labels, [("out_file", "in_file")]), |
| 230 | + (map_labels, outputnode, [("out_file", "anat_mcrib_aseg")]), |
185 | 231 | ])
|
186 | 232 | # fmt: on
|
| 233 | + |
187 | 234 | return wf
|
188 | 235 |
|
189 | 236 |
|
|
0 commit comments