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

Conversation

bpinsard
Copy link
Collaborator

@bpinsard bpinsard commented Sep 12, 2019

Changes proposed in this pull request

reference issue: nipreps/smriprep#104

Adding a --bids_filters option to further specify the options to select input files to the pipeline.
This points to a json files containing a dict with pybids entities filters, that is to be passed to nipype.interfaces.io.BIDSDataGrabber output_query option.
I created the same branch in smriprep with similar changes in run.py and workflow.base.py

While I was coding that I realized that f/smriprep uses in fact niworkflows.interfaces.bids.BIDSDataGrabber (this is a mistaking name btw).
Is there a specific reason to recode that part, could it be possible to use the original nipype one, or it is missing a feature?
I need you insight there.
Thanks

Documentation that should be reviewed

TODO/WIP

@welcome
Copy link

welcome bot commented Sep 12, 2019

Thanks for opening this pull request! We have detected this is the first time for you to contribute to fMRIPrep. Please check out our contributing guidelines.
We invite you to list yourself as a fMRIPrep contributor, so if your name is not already mentioned, please modify the .zenodo.json file with your data right above Russ' entry. Example:

{
   "name": "Contributor, New FMRIPrep",
   "affiliation": "Department of fMRI prep'ing, Open Science Made-Up University",
   "orcid": "<your id>"
},
{
   "name": "Poldrack, Russell A.",
   "affiliation": "Department of Psychology, Stanford University",
   "orcid": "0000-0001-6755-0259"
},

Of course, if you want to opt-out this time there is no problem at all with adding your name later. You will be always welcome to add it in the future whenever you feel it should be listed.

@bpinsard
Copy link
Collaborator Author

@effigies
Copy link
Member

Do you have an example JSON filter?

@bpinsard
Copy link
Collaborator Author

bpinsard commented Sep 12, 2019

For instance, the following add a filter for reconstruction (rec-xxx), and bold is the same filter as default.

{
    "t1w": {
        "datatype": "anat",
        "reconstruction": null,
        "suffix": "T1w"
    },
    "bold": {
        "datatype": "func",
        "suffix": "bold"
    }
}

( adding this for reference: https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json )

Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

Minimal nitpick 👍 . Will check the PR to niworkflows when ready.

fmriprep/cli/run.py Outdated Show resolved Hide resolved
fmriprep/cli/run.py Outdated Show resolved Hide resolved
bpinsard and others added 2 commits September 30, 2019 09:56
Co-Authored-By: Oscar Esteban <code@oscaresteban.es>
Co-Authored-By: Oscar Esteban <code@oscaresteban.es>
fmriprep/cli/run.py Outdated Show resolved Hide resolved
@pep8speaks
Copy link

pep8speaks commented Oct 23, 2019

Hello @bpinsard! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-02-14 13:56:28 UTC

@emdupre
Copy link
Collaborator

emdupre commented Dec 11, 2019

I wonder if this work wouldn't make sense to upstream to BIDS Apps more generally ? I'm thinking in particular of the spec @effigies was co-leading. It seems like a general question of how BIDS Apps should handle multiple eligible inputs.

@bpinsard and I discussed this in person, and I would have thought the best "BIDS" way to do this for the moment is just to modify a study's .bidsignore when generating the derivatives. The work here is a much more rigorous solution, but it would seem like something that should exist beyond f/smriprep and/or niworkflows ?

@bpinsard
Copy link
Collaborator Author

@emdupre
This is definitely a recurring issues when using BIDSApps on complex datasets. It would make sense to factor it, but for now BIDS grabbing is coded in each run.py of each BIDSApps.
For fMRIPrep, as the BIDS grabbing is not at the top level, but goes through multiple layers of fmriprep/smriprep/niworkflows, this is more difficult to factor it with other BIDSApps.

@emdupre
Copy link
Collaborator

emdupre commented Dec 11, 2019

For fMRIPrep, as the BIDS grabbing is not at the top level, but goes through multiple layers of fmriprep/smriprep/niworkflows, this is more difficult to factor it with other BIDSApps.

I completely understand that 😸

I just mean that this seems like something that we would want to upstream to the BIDS Execution specification, since it strikes me as a very general issue.

EDIT: And sorry if this is the wrong place to post this ! There are a few cross-linked issues and PRs, now, so I'm not sure where's the best place to have this discussion....

@bpinsard
Copy link
Collaborator Author

Tests fails due to dependency on niworkflow changes, same for PR on smriprep.
Otherwise I think these changes are ready.

@effigies effigies changed the title first quick attempt to add bids filters to further specify pipeline inputs ENH: Enable users to pass JSON filters to select subsets of data Feb 12, 2020
@effigies
Copy link
Member

I think this is in good shape. How do we feel about squeezing it in to 20.0.0? It adds a CLI option but does not change anything when the option is not passed.

Need to merge nipreps/smriprep#143 and release niworkflows and smriprep, but we can do that tomorrow if everybody's happy.

@bpinsard Have you been actually testing this? I can try it with a multi-session OpenNeuro dataset tomorrow if not. Or we can push a docker/ branch to get a test image up on Docker Hub.

Copy link
Collaborator

@mgxd mgxd left a comment

Choose a reason for hiding this comment

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

Minor suggestion, but overall this looks good. We can definitely get this in for 20.0.0, will target a smriprep / niworkflow release for tomorrow.

@@ -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-filters', action='store', type=Path,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think making it explicit this is a file will improve clarity and be more in line with the other file cli arguments

Suggested change
'--bids-filters', action='store', type=Path,
'--bids-filter-file', action='store', type=Path,

@@ -499,6 +505,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()) \

@@ -499,6 +505,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()) \
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

@effigies effigies requested a review from mgxd February 14, 2020 02:10
Copy link
Collaborator

@mgxd mgxd left a comment

Choose a reason for hiding this comment

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

Cool - thanks. I suggested the updated pins, will commit once those are live on pypi and then we can merge this in

setup.cfg Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants