Skip to content

Commit f682c9e

Browse files
authored
Merge pull request #1770 from bpinsard/enh/bids_filter
ENH: Enable users to pass JSON filters to select subsets of data
2 parents e13e827 + ec73b2d commit f682c9e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

docs/workflows.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ is presented below:
6262
use_aroma=False,
6363
use_bbr=True,
6464
use_syn=True,
65+
bids_filters=None,
6566
)
6667

6768
T1w/T2w preprocessing

fmriprep/cli/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gc
1111
import uuid
1212
import warnings
13+
import json
1314
from argparse import ArgumentParser
1415
from argparse import ArgumentDefaultsHelpFormatter
1516
from multiprocessing import cpu_count
@@ -76,6 +77,11 @@ def get_parser():
7677
# Re-enable when option is actually implemented
7778
# g_bids.add_argument('-r', '--run-id', action='store', default='single_run',
7879
# help='select a specific run to be processed')
80+
g_bids.add_argument(
81+
'--bids-filter-file', action='store', type=Path, metavar='PATH',
82+
help='a JSON file describing custom BIDS input filter using pybids '
83+
'{<suffix>:{<entity>:<filter>,...},...} '
84+
'(https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json)')
7985
g_bids.add_argument('-t', '--task-id', action='store',
8086
help='select a specific task to be processed')
8187
g_bids.add_argument('--echo-idx', action='store', type=int,
@@ -500,6 +506,7 @@ def build_workflow(opts, retval):
500506
bids_dir = opts.bids_dir.resolve()
501507
output_dir = opts.output_dir.resolve()
502508
work_dir = opts.work_dir.resolve()
509+
bids_filters = json.loads(opts.bids_filter_file.read_text()) if opts.bids_filter_file else None
503510

504511
if opts.clean_workdir:
505512
from niworkflows.utils.misc import clean_directory
@@ -675,6 +682,7 @@ def build_workflow(opts, retval):
675682
use_bbr=opts.use_bbr,
676683
use_syn=opts.use_syn_sdc,
677684
work_dir=str(work_dir),
685+
bids_filters=bids_filters,
678686
)
679687
retval['return_code'] = 0
680688

fmriprep/workflows/base.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ def init_fmriprep_wf(
6767
use_bbr,
6868
use_syn,
6969
work_dir,
70+
bids_filters,
7071
):
7172
"""
7273
Build *fMRIPrep*'s pipeline.
7374
7475
This workflow organizes the execution of FMRIPREP, with a sub-workflow for
7576
each subject.
77+
7678
If FreeSurfer's ``recon-all`` is to be run, a corresponding folder is created
7779
and populated with any needed template subjects under the derivatives folder.
7880
@@ -129,6 +131,7 @@ def init_fmriprep_wf(
129131
use_bbr=True,
130132
use_syn=True,
131133
work_dir='.',
134+
bids_filters=None,
132135
)
133136
134137
@@ -213,6 +216,9 @@ def init_fmriprep_wf(
213216
If fieldmaps are present and enabled, this is not run, by default.
214217
work_dir : str
215218
Directory in which to store workflow execution state and temporary files
219+
bids_filters : dict
220+
Provides finer specification of the pipeline input files using pybids entities filters.
221+
A dict with the following structure {<suffix>:{<entity>:<filter>,...},...}
216222
217223
"""
218224
fmriprep_wf = Workflow(name='fmriprep_wf')
@@ -265,6 +271,7 @@ def init_fmriprep_wf(
265271
use_aroma=use_aroma,
266272
use_bbr=use_bbr,
267273
use_syn=use_syn,
274+
bids_filters=bids_filters,
268275
)
269276

270277
single_subject_wf.config['execution']['crashdump_dir'] = (
@@ -316,6 +323,7 @@ def init_single_subject_wf(
316323
use_aroma,
317324
use_bbr,
318325
use_syn,
326+
bids_filters,
319327
):
320328
"""
321329
This workflow organizes the preprocessing pipeline for a single subject.
@@ -377,6 +385,7 @@ def init_single_subject_wf(
377385
use_aroma=False,
378386
use_bbr=True,
379387
use_syn=True,
388+
bids_filters=None,
380389
)
381390
382391
Parameters
@@ -463,6 +472,9 @@ def init_single_subject_wf(
463472
use_syn : bool
464473
**Experimental**: Enable ANTs SyN-based susceptibility distortion correction (SDC).
465474
If fieldmaps are present and enabled, this is not run, by default.
475+
bids_filters : dict
476+
Provides finer specification of the pipeline input files using pybids entities filters.
477+
A dict with the following structure {<suffix>:{<entity>:<filter>,...},...}
466478
467479
Inputs
468480
------
@@ -477,7 +489,8 @@ def init_single_subject_wf(
477489
'bold': ['/completely/made/up/path/sub-01_task-nback_bold.nii.gz']
478490
}
479491
else:
480-
subject_data = collect_data(layout, subject_id, task_id, echo_idx)[0]
492+
subject_data = collect_data(layout, subject_id, task_id, echo_idx,
493+
bids_filters=bids_filters)[0]
481494

482495
# Make sure we always go through these two checks
483496
if not anat_only and subject_data['bold'] == []:

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ install_requires =
2424
nibabel >= 3.0.1
2525
nipype >=1.3.1
2626
nitime
27-
niworkflows ~= 1.1.6
27+
niworkflows @ git+https://github.com/poldracklab/niworkflows.git@edeea81352f3f2b276f11e42e7829e1c5a03770f
2828
numpy
2929
pandas
3030
psutil >=5.4
3131
pybids ~= 0.9.4
3232
pyyaml
3333
sdcflows ~=1.1.0
34-
smriprep ~= 0.5.1
34+
smriprep @ git+https://github.com/poldracklab/smriprep.git@07a7ba3fce8a9953923bcd0fa6ffbffac401208d
3535
tedana >=0.0.5
3636
templateflow ~= 0.4.2rc1
3737
test_requires =

0 commit comments

Comments
 (0)