|
17 | 17 | from ..interfaces import DerivativesDataSink, BIDSDataGrabber
|
18 | 18 | from ..interfaces.reports import SubjectSummary, AboutSummary
|
19 | 19 | from ..utils.bids import collect_data
|
20 |
| -from .dwi.base import init_early_b0ref_wf |
21 |
| -from .fmap.base import init_fmap_estimation_wf |
22 | 20 |
|
23 | 21 |
|
24 | 22 | def init_dmriprep_wf():
|
@@ -287,6 +285,7 @@ def init_single_subject_wf(subject_id):
|
287 | 285 | if anat_only:
|
288 | 286 | return workflow
|
289 | 287 |
|
| 288 | + from .dwi.base import init_early_b0ref_wf |
290 | 289 | # Append the dMRI section to the existing anatomical excerpt
|
291 | 290 | # That way we do not need to stream down the number of DWI datasets
|
292 | 291 | anat_preproc_wf.__postdesc__ = (
|
@@ -399,17 +398,71 @@ def _bold_reg_suffix(fallback):
|
399 | 398 | ])
|
400 | 399 | # fmt:on
|
401 | 400 |
|
402 |
| - fmap_estimation_wf = init_fmap_estimation_wf( |
403 |
| - subject_data["dwi"], debug=config.execution.debug |
| 401 | + if "fieldmap" in config.workflow.ignore: |
| 402 | + return workflow |
| 403 | + |
| 404 | + from niworkflows.interfaces.utility import KeySelect |
| 405 | + from sdcflows import fieldmaps as fm |
| 406 | + from sdcflows.utils.wrangler import find_estimators |
| 407 | + from sdcflows.workflows.base import init_fmap_preproc_wf |
| 408 | + |
| 409 | + # SDCFlows connection |
| 410 | + # Step 1: Run basic heuristics to identify available data for fieldmap estimation |
| 411 | + estimators = find_estimators(layout) |
| 412 | + |
| 413 | + if not estimators and config.workflow.use_syn: # Add fieldmap-less estimators |
| 414 | + # estimators = [fm.FieldmapEstimation()] |
| 415 | + raise NotImplementedError |
| 416 | + |
| 417 | + # Step 2: Manually add further estimators (e.g., fieldmap-less) |
| 418 | + fmap_wf = init_fmap_preproc_wf( |
| 419 | + debug=config.execution.debug, |
| 420 | + estimators=estimators, |
| 421 | + omp_nthreads=config.nipype.omp_nthreads, |
| 422 | + output_dir=str(output_dir), |
| 423 | + subject=subject_id, |
404 | 424 | )
|
405 |
| - # fmt:off |
406 |
| - workflow.connect([ |
407 |
| - (referencenode, fmap_estimation_wf, [ |
408 |
| - ("dwi_reference", "inputnode.dwi_reference"), |
409 |
| - ("dwi_mask", "inputnode.dwi_mask"), |
410 |
| - ]), |
411 |
| - ]) |
412 |
| - # fmt:on |
| 425 | + |
| 426 | + # Overwrite ``out_path_base`` of sdcflows's DataSinks |
| 427 | + for node in fmap_wf.list_node_names(): |
| 428 | + if node.split(".")[-1].startswith("ds_"): |
| 429 | + fmap_wf.get_node(node).interface.out_path_base = "dmriprep" |
| 430 | + workflow.add_nodes([fmap_wf]) |
| 431 | + |
| 432 | + # Step 3: Manually connect PEPOLAR |
| 433 | + for estimator in estimators: |
| 434 | + if estimator.method != fm.EstimatorType.PEPOLAR: |
| 435 | + continue |
| 436 | + |
| 437 | + suffices = set(s.suffix for s in estimator.sources) |
| 438 | + |
| 439 | + if sorted(suffices) == ["epi"]: |
| 440 | + getattr(fmap_wf.inputs, f"in_{estimator.bids_id}").in_data = [ |
| 441 | + str(s.path) for s in estimator.sources |
| 442 | + ] |
| 443 | + getattr(fmap_wf.inputs, f"in_{estimator.bids_id}").metadata = [ |
| 444 | + s.metadata for s in estimator.sources |
| 445 | + ] |
| 446 | + else: |
| 447 | + est_id = estimator.bids_id |
| 448 | + fmap_select = pe.MapNode( |
| 449 | + KeySelect(fields=["metadata", "dwi_reference", "dwi_mask", "gradients_rasb",]), |
| 450 | + name=f"fmap_select_{est_id}", |
| 451 | + run_without_submitting=True, |
| 452 | + iterfields=["key"] |
| 453 | + ) |
| 454 | + fmap_select.inputs.key = [ |
| 455 | + str(s.path) for s in estimator.sources if s.suffix in ("epi", "dwi", "sbref") |
| 456 | + ] |
| 457 | + # fmt:off |
| 458 | + workflow.connect([ |
| 459 | + (referencenode, fmap_select, [("dwi_file", "keys"), |
| 460 | + ("metadata", "metadata"), |
| 461 | + ("dwi_reference", "dwi_reference"), |
| 462 | + ("gradients_rasb", "gradients_rasb")]), |
| 463 | + ]) |
| 464 | + # fmt:on |
| 465 | + |
413 | 466 | return workflow
|
414 | 467 |
|
415 | 468 |
|
|
0 commit comments