Skip to content

Commit 35419d5

Browse files
committed
ENH: Incorporate new boldref workflow
1 parent e787f88 commit 35419d5

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

nibabies/workflows/bold/base.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from ...interfaces.reports import FunctionalSummary
5858
from ...utils.bids import extract_entities
5959
from ...utils.misc import combine_meepi_source
60+
from .boldref import init_infant_epi_reference_wf
6061

6162
# BOLD workflows
6263
from .confounds import init_bold_confs_wf, init_carpetplot_wf
@@ -127,12 +128,6 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
127128
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
128129
fsnative2t1w_xfm
129130
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
130-
bold_ref
131-
BOLD reference file
132-
bold_ref_xfm
133-
Transform file in LTA format from bold to reference
134-
n_dummy_scans
135-
Number of nonsteady states at the beginning of the BOLD run
136131
137132
Outputs
138133
-------
@@ -177,6 +172,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
177172
178173
"""
179174
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
175+
from niworkflows.interfaces.bold import NonsteadyStatesDetector
180176
from niworkflows.interfaces.nibabel import ApplyMask
181177
from niworkflows.interfaces.utility import DictMerge, KeySelect
182178
from niworkflows.workflows.epi.refmap import init_epi_reference_wf
@@ -244,9 +240,14 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
244240
)
245241

246242
# Find associated sbref, if possible
247-
entities["suffix"] = "sbref"
248-
entities["extension"] = [".nii", ".nii.gz"] # Overwrite extensions
249-
sbref_files = layout.get(scope="raw", return_type="file", **entities)
243+
overrides = {
244+
"suffix": "sbref",
245+
"extension": [".nii", ".nii.gz"],
246+
}
247+
if config.execution.bids_filters:
248+
overrides.update(config.execution.bids_filters.get('sbref', {}))
249+
sb_ents = {**entities, **overrides}
250+
sbref_files = layout.get(return_type="file", **sb_ents)
250251

251252
sbref_msg = f"No single-band-reference found for {os.path.basename(ref_file)}."
252253
if sbref_files and "sbref" in config.workflow.ignore:
@@ -319,10 +320,6 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
319320
"anat2std_xfm",
320321
"std2anat_xfm",
321322
"template",
322-
# from bold reference workflow
323-
"bold_ref",
324-
"bold_ref_xfm",
325-
"n_dummy_scans",
326323
# from sdcflows (optional)
327324
"fmap",
328325
"fmap_ref",
@@ -514,12 +511,16 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
514511
)
515512
bold_confounds_wf.get_node("inputnode").inputs.t1_transform_flags = [False]
516513

514+
# Detect dummy scans
515+
nss_detector = pe.Node(NonsteadyStatesDetector(), name='nss_detector')
516+
nss_detector.inputs.inputnode = bold_file
517+
517518
# SLICE-TIME CORRECTION (or bypass) #############################################
518519
if run_stc:
519520
bold_stc_wf = init_bold_stc_wf(name="bold_stc_wf", metadata=metadata)
520521
# fmt:off
521522
workflow.connect([
522-
(inputnode, bold_stc_wf, [('n_dummy_scans', 'inputnode.skip_vols')]),
523+
(nss_detector, bold_stc_wf, [('n_dummy', 'inputnode.skip_vols')]),
523524
(select_bold, bold_stc_wf, [("out", 'inputnode.bold_file')]),
524525
(bold_stc_wf, boldbuffer, [('outputnode.stc_file', 'bold_file')]),
525526
])
@@ -577,8 +578,9 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
577578
name="bold_final",
578579
)
579580

580-
# Mask input BOLD reference image
581-
initial_boldref_mask = pe.Node(BrainExtraction(), name="initial_boldref_mask")
581+
# Create a reference image for the bold run
582+
initial_boldref_wf = init_infant_epi_reference_wf(omp_nthreads, is_sbref=bool(sbref_files))
583+
initial_boldref_wf.inputs.inputnode.epi_file = pop_file(sbref_files) or pop_file(bold_file)
582584

583585
# This final boldref will be calculated after bold_bold_trans_wf, which includes one or more:
584586
# HMC (head motion correction)
@@ -602,8 +604,8 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
602604
# BOLD buffer has slice-time corrected if it was run, original otherwise
603605
(boldbuffer, bold_split, [('bold_file', 'in_file')]),
604606
# HMC
605-
(inputnode, bold_hmc_wf, [
606-
('bold_ref', 'inputnode.raw_ref_image')]),
607+
(initial_boldref_wf, bold_hmc_wf, [
608+
('outputnode.boldref_file', 'inputnode.raw_ref_image')]),
607609
(validate_bolds, bold_hmc_wf, [
608610
(("out_file", pop_file), 'inputnode.bold_file')]),
609611
(bold_hmc_wf, outputnode, [
@@ -659,8 +661,8 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
659661
('outputnode.rmsd_file', 'inputnode.rmsd_file')]),
660662
(bold_reg_wf, bold_confounds_wf, [
661663
('outputnode.itk_t1_to_bold', 'inputnode.t1_bold_xform')]),
662-
(inputnode, bold_confounds_wf, [
663-
('n_dummy_scans', 'inputnode.skip_vols')]),
664+
(nss_detector, bold_confounds_wf, [
665+
('n_dummy', 'inputnode.skip_vols')]),
664666
(bold_final, bold_confounds_wf, [
665667
('bold', 'inputnode.bold'),
666668
('mask', 'inputnode.bold_mask'),
@@ -672,7 +674,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
672674
('outputnode.tcompcor_mask', 'tcompcor_mask'),
673675
]),
674676
# Summary
675-
(inputnode, summary, [('n_dummy_scans', 'algo_dummy_scans')]),
677+
(nss_detector, summary, [('n_dummy', 'algo_dummy_scans')]),
676678
(bold_reg_wf, summary, [('outputnode.fallback', 'fallback')]),
677679
(outputnode, summary, [('confounds', 'confounds_file')]),
678680
# Select echo indices for original/validated BOLD files
@@ -874,8 +876,8 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
874876
('bold_file', 'inputnode.name_source')]),
875877
(bold_hmc_wf, ica_aroma_wf, [
876878
('outputnode.movpar_file', 'inputnode.movpar_file')]),
877-
(inputnode, ica_aroma_wf, [
878-
('n_dummy_scans', 'inputnode.skip_vols')]),
879+
(nss_detector, ica_aroma_wf, [
880+
('n_dummy', 'inputnode.skip_vols')]),
879881
(bold_confounds_wf, join, [
880882
('outputnode.confounds_file', 'in_file')]),
881883
(bold_confounds_wf, mrg_conf_metadata,
@@ -1051,9 +1053,8 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
10511053
("outputnode.bold", "inputnode.in_files"),
10521054
]),
10531055
] if not multiecho else [
1054-
(inputnode, initial_boldref_mask, [('bold_ref', 'in_file')]),
1055-
(initial_boldref_mask, bold_t2s_wf, [
1056-
("out_mask", "inputnode.bold_mask"),
1056+
(initial_boldref_wf, bold_t2s_wf, [
1057+
("outputnode.boldref_mask", "inputnode.bold_mask"),
10571058
]),
10581059
(bold_bold_trans_wf, join_echos, [
10591060
("outputnode.bold", "bold_files"),
@@ -1125,14 +1126,13 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False, existing_derivatives=Non
11251126
("fmap_coeff", "inputnode.fmap_coeff"),
11261127
("fmap_mask", "inputnode.fmap_mask")]),
11271128
(output_select, summary, [("sdc_method", "distortion_correction")]),
1128-
(inputnode, initial_boldref_mask, [('bold_ref', 'in_file')]),
1129-
(inputnode, coeff2epi_wf, [
1130-
("bold_ref", "inputnode.target_ref")]),
1131-
(initial_boldref_mask, coeff2epi_wf, [
1132-
("out_mask", "inputnode.target_mask")]), # skull-stripped brain
1129+
(initial_boldref_wf, coeff2epi_wf, [
1130+
("outputnode.boldref_file", "inputnode.target_ref")]),
1131+
(initial_boldref_wf, coeff2epi_wf, [
1132+
("outputnode.boldref_mask", "inputnode.target_mask")]), # skull-stripped brain
11331133
(coeff2epi_wf, unwarp_wf, [
11341134
("outputnode.fmap_coeff", "inputnode.fmap_coeff")]),
1135-
(inputnode, sdc_report, [("bold_ref", "before")]),
1135+
(initial_boldref_wf, sdc_report, [("outputnode.boldref_file", "before")]),
11361136
(bold_hmc_wf, unwarp_wf, [
11371137
("outputnode.xforms", "inputnode.hmc_xforms")]),
11381138
(bold_split, unwarp_wf, [

0 commit comments

Comments
 (0)