Skip to content

Commit

Permalink
Merge pull request #1770 from bpinsard/enh/bids_filter
Browse files Browse the repository at this point in the history
ENH: Enable users to pass JSON filters to select subsets of data
  • Loading branch information
effigies authored Feb 14, 2020
2 parents e13e827 + ec73b2d commit f682c9e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ is presented below:
use_aroma=False,
use_bbr=True,
use_syn=True,
bids_filters=None,
)

T1w/T2w preprocessing
Expand Down
8 changes: 8 additions & 0 deletions fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gc
import uuid
import warnings
import json
from argparse import ArgumentParser
from argparse import ArgumentDefaultsHelpFormatter
from multiprocessing import cpu_count
Expand Down Expand Up @@ -76,6 +77,11 @@ def get_parser():
# Re-enable when option is actually implemented
# g_bids.add_argument('-r', '--run-id', action='store', default='single_run',
# help='select a specific run to be processed')
g_bids.add_argument(
'--bids-filter-file', action='store', type=Path, metavar='PATH',
help='a JSON file describing custom BIDS input filter using pybids '
'{<suffix>:{<entity>:<filter>,...},...} '
'(https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json)')
g_bids.add_argument('-t', '--task-id', action='store',
help='select a specific task to be processed')
g_bids.add_argument('--echo-idx', action='store', type=int,
Expand Down Expand Up @@ -500,6 +506,7 @@ def build_workflow(opts, retval):
bids_dir = opts.bids_dir.resolve()
output_dir = opts.output_dir.resolve()
work_dir = opts.work_dir.resolve()
bids_filters = json.loads(opts.bids_filter_file.read_text()) if opts.bids_filter_file else None

if opts.clean_workdir:
from niworkflows.utils.misc import clean_directory
Expand Down Expand Up @@ -675,6 +682,7 @@ def build_workflow(opts, retval):
use_bbr=opts.use_bbr,
use_syn=opts.use_syn_sdc,
work_dir=str(work_dir),
bids_filters=bids_filters,
)
retval['return_code'] = 0

Expand Down
15 changes: 14 additions & 1 deletion fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ def init_fmriprep_wf(
use_bbr,
use_syn,
work_dir,
bids_filters,
):
"""
Build *fMRIPrep*'s pipeline.
This workflow organizes the execution of FMRIPREP, with a sub-workflow for
each subject.
If FreeSurfer's ``recon-all`` is to be run, a corresponding folder is created
and populated with any needed template subjects under the derivatives folder.
Expand Down Expand Up @@ -129,6 +131,7 @@ def init_fmriprep_wf(
use_bbr=True,
use_syn=True,
work_dir='.',
bids_filters=None,
)
Expand Down Expand Up @@ -213,6 +216,9 @@ def init_fmriprep_wf(
If fieldmaps are present and enabled, this is not run, by default.
work_dir : str
Directory in which to store workflow execution state and temporary files
bids_filters : dict
Provides finer specification of the pipeline input files using pybids entities filters.
A dict with the following structure {<suffix>:{<entity>:<filter>,...},...}
"""
fmriprep_wf = Workflow(name='fmriprep_wf')
Expand Down Expand Up @@ -265,6 +271,7 @@ def init_fmriprep_wf(
use_aroma=use_aroma,
use_bbr=use_bbr,
use_syn=use_syn,
bids_filters=bids_filters,
)

single_subject_wf.config['execution']['crashdump_dir'] = (
Expand Down Expand Up @@ -316,6 +323,7 @@ def init_single_subject_wf(
use_aroma,
use_bbr,
use_syn,
bids_filters,
):
"""
This workflow organizes the preprocessing pipeline for a single subject.
Expand Down Expand Up @@ -377,6 +385,7 @@ def init_single_subject_wf(
use_aroma=False,
use_bbr=True,
use_syn=True,
bids_filters=None,
)
Parameters
Expand Down Expand Up @@ -463,6 +472,9 @@ def init_single_subject_wf(
use_syn : bool
**Experimental**: Enable ANTs SyN-based susceptibility distortion correction (SDC).
If fieldmaps are present and enabled, this is not run, by default.
bids_filters : dict
Provides finer specification of the pipeline input files using pybids entities filters.
A dict with the following structure {<suffix>:{<entity>:<filter>,...},...}
Inputs
------
Expand All @@ -477,7 +489,8 @@ def init_single_subject_wf(
'bold': ['/completely/made/up/path/sub-01_task-nback_bold.nii.gz']
}
else:
subject_data = collect_data(layout, subject_id, task_id, echo_idx)[0]
subject_data = collect_data(layout, subject_id, task_id, echo_idx,
bids_filters=bids_filters)[0]

# Make sure we always go through these two checks
if not anat_only and subject_data['bold'] == []:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ install_requires =
nibabel >= 3.0.1
nipype >=1.3.1
nitime
niworkflows ~= 1.1.6
niworkflows @ git+https://github.com/poldracklab/niworkflows.git@edeea81352f3f2b276f11e42e7829e1c5a03770f
numpy
pandas
psutil >=5.4
pybids ~= 0.9.4
pyyaml
sdcflows ~=1.1.0
smriprep ~= 0.5.1
smriprep @ git+https://github.com/poldracklab/smriprep.git@07a7ba3fce8a9953923bcd0fa6ffbffac401208d
tedana >=0.0.5
templateflow ~= 0.4.2rc1
test_requires =
Expand Down

0 comments on commit f682c9e

Please sign in to comment.