4646
4747from ...config import DEFAULT_MEMORY_MIN_GB
4848from ...interfaces .workbench import MetricDilate , MetricMask , MetricResample
49+ from .outputs import prepare_timing_parameters
4950
5051if ty .TYPE_CHECKING :
5152 from niworkflows .utils .spaces import SpatialReferences
@@ -56,6 +57,8 @@ def init_bold_surf_wf(
5657 mem_gb : float ,
5758 surface_spaces : ty .List [str ],
5859 medial_surface_nan : bool ,
60+ metadata : dict ,
61+ output_dir : str ,
5962 name : str = "bold_surf_wf" ,
6063):
6164 """
@@ -90,6 +93,8 @@ def init_bold_surf_wf(
9093 Inputs
9194 ------
9295 source_file
96+ Original BOLD series
97+ bold_t1w
9398 Motion-corrected BOLD series in T1 space
9499 subjects_dir
95100 FreeSurfer SUBJECTS_DIR
@@ -109,6 +114,10 @@ def init_bold_surf_wf(
109114 from niworkflows .interfaces .nitransforms import ConcatenateXFMs
110115 from niworkflows .interfaces .surf import GiftiSetAnatomicalStructure
111116
117+ from fmriprep .interfaces import DerivativesDataSink
118+
119+ timing_parameters = prepare_timing_parameters (metadata )
120+
112121 workflow = Workflow (name = name )
113122 workflow .__desc__ = """\
114123 The BOLD time-series were resampled onto the following surfaces
@@ -120,7 +129,13 @@ def init_bold_surf_wf(
120129
121130 inputnode = pe .Node (
122131 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+ ]
124139 ),
125140 name = "inputnode" ,
126141 )
@@ -140,13 +155,6 @@ def select_target(subject_id, space):
140155 mem_gb = DEFAULT_MEMORY_MIN_GB ,
141156 )
142157
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- )
150158 itk2lta = pe .Node (
151159 ConcatenateXFMs (out_fmt = "fs" , inverse = True ), name = "itk2lta" , run_without_submitting = True
152160 )
@@ -172,47 +180,43 @@ def select_target(subject_id, space):
172180 mem_gb = DEFAULT_MEMORY_MIN_GB ,
173181 )
174182
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 ,
184194 )
195+ ds_bold_surfs .inputs .hemi = ["L" , "R" ]
185196
186- # fmt: off
187197 workflow .connect ([
188198 (inputnode , get_fsnative , [
189199 ("subject_id" , "subject_id" ),
190200 ("subjects_dir" , "subjects_dir" )
191201 ]),
192202 (inputnode , targets , [("subject_id" , "subject_id" )]),
193203 (inputnode , itk2lta , [
194- ("source_file " , "reference" ),
204+ ("bold_t1w " , "reference" ),
195205 ("fsnative2t1w_xfm" , "in_xfms" ),
196206 ]),
197207 (get_fsnative , itk2lta , [("T1" , "moving" )]),
198208 (inputnode , sampler , [
199209 ("subjects_dir" , "subjects_dir" ),
200210 ("subject_id" , "subject_id" ),
211+ ("bold_t1w" , "source_file" ),
201212 ]),
202213 (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" )]),
206214 (itk2lta , sampler , [("out_inv" , "reg_file" )]),
207215 (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
216220
217221 # Refine if medial vertices should be NaNs
218222 medial_nans = pe .MapNode (
0 commit comments