2828import nibabel as nb
2929from nipype .interfaces import utility as niu
3030from nipype .pipeline import engine as pe
31- from niworkflows .func .util import init_enhance_and_skullstrip_bold_wf , init_skullstrip_bold_wf
31+ from niworkflows .func .util import (
32+ init_bold_premask_wf ,
33+ init_enhance_and_skullstrip_bold_wf ,
34+ init_skullstrip_bold_wf ,
35+ )
3236from niworkflows .interfaces .header import ValidateImage
3337from niworkflows .interfaces .nitransforms import ConcatenateXFMs
3438from niworkflows .interfaces .utility import KeySelect
@@ -549,16 +553,28 @@ def init_bold_fit_wf(
549553 if not coreg_boldref :
550554 config .loggers .workflow .info ('Stage 4: Adding coregistration boldref workflow' )
551555
552- # If sbref files are available, add them to the list of sources
553- if sbref_files and nb .load (sbref_files [0 ]).ndim > 3 :
554- raw_sbref_wf = init_raw_boldref_wf (
555- name = 'raw_sbref_wf' ,
556- bold_file = sbref_files [0 ],
557- multiecho = len (sbref_files ) > 1 ,
558- )
559- workflow .connect (raw_sbref_wf , 'outputnode.boldref' , fmapref_buffer , 'sbref_files' )
556+ enhance_and_skullstrip_bold_wf = init_enhance_and_skullstrip_bold_wf (
557+ omp_nthreads = omp_nthreads ,
558+ pre_mask = bool (sbref_files ),
559+ )
560+
561+ if sbref_files :
562+ if nb .load (sbref_files [0 ]).ndim > 3 : # multivolume
563+ raw_sbref_wf = init_raw_boldref_wf (
564+ name = 'raw_sbref_wf' ,
565+ bold_file = sbref_files [0 ],
566+ multiecho = len (sbref_files ) > 1 ,
567+ )
568+ workflow .connect (raw_sbref_wf , 'outputnode.boldref' , fmapref_buffer , 'sbref_files' )
569+
570+ bold_premask_wf = init_bold_premask_wf (omp_nthreads = omp_nthreads )
571+ workflow .connect ([
572+ (hmcref_buffer , bold_premask_wf , [('boldref' , 'inputnode.in_file' )]),
573+ (bold_premask_wf , enhance_and_skullstrip_bold_wf , [
574+ ('outputnode.mask_file' , 'inputnode.pre_mask' ),
575+ ]),
576+ ]) # fmt:skip
560577
561- enhance_boldref_wf = init_enhance_and_skullstrip_bold_wf (omp_nthreads = omp_nthreads )
562578 coreg_ref_source_files = pe .Node (
563579 niu .Merge (3 ), name = 'coreg_ref_source_files' , run_without_submitting = True
564580 )
@@ -578,7 +594,7 @@ def init_bold_fit_wf(
578594 )
579595
580596 workflow .connect ([
581- (fmapref_buffer , enhance_boldref_wf , [('out' , 'inputnode.in_file' )]),
597+ (fmapref_buffer , enhance_and_skullstrip_bold_wf , [('out' , 'inputnode.in_file' )]),
582598 (fmapref_buffer , coreg_ref_source_files , [('out' , 'in1' )]),
583599 (coreg_ref_source_files , ds_coreg_boldref_wf , [('out' , 'inputnode.source_files' )]),
584600 (ds_coreg_boldref_wf , regref_buffer , [('outputnode.boldref' , 'boldref' )]),
@@ -608,7 +624,7 @@ def init_bold_fit_wf(
608624
609625 workflow .connect ([
610626 (fmapref_buffer , unwarp_boldref , [('out' , 'ref_file' )]),
611- (enhance_boldref_wf , unwarp_boldref , [
627+ (enhance_and_skullstrip_bold_wf , unwarp_boldref , [
612628 ('outputnode.bias_corrected_file' , 'in_file' ),
613629 ]),
614630 (boldref_fmap , unwarp_boldref , [('out_file' , 'fieldmap' )]),
@@ -631,17 +647,17 @@ def init_bold_fit_wf(
631647
632648 if not boldref2fmap_xform :
633649 workflow .connect ([
634- (enhance_boldref_wf , fmapreg_wf , [
650+ (enhance_and_skullstrip_bold_wf , fmapreg_wf , [
635651 ('outputnode.bias_corrected_file' , 'inputnode.target_ref' ),
636652 ('outputnode.mask_file' , 'inputnode.target_mask' ),
637653 ]),
638654 ]) # fmt:skip
639655 else :
640656 workflow .connect ([
641- (enhance_boldref_wf , ds_coreg_boldref_wf , [
657+ (enhance_and_skullstrip_bold_wf , ds_coreg_boldref_wf , [
642658 ('outputnode.bias_corrected_file' , 'inputnode.boldref' ),
643659 ]),
644- (enhance_boldref_wf , ds_boldmask_wf , [
660+ (enhance_and_skullstrip_bold_wf , ds_boldmask_wf , [
645661 ('outputnode.mask_file' , 'inputnode.boldmask' ),
646662 ]),
647663 ]) # fmt:skip
0 commit comments