From cf1ea8f7d8382d7b73b98aec5f8f4d1b74512d78 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 16 Aug 2024 06:25:26 +0200 Subject: [PATCH] sty: run ruff --- mriqc/cli/parser.py | 6 ++--- mriqc/interfaces/webapi.py | 30 +++++++++------------ mriqc/workflows/anatomical/base.py | 40 +++++++++++++++++----------- mriqc/workflows/diffusion/base.py | 9 ++++--- mriqc/workflows/functional/base.py | 10 ++++--- mriqc/workflows/functional/output.py | 2 +- 6 files changed, 53 insertions(+), 44 deletions(-) diff --git a/mriqc/cli/parser.py b/mriqc/cli/parser.py index d4181736..302d3227 100644 --- a/mriqc/cli/parser.py +++ b/mriqc/cli/parser.py @@ -479,7 +479,6 @@ def _bids_filter(value): def parse_args(args=None, namespace=None): """Parse args and run further checks on the command line.""" - from contextlib import suppress from json import loads from logging import DEBUG, FileHandler from pathlib import Path @@ -555,10 +554,9 @@ def parse_args(args=None, namespace=None): if output_dir == bids_dir: parser.error( 'The selected output folder is the same as the input BIDS folder. ' - 'Please modify the output path (suggestion: %s).' - % bids_dir + f'Please modify the output path (suggestion: {bids_dir}).' / 'derivatives' - / ('mriqc-%s' % version.split('+')[0]) + / ('mriqc-{}'.format(version.split('+')[0])) ) if bids_dir in work_dir.parents: diff --git a/mriqc/interfaces/webapi.py b/mriqc/interfaces/webapi.py index cfd906a8..02437305 100644 --- a/mriqc/interfaces/webapi.py +++ b/mriqc/interfaces/webapi.py @@ -169,15 +169,17 @@ def _run_interface(self, runtime): config.loggers.interface.info(messages.QC_UPLOAD_COMPLETE) return runtime - errmsg = '\n'.join([ - 'Unsuccessful upload.', - f'Server response status {response.status_code}:', - response.text, - '', - '', - 'Payload:', - json.dumps(payload, indent=2), - ]) + errmsg = '\n'.join( + [ + 'Unsuccessful upload.', + f'Server response status {response.status_code}:', + response.text, + '', + '', + 'Payload:', + json.dumps(payload, indent=2), + ] + ) config.loggers.interface.warning(errmsg) if self.inputs.strict: raise RuntimeError(errmsg) @@ -227,11 +229,7 @@ def upload_qc_metrics( data = deepcopy(in_data) # Check modality - modality = ( - meta.get('modality', None) - or meta.get('suffix', None) - or modality - ) + modality = meta.get('modality', None) or meta.get('suffix', None) or modality if modality not in ('T1w', 'bold', 'T2w'): errmsg = ( 'Submitting to MRIQCWebAPI: image modality should be "bold", "T1w", or "T2w", ' @@ -244,9 +242,7 @@ def upload_qc_metrics( # Check for fields with appended _id bids_meta_names = {k: k.replace('_id', '') for k in META_WHITELIST if k.endswith('_id')} - data['bids_meta'].update({ - k: meta[v] for k, v in bids_meta_names.items() if v in meta - }) + data['bids_meta'].update({k: meta[v] for k, v in bids_meta_names.items() if v in meta}) # For compatibility with WebAPI. Should be rolled back to int if (run_id := data['bids_meta'].get('run_id', None)) is not None: diff --git a/mriqc/workflows/anatomical/base.py b/mriqc/workflows/anatomical/base.py index bb517f64..a697a7b4 100644 --- a/mriqc/workflows/anatomical/base.py +++ b/mriqc/workflows/anatomical/base.py @@ -53,6 +53,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 @@ -94,18 +95,24 @@ def anat_qc_workflow(name='anatMRIQC'): # 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', []), - )) + 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.', @@ -117,9 +124,12 @@ def anat_qc_workflow(name='anatMRIQC'): # Define workflow, inputs and outputs # 0. Get data - inputnode = pe.Node(niu.IdentityInterface( - fields=['in_file', 'metadata', 'entities'], - ), name='inputnode') + 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), diff --git a/mriqc/workflows/diffusion/base.py b/mriqc/workflows/diffusion/base.py index a8e4e100..2155b74a 100644 --- a/mriqc/workflows/diffusion/base.py +++ b/mriqc/workflows/diffusion/base.py @@ -98,9 +98,12 @@ def dmri_qc_workflow(name='dwiMRIQC'): # Define workflow, inputs and outputs # 0. Get data, put it in RAS orientation workflow = pe.Workflow(name=name) - inputnode = pe.Node(niu.IdentityInterface( - fields=['in_file', 'metadata', 'entities'], - ), name='inputnode') + 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), diff --git a/mriqc/workflows/functional/base.py b/mriqc/workflows/functional/base.py index 5feae06c..b55d78b6 100644 --- a/mriqc/workflows/functional/base.py +++ b/mriqc/workflows/functional/base.py @@ -43,7 +43,6 @@ This workflow is orchestrated by :py:func:`fmri_qc_workflow`. """ - from nipype.interfaces import utility as niu from nipype.pipeline import engine as pe from niworkflows.utils.connections import pop_file as _pop @@ -86,9 +85,12 @@ def fmri_qc_workflow(name='funcMRIQC'): # Define workflow, inputs and outputs # 0. Get data, put it in RAS orientation workflow = pe.Workflow(name=name) - inputnode = pe.Node(niu.IdentityInterface( - fields=['in_file', 'metadata', 'entities'], - ), name='inputnode') + 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), diff --git a/mriqc/workflows/functional/output.py b/mriqc/workflows/functional/output.py index 56a86aaa..427b7683 100644 --- a/mriqc/workflows/functional/output.py +++ b/mriqc/workflows/functional/output.py @@ -49,7 +49,7 @@ def init_func_report_wf(name='func_report_wf'): # from mriqc.interfaces.reports import IndividualReport verbose = config.execution.verbose_reports - mem_gb = config.workflow.biggest_file_gb["bold"] + mem_gb = config.workflow.biggest_file_gb['bold'] reportlets_dir = config.execution.work_dir / 'reportlets' workflow = pe.Workflow(name=name)