Skip to content

Commit

Permalink
Merge pull request #1120 from nipreps/fix/skip_short_bold
Browse files Browse the repository at this point in the history
FIX: Skip short BOLD runs that break outlier detection
  • Loading branch information
oesteban committed Apr 10, 2024
2 parents 4d0e48c + 92346d8 commit f39c4bf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions mriqc/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ def _bids_filter(value):

# Functional workflow settings
g_func = parser.add_argument_group('Functional MRI workflow configuration')
g_func.add_argument(
'--min-bold-length',
action='store',
default=config.workflow.min_len_bold,
dest='min_len_bold',
help='Drop BOLD runs with fewer time points than this threshold.',
type=int,
)
g_func.add_argument(
'--fft-spikes-detector',
action='store_true',
Expand Down
2 changes: 2 additions & 0 deletions mriqc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ class workflow(_Config):
Minimum DWI length to be considered a "processable" dataset
(default: 7, assuming one low-b and six gradients for diffusion tensor imaging).
"""
min_len_bold = 5
"""Minimum BOLD length to be considered a "processable" dataset."""
species = 'human'
"""Subject species to choose most appropriate template"""
template_id = 'MNI152NLin2009cAsym'
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 23 additions & 3 deletions mriqc/workflows/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
This workflow is orchestrated by :py:func:`fmri_qc_workflow`.
"""
import nibabel as nb
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.utils.connections import pop_file as _pop
Expand Down Expand Up @@ -77,21 +78,40 @@ def fmri_qc_workflow(name='funcMRIQC'):
mem_gb = config.workflow.biggest_file_gb

dataset = config.workflow.inputs.get('bold', [])
full_files = []
for bold_path in dataset:
try:
bold_len = nb.load(bold_path).shape[3]
except nb.filebasedimages.ImageFileError:
bold_len = config.workflow.min_len_bold
except IndexError: # shape has only 3 elements
bold_len = 0
if bold_len >= config.workflow.min_len_bold:
full_files.append(bold_path)
else:
config.loggers.workflow.warn(
f'Dismissing {bold_path} for processing: insufficient number of '
f'timepoints ({bold_len}) to execute the workflow.'
)

message = BUILDING_WORKFLOW.format(
modality='functional',
detail=(
f'for {len(dataset)} BOLD runs.'
if len(dataset) > 2
f'for {len(full_files)} BOLD runs.'
if len(full_files) > 2
else f"({' and '.join('<%s>' % v for v in dataset)})."
),
)
config.loggers.workflow.info(message)

if set(dataset) - set(full_files):
config.workflow.inputs['bold'] = full_files
config.to_filename()

# Define workflow, inputs and outputs
# 0. Get data, put it in RAS orientation
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode')
inputnode.iterables = [('in_file', dataset)]
inputnode.iterables = [('in_file', full_files)]

datalad_get = pe.MapNode(
DataladIdentityInterface(fields=['in_file'], dataset_path=config.execution.bids_dir),
Expand Down

0 comments on commit f39c4bf

Please sign in to comment.