Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Enable users to pass JSON filters to select subsets of data #1770

Merged
merged 20 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -81,6 +82,8 @@ 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_filters', action='store', type=Path,
bpinsard marked this conversation as resolved.
Show resolved Hide resolved
help='the path to a JSON file describing custom BIDS input filter')
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 @@ -522,6 +525,8 @@ 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_filters.read_text()) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bids_filters = json.loads(opts.bids_filters.read_text()) \
bids_filters = json.loads(opts.bids_filter_file.read_text()) \

if opts.bids_filters else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if opts.bids_filters else None
if opts.bids_filter_file else None


retval['return_code'] = 1
retval['workflow'] = None
Expand Down Expand Up @@ -672,6 +677,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
10 changes: 8 additions & 2 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def init_fmriprep_wf(
use_bbr,
use_syn,
work_dir,
bids_filters,
):
"""
This workflow organizes the execution of FMRIPREP, with a sub-workflow for
Expand Down Expand Up @@ -123,6 +124,7 @@ def init_fmriprep_wf(
use_bbr=True,
use_syn=True,
work_dir='.',
bids_filters=None,
)


Expand Down Expand Up @@ -257,6 +259,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 @@ -308,6 +311,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 @@ -363,6 +367,7 @@ def init_single_subject_wf(
use_aroma=False,
use_bbr=True,
use_syn=True,
bids_filters=None,
)


Expand Down Expand Up @@ -449,7 +454,8 @@ 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
For BIDSDataGrabber output_query

Inputs

Expand All @@ -465,7 +471,7 @@ 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