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 filtering for ANY or NONE in --bids-filter-file #2123

Merged
merged 7 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ fMRIPrep uses the following queries, by default::
}

Only modifications of these queries will have any effect. You may filter on any entity defined
in the the PyBIDS
in the PyBIDS
`config file <https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json>`__.
To select images that do not have the entity set, use json value: ``null``.
To select images that have any non-empty value for an entity use string: ``'__any__'``

Can *fMRIPrep* continue to run after encountering an error?
-----------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ def _drop_sub(value):
value = str(value)
return value.lstrip('sub-')

def _filter_pybids_none_any(dct):
import bids
for k, v in dct.items():
if v is None:
dct[k] = bids.layout.Query.NONE
Copy link
Member

Choose a reason for hiding this comment

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

PyBIDS should already treat None like Query.None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Weird, I tried and it did not, and now it does.
Maybe my sleep deprived brain is just making a lot of typos. :/
I will remove it.

elif v == '__any__':
dct[k] = bids.layout.Query.ANY
return dct

def _bids_filter(value):
from json import loads
if value and Path(value).exists():
return loads(Path(value).read_text())
return loads(Path(value).read_text(), object_hook=_filter_pybids_none_any)

verstr = f'fMRIPrep v{config.environment.version}'
currentv = Version(config.environment.version)
Expand Down