@@ -316,19 +316,6 @@ def init_bold_fit_wf(
316316 config .loggers .workflow .debug (f'Reusing coregistration reference: { coreg_boldref } ' )
317317 fmapref_buffer .inputs .sbref_files = sbref_files
318318
319- # If sbref files are available, add them to the list of sources
320- boldref_source_files = [bold_file ]
321- if sbref_files :
322- boldref_source_files .append (sbref_files [0 ])
323-
324- if nb .load (sbref_files [0 ]).ndim > 3 :
325- raw_sbref_wf = init_raw_boldref_wf (
326- name = 'raw_sbref_wf' ,
327- bold_file = sbref_files [0 ],
328- multiecho = len (sbref_files ) > 1 ,
329- )
330- workflow .connect (raw_sbref_wf , 'outputnode.boldref' , fmapref_buffer , 'sbref_files' )
331-
332319 summary = pe .Node (
333320 FunctionalSummary (
334321 distortion_correction = 'None' , # Can override with connection
@@ -521,23 +508,31 @@ def init_bold_fit_wf(
521508 )
522509
523510 itk_mat2txt = pe .Node (ConcatenateXFMs (out_fmt = 'itk' ), name = 'itk_mat2txt' )
511+ fmapreg_source_files = pe .Node (
512+ niu .Merge (2 ), name = 'fmapreg_source_files' , run_without_submitting = True
513+ )
524514
525515 ds_fmapreg_wf = init_ds_registration_wf (
526516 bids_root = layout .root ,
527517 output_dir = config .execution .fmriprep_dir ,
528518 source = 'boldref' ,
529519 dest = re .sub (r'[^a-zA-Z0-9]' , '' , fieldmap_id ),
520+ desc = 'fmap' ,
530521 name = 'ds_fmapreg_wf' ,
531522 )
532- ds_fmapreg_wf .inputs .inputnode .source_files = boldref_source_files
533523
534524 workflow .connect ([
535525 (fmap_select , fmapreg_wf , [
536526 ('fmap_ref' , 'inputnode.fmap_ref' ),
537527 ('fmap_mask' , 'inputnode.fmap_mask' ),
538528 ]),
529+ (fmapref_buffer , fmapreg_source_files , [('out' , 'in1' )]),
530+ (fmap_select , fmapreg_source_files , [
531+ ('fmap_ref' , 'in2' ),
532+ ]),
539533 (fmapreg_wf , itk_mat2txt , [('outputnode.target2fmap_xfm' , 'in_xfms' )]),
540534 (itk_mat2txt , ds_fmapreg_wf , [('out_xfm' , 'inputnode.xform' )]),
535+ (fmapreg_source_files , ds_fmapreg_wf , [('out' , 'inputnode.source_files' )]),
541536 (ds_fmapreg_wf , fmapreg_buffer , [('outputnode.xform' , 'boldref2fmap_xfm' )]),
542537 ]) # fmt:skip
543538 else :
@@ -551,7 +546,19 @@ def init_bold_fit_wf(
551546 if not coreg_boldref :
552547 config .loggers .workflow .info ('Stage 4: Adding coregistration boldref workflow' )
553548
549+ # If sbref files are available, add them to the list of sources
550+ if sbref_files and nb .load (sbref_files [0 ]).ndim > 3 :
551+ raw_sbref_wf = init_raw_boldref_wf (
552+ name = 'raw_sbref_wf' ,
553+ bold_file = sbref_files [0 ],
554+ multiecho = len (sbref_files ) > 1 ,
555+ )
556+ workflow .connect (raw_sbref_wf , 'outputnode.boldref' , fmapref_buffer , 'sbref_files' )
557+
554558 enhance_boldref_wf = init_enhance_and_skullstrip_bold_wf (omp_nthreads = omp_nthreads )
559+ coreg_ref_source_files = pe .Node (
560+ niu .Merge (3 ), name = 'coreg_ref_source_files' , run_without_submitting = True
561+ )
555562
556563 ds_coreg_boldref_wf = init_ds_boldref_wf (
557564 bids_root = layout .root ,
@@ -564,14 +571,13 @@ def init_bold_fit_wf(
564571 desc = 'brain' ,
565572 name = 'ds_boldmask_wf' ,
566573 )
567- ds_boldmask_wf .inputs .inputnode .source_files = boldref_source_files
568574
569575 workflow .connect ([
570576 (fmapref_buffer , enhance_boldref_wf , [('out' , 'inputnode.in_file' )]),
571- (hmc_boldref_source_buffer , ds_coreg_boldref_wf , [
572- ('in_file' , 'inputnode.source_files' ),
573- ]),
577+ (fmapref_buffer , coreg_ref_source_files , [('out' , 'in1' )]),
578+ (coreg_ref_source_files , ds_coreg_boldref_wf , [('out' , 'inputnode.source_files' )]),
574579 (ds_coreg_boldref_wf , regref_buffer , [('outputnode.boldref' , 'boldref' )]),
580+ (ds_coreg_boldref_wf , ds_boldmask_wf , [('outputnode.boldref' , 'inputnode.source_files' )]),
575581 (ds_boldmask_wf , regref_buffer , [('outputnode.boldmask' , 'boldmask' )]),
576582 ]) # fmt:skip
577583
@@ -614,6 +620,8 @@ def init_bold_fit_wf(
614620 (skullstrip_bold_wf , ds_boldmask_wf , [
615621 ('outputnode.mask_file' , 'inputnode.boldmask' ),
616622 ]),
623+ (fmapreg_buffer , coreg_ref_source_files , [('boldref2fmap_xfm' , 'in2' )]),
624+ (fmap_select , coreg_ref_source_files , [('fmap_coeff' , 'in3' )]),
617625 ]) # fmt:skip
618626
619627 if not boldref2fmap_xform :
@@ -668,6 +676,7 @@ def init_bold_fit_wf(
668676 output_dir = config .execution .fmriprep_dir ,
669677 source = 'boldref' ,
670678 dest = 'T1w' ,
679+ desc = 'coreg' ,
671680 name = 'ds_boldreg_wf' ,
672681 )
673682
0 commit comments