Skip to content

Commit

Permalink
Update documentation with new filter syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pvandyken committed Jul 13, 2024
1 parent 31f8582 commit e49f73b
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions snakebids/plugins/component_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from snakebids import bidsapp
from snakebids.plugins.base import PluginBase
from snakebids.types import OptionalFilter
from snakebids.utils.utils import text_fold


class FilterParseError(Exception):
Expand Down Expand Up @@ -111,6 +112,16 @@ class ComponentEdit(PluginBase):
arguments are read and used to update the original component specification within
config.
Filters are specified on the CLI using ``ENTITY[:METHOD][=VALUE]``, as follows:
1. ``ENTITY=VALUE`` selects paths based on an exact value match.
2. ``ENTITY:match=REGEX`` and ``ENTITY:search=REGEX`` selects paths using regex
with :func:`re.match` and :func:`re.search` respectively. This syntax can be used
to select multiple values (e.g. ``'session:match=01|02'``).
3. ``ENTITY:required`` selects all paths with the entity, regardless of value.
4. ``ENTITY:none`` selects all paths without the entity.
5. ``ENTITY:any`` removes filters for the entity.
CLI arguments created by this plugin cannot be overriden.
Parameters
Expand Down Expand Up @@ -139,9 +150,17 @@ def add_cli_arguments(
# create filter parsers, one for each input_type
filter_opts = parser.add_argument_group(
"BIDS FILTERS",
"Filters to customize PyBIDS get() as key=value pairs, or as "
"key:{REQUIRED|OPTIONAL|NONE} (case-insensitive), to enforce the presence "
"or absence of values for that key.",
text_fold(
"""
Update filters for input components. Each filter can be specified as a
ENTITY=VALUE pair to select an value directly. To use regex filtering,
ENTITY:match=REGEX or ENTITY:search=REGEX can be used for re.match() or
re.search() respectively. Regex can also be used to select multiple
values, e.g. 'session:match=01|02'. ENTITY:required and ENTITY:none can
be used to require or prohibit presence of an entity in selected paths,
respectively. ENTITY:optional can be used to remove a filter.
"""
),
)

for input_type in pybids_inputs:
Expand All @@ -155,7 +174,7 @@ def add_cli_arguments(
nargs="+",
action=FilterParse,
dest=f"{self.PREFIX}.filter.{input_type}",
metavar="ENTITY=VALUE",
metavar="ENTITY[:METHOD][=VALUE]",
help=f"(default: {' '.join(arglist_default)})",
)

Expand All @@ -164,7 +183,7 @@ def add_cli_arguments(
# create wildcards parsers, one for each input_type
wildcards_opts = parser.add_argument_group(
"INPUT WILDCARDS",
"File path entities to use as wildcards in snakemake",
"Provide entities to be used as wildcards.",
)

for input_type in pybids_inputs:
Expand Down

0 comments on commit e49f73b

Please sign in to comment.