1
1
# Use infant_recon_all to generate subcortical segmentations and cortical parcellations
2
2
3
- from nipype .interfaces import freesurfer as fs
4
- from nipype .interfaces import utility as niu
5
- from nipype .pipeline import engine as pe
6
- from niworkflows .interfaces .freesurfer import PatchedLTAConvert as LTAConvert
7
- from smriprep .workflows .surfaces import init_gifti_surface_wf
8
-
9
- from ...interfaces .freesurfer import InfantReconAll
10
-
11
3
12
4
def init_infant_surface_recon_wf (* , age_months , use_aseg = False , name = "infant_surface_recon_wf" ):
5
+ from nipype .interfaces import freesurfer as fs
6
+ from nipype .interfaces import io as nio
7
+ from nipype .interfaces import utility as niu
8
+ from nipype .pipeline import engine as pe
13
9
from niworkflows .engine .workflows import LiterateWorkflow
10
+ from niworkflows .interfaces .freesurfer import PatchedLTAConvert as LTAConvert
11
+ from niworkflows .interfaces .freesurfer import (
12
+ PatchedRobustRegister as RobustRegister ,
13
+ )
14
+ from smriprep .workflows .surfaces import init_gifti_surface_wf
15
+
16
+ from nibabies .interfaces .freesurfer import InfantReconAll
14
17
15
18
wf = LiterateWorkflow (name = name )
16
19
inputnode = pe .Node (
@@ -52,29 +55,24 @@ def init_infant_surface_recon_wf(*, age_months, use_aseg=False, name="infant_sur
52
55
53
56
# inject the intensity-normalized skull-stripped t1w from the brain extraction workflow
54
57
recon = pe .Node (InfantReconAll (age = age_months ), name = "reconall" )
58
+ fssource = pe .Node (nio .FreeSurferSource (), name = 'fssource' , run_without_submitting = True )
55
59
56
- # these files are created by babyFS, but transforms are for masked anatomicals
57
- # https://github.com/freesurfer/freesurfer/blob/
58
- # 8b40551f096294cc6603ce928317b8df70bce23e/infant/infant_recon_all#L744
59
- # TODO: calculate full anat -> fsnative transform?
60
- get_tal_lta = pe .Node (
61
- niu .Function (function = _get_talairch_lta ),
62
- name = "get_tal_xfm" ,
63
- )
64
60
fsnative2anat_xfm = pe .Node (
61
+ RobustRegister (auto_sens = True , est_int_scale = True ),
62
+ name = 'fsnative2anat_xfm' ,
63
+ )
64
+
65
+ anat2fsnative_xfm = pe .Node (
65
66
LTAConvert (out_lta = True , invert = True ),
66
- name = "fsnative2anat_xfm " ,
67
+ name = "anat2fsnative_xfm " ,
67
68
)
68
69
69
70
# convert generated surfaces to GIFTIs
70
71
gifti_surface_wf = init_gifti_surface_wf ()
71
72
72
- get_aseg = pe .Node (niu .Function (function = _get_aseg ), name = "get_aseg" )
73
- get_aparc = pe .Node (niu .Function (function = _get_aparc ), name = "get_aparc" )
74
73
aparc2nii = pe .Node (fs .MRIConvert (out_type = "niigz" ), name = "aparc2nii" )
75
74
76
75
if use_aseg :
77
- # TODO: Add precomputed segmentation upon new babyFS rel
78
76
wf .connect (inputnode , "anat_aseg" , recon , "aseg_file" )
79
77
80
78
# fmt: off
@@ -94,39 +92,36 @@ def init_infant_surface_recon_wf(*, age_months, use_aseg=False, name="infant_sur
94
92
('subject_id' , 'subject_id' ),
95
93
(('outdir' , _parent ), 'subjects_dir' ),
96
94
]),
95
+ (recon , fssource , [
96
+ ('subject_id' , 'subject_id' ),
97
+ (('outdir' , _parent ), 'subjects_dir' ),
98
+ ]),
97
99
(recon , gifti_surface_wf , [
98
100
('subject_id' , 'inputnode.subject_id' ),
99
101
(('outdir' , _parent ), 'inputnode.subjects_dir' ),
100
102
]),
101
- (recon , get_aparc , [
102
- ('outdir ' , 'fs_subject_dir ' ),
103
+ (fssource , outputnode , [
104
+ (( 'aseg ' , _replace_mgz ), 'anat_aseg ' ),
103
105
]),
104
- (recon , get_aseg , [
105
- ('outdir' , 'fs_subject_dir' ),
106
+ (inputnode , fsnative2anat_xfm , [('anat_skullstripped' , 'target_file' )]),
107
+ (fssource , fsnative2anat_xfm , [
108
+ (('norm' , _replace_mgz ), 'source_file' ),
106
109
]),
107
- (get_aseg , outputnode , [
108
- ('out' , 'anat_aseg' ),
109
- ]),
110
- (get_aparc , aparc2nii , [
111
- ('out' , 'in_file' ),
110
+ (fsnative2anat_xfm , anat2fsnative_xfm , [('out_reg_file' , 'in_lta' )]),
111
+ (fssource , aparc2nii , [
112
+ ('aparc_aseg' , 'in_file' ),
112
113
]),
113
114
(aparc2nii , outputnode , [
114
115
('out_file' , 'anat_aparc' ),
115
116
]),
116
- (recon , get_tal_lta , [
117
- ('outdir' , 'fs_subject_dir' ),
118
- ]),
119
- (get_tal_lta , outputnode , [
120
- ('out' , 'anat2fsnative_xfm' ),
121
- ]),
122
- (get_tal_lta , fsnative2anat_xfm , [
123
- ('out' , 'in_lta' ),
124
- ]),
125
117
(fsnative2anat_xfm , outputnode , [
126
- ('out_lta' , 'fsnative2anat_xfm' ),
118
+ ('out_reg_file' , 'fsnative2anat_xfm' ),
119
+ ]),
120
+ (anat2fsnative_xfm , outputnode , [
121
+ ('out_lta' , 'anat2fsnative_xfm' ),
127
122
]),
128
123
(fsnative2anat_xfm , gifti_surface_wf , [
129
- ('out_lta ' , 'inputnode.fsnative2t1w_xfm' )]),
124
+ ('out_reg_file ' , 'inputnode.fsnative2t1w_xfm' )]),
130
125
(gifti_surface_wf , outputnode , [
131
126
('outputnode.surfaces' , 'surfaces' ),
132
127
]),
@@ -149,31 +144,5 @@ def _gen_recon_dir(subjects_dir, subject_id):
149
144
return str (p )
150
145
151
146
152
- def _get_talairch_lta (fs_subject_dir ):
153
- """Fetch pre-computed transform from infant_recon_all"""
154
- from pathlib import Path
155
-
156
- xfm = Path (fs_subject_dir ) / "mri" / "transforms" / "niftyreg_affine.lta"
157
- if not xfm .exists ():
158
- raise FileNotFoundError ("Could not find talairach transform." )
159
- return str (xfm .absolute ())
160
-
161
-
162
- def _get_aseg (fs_subject_dir ):
163
- """Fetch infant_recon_all's aparc+aseg"""
164
- from pathlib import Path
165
-
166
- aseg = Path (fs_subject_dir ) / "mri" / "aseg.nii.gz"
167
- if not aseg .exists ():
168
- raise FileNotFoundError ("Could not find aseg." )
169
- return str (aseg )
170
-
171
-
172
- def _get_aparc (fs_subject_dir ):
173
- """Fetch infant_recon_all's aparc+aseg"""
174
- from pathlib import Path
175
-
176
- aparc = Path (fs_subject_dir ) / "mri" / "aparc+aseg.mgz"
177
- if not aparc .exists ():
178
- raise FileNotFoundError ("Could not find aparc." )
179
- return str (aparc )
147
+ def _replace_mgz (in_file ):
148
+ return in_file .replace ('.mgz' , '.nii.gz' )
0 commit comments