Skip to content

Commit 1d907c3

Browse files
committed
FIX: Split joinnode from outputnode, reorder and comment optional connections
1 parent 57c35ef commit 1d907c3

File tree

1 file changed

+77
-90
lines changed

1 file changed

+77
-90
lines changed

nibabies/workflows/bold/resampling.py

Lines changed: 77 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,64 @@ def select_target(subject_id, space):
166166
)
167167
sampler.inputs.hemi = ["lh", "rh"]
168168

169+
update_metadata = pe.MapNode(
170+
GiftiSetAnatomicalStructure(),
171+
iterfield=["in_file"],
172+
name="update_metadata",
173+
mem_gb=DEFAULT_MEMORY_MIN_GB,
174+
)
175+
176+
joinnode = pe.JoinNode(
177+
niu.IdentityInterface(fields=["surfaces", "target"]),
178+
joinsource="itersource",
179+
name="joinnode",
180+
)
181+
182+
outputnode = pe.Node(
183+
niu.IdentityInterface(fields=["surfaces", "target", "goodvoxels_ribbon"]),
184+
name="outputnode",
185+
)
186+
187+
# fmt: off
188+
workflow.connect([
189+
(inputnode, get_fsnative, [
190+
("subject_id", "subject_id"),
191+
("subjects_dir", "subjects_dir")
192+
]),
193+
(inputnode, targets, [("subject_id", "subject_id")]),
194+
(inputnode, itk2lta, [
195+
("source_file", "src_file"),
196+
("t1w2fsnative_xfm", "in_file"),
197+
]),
198+
(get_fsnative, itk2lta, [("T1", "dst_file")]),
199+
(inputnode, sampler, [
200+
("subjects_dir", "subjects_dir"),
201+
("subject_id", "subject_id"),
202+
]),
203+
(itersource, targets, [("target", "space")]),
204+
(itersource, rename_src, [("target", "subject")]),
205+
(rename_src, sampler, [("out_file", "source_file")]),
206+
(itk2lta, sampler, [("out", "reg_file")]),
207+
(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+
217+
# At this point, rename_src.in_file and update_metadata.in_file need connecting
218+
#
219+
# These depend on two optional steps: goodvoxel projection and medial wall nan replacment
220+
#
221+
# inputnode -> optional(goodvoxels_bold_mask_wf) -> rename_src
222+
# sampler -> optional(metric_dilate) -> optional(medial_nans) -> update_metadata
223+
#
224+
169225
metric_dilate = pe.MapNode(
170-
MetricDilate(
171-
distance=10,
172-
nearest=True,
173-
),
226+
MetricDilate(distance=10, nearest=True),
174227
iterfield=["in_file", "surf_file"],
175228
name="metric_dilate",
176229
mem_gb=mem_gb * 3,
@@ -193,107 +246,41 @@ def select_target(subject_id, space):
193246
MedialNaNs(), iterfield=["in_file"], name="medial_nans", mem_gb=DEFAULT_MEMORY_MIN_GB
194247
)
195248

196-
# Rename the source file to the output space to simplify naming later
197-
prepend_hemi = pe.MapNode(
198-
niu.Rename(format_string="%(hemi)s.target.func.gii"),
199-
iterfield=["in_file", "hemi"],
200-
name="prepend_hemi",
201-
mem_gb=DEFAULT_MEMORY_MIN_GB,
202-
run_without_submitting=True,
203-
)
204-
prepend_hemi.inputs.hemi = ["lh", "rh"]
205-
206-
update_metadata = pe.MapNode(
207-
GiftiSetAnatomicalStructure(),
208-
iterfield=["in_file"],
209-
name="update_metadata",
210-
mem_gb=DEFAULT_MEMORY_MIN_GB,
211-
run_without_submitting=True,
212-
)
213-
214-
outputnode = pe.JoinNode(
215-
niu.IdentityInterface(fields=["surfaces", "target", "goodvoxels_ribbon"]),
216-
joinsource="itersource",
217-
name="outputnode",
218-
run_without_submitting=True,
219-
)
220-
221249
if project_goodvoxels:
222250
goodvoxels_bold_mask_wf = init_goodvoxels_bold_mask_wf(mem_gb)
223251

224252
# fmt: off
225253
workflow.connect([
226-
(inputnode, goodvoxels_bold_mask_wf, [("source_file", "inputnode.bold_file"),
227-
("anat_ribbon", "inputnode.anat_ribbon")]),
254+
(inputnode, goodvoxels_bold_mask_wf, [
255+
("source_file", "inputnode.bold_file"),
256+
("anat_ribbon", "inputnode.anat_ribbon"),
257+
]),
228258
(goodvoxels_bold_mask_wf, rename_src, [("outputnode.masked_bold", "in_file")]),
229-
(goodvoxels_bold_mask_wf, outputnode, [("outputnode.goodvoxels_ribbon",
230-
"goodvoxels_ribbon")]),
259+
(goodvoxels_bold_mask_wf, outputnode, [
260+
("outputnode.goodvoxels_ribbon", "goodvoxels_ribbon"),
261+
]),
262+
(sampler, metric_dilate, [("out_file", "in_file")]),
231263
])
232264
# fmt: on
233265
else:
266+
workflow.connect(inputnode, "source_file", rename_src, "in_file")
267+
268+
if medial_surface_nan:
234269
# fmt: off
235270
workflow.connect([
236-
(inputnode, rename_src, [("source_file", "in_file")]),
271+
(inputnode, medial_nans, [("subjects_dir", "subjects_dir")]),
272+
(medial_nans, update_metadata, [("out_file", "in_file")]),
237273
])
238274
# fmt: on
239275

240-
# fmt: off
241-
workflow.connect(
242-
[
243-
(
244-
inputnode,
245-
get_fsnative,
246-
[("subject_id", "subject_id"), ("subjects_dir", "subjects_dir")],
247-
),
248-
(inputnode, targets, [("subject_id", "subject_id")]),
249-
(inputnode, itk2lta, [("source_file", "src_file"), ("t1w2fsnative_xfm", "in_file")]),
250-
(get_fsnative, itk2lta, [("brain", "dst_file")]), # InfantFS: Use brain instead of T1
251-
(inputnode, sampler, [("subjects_dir", "subjects_dir"), ("subject_id", "subject_id")]),
252-
(itersource, targets, [("target", "space")]),
253-
(itersource, rename_src, [("target", "subject")]),
254-
(rename_src, sampler, [("out_file", "source_file")]),
255-
(itk2lta, sampler, [("out", "reg_file")]),
256-
(targets, sampler, [("out", "target_subject")]),
257-
(update_metadata, outputnode, [("out_file", "surfaces")]),
258-
(itersource, outputnode, [("target", "target")]),
259-
]
260-
)
261-
# fmt: on
262-
263-
if medial_surface_nan:
264-
if project_goodvoxels:
265-
# fmt: off
266-
workflow.connect([
267-
(inputnode, medial_nans, [("subjects_dir", "subjects_dir")]),
268-
(sampler, metric_dilate, [("out_file", "in_file")]),
269-
(metric_dilate, medial_nans, [("out_file", "in_file")]),
270-
(medial_nans, update_metadata, [("out_file", "in_file")]),
271-
])
272-
# fmt: on
273-
else:
274-
# fmt: off
275-
workflow.connect([
276-
(inputnode, medial_nans, [("subjects_dir", "subjects_dir")]),
277-
(sampler, medial_nans, [("out_file", "in_file")]),
278-
(medial_nans, update_metadata, [("out_file", "in_file")]),
279-
])
280-
# fmt: on
281-
276+
if medial_surface_nan and project_goodvoxels:
277+
workflow.connect(metric_dilate, "out_file", medial_nans, "in_file")
278+
elif medial_surface_nan:
279+
workflow.connect(sampler, "out_file", medial_nans, "in_file")
280+
elif project_goodvoxels:
281+
workflow.connect(metric_dilate, "out_file", update_metadata, "in_file")
282282
else:
283-
if project_goodvoxels:
284-
# fmt: off
285-
workflow.connect([
286-
(sampler, metric_dilate, [("out_file", "in_file")]),
287-
(metric_dilate, update_metadata, [("out_file", "in_file")]),
288-
])
289-
# fmt: on
290-
else:
291-
# fmt: off
292-
workflow.connect([
293-
(sampler, update_metadata, [("out_file", "in_file")]),
294-
])
295-
# fmt: on
296-
283+
workflow.connect(sampler, "out_file", update_metadata, "in_file")
297284
return workflow
298285

299286

0 commit comments

Comments
 (0)