Skip to content

[DOC] Update SelectFiles docstring to match actual behavior #3041

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

Merged
merged 2 commits into from
Feb 23, 2020
Merged
Changes from 1 commit
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
24 changes: 14 additions & 10 deletions nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,32 +1296,36 @@ class SelectFilesInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
class SelectFiles(IOBase):
"""Flexibly collect data from disk to feed into workflows.

This interface uses the {}-based string formatting syntax to plug
This interface uses Python's {}-based string formatting syntax to plug
values (possibly known only at workflow execution time) into string
templates and collect files from persistant storage. These templates
can also be combined with glob wildcards. The field names in the
formatting template (i.e. the terms in braces) will become inputs
fields on the interface, and the keys in the templates dictionary
will form the output fields.
templates and collect files from persistant storage. These templates can
also be combined with glob wildcards (*, ?) and character ranges ([...]).
The field names in the formatting template (i.e. the terms in braces) will
become inputs fields on the interface, and the keys in the templates
dictionary will form the output fields.

Examples
--------

>>> import pprint
>>> from nipype import SelectFiles, Node
>>> templates={"T1": "{subject_id}/struct/T1.nii",
... "epi": "{subject_id}/func/f[0, 1].nii"}
... "epi": "{subject_id}/func/f[0,1].nii"}
>>> dg = Node(SelectFiles(templates), "selectfiles")
>>> dg.inputs.subject_id = "subj1"
>>> pprint.pprint(dg.outputs.get()) # doctest:
{'T1': <undefined>, 'epi': <undefined>}

The same thing with dynamic grabbing of specific files:
Note that SelectFiles does not support lists as inputs for the dynamic
fields. Attempts to do so may lead to unexpected results because brackets
also express glob character ranges. For example,

>>> templates["epi"] = "{subject_id}/func/f{run!s}.nii"
>>> templates["epi"] = "{subject_id}/func/f{run}.nii"
>>> dg = Node(SelectFiles(templates), "selectfiles")
>>> dg.inputs.subject_id = "subj1"
>>> dg.inputs.run = [2, 4]
>>> dg.inputs.run = [10, 11]

would match f0.nii or f1.nii, not f10.nii or f11.nii.
Copy link
Member

Choose a reason for hiding this comment

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

Oh. I think I misunderstood #2712. I interpreted it as you saying that

templates["epi"] = "{subject_id}/func/f[10].nii"

would produce the result you describe. For the code above, I would have expected to match f10.nii and f11.nii.

Possibly @mwaskom can clarify whether this was the intended behavior, though it's been a long time since #623.


"""
input_spec = SelectFilesInputSpec
Expand Down