From 0d5e5b315794b483909cec6ee615add0ecd9cbb9 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Wed, 14 Aug 2024 09:49:42 +0200 Subject: [PATCH] fix: update anatomical wf to new metadata crawling --- mriqc/workflows/anatomical/base.py | 68 +++++++++++++++++------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/mriqc/workflows/anatomical/base.py b/mriqc/workflows/anatomical/base.py index 74c5fc65..bb517f64 100644 --- a/mriqc/workflows/anatomical/base.py +++ b/mriqc/workflows/anatomical/base.py @@ -52,6 +52,7 @@ """ +from itertools import chain from nipype.interfaces import utility as niu from nipype.pipeline import engine as pe from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms @@ -88,30 +89,43 @@ def anat_qc_workflow(name='anatMRIQC'): """ from mriqc.workflows.shared import synthstrip_wf - dataset = config.workflow.inputs.get('t1w', []) + config.workflow.inputs.get('t2w', []) - + # Enable if necessary + # mem_gb = max( + # config.workflow.biggest_file_gb['t1w'], + # config.workflow.biggest_file_gb['t2w'], + # ) + dataset = list(chain( + config.workflow.inputs.get('t1w', []), + config.workflow.inputs.get('t2w', []), + )) + metadata = list(chain( + config.workflow.inputs_metadata.get('t1w', []), + config.workflow.inputs_metadata.get('t2w', []), + )) + entities = list(chain( + config.workflow.inputs_entities.get('t1w', []), + config.workflow.inputs_entities.get('t2w', []), + )) message = BUILDING_WORKFLOW.format( modality='anatomical', - detail=( - f'for {len(dataset)} NIfTI files.' - if len(dataset) > 2 - else f"({' and '.join('<%s>' % v for v in dataset)})." - ), + detail=f'for {len(dataset)} NIfTI files.', ) config.loggers.workflow.info(message) - if config.execution.datalad_get: - from mriqc.utils.misc import _datalad_get - - _datalad_get(dataset) - # Initialize workflow workflow = pe.Workflow(name=name) # Define workflow, inputs and outputs # 0. Get data - inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') - inputnode.iterables = [('in_file', dataset)] + inputnode = pe.Node(niu.IdentityInterface( + fields=['in_file', 'metadata', 'entities'], + ), name='inputnode') + inputnode.synchronize = True # Do not test combinations of iterables + inputnode.iterables = [ + ('in_file', dataset), + ('metadata', metadata), + ('entities', entities), + ] outputnode = pe.Node(niu.IdentityInterface(fields=['out_json']), name='outputnode') @@ -146,7 +160,9 @@ def anat_qc_workflow(name='anatMRIQC'): ('in_file', 'inputnode.name_source'), ]), (inputnode, to_ras, [('in_file', 'in_file')]), - (inputnode, iqmswf, [('in_file', 'inputnode.in_file')]), + (inputnode, iqmswf, [('in_file', 'inputnode.in_file'), + ('metadata', 'inputnode.metadata'), + ('entities', 'inputnode.entities')]), (inputnode, norm, [(('in_file', _get_mod), 'inputnode.modality')]), (to_ras, skull_stripping, [('out_file', 'inputnode.in_files')]), (skull_stripping, hmsk, [ @@ -403,7 +419,6 @@ def compute_iqms(name='ComputeIQMs'): wf = compute_iqms() """ - from niworkflows.interfaces.bids import ReadSidecarJSON from mriqc.interfaces.anatomical import Harmonize from mriqc.workflows.utils import _tofloat @@ -413,6 +428,8 @@ def compute_iqms(name='ComputeIQMs'): niu.IdentityInterface( fields=[ 'in_file', + 'metadata', + 'entities', 'in_ras', 'brainmask', 'airmask', @@ -424,7 +441,6 @@ def compute_iqms(name='ComputeIQMs'): 'inu_corrected', 'in_inu', 'pvms', - 'metadata', 'std_tpms', ] ), @@ -435,9 +451,6 @@ def compute_iqms(name='ComputeIQMs'): name='outputnode', ) - # Extract metadata - meta = pe.Node(ReadSidecarJSON(index_db=config.execution.bids_database_dir), name='metadata') - # Add provenance addprov = pe.Node(AddProvenance(), name='provenance', run_without_submitting=True) @@ -472,17 +485,12 @@ def _getwm(inlist): # fmt: off workflow.connect([ - (inputnode, meta, [('in_file', 'in_file')]), - (inputnode, datasink, [('in_file', 'in_file'), - (('in_file', _get_mod), 'modality')]), + (inputnode, datasink, [ + ('in_file', 'in_file'), + (('in_file', _get_mod), 'modality'), + ('metadata', 'metadata'), + ('entities', 'entities')]), (inputnode, addprov, [(('in_file', _get_mod), 'modality')]), - (meta, datasink, [('subject', 'subject_id'), - ('session', 'session_id'), - ('task', 'task_id'), - ('acquisition', 'acq_id'), - ('reconstruction', 'rec_id'), - ('run', 'run_id'), - ('out_dict', 'metadata')]), (inputnode, addprov, [('in_file', 'in_file'), ('airmask', 'air_msk'), ('rotmask', 'rot_msk')]),