46
46
47
47
from ...config import DEFAULT_MEMORY_MIN_GB
48
48
from ...interfaces .workbench import MetricDilate , MetricMask , MetricResample
49
+ from .outputs import prepare_timing_parameters
49
50
50
51
if ty .TYPE_CHECKING :
51
52
from niworkflows .utils .spaces import SpatialReferences
@@ -56,6 +57,8 @@ def init_bold_surf_wf(
56
57
mem_gb : float ,
57
58
surface_spaces : ty .List [str ],
58
59
medial_surface_nan : bool ,
60
+ metadata : dict ,
61
+ output_dir : str ,
59
62
name : str = "bold_surf_wf" ,
60
63
):
61
64
"""
@@ -90,6 +93,8 @@ def init_bold_surf_wf(
90
93
Inputs
91
94
------
92
95
source_file
96
+ Original BOLD series
97
+ bold_t1w
93
98
Motion-corrected BOLD series in T1 space
94
99
subjects_dir
95
100
FreeSurfer SUBJECTS_DIR
@@ -109,6 +114,10 @@ def init_bold_surf_wf(
109
114
from niworkflows .interfaces .nitransforms import ConcatenateXFMs
110
115
from niworkflows .interfaces .surf import GiftiSetAnatomicalStructure
111
116
117
+ from fmriprep .interfaces import DerivativesDataSink
118
+
119
+ timing_parameters = prepare_timing_parameters (metadata )
120
+
112
121
workflow = Workflow (name = name )
113
122
workflow .__desc__ = """\
114
123
The BOLD time-series were resampled onto the following surfaces
@@ -120,7 +129,13 @@ def init_bold_surf_wf(
120
129
121
130
inputnode = pe .Node (
122
131
niu .IdentityInterface (
123
- fields = ["source_file" , "subject_id" , "subjects_dir" , "fsnative2t1w_xfm" ]
132
+ fields = [
133
+ "source_file" ,
134
+ "bold_t1w" ,
135
+ "subject_id" ,
136
+ "subjects_dir" ,
137
+ "fsnative2t1w_xfm" ,
138
+ ]
124
139
),
125
140
name = "inputnode" ,
126
141
)
@@ -140,13 +155,6 @@ def select_target(subject_id, space):
140
155
mem_gb = DEFAULT_MEMORY_MIN_GB ,
141
156
)
142
157
143
- # Rename the source file to the output space to simplify naming later
144
- rename_src = pe .Node (
145
- niu .Rename (format_string = "%(subject)s" , keep_ext = True ),
146
- name = "rename_src" ,
147
- run_without_submitting = True ,
148
- mem_gb = DEFAULT_MEMORY_MIN_GB ,
149
- )
150
158
itk2lta = pe .Node (
151
159
ConcatenateXFMs (out_fmt = "fs" , inverse = True ), name = "itk2lta" , run_without_submitting = True
152
160
)
@@ -172,47 +180,43 @@ def select_target(subject_id, space):
172
180
mem_gb = DEFAULT_MEMORY_MIN_GB ,
173
181
)
174
182
175
- joinnode = pe .JoinNode (
176
- niu .IdentityInterface (fields = ["surfaces" , "target" ]),
177
- joinsource = "itersource" ,
178
- name = "joinnode" ,
179
- )
180
-
181
- outputnode = pe .Node (
182
- niu .IdentityInterface (fields = ["surfaces" , "target" ]),
183
- name = "outputnode" ,
183
+ ds_bold_surfs = pe .MapNode (
184
+ DerivativesDataSink (
185
+ base_directory = output_dir ,
186
+ extension = ".func.gii" ,
187
+ TaskName = metadata .get ('TaskName' ),
188
+ ** timing_parameters ,
189
+ ),
190
+ iterfield = ['in_file' , 'hemi' ],
191
+ name = 'ds_bold_surfs' ,
192
+ run_without_submitting = True ,
193
+ mem_gb = DEFAULT_MEMORY_MIN_GB ,
184
194
)
195
+ ds_bold_surfs .inputs .hemi = ["L" , "R" ]
185
196
186
- # fmt: off
187
197
workflow .connect ([
188
198
(inputnode , get_fsnative , [
189
199
("subject_id" , "subject_id" ),
190
200
("subjects_dir" , "subjects_dir" )
191
201
]),
192
202
(inputnode , targets , [("subject_id" , "subject_id" )]),
193
203
(inputnode , itk2lta , [
194
- ("source_file " , "reference" ),
204
+ ("bold_t1w " , "reference" ),
195
205
("fsnative2t1w_xfm" , "in_xfms" ),
196
206
]),
197
207
(get_fsnative , itk2lta , [("T1" , "moving" )]),
198
208
(inputnode , sampler , [
199
209
("subjects_dir" , "subjects_dir" ),
200
210
("subject_id" , "subject_id" ),
211
+ ("bold_t1w" , "source_file" ),
201
212
]),
202
213
(itersource , targets , [("target" , "space" )]),
203
- (inputnode , rename_src , [("source_file" , "in_file" )]),
204
- (itersource , rename_src , [("target" , "subject" )]),
205
- (rename_src , sampler , [("out_file" , "source_file" )]),
206
214
(itk2lta , sampler , [("out_inv" , "reg_file" )]),
207
215
(targets , sampler , [("out" , "target_subject" )]),
208
- (update_metadata , joinnode , [("out_file" , "surfaces" )]),
209
- (itersource , joinnode , [("target" , "target" )]),
210
- (joinnode , outputnode , [
211
- ("surfaces" , "surfaces" ),
212
- ("target" , "target" ),
213
- ]),
214
- ])
215
- # fmt: on
216
+ (inputnode , ds_bold_surfs , [("source_file" , "source_file" )]),
217
+ (itersource , ds_bold_surfs , [("target" , "space" )]),
218
+ (update_metadata , ds_bold_surfs , [("out_file" , "in_file" )]),
219
+ ]) # fmt:skip
216
220
217
221
# Refine if medial vertices should be NaNs
218
222
medial_nans = pe .MapNode (
0 commit comments