Skip to content

Commit de72dda

Browse files
committed
FIX: Only connect template_iterator_wf if it exists
1 parent 2ed5d1b commit de72dda

File tree

3 files changed

+40
-42
lines changed

3 files changed

+40
-42
lines changed

fmriprep/workflows/base.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def init_single_subject_wf(subject_id: str):
333333
]) # fmt:skip
334334

335335
# Set up the template iterator once, if used
336+
template_iterator_wf = None
336337
if config.workflow.level == "full":
337338
if spaces.cached.get_spaces(nonstandard=False, dim=(3,)):
338339
template_iterator_wf = init_template_iterator_wf(spaces=spaces)
@@ -556,16 +557,17 @@ def init_single_subject_wf(subject_id: str):
556557
]) # fmt:skip
557558

558559
if config.workflow.level == "full":
559-
workflow.connect([
560-
(template_iterator_wf, bold_wf, [
561-
("outputnode.anat2std_xfm", "inputnode.anat2std_xfm"),
562-
("outputnode.space", "inputnode.std_space"),
563-
("outputnode.resolution", "inputnode.std_resolution"),
564-
("outputnode.cohort", "inputnode.std_cohort"),
565-
("outputnode.std_t1w", "inputnode.std_t1w"),
566-
("outputnode.std_mask", "inputnode.std_mask"),
567-
]),
568-
]) # fmt:skip
560+
if template_iterator_wf is not None:
561+
workflow.connect([
562+
(template_iterator_wf, bold_wf, [
563+
("outputnode.anat2std_xfm", "inputnode.anat2std_xfm"),
564+
("outputnode.space", "inputnode.std_space"),
565+
("outputnode.resolution", "inputnode.std_resolution"),
566+
("outputnode.cohort", "inputnode.std_cohort"),
567+
("outputnode.std_t1w", "inputnode.std_t1w"),
568+
("outputnode.std_mask", "inputnode.std_mask"),
569+
]),
570+
]) # fmt:skip
569571

570572
# Thread MNI152NLin6Asym standard outputs to CIFTI subworkflow, skipping
571573
# the iterator, which targets only output spaces.

fmriprep/workflows/bold/base.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
init_ds_registration_wf,
5555
init_ds_volumes_wf,
5656
init_func_derivatives_wf,
57+
prepare_timing_parameters,
5758
)
5859
from .registration import init_bold_reg_wf, init_bold_t1_trans_wf
5960
from .resampling import (
@@ -399,7 +400,7 @@ def init_bold_wf(
399400
(bold_anat_wf, ds_bold_t1_wf, [('outputnode.bold_file', 'inputnode.bold')]),
400401
]) # fmt:skip
401402

402-
if spaces.get_spaces(nonstandard=False, dim=(3,)):
403+
if spaces.cached.get_spaces(nonstandard=False, dim=(3,)):
403404
# Missing:
404405
# * Clipping BOLD after resampling
405406
# * Resampling parcellations
@@ -495,6 +496,21 @@ def init_bold_wf(
495496
repetition_time=all_metadata[0]["RepetitionTime"],
496497
)
497498

499+
ds_bold_cifti = pe.Node(
500+
DerivativesDataSink(
501+
base_directory=fmriprep_dir,
502+
space='fsLR',
503+
density=config.workflow.cifti_output,
504+
suffix='bold',
505+
compress=False,
506+
TaskName=all_metadata[0].get('TaskName'),
507+
**prepare_timing_parameters(all_metadata[0]),
508+
),
509+
name='ds_bold_cifti',
510+
run_without_submitting=True,
511+
)
512+
ds_bold_cifti.inputs.source_file = bold_file
513+
498514
workflow.connect([
499515
# Resample BOLD to MNI152NLin6Asym, may duplicate bold_std_wf above
500516
(inputnode, bold_MNI6_wf, [
@@ -532,6 +548,10 @@ def init_bold_wf(
532548
(bold_fsLR_resampling_wf, bold_grayords_wf, [
533549
("outputnode.bold_fsLR", "inputnode.bold_fsLR"),
534550
]),
551+
(bold_grayords_wf, ds_bold_cifti, [
552+
('outputnode.cifti_bold', 'in_file'),
553+
(('outputnode.cifti_metadata', _read_json), 'meta_dict'),
554+
]),
535555
]) # fmt:skip
536556

537557
bold_confounds_wf = init_bold_confs_wf(
@@ -975,3 +995,10 @@ def get_img_orientation(imgf):
975995
"""Return the image orientation as a string"""
976996
img = nb.load(imgf)
977997
return "".join(nb.aff2axcodes(img.affine))
998+
999+
1000+
def _read_json(in_file):
1001+
from json import loads
1002+
from pathlib import Path
1003+
1004+
return loads(Path(in_file).read_text())

fmriprep/workflows/bold/outputs.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -982,30 +982,6 @@ def init_func_derivatives_wf(
982982
])
983983
# fmt:on
984984

985-
# CIFTI output
986-
if cifti_output:
987-
ds_bold_cifti = pe.Node(
988-
DerivativesDataSink(
989-
base_directory=output_dir,
990-
suffix='bold',
991-
compress=False,
992-
TaskName=metadata.get('TaskName'),
993-
space='fsLR',
994-
**timing_parameters,
995-
),
996-
name='ds_bold_cifti',
997-
run_without_submitting=True,
998-
mem_gb=DEFAULT_MEMORY_MIN_GB,
999-
)
1000-
# fmt:off
1001-
workflow.connect([
1002-
(inputnode, ds_bold_cifti, [(('bold_cifti', _unlist), 'in_file'),
1003-
('source_file', 'source_file'),
1004-
('cifti_density', 'density'),
1005-
(('cifti_metadata', _read_json), 'meta_dict')])
1006-
])
1007-
# fmt:on
1008-
1009985
if "compcor" in config.execution.debug:
1010986
ds_acompcor_masks = pe.Node(
1011987
DerivativesDataSink(
@@ -1120,10 +1096,3 @@ def _unlist(in_file):
11201096
while isinstance(in_file, (list, tuple)) and len(in_file) == 1:
11211097
in_file = in_file[0]
11221098
return in_file
1123-
1124-
1125-
def _read_json(in_file):
1126-
from json import loads
1127-
from pathlib import Path
1128-
1129-
return loads(Path(in_file).read_text())

0 commit comments

Comments
 (0)